]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add compile test for color option
authorTom Tromey <tromey@adacore.com>
Thu, 20 Feb 2025 14:36:51 +0000 (07:36 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 24 Mar 2025 15:37:27 +0000 (09:37 -0600)
Commit 3aaca06b672 ("gdb: fix color_option_def compile error (clang)")
fixed a compilation error in color_option_def when building with
clang.  It seemed to me that it would be good to add a compile test
for this code.

gdb/maint-test-options.c
gdb/testsuite/gdb.base/options.exp

index 9d7681777984e886589352b4a9da215c7193abda..da9765e0733ddafc1676ce712b9c88905e1fc140 100644 (file)
@@ -137,6 +137,7 @@ struct test_options_opts
   int pint_unl_opt = 0;
   std::string string_opt;
   std::string filename_opt;
+  ui_file_style::color color_opt { ui_file_style::MAGENTA };
 
   test_options_opts () = default;
 
@@ -149,7 +150,7 @@ struct test_options_opts
     gdb_printf (file,
                _("-flag %d -xx1 %d -xx2 %d -bool %d "
                  "-enum %s -uint-unl %s -pint-unl %s -string '%s' "
-                 "-filename '%s' -- %s\n"),
+                 "-filename '%s' -color %s -- %s\n"),
                flag_opt,
                xx1_opt,
                xx2_opt,
@@ -163,6 +164,7 @@ struct test_options_opts
                 : plongest (pint_unl_opt)),
                string_opt.c_str (),
                filename_opt.c_str (),
+               color_opt.to_string ().c_str (),
                args);
   }
 };
@@ -245,6 +247,14 @@ static const gdb::option::option_def test_options_option_defs[] = {
     nullptr, /* show_cmd_cb */
     N_("A filename option."),
   },
+
+  /* A color option.  */
+  gdb::option::color_option_def<test_options_opts> {
+    "color",
+    [] (test_options_opts *opts) { return &opts->color_opt; },
+    nullptr, /* show_cmd_cb */
+    N_("A color option."),
+  },
 };
 
 /* Create an option_def_group for the test_options_opts options, with
index a1ca39eab11794445d52a8668216f35cb591fac9..8760a918082627246e4b7fd78a41fe33b59db66b 100644 (file)
@@ -99,21 +99,21 @@ proc make_cmd {variant} {
 # operand.
 proc expect_none {operand} {
     return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\
-           -string '' -filename '' -- $operand"
+           -string '' -filename '' -color magenta -- $operand"
 }
 
 # Return a string for the expected result of running "maint
 # test-options xxx", with -flag set.  OPERAND is the expected operand.
 proc expect_flag {operand} {
     return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\
-           -string '' -filename '' -- $operand"
+           -string '' -filename '' -color magenta -- $operand"
 }
 
 # Return a string for the expected result of running "maint
 # test-options xxx", with -bool set.  OPERAND is the expected operand.
 proc expect_bool {operand} {
     return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint-unl 0 -pint-unl 0\
-           -string '' -filename '' -- $operand"
+           -string '' -filename '' -color magenta -- $operand"
 }
 
 # Return a string for the expected result of running "maint
@@ -123,10 +123,10 @@ proc expect_bool {operand} {
 proc expect_integer {option val operand} {
     if {$option == "uinteger-unlimited"} {
        return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl $val\
-               -pint-unl 0 -string '' -filename '' -- $operand"
+               -pint-unl 0 -string '' -filename '' -color magenta -- $operand"
     } elseif {$option == "pinteger-unlimited"} {
        return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0\
-               -pint-unl $val -string '' -filename '' -- $operand"
+               -pint-unl $val -string '' -filename '' -color magenta -- $operand"
     } else {
        error "unsupported option: $option"
     }
@@ -144,7 +144,7 @@ proc expect_string {str operand} {
        set str [string range $str 1 end-1]
     }
     return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\
-           -string '$str' -filename '' -- $operand"
+           -string '$str' -filename '' -color magenta -- $operand"
 }
 
 # Return a string for the expected result of running "maint
@@ -159,11 +159,12 @@ proc expect_filename {str operand} {
        set str [string range $str 1 end-1]
     }
     return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\
-           -string '' -filename '$str' -- $operand"
+           -string '' -filename '$str' -color magenta -- $operand"
 }
 
 set all_options {
     "-bool"
+    "-color"
     "-enum"
     "-filename"
     "-flag"
@@ -628,7 +629,7 @@ proc_with_prefix test-flag {variant} {
     # Extract twice the same flag, separated by one space.
     gdb_test "$cmd -xx1     -xx2 -xx1  -xx2 -xx1    -- non flags args" \
        "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0\
-        -string '' -filename '' -- non flags args"
+        -string '' -filename '' -color magenta -- non flags args"
 
     # Extract 2 known flags in front of unknown flags.
     gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \