unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test: make test_expect_equal_file() arguments flexible
@ 2012-02-01  7:19 Dmitry Kurochkin
  2012-02-01  8:12 ` David Edmondson
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Dmitry Kurochkin @ 2012-02-01  7:19 UTC (permalink / raw)
  To: notmuch

Before the change, test_expect_equal_file() function treated 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 was 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 solves the issue by changing test_expect_equal_file() to
treat arguments just as two files, without any special properties
(like "actual" and "expected").  The file names for copying is now
based on the given file name: "$testname.$file1" and
"$testname.$file2".  E.g. if test_expect_equal_file() is called with
"OUTPUT" and "EXPECTED", the copied files can be named
"emacs.1.OUTPUT" and "emacs.1.EXPECTED".

The down side of this approach is that diff argument order depends on
test_expect_equal_file() argument order.  So sometimes we get diff
from expected to actual results, and sometimes the other way around.
But the files are always named correctly.
---
 test/README      |   10 +++++-----
 test/test-lib.sh |   12 ++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/test/README b/test/README
index 43656a3..e0364e8 100644
--- a/test/README
+++ b/test/README
@@ -176,12 +176,12 @@ library for your script to use.
    will generate a failure and print the difference of the two
    strings.
 
- test_expect_equal_file <output> <expected>
+ test_expect_equal_file <file1> <file2>
 
-   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.
+   Identical to test_exepect_equal, except that <file1> and <file2>
+   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.
 
  test_debug <script>
 
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 8158328..581b8be 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -488,17 +488,17 @@ test_expect_equal_file ()
 	test "$#" = 2 ||
 	error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
 
-	output="$1"
-	expected="$2"
+	file1="$1"
+	file2="$2"
 	if ! test_skip "$test_subtest_name"
 	then
-		if diff -q "$expected" "$output" >/dev/null ; then
+		if diff -q "$file1" "$file2" >/dev/null ; then
 			test_ok_ "$test_subtest_name"
 		else
 			testname=$this_test.$test_count
-			cp "$output" $testname.output
-			cp "$expected" $testname.expected
-			test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"
+			cp "$file1" "$testname.$file1"
+			cp "$file2" "$testname.$file2"
+			test_failure_ "$test_subtest_name" "$(diff -u "$testname.$file1" "$testname.$file2")"
 		fi
     fi
 }
-- 
1.7.9

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

end of thread, other threads:[~2012-09-02  2:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-01  7:19 [PATCH] test: make test_expect_equal_file() arguments flexible Dmitry Kurochkin
2012-02-01  8:12 ` David Edmondson
2012-02-01  8:47 ` Jameson Graef Rollins
2012-02-01  8:55   ` Tomi Ollila
2012-02-01  9:23     ` Dmitry Kurochkin
2012-02-01  9:19   ` Dmitry Kurochkin
2012-02-01 10:18     ` Tomi Ollila
2012-02-01 10:37       ` Dmitry Kurochkin
2012-02-01 17:24         ` Jameson Graef Rollins
2012-02-01 23:42           ` Dmitry Kurochkin
2012-02-02  0:07             ` Dmitry Kurochkin
2012-02-02 14:33           ` David Edmondson
2012-02-02 15:25             ` Tomi Ollila
2012-02-02 17:40 ` Jameson Graef Rollins
2012-09-02  2:38 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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).