[PATCH] test: make test_expect_equal_file() arguments flexible
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Wed, 1 Feb 2012 07:19:54 +0000 (11:19 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:51 +0000 (09:43 -0800)
c3/0e6241a8c69bc76b68e61731a5f5161c8d7129 [new file with mode: 0644]

diff --git a/c3/0e6241a8c69bc76b68e61731a5f5161c8d7129 b/c3/0e6241a8c69bc76b68e61731a5f5161c8d7129
new file mode 100644 (file)
index 0000000..2615fee
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 28868431E64\r
+       for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 23:21:11 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 95Loiri3Irfb for <notmuch@notmuchmail.org>;\r
+       Tue, 31 Jan 2012 23:21:10 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 42FF2431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 23:21:10 -0800 (PST)\r
+Received: by bke11 with SMTP id 11so817306bke.26\r
+       for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 23:21:07 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:subject:date:message-id:x-mailer;\r
+       bh=iD0SGwyFbNav9t1BddkGbRV4n4UbIJzo3hLAHRZzkSo=;\r
+       b=KCSPbRZ/5yJp3A5n3inzP5F6xl7DUQy40GYtr2XdDug29Gr0qJwjJcPbZb7EVJtXFh\r
+       GOu9dXXq8d3tXUz+x5ufPIKcekQFOwHp2OnLIPWTzJQe7TJ5hXVqVXnadV81GRRcqBbO\r
+       pwGpBDNTDQi4umcrTakpCMV65ltmN5lETrYRw=\r
+Received: by 10.204.133.201 with SMTP id g9mr12403655bkt.137.1328080867433;\r
+       Tue, 31 Jan 2012 23:21:07 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id ga13sm51760580bkc.5.2012.01.31.23.21.06\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 31 Jan 2012 23:21:07 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] test: make test_expect_equal_file() arguments flexible\r
+Date: Wed,  1 Feb 2012 11:19:54 +0400\r
+Message-Id: <1328080794-24670-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.9\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 01 Feb 2012 07:21:11 -0000\r
+\r
+Before the change, test_expect_equal_file() function treated the first\r
+argument as "actual output file" and the second argument as "expected\r
+output file".  When the test fails, the files are copied for later\r
+inspection.  The first files was copied to "$testname.output" and the\r
+second file to "$testname.expected".  The argument order for\r
+test_expect_equal_file() is often wrong which results in confusing\r
+diff output and incorrectly named files.\r
+\r
+The patch solves the issue by changing test_expect_equal_file() to\r
+treat arguments just as two files, without any special properties\r
+(like "actual" and "expected").  The file names for copying is now\r
+based on the given file name: "$testname.$file1" and\r
+"$testname.$file2".  E.g. if test_expect_equal_file() is called with\r
+"OUTPUT" and "EXPECTED", the copied files can be named\r
+"emacs.1.OUTPUT" and "emacs.1.EXPECTED".\r
+\r
+The down side of this approach is that diff argument order depends on\r
+test_expect_equal_file() argument order.  So sometimes we get diff\r
+from expected to actual results, and sometimes the other way around.\r
+But the files are always named correctly.\r
+---\r
+ test/README      |   10 +++++-----\r
+ test/test-lib.sh |   12 ++++++------\r
+ 2 files changed, 11 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/test/README b/test/README\r
+index 43656a3..e0364e8 100644\r
+--- a/test/README\r
++++ b/test/README\r
+@@ -176,12 +176,12 @@ library for your script to use.\r
+    will generate a failure and print the difference of the two\r
+    strings.\r
+ \r
+- test_expect_equal_file <output> <expected>\r
++ test_expect_equal_file <file1> <file2>\r
+ \r
+-   Identical to test_exepect_equal, except that <output> and\r
+-   <expected> are files instead of strings.  This is a much more\r
+-   robust method to compare formatted textual information, since it\r
+-   also notices whitespace and closing newline differences.\r
++   Identical to test_exepect_equal, except that <file1> and <file2>\r
++   are files instead of strings.  This is a much more robust method to\r
++   compare formatted textual information, since it also notices\r
++   whitespace and closing newline differences.\r
+ \r
+  test_debug <script>\r
+ \r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 8158328..581b8be 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -488,17 +488,17 @@ test_expect_equal_file ()\r
+       test "$#" = 2 ||\r
+       error "bug in the test script: not 2 or 3 parameters to test_expect_equal"\r
+ \r
+-      output="$1"\r
+-      expected="$2"\r
++      file1="$1"\r
++      file2="$2"\r
+       if ! test_skip "$test_subtest_name"\r
+       then\r
+-              if diff -q "$expected" "$output" >/dev/null ; then\r
++              if diff -q "$file1" "$file2" >/dev/null ; then\r
+                       test_ok_ "$test_subtest_name"\r
+               else\r
+                       testname=$this_test.$test_count\r
+-                      cp "$output" $testname.output\r
+-                      cp "$expected" $testname.expected\r
+-                      test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"\r
++                      cp "$file1" "$testname.$file1"\r
++                      cp "$file2" "$testname.$file2"\r
++                      test_failure_ "$test_subtest_name" "$(diff -u "$testname.$file1" "$testname.$file2")"\r
+               fi\r
+     fi\r
+ }\r
+-- \r
+1.7.9\r
+\r