1 # Copyright 2006, 2007 Free Software Foundation, Inc.
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # This test checks that the if .. else .. end construct works and may
18 # contain empty bodies without crashing.
27 # First test that the if command works with an empty body
28 # Test with different conditions because the body is ignored
29 # if it is not executed.
32 set message "if 1 with empty body"
33 gdb_test_multiple "if 1\nend" $message {
34 -re "$gdb_prompt $" {pass $message}
36 fail "$message (crashed)"
42 # with false condition
43 set message "if 0 with empty body"
44 gdb_test_multiple "if 0\nend" $message {
45 -re "$gdb_prompt $" {pass $message}
47 fail "$message (crashed)"
53 # Second, do the same tests with an empty else body.
54 # This fails in GDB <=6.5
56 # Unfortunately it was an uninitialised memory problem so
57 # sometimes it just works. Preceed it with an if else end with
58 # bodies and hopefully the memory with be dirty and the problem
59 # will show itself (this works at time of writing).
61 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
64 set message "if 1 .. else with empty body"
65 gdb_test_multiple "if 1\nelse\nend" $message {
66 -re "$gdb_prompt $" {pass $message}
68 fail "$message (crashed)"
75 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
77 # with false condition
78 set message "if 0 .. else with empty body"
79 gdb_test_multiple "if 0\nelse\nend" $message {
80 -re "$gdb_prompt $" {pass $message}
82 fail "$message (crashed)"
88 gdb_test "set confirm off" "" ""
90 # Test that a define with an empty else can be replaced.
91 # If there is memory corruption then free will fail.
93 gdb_test "if 1\necho true\\n\nelse\necho false\\n\nend" "true" ""
95 gdb_test "define abc\nif 1\nelse\nend\nend" "" "create define with empty else"
96 # call (note that condition is 1 so should pass)
97 gdb_test "abc" "" "call original define"
99 set message "replace define with if .. else with empty body"
100 gdb_test_multiple "define abc\necho got here\\n\nend" $message {
101 -re "$gdb_prompt $" {pass $message}
102 eof {fail "$message (crashed)"}
105 gdb_test "abc" "got here" "call replacement define"