bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: use "compare exp out", not "compare out exp"


From: Jim Meyering
Subject: [PATCH] tests: use "compare exp out", not "compare out exp"
Date: Tue, 29 Nov 2011 17:36:24 +0100

Normalizing some tests.
An incoming gnulib syntax-check will test for these.

>From 5f2a03af5258eabb1263e58229fd4d1f395ca14a Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 29 Nov 2011 17:06:11 +0100
Subject: [PATCH] tests: use "compare exp out", not "compare out exp"

Likewise, when an empty file is expected, use "compare /dev/null out",
not "compare out /dev/null". I.e., specify the expected/desired contents
via the first file name.  Prompted by a suggestion from Bruno Haible
in http://thread.gmane.org/gmane.comp.gnu.grep.bugs/4020/focus=29154

Run these commands:

    git grep -l -E 'compare [^ ]+ exp' \
      |xargs perl -pi -e 's/(compare) (\S+) (exp\S*)/$1 $3 $2/'
    git grep -l -E 'compare [^ ]+ /dev/null' \
      |xargs perl -pi -e 's/(compare) (\S+) (\/dev\/null)/$1 $3 $2/'
---
 tests/backref-word             |    2 +-
 tests/case-fold-backref        |    2 +-
 tests/case-fold-char-class     |    4 ++--
 tests/case-fold-char-range     |    4 ++--
 tests/case-fold-char-type      |    4 ++--
 tests/char-class-multibyte     |    4 ++--
 tests/dfaexec-multibyte        |    6 +++---
 tests/fgrep-infloop            |    2 +-
 tests/ignore-mmap              |    2 +-
 tests/include-exclude          |   14 +++++++-------
 tests/init.cfg                 |    2 +-
 tests/max-count-vs-context     |    4 ++--
 tests/pcre-abort               |    2 +-
 tests/pcre-z                   |    8 ++++----
 tests/prefix-of-multibyte      |    2 +-
 tests/reversed-range-endpoints |    2 +-
 tests/sjis-mb                  |    4 ++--
 tests/warn-char-classes        |    2 +-
 tests/word-delim-multibyte     |    2 +-
 tests/word-multi-file          |    4 ++--
 20 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/tests/backref-word b/tests/backref-word
index adf6a10..557c6d8 100755
--- a/tests/backref-word
+++ b/tests/backref-word
@@ -8,7 +8,7 @@ fail=0
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out1-$LOC
   LC_ALL=$LOC grep -w '\(foo\) \1' exp1 > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 Exit $fail
diff --git a/tests/case-fold-backref b/tests/case-fold-backref
index ef9e9bc..dfa4161 100755
--- a/tests/case-fold-backref
+++ b/tests/case-fold-backref
@@ -8,7 +8,7 @@ fail=0
 for LOC in en_US.UTF-8 en_US zh_CN $LOCALE_FR_UTF8 C; do
   out=out1-$LOC
   LC_ALL=$LOC grep -Ei '(foo) \1' exp1 > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 Exit $fail
diff --git a/tests/case-fold-char-class b/tests/case-fold-char-class
index 018d2d2..ac8f3ee 100755
--- a/tests/case-fold-char-class
+++ b/tests/case-fold-char-class
@@ -8,7 +8,7 @@ fail=0
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out1-$LOC
   printf 'X\nY\nZ\n' | LC_ALL=$LOC grep -i '[y]' > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 printf 'y\n'      > exp2 || framework_failure_
@@ -16,7 +16,7 @@ printf 'y\n'      > exp2 || framework_failure_
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out2-$LOC
   printf 'x\ny\nz\n' | LC_ALL=$LOC grep -i '[Y]' > $out || fail=1
-  compare $out exp2 || fail=1
+  compare exp2 $out || fail=1
 done

 Exit $fail
diff --git a/tests/case-fold-char-range b/tests/case-fold-char-range
index d036492..4203024 100755
--- a/tests/case-fold-char-range
+++ b/tests/case-fold-char-range
@@ -8,7 +8,7 @@ fail=0
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out1-$LOC
   printf 'A\n1\nZ\n.\n' | LC_ALL=$LOC grep -i '[a-z]' > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 # This actually passes also for grep-2.5.3
@@ -17,7 +17,7 @@ printf 'a\nz\n'      > exp2 || framework_failure_
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out2-$LOC
   printf 'a\n1\nz\n.\n' | LC_ALL=$LOC grep -i '[A-Z]' > $out || fail=1
-  compare $out exp2 || fail=1
+  compare exp2 $out || fail=1
 done

 Exit $fail
diff --git a/tests/case-fold-char-type b/tests/case-fold-char-type
index 7ae7d4b..d5fd67c 100755
--- a/tests/case-fold-char-type
+++ b/tests/case-fold-char-type
@@ -8,7 +8,7 @@ fail=0
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out1-$LOC
   printf '1\nY\n.\n' | LC_ALL=$LOC grep -i '[[:lower:]]' > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 printf 'y\n'      > exp2 || framework_failure_
@@ -16,7 +16,7 @@ printf 'y\n'      > exp2 || framework_failure_
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out2-$LOC
   printf '1\ny\n.\n' | LC_ALL=$LOC grep -i '[[:upper:]]' > $out || fail=1
-  compare $out exp2 || fail=1
+  compare exp2 $out || fail=1
 done

 Exit $fail
diff --git a/tests/char-class-multibyte b/tests/char-class-multibyte
index 88b8fa0..fae7511 100755
--- a/tests/char-class-multibyte
+++ b/tests/char-class-multibyte
@@ -11,7 +11,7 @@ fail=0
 for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
   out=out1-$LOC
   printf 'á\nç\né\n' | LC_ALL=$LOC grep '[é]' > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1
 done

 printf 'É\n'      > exp2 || framework_failure_
@@ -19,7 +19,7 @@ printf 'É\n'      > exp2 || framework_failure_
 for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
   out=out2-$LOC
   printf 'Á\nÇ\nÉ\n' | LC_ALL=$LOC grep '[É]' > $out || fail=1
-  compare $out exp2 || fail=1
+  compare exp2 $out || fail=1
 done

 for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
diff --git a/tests/dfaexec-multibyte b/tests/dfaexec-multibyte
index eea6315..baac9ba 100755
--- a/tests/dfaexec-multibyte
+++ b/tests/dfaexec-multibyte
@@ -10,15 +10,15 @@ fail=0
 for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
   out=out1-ab-$LOC
   LC_ALL=$LOC grep -E '([a]|[b]){2}' < exp1 > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1

   out=out1-ba-$LOC
   LC_ALL=$LOC grep -E '([b]|[a]){2}' < exp1 > $out || fail=1
-  compare $out exp1 || fail=1
+  compare exp1 $out || fail=1

   out=out2-$LOC
   LC_ALL=$LOC grep -E '^([[:digit:]]+[[:space:]]+){2}' < exp2 > $out || fail=1
-  compare $out exp2 || fail=1
+  compare exp2 $out || fail=1

 done

diff --git a/tests/fgrep-infloop b/tests/fgrep-infloop
index 7ef8297..07a0ce0 100755
--- a/tests/fgrep-infloop
+++ b/tests/fgrep-infloop
@@ -15,7 +15,7 @@ for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
   encode ABC \
     | LC_ALL=$LOC timeout 10s grep -F "$(encode BC)" > $out 2>&1
   test $? = 1 || fail=1
-  compare $out /dev/null || fail=1
+  compare /dev/null $out || fail=1
 done

 Exit $fail
diff --git a/tests/ignore-mmap b/tests/ignore-mmap
index a757216..a6d30ca 100755
--- a/tests/ignore-mmap
+++ b/tests/ignore-mmap
@@ -11,6 +11,6 @@ compare out in || fail=1
 grep --mmap b in > out 2>&1
 # Expect no match and no output.
 test $? = 1 || fail=1
-compare out /dev/null || fail=1
+compare /dev/null out || fail=1

 Exit $fail
diff --git a/tests/include-exclude b/tests/include-exclude
index 4be5c78..4249c56 100755
--- a/tests/include-exclude
+++ b/tests/include-exclude
@@ -15,32 +15,32 @@ printf '%s\n' x/a:aaa             > exp-a       || 
framework_failure_

 grep -r --exclude='a*'    . x > out || fail=1
 sort out > k && mv k out
-compare out exp-not-a || fail=1
+compare exp-not-a out || fail=1

 grep -r --exclude='[ab]'  . x > out || fail=1
 sort out > k && mv k out
-compare out exp-not-ab || fail=1
+compare exp-not-ab out || fail=1

 grep -r --exclude='*d'    . x > out || fail=1
 sort out > k && mv k out
-compare out exp-not-d || fail=1
+compare exp-not-d out || fail=1

 grep -r --exclude-dir=dir . x > out || fail=1
 sort out > k && mv k out
-compare out exp-not-dir || fail=1
+compare exp-not-dir out || fail=1

 # Test with a non-glob.
 grep -r --include=a    . x > out || fail=1
 # no need to sort
-compare out exp-a || fail=1
+compare exp-a out || fail=1

 # Also test --include with a "glob".
 grep -r --include='a*'    . x > out || fail=1
 # no need to sort
-compare out exp-a || fail=1
+compare exp-a out || fail=1

 # --include (without --recursive) uses different code
 grep --include=a '^aaa$' x/* > out || fail=1
-compare out exp-a || fail=1
+compare exp-a out || fail=1

 Exit $fail
diff --git a/tests/init.cfg b/tests/init.cfg
index e04d90f..772e119 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -48,7 +48,7 @@ require_timeout_()
 require_pcre_()
 {
   echo . | grep -P . 2>err || skip_ no PCRE support
-  compare err /dev/null || fail_ PCRE available, but stderr not empty.
+  compare /dev/null err || fail_ PCRE available, but stderr not empty.
 }

 # Some tests would fail without this particular locale.
diff --git a/tests/max-count-vs-context b/tests/max-count-vs-context
index ec20728..5633dd6 100755
--- a/tests/max-count-vs-context
+++ b/tests/max-count-vs-context
@@ -17,7 +17,7 @@ sed 4q in > exp || framework_failure_
 fail=0
 grep -m1 -A5 needle in > out 2>err || fail=1

-compare out exp || fail=1
-compare err /dev/null || fail=1
+compare exp out || fail=1
+compare /dev/null err || fail=1

 Exit $fail
diff --git a/tests/pcre-abort b/tests/pcre-abort
index 131fa47..0b605aa 100755
--- a/tests/pcre-abort
+++ b/tests/pcre-abort
@@ -16,6 +16,6 @@ fail=0
 echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab > in || framework_failure_
 grep -P '((a+)*)+$' in > out
 test $? = 2 || fail=1
-compare out /dev/null || fail=1
+compare /dev/null out || fail=1

 Exit $fail
diff --git a/tests/pcre-z b/tests/pcre-z
index 169c44e..99ebc43 100755
--- a/tests/pcre-z
+++ b/tests/pcre-z
@@ -8,16 +8,16 @@ REGEX=a
 printf "%s\n0" abc def ghi aaa gah | tr 0 \\0 > in

 grep -z "$REGEX" in > exp 2>err || fail_ 'Cannot do BRE (grep -z) match.'
-compare err /dev/null || fail_ 'stderr not empty on grep -z.'
+compare /dev/null err || fail_ 'stderr not empty on grep -z.'

 # Sanity check the output
 test "$(grep -cz $REGEX in 2>err)" = 3 \
     || fail_ 'Incorrect BRE (grep -cz) match.'
-compare err /dev/null || fail_ 'stderr not empty on grep -cz.'
+compare /dev/null err || fail_ 'stderr not empty on grep -cz.'

 fail=0
 grep -Pz "$REGEX" in > out 2>err || fail=1
-compare out exp || fail=1
-compare err /dev/null || fail=1
+compare exp out || fail=1
+compare /dev/null err || fail=1

 Exit $fail
diff --git a/tests/prefix-of-multibyte b/tests/prefix-of-multibyte
index 851e1f6..b15fa9b 100755
--- a/tests/prefix-of-multibyte
+++ b/tests/prefix-of-multibyte
@@ -14,7 +14,7 @@ for LOC in en_US.UTF-8 $LOCALE_FR_UTF8; do
     out=out-$opt-$LOC
     encode ABC | LC_ALL=$LOC grep $opt "$(encode A)" > $out 2>&1
     test $? = 1 || fail=1
-    compare $out /dev/null || fail=1
+    compare /dev/null $out || fail=1
   done
 done

diff --git a/tests/reversed-range-endpoints b/tests/reversed-range-endpoints
index eb84594..9256724 100755
--- a/tests/reversed-range-endpoints
+++ b/tests/reversed-range-endpoints
@@ -13,7 +13,7 @@ for prog in grep egrep 'grep -E'; do
   # Remove "program_name: " prefix from actual output.
   sed 's/^[a-z]*: //' out > k && mv k out

-  compare out exp || fail=1
+  compare exp out || fail=1
 done

 Exit $fail
diff --git a/tests/sjis-mb b/tests/sjis-mb
index b1ec853..990c770 100755
--- a/tests/sjis-mb
+++ b/tests/sjis-mb
@@ -29,7 +29,7 @@ test_grep_reject() {
   encode "$2" | \
     LC_ALL=$locale \
       timeout 10s grep $1 $(encode "$3") > out$k 2>&1
-  test $? = 1 && compare out$k /dev/null
+  test $? = 1 && compare /dev/null out$k
 }

 test_grep() {
@@ -37,7 +37,7 @@ test_grep() {
   encode "$2" > exp$k
   LC_ALL=$locale \
     timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
-  test $? = 0 && compare out$k exp$k
+  test $? = 0 && compare exp$k out$k
 }

 test "$(get-mb-cur-max $locale)" = 2 || skip_ 'SJIS locale not found'
diff --git a/tests/warn-char-classes b/tests/warn-char-classes
index 8cc6563..1b49b87 100755
--- a/tests/warn-char-classes
+++ b/tests/warn-char-classes
@@ -12,7 +12,7 @@ printf 'grep: character class syntax is [[:space:]], not 
[:space:]\n' \

 grep '[:space:]' x 2> err
 test $? = 2 || fail=1
-compare err exp-err || fail=1
+compare exp-err err || fail=1

 grep '[[:space:]]' x 2> err
 test $? = 1 || fail=1
diff --git a/tests/word-delim-multibyte b/tests/word-delim-multibyte
index e0fa266..b7f1576 100755
--- a/tests/word-delim-multibyte
+++ b/tests/word-delim-multibyte
@@ -14,6 +14,6 @@ fail=0
 grep "\<$e_acute" in > out 2>err || fail=1

 compare out in || fail=1
-compare err /dev/null || fail=1
+compare /dev/null err || fail=1

 Exit $fail
diff --git a/tests/word-multi-file b/tests/word-multi-file
index 6614ab6..1816d60 100755
--- a/tests/word-multi-file
+++ b/tests/word-multi-file
@@ -21,9 +21,9 @@ sed s/..// exp1 > exp2 || framework_failure_
 fail=0
 grep -rw bb a > out || fail=1
 sort < out > k; mv k out
-compare out exp1 || fail=1
+compare exp1 out || fail=1

 (cd a && grep -w bb [1-4]) > out || fail=1
-compare out exp2 || fail=1
+compare exp2 out || fail=1

 Exit $fail
--
1.7.8.rc4



reply via email to

[Prev in Thread] Current Thread [Next in Thread]