[PATCH 1 of 3 STABLE] tests: make pdiff return appropriate exit code at comparison of files

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Aug 1 11:52:20 UTC 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1501474219 -32400
#      Mon Jul 31 13:10:19 2017 +0900
# Branch stable
# Node ID 3277d2061d402e571111a282e1568f8e3bec189d
# Parent  92f7dcf9a40b056573be89f611e1f093521696d7
# Available At https://bitbucket.org/foozy/mercurial-wip
#              hg pull https://bitbucket.org/foozy/mercurial-wip -r 3277d2061d40
# EXP-Topic tests-portability
tests: make pdiff return appropriate exit code at comparison of files

Before this patch, pdiff script returns 0, even if diff is detected.

This issue doesn't cause failure of tests using it, if it is invoked
via extdiff extension, because extdiff itself examines changes between
specified revisions and decides exit code.

BTW, this patch ignores recursive comparison case, because:

  - there is no portable way for current while-read based
    implementation to return 1 at detecting changes

  - it isn't yet needed to replace direct "diff -r" invocation by
    pdiff for portability

diff --git a/tests/pdiff b/tests/pdiff
--- a/tests/pdiff
+++ b/tests/pdiff
@@ -41,6 +41,9 @@ filediff(){
     diff -u "$file1" "$file2" |
     sed "s@^--- /dev/null\(.*\)\$@--- $1\1@" |
     sed "s@^\+\+\+ /dev/null\(.*\)\$@+++ $2\1@"
+
+    # in this case, files differ from each other
+    return 1
 }
 
 if test -d "$1" -o -d "$2"; then
@@ -53,6 +56,14 @@ if test -d "$1" -o -d "$2"; then
     while read file; do
         filediff "$1/$file" "$2/$file" "diff -Nru $1/$file $2/$file"
     done
+
+    # TODO: there is no portable way for current while-read based
+    # implementation to return 1 at detecting changes.
+    #
+    # On bash and dash, assignment to variable inside while-block
+    # doesn't affect outside, because inside while-block is executed
+    # in sub-shell. BTW, it affects outside while-block on ksh (as sh
+    # on Solaris).
 else
     filediff "$1" "$2"
 fi


More information about the Mercurial-devel mailing list