[PATCH 1/2] test: add check for <expected> filename argument for test_expect_equal_file

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Wed Feb 1 16:04:09 PST 2012


Test_expect_equal_file() function treats the first argument as "actual
output file" and the second argument as "expected output file".  When
the test fails, the files are copied for later inspection.  The first
files is copied to "$testname.output" and the second file to
"$testname.expected".  The argument order for test_expect_equal_file()
is often wrong which results in confusing diff output and incorrectly
named files.

The patch requires the <expected> filename argument for
test_expect_equal_file() function to contain 'EXPECT' or 'expect'
substring.  Otherwise test fails with appropriate error.  This allows
us to easily catch argument order errors during test development.

Most tests already comply with the required format.  But there are
some tests which are broken by this change.  Notably, the tests which
have wrong argument order for test_expect_equal_file() fail after the
change, which kind of proofs the idea.
---
 test/README      |    3 ++-
 test/test-lib.sh |    8 ++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/test/README b/test/README
index 43656a3..0105019 100644
--- a/test/README
+++ b/test/README
@@ -181,7 +181,8 @@ library for your script to use.
    Identical to test_exepect_equal, except that <output> and
    <expected> are files instead of strings.  This is a much more
    robust method to compare formatted textual information, since it
-   also notices whitespace and closing newline differences.
+   also notices whitespace and closing newline differences.  The
+   <expected> file name must contain 'expect' or 'EXPECT' substring.
 
  test_debug <script>
 
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 8158328..482f47b 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -490,6 +490,14 @@ test_expect_equal_file ()
 
 	output="$1"
 	expected="$2"
+	case "$expected" in
+	*expect*|*EXPECT*)
+		;;
+	*)
+		error "bug in the test script: test_expect_equal_file parameter '$expected' does not contain 'expect' substring"
+		;;
+	esac
+
 	if ! test_skip "$test_subtest_name"
 	then
 		if diff -q "$expected" "$output" >/dev/null ; then
-- 
1.7.9



More information about the notmuch mailing list