changeset 28052:b59ef0c21405

tests: use portable diff script via extdiff extension Before this patch, some tests using external "diff" command via extdiff extension fail on Solaris, because of incompatibility of "diff" command and its output. For example, system standard "diff" (= /usr/bin/diff) on Solaris differs from GNU diff in points below: - "-N" (treat absent files as empty) option isn't supported - files are examined not in dictionary order (maybe, in order in storage) This patch introduces portable diff script "pdiff" and make tests use it via extdiff extension. For portability of tests, this patch invokes "pdiff" script with explicit "sh", because standard shell of runtime platform ("cmd.exe" on Windows) is used at first to invoke external diff command.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 08 Feb 2016 18:29:17 +0900
parents 413201fbbc82
children 34a2944aac9b
files tests/pdiff tests/test-graft.t tests/test-largefiles-update.t tests/test-subrepo-deep-nested-change.t
diffstat 4 files changed, 74 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/pdiff	Mon Feb 08 18:29:17 2016 +0900
@@ -0,0 +1,58 @@
+#!/bin/sh
+
+# Script to get stable diff output on any platform.
+#
+# Output of this script is almost equivalent to GNU diff with "-Nru".
+#
+# Use this script as "hg pdiff" via extdiff extension with preparation
+# below in test scripts:
+#
+#   $ cat >> $HGRCPATH <<EOF
+#   > [extdiff]
+#   > pdiff = sh "$RUNTESTDIR/pdiff"
+#   > EOF
+
+filediff(){
+    # USAGE: filediff file1 file2 [header]
+
+    # compare with /dev/null if file doesn't exist (as "-N" option)
+    file1="$1"
+    if test ! -f "$file1"; then
+        file1=/dev/null
+    fi
+    file2="$2"
+    if test ! -f "$file2"; then
+        file2=/dev/null
+    fi
+
+    if cmp -s "$file1" "$file2"; then
+        # Return immediately, because comparison isn't needed. This
+        # also avoids redundant message of diff like "No differences
+        # encountered" (on Solaris)
+        return
+    fi
+
+    if test -n "$3"; then
+        # show header only in recursive case
+        echo "$3"
+    fi
+
+    # replace "/dev/null" by corresponded filename (as "-N" option)
+    diff -u "$file1" "$file2" |
+    sed "s@^--- /dev/null\(.*\)\$@--- $1\1@" |
+    sed "s@^\+\+\+ /dev/null\(.*\)\$@+++ $2\1@"
+}
+
+if test -d "$1" -o -d "$2"; then
+    # ensure comparison in dictionary order
+    (
+    if test -d "$1"; then (cd "$1" && find . -type f); fi
+    if test -d "$2"; then (cd "$2" && find . -type f); fi
+    ) |
+    sed 's@^\./@@g' | sort | uniq |
+    while read file; do
+        filediff "$1/$file" "$2/$file" "diff -Nru $1/$file $2/$file"
+    done
+else
+    filediff "$1" "$2"
+fi
--- a/tests/test-graft.t	Sun Feb 07 09:36:09 2016 +0100
+++ b/tests/test-graft.t	Mon Feb 08 18:29:17 2016 +0900
@@ -1,7 +1,7 @@
   $ cat >> $HGRCPATH <<EOF
-  > [defaults]
-  > # for portability
-  > extdiff = --option -Nru
+  > [extdiff]
+  > # for portability:
+  > pdiff = sh "$RUNTESTDIR/pdiff"
   > EOF
 
 Create a repo with some stuff in it:
@@ -348,7 +348,7 @@
   skipping already grafted revision 7:ef0ef43d49e7 (was grafted from 2:5c095ad7e90f)
   [255]
 
-  $ hg extdiff --config extensions.extdiff= --patch -r 2 -r 13
+  $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13
   --- */hg-5c095ad7e90f.patch	* (glob)
   +++ */hg-7a4785234d87.patch	* (glob)
   @@ -1,18 +1,18 @@
@@ -379,7 +379,7 @@
   ++a
   [1]
 
-  $ hg extdiff --config extensions.extdiff= --patch -r 2 -r 13 -X .
+  $ hg pdiff --config extensions.extdiff= --patch -r 2 -r 13 -X .
   --- */hg-5c095ad7e90f.patch	* (glob)
   +++ */hg-7a4785234d87.patch	* (glob)
   @@ -1,8 +1,8 @@
--- a/tests/test-largefiles-update.t	Sun Feb 07 09:36:09 2016 +0100
+++ b/tests/test-largefiles-update.t	Mon Feb 08 18:29:17 2016 +0900
@@ -6,9 +6,9 @@
   > merge = internal:fail
   > [extensions]
   > largefiles =
-  > [defaults]
-  > # for portability
-  > extdiff = --option -Nru
+  > [extdiff]
+  > # for portability:
+  > pdiff = sh "$RUNTESTDIR/pdiff"
   > EOF
 
   $ hg init repo
@@ -23,7 +23,7 @@
   $ echo 'large1 in #1' > large1
   $ echo 'normal1 in #1' > normal1
   $ hg commit -m '#1'
-  $ hg extdiff -r '.^' --config extensions.extdiff=
+  $ hg pdiff -r '.^' --config extensions.extdiff=
   diff -Nru repo.0d9d9b8dc9a3/.hglf/large1 repo/.hglf/large1
   --- repo.0d9d9b8dc9a3/.hglf/large1	* (glob)
   +++ repo/.hglf/large1	* (glob)
--- a/tests/test-subrepo-deep-nested-change.t	Sun Feb 07 09:36:09 2016 +0100
+++ b/tests/test-subrepo-deep-nested-change.t	Mon Feb 08 18:29:17 2016 +0900
@@ -1,7 +1,7 @@
   $ cat >> $HGRCPATH <<EOF
-  > [defaults]
-  > # for portability
-  > extdiff = --option -Nru
+  > [extdiff]
+  > # for portability:
+  > pdiff = sh "$RUNTESTDIR/pdiff"
   > EOF
 
 Preparing the subrepository 'sub2'
@@ -717,9 +717,9 @@
 
 Interaction with extdiff, largefiles and subrepos
 
-  $ hg --config extensions.extdiff= extdiff -S
+  $ hg --config extensions.extdiff= pdiff -S
 
-  $ hg --config extensions.extdiff= extdiff -r '.^' -S
+  $ hg --config extensions.extdiff= pdiff -r '.^' -S
   diff -Nru cloned.*/.hgsub cloned/.hgsub (glob)
   --- cloned.*/.hgsub	* (glob)
   +++ cloned/.hgsub	* (glob)
@@ -734,7 +734,7 @@
   -b1a26de6f2a045a9f079323693614ee322f1ff7e sub3
   [1]
 
-  $ hg --config extensions.extdiff= extdiff -r 0 -r '.^' -S
+  $ hg --config extensions.extdiff= pdiff -r 0 -r '.^' -S
   diff -Nru cloned.*/.hglf/b.dat cloned.*/.hglf/b.dat (glob)
   --- cloned.*/.hglf/b.dat	* (glob)
   +++ cloned.*/.hglf/b.dat	* (glob)
@@ -799,7 +799,7 @@
   [1]
 
   $ echo mod > sub1/sub2/sub2
-  $ hg --config extensions.extdiff= extdiff -S
+  $ hg --config extensions.extdiff= pdiff -S
   --- */cloned.*/sub1/sub2/sub2	* (glob)
   +++ */cloned/sub1/sub2/sub2	* (glob)
   @@ -1* +1* @@ (glob)