This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 4/9] testsuite: Introduce gdb_assert


Often we'll do something like:

    if {$ok} {
	fail "whatever"
    } else {
	pass "whatever"
    }

This adds a helper procedure for that, and converts one random place
to use it, as an example.

2014-07-02  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_assert): New procedure.
	* gdb.trace/backtrace.exp (gdb_backtrace_tdp_4): Use it.
---
 gdb/testsuite/gdb.trace/backtrace.exp |  7 ++-----
 gdb/testsuite/lib/gdb.exp             | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.trace/backtrace.exp b/gdb/testsuite/gdb.trace/backtrace.exp
index a74fc3f..cb50f06 100644
--- a/gdb/testsuite/gdb.trace/backtrace.exp
+++ b/gdb/testsuite/gdb.trace/backtrace.exp
@@ -256,11 +256,8 @@ proc gdb_backtrace_tdp_4 { msg depth traceframe } {
 
 	# Output of 'tdump' on frame 0 and frame 1 should be
 	# identical.
-	if ![string compare $output_string0 $output_string1]  {
-	    pass "tdump output"
-	} else {
-	    fail "tdump output"
-	}
+	gdb_assert ![string compare $output_string0 $output_string1] \
+	    "tdump output"
     }
 }
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 30463a9..36cbf05 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1204,6 +1204,27 @@ proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_ma
     }
 }
 
+
+# Issue a PASS and return true if evaluating CONDITION in the caller's
+# frame returns true, and issue a FAIL and return false otherwise.
+# MESSAGE is the pass/fail message to be printed.  If MESSAGE is
+# omitted or is empty, then the pass/fail messages use the condition
+# string as the message.
+
+proc gdb_assert { condition {message ""} } {
+    if { $message == ""} {
+	set message $condition
+    }
+
+    set res [uplevel 1 expr $condition]
+    if {!$res} {
+	fail $message
+    } else {
+	pass $message
+    }
+    return $res
+}
+
 proc gdb_reinitialize_dir { subdir } {
     global gdb_prompt
 
-- 
1.9.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]