Tweak the handling of $GDBHISTSIZE edge cases [PR gdb/16999]
[external/binutils.git] / gdb / testsuite / gdb.base / gdbhistsize-history.exp
1 # Copyright 2015 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the gdb testsuite.
17
18 # Test the setting of "history size" via the GDBHISTSIZE environment variable
19
20
21 # Check that the history size is properly set to SIZE when the environment
22 # variable ENV_VAR is set to GDBHISTSIZE.
23
24 proc test_histsize_history_setting { histsize size { env_var "GDBHISTSIZE" } } {
25     global env
26
27     set have_old_gdbhistsize 0
28     if [info exists env($env_var)] {
29         set have_old_gdbhistsize 1
30         set old_gdbhistsize $env($env_var)
31     }
32     set env($env_var) $histsize
33
34     with_test_prefix "histsize=$histsize" {
35         gdb_exit
36         gdb_start
37
38         gdb_test "show history size" "The size of the command history is $size."
39
40         if { $size == "0" } {
41             gdb_test_no_output "show commands"
42         } elseif { $size != "1" } {
43             gdb_test "show commands" \
44                      "    .  show history size\r\n    .  show commands"
45         }
46
47         if { $have_old_gdbhistsize } {
48             set env($env_var) $old_gdbhistsize
49         } else {
50             unset env($env_var)
51         }
52     }
53 }
54
55 test_histsize_history_setting "" "unlimited"
56 test_histsize_history_setting "0" "0"
57 test_histsize_history_setting "20" "20"
58 test_histsize_history_setting " 20 " "20"
59 test_histsize_history_setting "-5" "unlimited"
60
61 # Test defaulting to 256 upon encountering a non-numeric GDBHISTSIZE.
62 test_histsize_history_setting "not_an_integer" "256"
63 test_histsize_history_setting "10zab" "256"
64 test_histsize_history_setting "-5ab" "256"
65
66 # A huge number (hopefully larger than INT_MAX)
67 test_histsize_history_setting "99999999999999999999999999999999999" "unlimited"
68
69 # We no longer read HISTSIZE
70 test_histsize_history_setting "50" "256" "HISTSIZE"