Home | History | Annotate | Line # | Download | only in gdb.base
settings.exp revision 1.1.1.1
      1  1.1  christos # This testcase is part of GDB, the GNU debugger.
      2  1.1  christos 
      3  1.1  christos # Copyright 2019-2020 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos # This program is free software; you can redistribute it and/or modify
      6  1.1  christos # it under the terms of the GNU General Public License as published by
      7  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      8  1.1  christos # (at your option) any later version.
      9  1.1  christos #
     10  1.1  christos # This program is distributed in the hope that it will be useful,
     11  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  1.1  christos # GNU General Public License for more details.
     14  1.1  christos #
     15  1.1  christos # You should have received a copy of the GNU General Public License
     16  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17  1.1  christos 
     18  1.1  christos # Test the set/show commands framework.  The test uses the
     19  1.1  christos # "maintenance test-settings set/show xxx" subcommands to exercise
     20  1.1  christos # TAB-completion and setting processing.
     21  1.1  christos 
     22  1.1  christos load_lib completion-support.exp
     23  1.1  christos 
     24  1.1  christos standard_testfile .c
     25  1.1  christos 
     26  1.1  christos if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
     27  1.1  christos     return -1
     28  1.1  christos }
     29  1.1  christos 
     30  1.1  christos clean_restart
     31  1.1  christos 
     32  1.1  christos if { ![readline_is_used] } {
     33  1.1  christos     untested "no tab completion support without readline"
     34  1.1  christos     return -1
     35  1.1  christos }
     36  1.1  christos 
     37  1.1  christos # Test the show command SHOW_CMD.  EXPECTED_RE is the expected output.
     38  1.1  christos # Also verifies that $_gdb_maint_setting_str produces an equivalent output,
     39  1.1  christos # matching it with EXPECTED_RE.  EXPECTED_RE double quotes are escaped
     40  1.1  christos # unless EXPECTED_RE_ESCAPED is true, indicating the quotes in EXPECTED_RE
     41  1.1  christos # are already escaped.
     42  1.1  christos # The value for the setting corresponding to SHOW_CMD is then reset
     43  1.1  christos # to RESET_VALUE, then set again to the value given by $_gdb_maint_setting_str
     44  1.1  christos # and $_gdb_maint_setting.  The default value of RESET_VALUE (0) should work for
     45  1.1  christos # most settings.  Note that we do not check that RESET_VALUE differs from
     46  1.1  christos # the expected value, as we assume different values will be verified.
     47  1.1  christos # The setting value must still be the one in force before calling show_setting.
     48  1.1  christos # In other words, this verifies that
     49  1.1  christos #   maint set test-settings <some_setting> $_gdb_maint_setting_str(<some_setting>)
     50  1.1  christos #   maint set test-settings <some_setting> $_gdb_maint_setting(<some_setting>)
     51  1.1  christos # do not change the setting value.
     52  1.1  christos # This procedure makes it easier to make the test
     53  1.1  christos # name/message unique, since we test the "show" commands many times.
     54  1.1  christos # EXPECTED_RE is made part of the test name.
     55  1.1  christos proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} {
     56  1.1  christos     global gdb_prompt
     57  1.1  christos 
     58  1.1  christos     with_test_prefix "$show_cmd $expected_re" {
     59  1.1  christos 	gdb_test "$show_cmd" $expected_re "show"
     60  1.1  christos 
     61  1.1  christos 	# Remove the first two words (such as "maint show") to have the
     62  1.1  christos 	# setting name to use for $_gdb_maint_setting_str.
     63  1.1  christos 	regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting
     64  1.1  christos 	if {$expected_re_escaped} {
     65  1.1  christos 	    set escaped_expected_re $expected_re
     66  1.1  christos 	} else {
     67  1.1  christos 	    regsub -all "\"" $expected_re "\\\\\\\"" escaped_expected_re
     68  1.1  christos 	}
     69  1.1  christos 	set test "print \$_gdb_maint_setting_str"
     70  1.1  christos 	set setting_str_value "xxxYYYxxx"
     71  1.1  christos 	gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test {
     72  1.1  christos 	    -re " = \"\($escaped_expected_re\)\".*$gdb_prompt $" {
     73  1.1  christos 		set setting_str_value $expect_out(1,string)
     74  1.1  christos 		regsub -all "\\\\" $expect_out(1,string) "" setting_str_value
     75  1.1  christos 		pass $test
     76  1.1  christos 	    }
     77  1.1  christos 	}
     78  1.1  christos 
     79  1.1  christos 	# Change the setting value to RESET_VALUE, set it back to setting_str_value
     80  1.1  christos 	# and check we still have the original value.
     81  1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $reset_value"
     82  1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again"
     83  1.1  christos 	gdb_test "$show_cmd" $expected_re "str show after reset+set again"
     84  1.1  christos 
     85  1.1  christos 	# Same test, but with value captured from $_gdb_maint_setting.
     86  1.1  christos 	set test "print \$_gdb_maint_setting"
     87  1.1  christos 	set setting_value "xxxYYYxxx"
     88  1.1  christos 	gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test {
     89  1.1  christos 	    -re " = \"\(.*\)\".*$gdb_prompt $" {
     90  1.1  christos 		set setting_value $expect_out(1,string)
     91  1.1  christos 		regsub -all "\\\\" $expect_out(1,string) "" setting_value
     92  1.1  christos 		pass $test
     93  1.1  christos 	    }
     94  1.1  christos 	    -re " = \(.*\)\r\n$gdb_prompt $" {
     95  1.1  christos 		set setting_value $expect_out(1,string)
     96  1.1  christos 		pass $test
     97  1.1  christos 	    }
     98  1.1  christos 	}
     99  1.1  christos 
    100  1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $reset_value"
    101  1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again"
    102  1.1  christos 	gdb_test "$show_cmd" $expected_re "show after reset+set again"
    103  1.1  christos     }
    104  1.1  christos }
    105  1.1  christos 
    106  1.1  christos # Verifies that $_gdb_setting (SETTING) gives a value whose ptype matches EXPECTED.
    107  1.1  christos proc check_type {setting expected} {
    108  1.1  christos     with_test_prefix "check_type $setting $expected" {
    109  1.1  christos 	gdb_test "print \$_gdb_maint_setting(\"$setting\")"
    110  1.1  christos 	gdb_test "ptype $" "$expected"
    111  1.1  christos 
    112  1.1  christos 	# Currently, GDB ptype <internal function> always tells it is type int.
    113  1.1  christos 	# ptype should better report an error such as:
    114  1.1  christos 	#   "No type information for GDB functions"
    115  1.1  christos 	# Test 'type int', so as to make it fail if ptype is changed.
    116  1.1  christos 	gdb_test "ptype \$_gdb_maint_setting(\"$setting\")" \
    117  1.1  christos             "type = int"
    118  1.1  christos     }
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos # var_Xinteger tests.  VARIANT determines which command/variant to
    122  1.1  christos # exercise.
    123  1.1  christos proc test-integer {variant} {
    124  1.1  christos     set set_cmd "maint set test-settings $variant"
    125  1.1  christos     set show_cmd "maint show test-settings $variant"
    126  1.1  christos 
    127  1.1  christos     # A bogus value.
    128  1.1  christos     gdb_test "$set_cmd bogus" \
    129  1.1  christos 	"No symbol table is loaded\\.  Use the \"file\" command\\."
    130  1.1  christos 
    131  1.1  christos     # Seemingly-valid but not quite valid value.
    132  1.1  christos     gdb_test "$set_cmd 1a" \
    133  1.1  christos 	"Invalid number \"1a\"\\."
    134  1.1  christos 
    135  1.1  christos     # Valid value followed by garbage.
    136  1.1  christos     gdb_test "$set_cmd 1 1" \
    137  1.1  christos 	"A syntax error in expression, near `1'\\."
    138  1.1  christos 
    139  1.1  christos     # Valid value followed by garbage.
    140  1.1  christos     gdb_test "$set_cmd 1 x" \
    141  1.1  christos 	"A syntax error in expression, near `x'\\."
    142  1.1  christos 
    143  1.1  christos     if {$variant == "zuinteger-unlimited"} {
    144  1.1  christos 	# -1 means unlimited.  Other negative values are rejected.  -1
    145  1.1  christos 	# -is tested further below, along the "unlimited" tests.
    146  1.1  christos 	gdb_test "$set_cmd -2" "only -1 is allowed to set as unlimited"
    147  1.1  christos 	check_type "test-settings $variant" "type = int"
    148  1.1  christos     } elseif {$variant == "uinteger" || $variant == "zuinteger"} {
    149  1.1  christos 	# Negative values are not accepted.
    150  1.1  christos 	gdb_test "$set_cmd -1" "integer -1 out of range"
    151  1.1  christos 	gdb_test "$set_cmd -2" "integer -2 out of range"
    152  1.1  christos 	check_type "test-settings $variant" "type = unsigned int"
    153  1.1  christos     } else {
    154  1.1  christos 	# Negative values are not accepted.
    155  1.1  christos 	gdb_test_no_output "$set_cmd -1"
    156  1.1  christos 	show_setting "$show_cmd" "-1"
    157  1.1  christos 	gdb_test_no_output "$set_cmd -2"
    158  1.1  christos 	show_setting "$show_cmd" "-2"
    159  1.1  christos 	check_type "test-settings $variant" "type = int"
    160  1.1  christos     }
    161  1.1  christos 
    162  1.1  christos     # Regular integer is accepted.
    163  1.1  christos     gdb_test_no_output "$set_cmd 999"
    164  1.1  christos     show_setting "$show_cmd" "999"
    165  1.1  christos 
    166  1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    167  1.1  christos 	# 0 means 0.
    168  1.1  christos 	gdb_test_no_output "$set_cmd 0"
    169  1.1  christos 	show_setting "$show_cmd" "0"
    170  1.1  christos     } else {
    171  1.1  christos 	# Either 0 or -1 mean unlimited.  Test both the number and
    172  1.1  christos 	# "unlimited".  For the latter, test both full name and
    173  1.1  christos 	# abbreviations.
    174  1.1  christos 
    175  1.1  christos 	if {$variant == "zuinteger-unlimited"} {
    176  1.1  christos 	    gdb_test_no_output "$set_cmd -1"
    177  1.1  christos 	} else {
    178  1.1  christos 	    gdb_test_no_output "$set_cmd 0"
    179  1.1  christos 	}
    180  1.1  christos 	show_setting "$show_cmd" "unlimited"
    181  1.1  christos 
    182  1.1  christos 	foreach_with_prefix value {
    183  1.1  christos 	    "u"
    184  1.1  christos 	    "un"
    185  1.1  christos 	    "unl"
    186  1.1  christos 	    "unli"
    187  1.1  christos 	    "unlim"
    188  1.1  christos 	    "unlimi"
    189  1.1  christos 	    "unlimit"
    190  1.1  christos 	    "unlimite"
    191  1.1  christos 	    "unlimited"
    192  1.1  christos 	} {
    193  1.1  christos 	    # Alternate between integer and unlimited, to make sure the
    194  1.1  christos 	    # setting really took effect.
    195  1.1  christos 	    gdb_test_no_output "$set_cmd 1"
    196  1.1  christos 	    show_setting "$show_cmd" "1"
    197  1.1  christos 
    198  1.1  christos 	    gdb_test_no_output "$set_cmd $value"
    199  1.1  christos 	    show_setting "$show_cmd" "unlimited"
    200  1.1  christos 	}
    201  1.1  christos     }
    202  1.1  christos 
    203  1.1  christos     if {$variant == "zuinteger"} {
    204  1.1  christos 	test_gdb_complete_multiple "maint set test-settings " "zuinteger" "" {
    205  1.1  christos 	    "zuinteger"
    206  1.1  christos 	    "zuinteger-unlimited"
    207  1.1  christos 	}
    208  1.1  christos     } else {
    209  1.1  christos 	test_gdb_complete_unique \
    210  1.1  christos 	    "$set_cmd" \
    211  1.1  christos 	    "$set_cmd"
    212  1.1  christos     }
    213  1.1  christos 
    214  1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    215  1.1  christos 	test_gdb_complete_none \
    216  1.1  christos 	    "$set_cmd " \
    217  1.1  christos     } else {
    218  1.1  christos 	test_gdb_complete_unique \
    219  1.1  christos 	    "$set_cmd " \
    220  1.1  christos 	    "$set_cmd unlimited"
    221  1.1  christos     }
    222  1.1  christos 
    223  1.1  christos     # Check junk after "unlimited".
    224  1.1  christos     gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
    225  1.1  christos 
    226  1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    227  1.1  christos 	gdb_test "$set_cmd unlimited u" "No symbol table is loaded.*"
    228  1.1  christos 	gdb_test "$set_cmd unlimited 1" "No symbol table is loaded.*"
    229  1.1  christos 	gdb_test "$set_cmd unlimited -1" "No symbol table is loaded.*"
    230  1.1  christos     } else {
    231  1.1  christos 	gdb_test "$set_cmd unlimited u" "Junk after \"unlimited\": u"
    232  1.1  christos 	gdb_test "$set_cmd unlimited 1" "Junk after \"unlimited\": 1"
    233  1.1  christos 	gdb_test "$set_cmd unlimited -1" "Junk after \"unlimited\": -1"
    234  1.1  christos     }
    235  1.1  christos 
    236  1.1  christos     test_gdb_complete_none "$set_cmd unlimited "
    237  1.1  christos     test_gdb_complete_none "$set_cmd unlimitedu"
    238  1.1  christos     test_gdb_complete_none "$set_cmd unlimited u"
    239  1.1  christos     test_gdb_complete_none "$set_cmd unlimited 1"
    240  1.1  christos     test_gdb_complete_none "$set_cmd x"
    241  1.1  christos     test_gdb_complete_none "$set_cmd x "
    242  1.1  christos     test_gdb_complete_none "$set_cmd -1"
    243  1.1  christos     test_gdb_complete_none "$set_cmd -1 "
    244  1.1  christos     test_gdb_complete_none "$set_cmd 1 "
    245  1.1  christos 
    246  1.1  christos     # Check show command completion.
    247  1.1  christos     if {$variant == "zuinteger"} {
    248  1.1  christos 	test_gdb_complete_multiple "maintenance show test-settings " "zuinteger" "" {
    249  1.1  christos 	    "zuinteger"
    250  1.1  christos 	    "zuinteger-unlimited"
    251  1.1  christos 	}
    252  1.1  christos     } else {
    253  1.1  christos 	test_gdb_complete_unique \
    254  1.1  christos 	    "$show_cmd" \
    255  1.1  christos 	    "$show_cmd"
    256  1.1  christos     }
    257  1.1  christos     test_gdb_complete_none "$show_cmd "
    258  1.1  christos }
    259  1.1  christos 
    260  1.1  christos # boolean tests.
    261  1.1  christos proc_with_prefix test-boolean {} {
    262  1.1  christos     # Use these variables to make sure we don't call the wrong command
    263  1.1  christos     # by mistake.
    264  1.1  christos     set set_cmd "maint set test-settings boolean"
    265  1.1  christos     set show_cmd "maint show test-settings boolean"
    266  1.1  christos 
    267  1.1  christos     # A bogus value.
    268  1.1  christos     gdb_test "$set_cmd bogus" \
    269  1.1  christos 	"\"on\" or \"off\" expected\\."
    270  1.1  christos 
    271  1.1  christos     # Seemingly-valid but not quite valid value.
    272  1.1  christos     gdb_test "$set_cmd on1" \
    273  1.1  christos 	"\"on\" or \"off\" expected\\."
    274  1.1  christos 
    275  1.1  christos     # Valid value followed by garbage.
    276  1.1  christos     gdb_test "$set_cmd on 1" \
    277  1.1  christos 	"\"on\" or \"off\" expected\\."
    278  1.1  christos 
    279  1.1  christos     # Unlike auto-bool settings, "-1" is not accepted.
    280  1.1  christos     gdb_test "$set_cmd -1" \
    281  1.1  christos 	"\"on\" or \"off\" expected\\."
    282  1.1  christos 
    283  1.1  christos     # Nor "auto".
    284  1.1  christos     gdb_test "$set_cmd auto" \
    285  1.1  christos 	"\"on\" or \"off\" expected\\."
    286  1.1  christos 
    287  1.1  christos     # "o" is ambiguous.
    288  1.1  christos     gdb_test "$set_cmd o" \
    289  1.1  christos 	"\"on\" or \"off\" expected\\."
    290  1.1  christos 
    291  1.1  christos     # Various valid values.  Test both full value names and
    292  1.1  christos     # abbreviations.
    293  1.1  christos 
    294  1.1  christos     # Note that unlike with auto-bool, empty value implies "on".
    295  1.1  christos     foreach_with_prefix value {
    296  1.1  christos 	""
    297  1.1  christos 	"on"
    298  1.1  christos 	"1"
    299  1.1  christos 	"y"
    300  1.1  christos 	"ye"
    301  1.1  christos 	"yes"
    302  1.1  christos 	"e"
    303  1.1  christos 	"en"
    304  1.1  christos 	"ena"
    305  1.1  christos 	"enab"
    306  1.1  christos 	"enabl"
    307  1.1  christos 	"enable"
    308  1.1  christos     } {
    309  1.1  christos 	gdb_test_no_output "$set_cmd off"
    310  1.1  christos 	show_setting "$show_cmd" "off"
    311  1.1  christos 
    312  1.1  christos 	gdb_test_no_output "$set_cmd $value"
    313  1.1  christos 	show_setting "$show_cmd" "on"
    314  1.1  christos     }
    315  1.1  christos 
    316  1.1  christos     check_type "test-settings boolean" "type = int"
    317  1.1  christos 
    318  1.1  christos     foreach_with_prefix value {
    319  1.1  christos 	"of"
    320  1.1  christos 	"off"
    321  1.1  christos 	"0"
    322  1.1  christos 	"n"
    323  1.1  christos 	"no"
    324  1.1  christos 	"d"
    325  1.1  christos 	"di"
    326  1.1  christos 	"dis"
    327  1.1  christos 	"disa"
    328  1.1  christos 	"disab"
    329  1.1  christos 	"disabl"
    330  1.1  christos 	"disable"
    331  1.1  christos     } {
    332  1.1  christos 	gdb_test_no_output "$set_cmd on"
    333  1.1  christos 	show_setting "$show_cmd" "on"
    334  1.1  christos 
    335  1.1  christos 	gdb_test_no_output "$set_cmd $value"
    336  1.1  christos 	show_setting "$show_cmd" "off"
    337  1.1  christos     }
    338  1.1  christos 
    339  1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "o" {
    340  1.1  christos 	"off"
    341  1.1  christos 	"on"
    342  1.1  christos     }
    343  1.1  christos 
    344  1.1  christos     test_gdb_complete_unique \
    345  1.1  christos 	"$set_cmd of" \
    346  1.1  christos 	"$set_cmd off"
    347  1.1  christos 
    348  1.1  christos     test_gdb_complete_none "$set_cmd x"
    349  1.1  christos 
    350  1.1  christos     # Check that the show command doesn't complete anything.
    351  1.1  christos     test_gdb_complete_unique \
    352  1.1  christos 	"$show_cmd" \
    353  1.1  christos 	"$show_cmd"
    354  1.1  christos     test_gdb_complete_none "$show_cmd "
    355  1.1  christos }
    356  1.1  christos 
    357  1.1  christos # auto-boolean tests.
    358  1.1  christos proc_with_prefix test-auto-boolean {} {
    359  1.1  christos     # Use these variables to make sure we don't call the wrong command
    360  1.1  christos     # by mistake.
    361  1.1  christos     set set_cmd "maint set test-settings auto-boolean"
    362  1.1  christos     set show_cmd "maint show test-settings auto-boolean"
    363  1.1  christos 
    364  1.1  christos     # A bogus value.
    365  1.1  christos     gdb_test "$set_cmd bogus" \
    366  1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    367  1.1  christos 
    368  1.1  christos     # Seemingly-valid but not quite valid value.
    369  1.1  christos     gdb_test "$set_cmd on1" \
    370  1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    371  1.1  christos 
    372  1.1  christos     # Valid value followed by garbage.
    373  1.1  christos     gdb_test "$set_cmd on 1" \
    374  1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    375  1.1  christos 
    376  1.1  christos     # "o" is ambiguous.
    377  1.1  christos     gdb_test "$set_cmd o" \
    378  1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    379  1.1  christos 
    380  1.1  christos     # Various valid values.  Test both full value names and
    381  1.1  christos     # abbreviations.
    382  1.1  christos 
    383  1.1  christos     foreach_with_prefix value {
    384  1.1  christos 	"on"
    385  1.1  christos 	"1"
    386  1.1  christos 	"y"
    387  1.1  christos 	"ye"
    388  1.1  christos 	"yes"
    389  1.1  christos 	"e"
    390  1.1  christos 	"en"
    391  1.1  christos 	"ena"
    392  1.1  christos 	"enab"
    393  1.1  christos 	"enabl"
    394  1.1  christos 	"enable"
    395  1.1  christos     } {
    396  1.1  christos 	gdb_test_no_output "$set_cmd off"
    397  1.1  christos 	show_setting "$show_cmd" "off"
    398  1.1  christos 
    399  1.1  christos 	gdb_test_no_output "$set_cmd $value"
    400  1.1  christos 	show_setting "$show_cmd" "on"
    401  1.1  christos     }
    402  1.1  christos 
    403  1.1  christos     foreach_with_prefix value {
    404  1.1  christos 	"of"
    405  1.1  christos 	"off"
    406  1.1  christos 	"0"
    407  1.1  christos 	"n"
    408  1.1  christos 	"no"
    409  1.1  christos 	"d"
    410  1.1  christos 	"di"
    411  1.1  christos 	"dis"
    412  1.1  christos 	"disa"
    413  1.1  christos 	"disab"
    414  1.1  christos 	"disabl"
    415  1.1  christos 	"disable"
    416  1.1  christos     } {
    417  1.1  christos 	gdb_test_no_output "$set_cmd on"
    418  1.1  christos 	show_setting "$show_cmd" "on"
    419  1.1  christos 
    420  1.1  christos 	gdb_test_no_output "$set_cmd $value"
    421  1.1  christos 	show_setting "$show_cmd" "off"
    422  1.1  christos     }
    423  1.1  christos 
    424  1.1  christos     foreach_with_prefix value {
    425  1.1  christos 	"a"
    426  1.1  christos 	"au"
    427  1.1  christos 	"aut"
    428  1.1  christos 	"auto"
    429  1.1  christos 	"-1"
    430  1.1  christos     } {
    431  1.1  christos 	gdb_test_no_output "$set_cmd on"
    432  1.1  christos 	show_setting "$show_cmd" "on"
    433  1.1  christos 
    434  1.1  christos 	gdb_test_no_output "$set_cmd $value"
    435  1.1  christos 	show_setting "$show_cmd" "auto"
    436  1.1  christos     }
    437  1.1  christos 
    438  1.1  christos     check_type "test-settings auto-boolean" "type = int"
    439  1.1  christos 
    440  1.1  christos     # "-" is not accepted as abbreviation of "-1".
    441  1.1  christos     gdb_test "$set_cmd -" \
    442  1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    443  1.1  christos 
    444  1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "" {
    445  1.1  christos 	"auto"
    446  1.1  christos 	"off"
    447  1.1  christos 	"on"
    448  1.1  christos     }
    449  1.1  christos 
    450  1.1  christos     test_gdb_complete_unique \
    451  1.1  christos 	"$set_cmd of" \
    452  1.1  christos 	"$set_cmd off"
    453  1.1  christos 
    454  1.1  christos     test_gdb_complete_none "$set_cmd x"
    455  1.1  christos 
    456  1.1  christos     # Check that the show command doesn't complete anything.
    457  1.1  christos     test_gdb_complete_unique \
    458  1.1  christos 	"$show_cmd" \
    459  1.1  christos 	"$show_cmd"
    460  1.1  christos     test_gdb_complete_none "$show_cmd "
    461  1.1  christos }
    462  1.1  christos 
    463  1.1  christos # Enum option tests.
    464  1.1  christos proc_with_prefix test-enum {} {
    465  1.1  christos     # Use these variables to make sure we don't call the wrong command
    466  1.1  christos     # by mistake.
    467  1.1  christos     set set_cmd "maint set test-settings enum"
    468  1.1  christos     set show_cmd "maint show test-settings enum"
    469  1.1  christos 
    470  1.1  christos     # Missing value.
    471  1.1  christos     gdb_test "$set_cmd" \
    472  1.1  christos 	"Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
    473  1.1  christos 
    474  1.1  christos     # A bogus value.
    475  1.1  christos     gdb_test "$set_cmd bogus" \
    476  1.1  christos 	"Undefined item: \"bogus\"."
    477  1.1  christos 
    478  1.1  christos     # Seemingly-valid but not quite valid value.
    479  1.1  christos     gdb_test "$set_cmd xxx1" \
    480  1.1  christos 	"Undefined item: \"xxx1\"."
    481  1.1  christos 
    482  1.1  christos     # Valid value followed by garbage.
    483  1.1  christos     gdb_test "$set_cmd xxx 1" \
    484  1.1  christos 	"Junk after item \"xxx\": 1"
    485  1.1  christos     # Valid value followed by garbage, with extra spaces.
    486  1.1  christos     gdb_test "$set_cmd xxx      1" \
    487  1.1  christos 	"Junk after item \"xxx\": 1"
    488  1.1  christos     # Abbreviated value followed by garbage.
    489  1.1  christos     gdb_test "$set_cmd xx 1" \
    490  1.1  christos 	"Junk after item \"xx\": 1"
    491  1.1  christos 
    492  1.1  christos     # Various valid values.  Test both full value names and
    493  1.1  christos     # abbreviations.
    494  1.1  christos     gdb_test_no_output "$set_cmd x"
    495  1.1  christos     show_setting "$show_cmd" "xxx" 0 "zzz"
    496  1.1  christos     gdb_test_no_output "$set_cmd yy"
    497  1.1  christos     show_setting "$show_cmd" "yyy" 0 "zzz"
    498  1.1  christos     gdb_test_no_output "$set_cmd zzz"
    499  1.1  christos     show_setting "$show_cmd" "zzz" 0 "yyy"
    500  1.1  christos 
    501  1.1  christos     check_type "test-settings enum" "type = char \\\[3\\\]"
    502  1.1  christos 
    503  1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "" {
    504  1.1  christos 	"xxx"
    505  1.1  christos 	"yyy"
    506  1.1  christos 	"zzz"
    507  1.1  christos     }
    508  1.1  christos 
    509  1.1  christos     test_gdb_complete_unique \
    510  1.1  christos 	"$set_cmd x" \
    511  1.1  christos 	"$set_cmd xxx"
    512  1.1  christos 
    513  1.1  christos     test_gdb_complete_none "$set_cmd a"
    514  1.1  christos 
    515  1.1  christos     # Check that the show command doesn't complete anything.
    516  1.1  christos     test_gdb_complete_unique \
    517  1.1  christos 	"$show_cmd" \
    518  1.1  christos 	"$show_cmd"
    519  1.1  christos     test_gdb_complete_none "$show_cmd "
    520  1.1  christos }
    521  1.1  christos 
    522  1.1  christos # string settings tests.
    523  1.1  christos proc test-string {variant} {
    524  1.1  christos     global gdb_prompt
    525  1.1  christos     global srcfile binfile
    526  1.1  christos 
    527  1.1  christos     # Load symbols for the completion test below.
    528  1.1  christos     clean_restart $binfile
    529  1.1  christos 
    530  1.1  christos     # Use these variables to make sure we don't call the wrong command
    531  1.1  christos     # by mistake.
    532  1.1  christos     set set_cmd "maint set test-settings $variant"
    533  1.1  christos     set show_cmd "maint show test-settings $variant"
    534  1.1  christos 
    535  1.1  christos     # Checks that gdb doesn't crash if we haven't set the string yet.
    536  1.1  christos     if {$variant != "filename"} {
    537  1.1  christos 	gdb_test "$show_cmd" "^$show_cmd\r\n" "$show_cmd: show default"
    538  1.1  christos     } else {
    539  1.1  christos 	gdb_test "$show_cmd" "/foo/bar" "$show_cmd: show default"
    540  1.1  christos     }
    541  1.1  christos 
    542  1.1  christos     # A string value.
    543  1.1  christos     gdb_test_no_output "$set_cmd hello world"
    544  1.1  christos     show_setting "$show_cmd" "hello world"
    545  1.1  christos 
    546  1.1  christos     check_type "test-settings $variant" "type = char \\\[\[1-9\]\[0-9\]*\\\]"
    547  1.1  christos 
    548  1.1  christos     # A quoted string value.
    549  1.1  christos     if {$variant == "string"} {
    550  1.1  christos 	gdb_test_no_output "$set_cmd \"hello world\""
    551  1.1  christos 	show_setting "$show_cmd" "\\\\\"hello world\\\\\"" 1
    552  1.1  christos     } else {
    553  1.1  christos 	gdb_test_no_output "$set_cmd \"hello world\""
    554  1.1  christos 	show_setting "$show_cmd" "\"hello world\""
    555  1.1  christos     }
    556  1.1  christos 
    557  1.1  christos     # Test clearing the string.
    558  1.1  christos     with_test_prefix "clear string" {
    559  1.1  christos 	if {$variant == "filename"} {
    560  1.1  christos 	    gdb_test "$set_cmd" \
    561  1.1  christos 		"Argument required \\(filename to set it to\\.\\)\\."
    562  1.1  christos 
    563  1.1  christos 	    # Check the value didn't change.
    564  1.1  christos 	    show_setting "$show_cmd" "\"hello world\""
    565  1.1  christos 	} else {
    566  1.1  christos 	    gdb_test_no_output "$set_cmd"
    567  1.1  christos 	    gdb_test "$show_cmd" \
    568  1.1  christos 		"^$show_cmd\r\n" "$show_cmd: empty second time"
    569  1.1  christos 	}
    570  1.1  christos     }
    571  1.1  christos 
    572  1.1  christos     # Test completion.
    573  1.1  christos     if {$variant == "string" || $variant == "string-noescape" } {
    574  1.1  christos 	# Make sure GDB doesn't try to complete on symbols, which
    575  1.1  christos 	# doesn't make any sense.
    576  1.1  christos 	test_gdb_complete_none "$set_cmd "
    577  1.1  christos     } else {
    578  1.1  christos 	# Complete on filename.
    579  1.1  christos 
    580  1.1  christos 	# See comments in gdb.base/completion.exp.
    581  1.1  christos 
    582  1.1  christos 	# We `cd' to ${srcdir}, and then do the completion relative to
    583  1.1  christos 	# the current directory.
    584  1.1  christos 
    585  1.1  christos 	# ${srcdir} may be a relative path.  We want to make sure we
    586  1.1  christos 	# end up in the right directory - so make sure we know where
    587  1.1  christos 	# it is.
    588  1.1  christos 	global srcdir
    589  1.1  christos 	set mydir [pwd]
    590  1.1  christos 	cd ${srcdir}
    591  1.1  christos 	set fullsrcdir [pwd]
    592  1.1  christos 	cd ${mydir}
    593  1.1  christos 
    594  1.1  christos 	gdb_test "cd ${fullsrcdir}" \
    595  1.1  christos 	    "Working directory [string_to_regexp ${fullsrcdir}].*" \
    596  1.1  christos 	    "cd to \${srcdir}"
    597  1.1  christos 
    598  1.1  christos 	set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
    599  1.1  christos 
    600  1.1  christos 	test_gdb_complete_unique \
    601  1.1  christos 	    "$set_cmd ${unique_file}" \
    602  1.1  christos 	    "$set_cmd ${unique_file}.txt"
    603  1.1  christos 
    604  1.1  christos 	test_gdb_complete_none "$set_cmd ${unique_file}.abc"
    605  1.1  christos     }
    606  1.1  christos 
    607  1.1  christos     # Check show command completion.
    608  1.1  christos     if {$variant == "string"} {
    609  1.1  christos 	test_gdb_complete_multiple "maint show test-settings " "string" "" {
    610  1.1  christos 	    "string"
    611  1.1  christos 	    "string-noescape"
    612  1.1  christos 	}
    613  1.1  christos     } else {
    614  1.1  christos 	test_gdb_complete_unique \
    615  1.1  christos 	    "$show_cmd" \
    616  1.1  christos 	    "$show_cmd"
    617  1.1  christos     }
    618  1.1  christos     test_gdb_complete_none "$show_cmd "
    619  1.1  christos }
    620  1.1  christos 
    621  1.1  christos foreach variant {
    622  1.1  christos     uinteger
    623  1.1  christos     integer
    624  1.1  christos     zinteger
    625  1.1  christos     zuinteger
    626  1.1  christos     zuinteger-unlimited
    627  1.1  christos } {
    628  1.1  christos     with_test_prefix "test-integer $variant" {
    629  1.1  christos 	test-integer $variant
    630  1.1  christos     }
    631  1.1  christos }
    632  1.1  christos 
    633  1.1  christos test-boolean
    634  1.1  christos test-auto-boolean
    635  1.1  christos test-enum
    636  1.1  christos 
    637  1.1  christos foreach variant {
    638  1.1  christos     string
    639  1.1  christos     string-noescape
    640  1.1  christos     optional-filename
    641  1.1  christos     filename
    642  1.1  christos } {
    643  1.1  christos     with_test_prefix "test-string $variant" {
    644  1.1  christos 	test-string $variant
    645  1.1  christos     }
    646  1.1  christos }
    647