aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/test-lib.sh
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-09-17 15:25:39 -0700
committerGravatar Carl Worth <cworth@cworth.org>2010-09-17 15:25:39 -0700
commitc92ad8bf6a7a798f5f0dd2861a6b087873fdf8b6 (patch)
tree92fc85bc0fb1f54740dca08ae36aee1308815c50 /test/test-lib.sh
parent222926abe1e221a6239ccb9436968af43e1b6fb2 (diff)
test: Rework test-suite input to avoid ulti-command strings
The original git test suite works by concatenating many commands into a very long string (each separated by &&). This is painful to work with since it prevents the editor from helping by parsing the shell script, indenting, colorizing, etc. Instead, we switch this back to something like the original notmuch test suite, and add two new functions to test-lib.sh (test_begin_subtest and test_expect_equal) to support these. This also fixes the test suite to once again display the diff when a test fails to generate the expected input.
Diffstat (limited to 'test/test-lib.sh')
-rw-r--r--test/test-lib.sh40
1 files changed, 29 insertions, 11 deletions
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 35ff3d98..15238705 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -373,19 +373,37 @@ add_message ()
notmuch new > /dev/null
}
-pass_if_equal ()
+test_begin_subtest ()
{
- output=$1
- expected=$2
+ test_subtest_name="$1"
+}
- if [ "$output" = "$expected" ]; then
- true
- else
- testname=$this_test.$test_count
- echo "$expected" > $testname.expected
- echo "$output" > $testname.output
- diff -u $testname.expected $testname.output
- false
+# Pass test if two arguments match
+#
+# Note: Unlike all other test_expect_* functions, this function does
+# not accept a test name. Instead, the caller should call
+# test_begin_subtest before calling this function in order to set the
+# name.
+test_expect_equal ()
+{
+ test "$#" = 3 && { prereq=$1; shift; } || prereq=
+ test "$#" = 2 ||
+ error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
+
+ output="$1"
+ expected="$2"
+ if ! test_skip "$@"
+ then
+ say >&3 "expecting success: diff $output $expected"
+ if [ "$output" = "$expected" ]; then
+ test_ok_ "$test_subtest_name"
+ else
+ testname=$this_test.$test_count
+ echo "$expected" > $testname.expected
+ echo "$output" > $testname.output
+ test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"
+ fi
+ echo >&3 ""
fi
}