[3/3] Add tests for loop_break and loop_continue commands

Message ID 1504388179-579-4-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi Sept. 2, 2017, 9:36 p.m. UTC
  I grepped the testsuite for loop_break and loop_continue and didn't find
anything, so I wrote some simple tests for those.

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp: Call the new procedures.
	(loop_break_test, loop_continue_test): New procedures.
---
 gdb/testsuite/gdb.base/commands.exp | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
  

Comments

Pedro Alves Sept. 4, 2017, 12:36 p.m. UTC | #1
On 09/02/2017 10:36 PM, Simon Marchi wrote:
> I grepped the testsuite for loop_break and loop_continue and didn't find
> anything, so I wrote some simple tests for those.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.base/commands.exp: Call the new procedures.
> 	(loop_break_test, loop_continue_test): New procedures.

LGTM, please push, and thanks for doing this.

I do wonder whether we handle loop_break/loop_continue in nested
loops correctly though, since the tests don't seem to
exercise that.

Thanks,
Pedro Alves
  
Simon Marchi Sept. 4, 2017, 5:15 p.m. UTC | #2
On 2017-09-04 14:36, Pedro Alves wrote:
> On 09/02/2017 10:36 PM, Simon Marchi wrote:
>> I grepped the testsuite for loop_break and loop_continue and didn't 
>> find
>> anything, so I wrote some simple tests for those.
>> 
>> gdb/testsuite/ChangeLog:
>> 
>> 	* gdb.base/commands.exp: Call the new procedures.
>> 	(loop_break_test, loop_continue_test): New procedures.
> 
> LGTM, please push, and thanks for doing this.
> 
> I do wonder whether we handle loop_break/loop_continue in nested
> loops correctly though, since the tests don't seem to
> exercise that.
> 
> Thanks,
> Pedro Alves

Ah good point.  I am pushing this one, and I'll work on another patch to 
test this.

Thanks,

Simon
  

Patch

diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 677361a..49a9242 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -1026,6 +1026,47 @@  proc define_if_without_arg_test {} {
     }
 }
 
+# Test the loop_break command.
+
+proc_with_prefix loop_break_test {} {
+    gdb_test_no_output "set \$a = 0" "initialize \$a"
+
+    gdb_test \
+    [multi_line_input \
+	 "while \$a < 5" \
+	 "  if \$a == 3" \
+	 "    loop_break" \
+	 "  end" \
+	 "  set \$a = \$a + 1" \
+	 "end"] \
+    "" \
+    "run while loop"
+
+    gdb_test "print \$a" " = 3" "validate \$a"
+}
+
+# Test the loop_continue command.
+
+proc_with_prefix loop_continue_test {} {
+    gdb_test_no_output "set \$a = 0" "initialize \$a"
+    gdb_test_no_output "set \$b = 0" "initialize \$b"
+
+    gdb_test \
+    [multi_line_input \
+	 "while \$a < 5" \
+	 "  set \$a = \$a + 1" \
+	 "  if \$a % 2 == 0" \
+	 "    loop_continue" \
+	 "  end" \
+	 "  set \$b = \$b + 1" \
+	 "end"] \
+    "" \
+    "run while loop"
+
+    gdb_test "print \$a" " = 5" "validate \$a"
+    gdb_test "print \$b" " = 3" "validate \$b"
+}
+
 # Test an input line split with a continuation character (backslash)
 # while entering a multi-line command (in a secondary prompt).
 
@@ -1092,5 +1133,7 @@  error_clears_commands_left
 redefine_hook_test
 backslash_in_multi_line_command_test
 define_if_without_arg_test
+loop_break_test
+loop_continue_test
 # This one should come last, as it redefines "backtrace".
 redefine_backtrace_test