public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add new Tcl/DejaGnu test module test_simple to simplify tests
@ 2018-09-04 22:35 Yichun Zhang (agentzh)
  2018-09-05  3:16 ` Yichun Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Yichun Zhang (agentzh) @ 2018-09-04 22:35 UTC (permalink / raw)
  To: systemtap; +Cc: Yichun Zhang (agentzh)

Ported the handy routines is(), isnt(), like(), unlike(), ok(), nok()
from Perl's Test::Simple module over to Tcl/DejaGnu as the test_simple
module.

Make use of these new test helpers in the return_no_val.exp and
ternary_op.exp test files to demonstrate its usage. It makes these test
files much simpler by avoiding a lot of boilerplate Tcl code.

The remaining test files I committed recently would get updated in
separate patches just to prevent this patch from getting too large.
---
 testsuite/config/unix.exp                  |   1 +
 testsuite/lib/test_simple.exp              | 140 +++++++
 testsuite/systemtap.base/return_no_val.exp | 642 ++++-------------------------
 testsuite/systemtap.base/ternary_op.exp    | 219 ++--------
 4 files changed, 236 insertions(+), 766 deletions(-)
 create mode 100644 testsuite/lib/test_simple.exp

diff --git a/testsuite/config/unix.exp b/testsuite/config/unix.exp
index bb4b0e2de..cd0748f35 100644
--- a/testsuite/config/unix.exp
+++ b/testsuite/config/unix.exp
@@ -10,3 +10,4 @@ load_lib "compile_flags.exp"
 load_lib "gen_load.exp"
 load_lib "stapi.exp"
 load_lib "http_server.exp"
+load_lib "test_simple.exp"
diff --git a/testsuite/lib/test_simple.exp b/testsuite/lib/test_simple.exp
new file mode 100644
index 000000000..5af443888
--- /dev/null
+++ b/testsuite/lib/test_simple.exp
@@ -0,0 +1,140 @@
+# test_simple.exp
+#
+# Simple commands for running user shell commands and checking their outputs.
+# Also provided commands for generic string value and boolean value checks.
+
+# run_cmd_2way CMD STDOUT_VAR STDERR_VAR
+# * CMD is a string value for the user shell command to run.
+# * STDOUT_VAR is the (output) variable name (without the `$` prefix!) to hold
+#   the stdout output.
+# * STDERR_VAR is the (output) variable name (without the `$` prefix!) to hold
+#   the stderr output.
+# Returns the exit code number
+# TODO add timeout protection
+
+proc run_cmd_2way { cmd stdout_var stderr_var } {
+    upvar 1 $stdout_var stdout
+    upvar 1 $stderr_var stderr
+
+    send_log "executing: $cmd\n"
+
+    set pipe [open "| sh -c {$cmd}" r]
+    set stdout [read $pipe]
+    set exit_code 0
+    if {[catch {close $pipe} stderr] != 0} {
+        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
+            # Alas. close() automatically remove the trailing newline, so we
+            # have to add it back here...
+            append stderr "\n"
+        }
+        global errorCode
+        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
+            set exit_code [lindex $errorCode 2]
+        }
+    }
+
+    return $exit_code
+}
+
+# like TEST_NAME GOT REGEX_PATTERN REGEX_OPTS
+# The test passes when the TARGET_STR string matches the regex in REGEX_PATTERN.
+# * TEST_NAME is a string describing the current check.
+# * GOT is the target string to be checked.
+# * REGEX_PATTERN is a tcl regular expression string to be matched against.
+# * REGEX_OPTS is optional regex options like -expanded and -nocase.
+# Returns 1 when the check passes, 0 otherwise.
+
+proc like { test_name target regex regex_opts } {
+    regsub -all -- {\n} $regex {\n} escaped_regex
+    if {[regexp {*}$regex_opts -- $regex $target]} {
+        pass "${test_name}: matches regex \"$escaped_regex\""
+        return 1
+    }
+    fail "${test_name}: fails to match regex \"$escaped_regex\": got \"$target\""
+    return 0
+}
+
+# unlike TEST_NAME GOT REGEX_PATTERN REGEX_OPTS
+# The test passes when the GOT string does NOT match the regex in
+# REGEX_PATTERN.
+# * TEST_NAME is a string describing the current check.
+# * GOT is the target string to be checked.
+# * REGEX_PATTERN is a tcl regular expression string to be matched against.
+# * REGEX_OPTS is optional regex options like -expanded and -nocase.
+# Returns 1 when the check passes, 0 otherwise.
+
+proc unlike { test_name got regex regex_opts } {
+    regsub -all -- {\n} $regex {\n} escaped_regex
+    if {[regexp {*}$regex_opts -- $regex $got]} {
+        fail "${test_name}: should NOT match regex \"$escaped_regex\" but matches: got \"$got\""
+        return 0
+    }
+    pass "${test_name}: matches regex \"$escaped_regex\""
+    return 1
+}
+
+# is TEST_NAME GOT EXPECTED
+# The test passes when the GOT string is (exactly) equal to the string EXPECTED.
+# * TEST_NAME is a string describing the current check.
+# * GOT is the target string to be checked.
+# * EXPECTED is the expected string to be matched.
+# Returns 1 when the check passes, 0 otherwise.
+
+proc is { test_name got expected } {
+    regsub -all -- {\n} $expected {\n} escaped_exp
+    if {$got eq $expected} {
+        pass "${test_name}: string is \"$escaped_exp\""
+        return 1
+    }
+    fail "${test_name}: string should be \"$escaped_exp\", but got \"$got\""
+    return 0
+}
+
+# isnt TEST_NAME GOT EXPECTED
+# The test passes when the GOT string is NOT equal to the string EXPECTED.
+# * TEST_NAME is a string describing the current check.
+# * GOT is the target string to be checked.
+# * EXPECTED is the expected string to be matched.
+# Returns 1 when the check passes, 0 otherwise.
+
+proc isnt { test_name got expected } {
+    regsub -all -- {\n} $expected {\n} escaped_exp
+    if {$got eq $expected} {
+        fail "${test_name}: string should NOT be \"$escaped_exp\", but got \"$got\""
+        return 0
+    }
+    pass "${test_name}: string should NOT be \"$escaped_exp\""
+    return 1
+}
+
+# ok TEST_NAME RESULT
+# The test passes when RESULT is a true value in Tcl.
+# * TEST_NAME is a string describing the current check.
+# * RESULT is the boolean value to be checked
+# Returns 1 when the check passes, 0 otherwise.
+
+proc ok { test_name result } {
+    regsub -all -- {\n} $expected {\n} escaped_exp
+    if {! $result} {
+        fail "${test_name}: not ok: $result"
+        return 0
+    }
+    pass "${test_name}: ok: $result"
+    return 1
+}
+
+# nok TEST_NAME RESULT
+# The test passes when RESULT is a *false* value in Tcl.
+# * TEST_NAME is a string describing the current check.
+# * RESULT is the boolean value to be checked
+# Returns 1 when the check passes, 0 otherwise.
+
+proc nok { test_name result } {
+    regsub -all -- {\n} $expected {\n} escaped_exp
+    if {$result} {
+        fail "${test_name}: should NOT be ok but is ok: $result"
+        return 0
+    }
+    pass "${test_name}: sould NOT be ok: $result"
+    return 1
+}
diff --git a/testsuite/systemtap.base/return_no_val.exp b/testsuite/systemtap.base/return_no_val.exp
index 4c61cce6a..912b0394d 100644
--- a/testsuite/systemtap.base/return_no_val.exp
+++ b/testsuite/systemtap.base/return_no_val.exp
@@ -12,47 +12,20 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest1 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_1.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_1.stp'" out stderr]
 
     set exp_out "enter f
 exit
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
     set stderr_pat "\\AWARNING: statement will never be reached: identifier 'println' at \[^\\n\]*?\\.stp:4:5
  source:     println\\(\"leave f\"\\);
              \\^
 \\Z"
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop"
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
 }
 
 # --- TEST 2 ---
@@ -64,45 +37,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest2 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'" out stderr]
 
     set exp_out "enter f
 leave f
 exit
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
     set exp_stderr ""
-    regsub -all -- {\n} $exp_stderr {\n} escaped_exp_stderr
-    if {$stderr eq $exp_stderr} {
-        pass "${test_name}: stderr matches \"$escaped_exp_stderr\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_exp_stderr\": got \"$stderr\""
-    }
+    is "${test_name}: stderr" $stderr $exp_stderr
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
 }
 
 # --- TEST 3 ---
@@ -110,34 +56,11 @@ exit
 set subtest3 "TEST 3: return nothing in long type func (inferred by another return stmt)"
 set test_name "$test: $subtest3"
 
-set cmd "stap '$srcdir/$subdir/${test}_3.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap '$srcdir/$subdir/${test}_3.stp'" out stderr]
 
 set exp_out ""
-regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-if {$out eq $exp_out} {
-    pass "${test_name}: stdout matches \"$escaped_exp_out\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-}
-
-if {$failed} {
-    pass "${test_name}: exit code should be non-zero"
-} else {
-    fail "${test_name}: exit code should be non-zero but is zero"
-}
+is "${test_name}: stdout" $out $exp_out
+isnt "${test_name}: exit code" $exit_code 0
 
 set stderr_pat "\\Asemantic error: type mismatch \\(unknown\\): keyword at \[^\\n\]*?\\.stp:3:9
         source:         return;
@@ -147,46 +70,18 @@ semantic error: type was first inferred here \\(long\\): number '1' at :5:12
         source:     return 1;
                            \\^
 "
-regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-if {[regexp -linestop -- $stderr_pat $stderr]} {
-    pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-} else {
-    fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-}
+like "${test_name}: stderr" $stderr $stderr_pat "-linestop"
 
 # --- TEST 4 ---
 
 set subtest4 "TEST 4: return nothing in long type func (inferred by caller)"
 set test_name "$test: $subtest4"
 
-set cmd "stap '$srcdir/$subdir/${test}_4.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap '$srcdir/$subdir/${test}_4.stp'" out stderr]
 
 set exp_out ""
-regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-if {$out eq $exp_out} {
-    pass "${test_name}: stdout matches \"$escaped_exp_out\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-}
-
-if {$failed} {
-    pass "${test_name}: exit code should be non-zero"
-} else {
-    fail "${test_name}: exit code should be non-zero but is zero"
-}
+is "${test_name}: stdout" $out $exp_out
+isnt "${test_name}: exit code" $exit_code 0
 
 set stderr_pat "\\Asemantic error: type mismatch \\(unknown\\): keyword at \[^\\n\]*?\\.stp:3:9
         source:         return;
@@ -197,46 +92,19 @@ semantic error: type was first inferred here \\(long\\): identifier 'f' at :8:17
                                 \\^
 
 "
-regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-if {[regexp -linestop -- $stderr_pat $stderr]} {
-    pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-} else {
-    fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-}
+like "${test_name}: stderr" $stderr $stderr_pat "-linestop"
 
 # --- TEST 5 ---
 
 set subtest5 "TEST 5: pretty-printer adds a semicolon (two return stmts in a row)"
 set test_name "$test: $subtest5"
 
-set cmd "stap -p1 '$srcdir/$subdir/${test}_5.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap -p1 '$srcdir/$subdir/${test}_5.stp'" out stderr]
 
 set out_pat "^return;\\nreturn;\\n"
-regsub -all -- {\n} $out_pat {\n} escaped_out_pat
-if {[regexp -linestop -lineanchor -- $out_pat $out]} {
-    pass "${test_name}: stdout matches \"$escaped_out_pat\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
-}
+like "${test_name}: stdout" $out $out_pat "-linestop -lineanchor"
 
-if {$failed} {
-    fail "${test_name}: exit code should be zero but is $failed"
-} else {
-    pass "${test_name}: exit code is zero"
-}
+is "${test_name}: exit code" $exit_code 0
 if {$stderr ne ""} {
     send_log "stderr:\n$stderr"
 }
@@ -246,36 +114,14 @@ if {$stderr ne ""} {
 set subtest6 "TEST 6: pretty-printer adds a semicolon (under if)"
 set test_name "$test: $subtest6"
 
-set cmd "stap -p1 '$srcdir/$subdir/${test}_6.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap -p1 '$srcdir/$subdir/${test}_6.stp'" out stderr]
 
 set out_pat "^if \\(1\\) return
 ;
 "
-regsub -all -- {\n} $out_pat {\n} escaped_out_pat
-if {[regexp -linestop -lineanchor -- $out_pat $out]} {
-    pass "${test_name}: stdout matches \"$escaped_out_pat\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
-}
+like "${test_name}: stdout" $out $out_pat "-linestop -lineanchor"
 
-if {$failed} {
-    fail "${test_name}: exit code should be zero but is $failed"
-} else {
-    pass "${test_name}: exit code is zero"
-}
+is "${test_name}: exit code" $exit_code 0
 if {$stderr ne ""} {
     send_log "stderr:\n$stderr"
 }
@@ -285,35 +131,13 @@ if {$stderr ne ""} {
 set subtest7 "TEST 7: pretty-printer adds a semicolon (under for)"
 set test_name "$test: $subtest7"
 
-set cmd "stap -p1 '$srcdir/$subdir/${test}_7.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap -p1 '$srcdir/$subdir/${test}_7.stp'" out stderr]
 
 set out_pat "^for \\(; 1; \\) return;
 "
-regsub -all -- {\n} $out_pat {\n} escaped_out_pat
-if {[regexp -linestop -lineanchor -- $out_pat $out]} {
-    pass "${test_name}: stdout matches \"$escaped_out_pat\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
-}
+like "${test_name}: stdout" $out $out_pat "-linestop -lineanchor"
 
-if {$failed} {
-    fail "${test_name}: exit code should be zero but is $failed"
-} else {
-    pass "${test_name}: exit code is zero"
-}
+is "${test_name}: exit code" $exit_code 0
 if {$stderr ne ""} {
     send_log "stderr:\n$stderr"
 }
@@ -323,35 +147,13 @@ if {$stderr ne ""} {
 set subtest8 "TEST 8: pretty-printer adds a semicolon (under while)"
 set test_name "$test: $subtest8"
 
-set cmd "stap -p1 '$srcdir/$subdir/${test}_8.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap -p1 '$srcdir/$subdir/${test}_8.stp'" out stderr]
 
 set out_pat "^for \\(; 1; \\) return;
 "
-regsub -all -- {\n} $out_pat {\n} escaped_out_pat
-if {[regexp -linestop -lineanchor -- $out_pat $out]} {
-    pass "${test_name}: stdout matches \"$escaped_out_pat\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
-}
+like "${test_name}: stdout" $out $out_pat "-linestop -lineanchor"
 
-if {$failed} {
-    fail "${test_name}: exit code should be zero but is $failed"
-} else {
-    pass "${test_name}: exit code is zero"
-}
+is "${test_name}: exit code" $exit_code 0
 if {$stderr ne ""} {
     send_log "stderr:\n$stderr"
 }
@@ -361,35 +163,13 @@ if {$stderr ne ""} {
 set subtest9 "TEST 9: pretty-printer adds a semicolon (under foreach)"
 set test_name "$test: $subtest9"
 
-set cmd "stap -p1 '$srcdir/$subdir/${test}_9.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap -p1 '$srcdir/$subdir/${test}_9.stp'" out stderr]
 
 set out_pat "^foreach \\(\\\[k\\\] in a\\) return;
 "
-regsub -all -- {\n} $out_pat {\n} escaped_out_pat
-if {[regexp -linestop -lineanchor -- $out_pat $out]} {
-    pass "${test_name}: stdout matches \"$escaped_out_pat\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
-}
+like "${test_name}: stdout" $out $out_pat "-linestop -lineanchor"
 
-if {$failed} {
-    fail "${test_name}: exit code should be zero but is $failed"
-} else {
-    pass "${test_name}: exit code is zero"
-}
+is "${test_name}: exit code" $exit_code 0
 if {$stderr ne ""} {
     send_log "stderr:\n$stderr"
 }
@@ -403,46 +183,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest10 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_10.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_10.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:4:5
      source:     if \\(1\\) \\\{
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 11 ---
@@ -454,46 +206,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest11 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_11.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_11.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:4:5
      source:     for \\(;;\\) \\\{
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 12 ---
@@ -505,46 +229,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest12 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_12.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_12.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:4:5
      source:     while \\(1\\) \\\{
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 13 ---
@@ -556,46 +252,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest13 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_13.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_13.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:6:5
      source:     foreach \\(k in a\\) \\\{
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 14 ---
@@ -607,46 +275,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest14 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_14.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_14.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:4:5
      source:     return
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 15 ---
@@ -658,46 +298,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest15 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_15.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_15.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:4:5
      source:     next
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 16 ---
@@ -709,46 +321,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest16 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_16.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_16.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:6:5
      source:     delete a
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 17 ---
@@ -760,46 +344,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest17 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_17.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_17.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:6:5
      source:     try \\\{
                  \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 18 ---
@@ -811,46 +367,18 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest18 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_18.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_18.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:5:9
      source:         break
                      \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
 
 # --- TEST 19 ---
@@ -862,44 +390,16 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest19 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_19.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_19.stp'" out stderr]
 
     set exp_out ""
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
-
-    if {$failed} {
-        pass "${test_name}: exit code should be non-zero"
-    } else {
-        fail "${test_name}: exit code should be non-zero but is zero"
-    }
+    is "${test_name}: stdout" $out $exp_out
+    isnt "${test_name}: exit code" $exit_code 0
 
     set stderr_pat "^parse error: expected literal string or number
         saw: keyword at \[^\\n\]*?\\.stp:5:9
      source:         continue
                      \\^
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 }
diff --git a/testsuite/systemtap.base/ternary_op.exp b/testsuite/systemtap.base/ternary_op.exp
index 03aa467ec..23261f863 100644
--- a/testsuite/systemtap.base/ternary_op.exp
+++ b/testsuite/systemtap.base/ternary_op.exp
@@ -12,35 +12,13 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest1 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_1.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_1.stp'" out stderr]
 
     set exp_out "positive 3
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
     if {$stderr ne ""} {
         send_log "stderr:\n$stderr"
     }
@@ -51,90 +29,34 @@ foreach runtime [get_runtime_list] {
 set subtest2 "TEST 2: ternary operator should be tighter than = (bad case)"
 set test_name "$test: $subtest2"
 
-set cmd "stap '$srcdir/$subdir/${test}_2.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap '$srcdir/$subdir/${test}_2.stp'" out stderr]
 
 set exp_out ""
-regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-if {$out eq $exp_out} {
-    pass "${test_name}: stdout matches \"$escaped_exp_out\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-}
-
-if {$failed} {
-    pass "${test_name}: exit code should be non-zero"
-} else {
-    fail "${test_name}: exit code should be non-zero but is zero"
-}
+is "${test_name}: stdout" $out $exp_out
+isnt "${test_name}: exit code" $exit_code 0
 
 set stderr_pat "^semantic error: Expecting lvalue for assignment: operator '=' at \[^\\n\]*?\\.stp:4:58
         source:     printf\\(\"a = %d, b = %d, c = %d\\\\n\", a > 0 \\? b = 4 : c = 5, b, c\\);
                                                                          \\^
 "
-regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-    pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-} else {
-    fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-}
+like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 
 # --- TEST 3 ---
 
 set subtest3 "TEST 3: ternary operator should be tighter than = (bad case, compatible 4.0)"
 set test_name "$test: $subtest3"
 
-set cmd "stap --compatible 4.0 '$srcdir/$subdir/${test}_2.stp'"
-send_log "executing: $cmd\n"
-set pipe [open "| sh -c {$cmd}" r]
-set out [read $pipe]
-set failed 0
-if {[catch {close $pipe} stderr] != 0} {
-    if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-        append stderr "\n"
-    }
-    global errorCode
-    if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-        set failed [lindex $errorCode 2]
-    }
-}
+set exit_code [run_cmd_2way "stap --compatible 4.0 '$srcdir/$subdir/${test}_2.stp'" out stderr]
 
 set exp_out ""
-regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-if {$out eq $exp_out} {
-    pass "${test_name}: stdout matches \"$escaped_exp_out\""
-} else {
-    fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-}
-
-if {$failed} {
-    pass "${test_name}: exit code should be non-zero"
-} else {
-    fail "${test_name}: exit code should be non-zero but is zero"
-}
+is "${test_name}: stdout" $out $exp_out
+isnt "${test_name}: exit code" $exit_code 0
 
 set stderr_pat "^semantic error: Expecting lvalue for assignment: operator '=' at \[^\\n\]*?\\.stp:4:58
         source:     printf\\(\"a = %d, b = %d, c = %d\\\\n\", a > 0 \\? b = 4 : c = 5, b, c\\);
                                                                          \\^
 "
-regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-if {[regexp -linestop -lineanchor -- $stderr_pat $stderr]} {
-    pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-} else {
-    fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-}
+like "${test_name}: stderr" $stderr $stderr_pat "-linestop -lineanchor"
 
 # --- TEST 4 ---
 
@@ -145,35 +67,13 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest4 ($runtime)"
 
-    set cmd "stap --compatible 3.3 --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --compatible 3.3 --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'" out stderr]
 
     set exp_out "a = 4, b = 4, c = 0
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
     if {$stderr ne ""} {
         send_log "stderr:\n$stderr"
     }
@@ -188,35 +88,13 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest5 ($runtime)"
 
-    set cmd "stap --compatible 3.2 --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --compatible 3.2 --runtime=$runtime '$srcdir/$subdir/${test}_2.stp'" out stderr]
 
     set exp_out "a = 4, b = 4, c = 0
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
     if {$stderr ne ""} {
         send_log "stderr:\n$stderr"
     }
@@ -231,46 +109,19 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest6 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_6.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_6.stp'" out stderr]
 
     set exp_out "3
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
     set stderr_pat "^WARNING: Eliding assignment to 'b': operator '=' at \[^\\n\]*?\\.stp:3:30
 .*?
 WARNING: Eliding assignment to 'c': operator '=' at :3:39
 "
-    regsub -all -- {\n} $stderr_pat {\n} escaped_stderr_pat
-    if {[regexp -lineanchor -- $stderr_pat $stderr]} {
-        pass "${test_name}: stderr matches \"$escaped_stderr_pat\""
-    } else {
-        fail "${test_name}: stderr fails to match \"$escaped_stderr_pat\": got \"$stderr\""
-    }
+    like "${test_name}: stderr" $stderr $stderr_pat "-lineanchor"
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
 }
 
 # --- TEST 7 ---
@@ -282,38 +133,16 @@ foreach runtime [get_runtime_list] {
     }
     set test_name "$test: $subtest7 ($runtime)"
 
-    set cmd "stap --runtime=$runtime '$srcdir/$subdir/${test}_7.stp'"
-    send_log "executing: $cmd\n"
-    set pipe [open "| sh -c {$cmd}" r]
-    set out [read $pipe]
-    set failed 0
-    if {[catch {close $pipe} stderr] != 0} {
-        if {$stderr ne "" && [string index $stderr end] ne "\n"} {
-            append stderr "\n"
-        }
-        global errorCode
-        if {"CHILDSTATUS" == [lindex $errorCode 0]} {
-            set failed [lindex $errorCode 2]
-        }
-    }
+    set exit_code [run_cmd_2way "stap --runtime=$runtime '$srcdir/$subdir/${test}_7.stp'" out stderr]
 
     set exp_out "3
 4
 6
 5
 "
-    regsub -all -- {\n} $exp_out {\n} escaped_exp_out
-    if {$out eq $exp_out} {
-        pass "${test_name}: stdout matches \"$escaped_exp_out\""
-    } else {
-        fail "${test_name}: stdout fails to match \"$escaped_exp_out\": got \"$out\""
-    }
+    is "${test_name}: stdout" $out $exp_out
 
-    if {$failed} {
-        fail "${test_name}: exit code should be zero but is $failed"
-    } else {
-        pass "${test_name}: exit code is zero"
-    }
+    is "${test_name}: exit code" $exit_code 0
     if {$stderr ne ""} {
         send_log "stderr:\n$stderr"
     }
-- 
2.11.0.295.gd7dffce

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add new Tcl/DejaGnu test module test_simple to simplify tests
  2018-09-04 22:35 [PATCH] Add new Tcl/DejaGnu test module test_simple to simplify tests Yichun Zhang (agentzh)
@ 2018-09-05  3:16 ` Yichun Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Yichun Zhang @ 2018-09-05  3:16 UTC (permalink / raw)
  To: systemtap

Hello!

On Tue, Sep 4, 2018 at 3:35 PM Yichun Zhang (agentzh)
<yichun@openresty.com> wrote:
>
> Ported the handy routines is(), isnt(), like(), unlike(), ok(), nok()
> from Perl's Test::Simple module over to Tcl/DejaGnu as the test_simple
> module.
>

Just committed to master with the approval from fche.

Best,
Yichun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-05  3:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-04 22:35 [PATCH] Add new Tcl/DejaGnu test module test_simple to simplify tests Yichun Zhang (agentzh)
2018-09-05  3:16 ` Yichun Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).