summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-10-30 12:13:13 -0700
committerJim Meyering <meyering@fb.com>2016-11-08 18:28:04 -0800
commita9cc55101cc9c10cf7a8857034fef88559f4c656 (patch)
tree8018bd112ba9a9d1e098181e7550431bfe43e4b8 /tests
parent68b82f6f8419a815cfcf962b3061352d414dc606 (diff)
downloaddiffutils-a9cc55101cc9c10cf7a8857034fef88559f4c656.tar.gz
tests: use "returns_" rather than explicit comparison with "$?"
* tests/colors: Use "returns_ 1" rather than testing $? = 1 * tests/basic: Likewise. * tests/binary: Likewise. * tests/filename-quoting: Likewise. * tests/function-line-vs-leading-space: Likewise. * tests/ignore-matching-lines: Likewise. * tests/label-vs-func: Likewise. * tests/new-file: Likewise. * tests/no-dereference: Likewise. * tests/no-newline-at-eof: Likewise. * tests/stdin: Likewise.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/basic2
-rwxr-xr-xtests/binary4
-rwxr-xr-xtests/colors26
-rwxr-xr-xtests/filename-quoting4
-rwxr-xr-xtests/function-line-vs-leading-space4
-rwxr-xr-xtests/ignore-matching-lines3
-rwxr-xr-xtests/label-vs-func2
-rwxr-xr-xtests/new-file16
-rw-r--r--tests/no-dereference42
-rwxr-xr-xtests/no-newline-at-eof9
-rwxr-xr-xtests/stdin2
11 files changed, 44 insertions, 70 deletions
diff --git a/tests/basic b/tests/basic
index 45b9c9c..161262d 100755
--- a/tests/basic
+++ b/tests/basic
@@ -33,7 +33,7 @@ EOF
echo a > a
echo b > b
for opt in '' -u -c; do
- diff $opt a b > out 2> err; test $? = 1 || fail=1
+ returns_ 1 diff $opt a b > out 2> err || fail=1
# Remove date and time.
sed -e 's/^\([-+*][-+*][-+*] [^ ]*\) .*/\1/' out > k; mv k out
compare exp-$(echo $opt|tr ' ' _) out || fail=1
diff --git a/tests/binary b/tests/binary
index 0110f6e..36fbe2d 100755
--- a/tests/binary
+++ b/tests/binary
@@ -7,10 +7,8 @@ printf 'Binary files - and /dev/null differ\n' > out-exp || fail_ setup
fail=0
-printf '\0'|diff - /dev/null > out 2> err
-
# diff must exit with status 1, stdout as above, and no stderr.
-test $? = 1 || fail=1
+printf '\0'| returns_ 1 diff - /dev/null > out 2> err || fail=1
compare out-exp out || fail=1
compare /dev/null err || fail=1
diff --git a/tests/colors b/tests/colors
index 8651a5b..4ca634d 100755
--- a/tests/colors
+++ b/tests/colors
@@ -81,44 +81,38 @@ $ad> b$rs
rs=0 hd=1 ad=32 de=31 ln=36
-diff --color=auto a b > out
-test $? = 1 || fail=1
+returns_ 1 diff --color=auto a b > out || fail=1
gen_exp_default > exp || framework_failure_
compare exp out || fail=1
-TERM=dumb diff ---presume-output-tty --color=auto a b > out
-test $? = 1 || fail=1
+TERM=dumb returns_ 1 diff ---presume-output-tty --color=auto a b > out \
+ || fail=1
gen_exp_default > exp || framework_failure_
compare exp out || fail=1
-diff --color=never a b > out
-test $? = 1 || fail=1
+returns_ 1 diff --color=never a b > out || fail=1
gen_exp_default > exp || framework_failure_
compare exp out || fail=1
-diff a b > out
-test $? = 1 || fail=1
+returns_ 1 diff a b > out || fail=1
gen_exp_default > exp || framework_failure_
compare exp out || fail=1
-diff --color=always a b > out
-test $? = 1 || fail=1
+returns_ 1 diff --color=always a b > out || fail=1
gen_exp_default_colors > exp || framework_failure_
compare exp out || fail=1
-diff -u --color=always a b > out
-test $? = 1 || fail=1
+returns_ 1 diff -u --color=always a b > out || fail=1
gen_exp_u > exp || framework_failure_
compare exp out || fail=1
-diff -c --color=always a b > out
-test $? = 1 || fail=1
+returns_ 1 diff -c --color=always a b > out || fail=1
gen_exp_c > exp || framework_failure_
compare exp out || fail=1
rs=0 hd=33 ad=34 de=35 ln=36
-diff -u --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out
-test $? = 1 || fail=1
+returns_ 1 diff -u --color=always \
+ --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out || fail=1
gen_exp_u > exp || framework_failure_
compare exp out || fail=1
diff --git a/tests/filename-quoting b/tests/filename-quoting
index e3e9193..2e75a03 100755
--- a/tests/filename-quoting
+++ b/tests/filename-quoting
@@ -32,7 +32,7 @@ EOF
mkdir a b
echo space > "b/ " || fail=1
for opt in '' -u -c; do
- diff -N -r $opt a b > out 2> err; test $? = 1 || fail=1
+ returns_ 1 diff -N -r $opt a b > out 2> err || fail=1
# Remove date and time.
sed -e 's/^\([-+*][-+*][-+*] [^ ]*\) .*/\1/' out > k; mv k out
compare exp-$(echo $opt|tr ' ' _) out || fail=1
@@ -53,7 +53,7 @@ x01=$(printf '\001')
echo tab > "a/$tab" || fail=1
echo one > "b/$x01" || fail=1
-diff -u "a/$tab" "b/$x01" > out 2> err; test $? = 1 || fail=1
+returns_ 1 diff -u "a/$tab" "b/$x01" > out 2> err || fail=1
# Remove date and time.
sed -e 's/^\([-+*][-+*][-+*] [^ ]*\) .*/\1/' out > k; mv k out
compare exp out || fail=1
diff --git a/tests/function-line-vs-leading-space b/tests/function-line-vs-leading-space
index 572427c..d67eaf4 100755
--- a/tests/function-line-vs-leading-space
+++ b/tests/function-line-vs-leading-space
@@ -52,8 +52,8 @@ EOF
fail=0
-diff -u -F '^[[:space:]]*\(function\|procedure\)' in in2 > out 2> err
-test $? = 1 || fail=1
+returns_ 1 diff -u -F '^[[:space:]]*\(function\|procedure\)' in in2 \
+ > out 2> err || fail=1
sed -n '3,$p' out > k && mv k out || fail=1
diff --git a/tests/ignore-matching-lines b/tests/ignore-matching-lines
index 5db9ba3..1b3259f 100755
--- a/tests/ignore-matching-lines
+++ b/tests/ignore-matching-lines
@@ -39,8 +39,7 @@ cat <<'EOF' >exp
+7
EOF
-diff -u --ignore-matching-lines 3 a b >out 2>err
-test $? = 1 || fail=1
+returns_ 1 diff -u --ignore-matching-lines 3 a b >out 2>err || fail=1
sed 1,2d out >outtail || framework_failure+
compare exp outtail || fail=1
diff --git a/tests/label-vs-func b/tests/label-vs-func
index 2de61f7..4b4c9b7 100755
--- a/tests/label-vs-func
+++ b/tests/label-vs-func
@@ -19,7 +19,7 @@ label:
EOF
sed s/1/2/ a > b || fail=1
-diff -p -u0 a b > out 2> err; test $? = 1 || fail=1
+returns_ 1 diff -p -u0 a b > out 2> err || fail=1
tail -3 out > k && mv k out || fail=1
diff --git a/tests/new-file b/tests/new-file
index af7cc4c..ab99708 100755
--- a/tests/new-file
+++ b/tests/new-file
@@ -10,29 +10,29 @@ echo a > a || fail=1
echo '0a1
> a' > exp || fail=1
-diff -N - a <&- > out; test $? = 1 || fail=1
+returns_ 1 diff -N - a <&- > out || fail=1
compare exp out || fail=1
-diff --unidirectional-new-file - a <&- > out; test $? = 1 || fail=1
+returns_ 1 diff --unidirectional-new-file - a <&- > out || fail=1
compare exp out || fail=1
-diff -N b - < a > out; test $? = 1 || fail=1
+returns_ 1 diff -N b - < a > out || fail=1
compare exp out || fail=1
-diff --unidirectional-new-file b - < a > out; test $? = 1 || fail=1
+returns_ 1 diff --unidirectional-new-file b - < a > out || fail=1
compare exp out || fail=1
echo '1d0
< a' > exp || fail=1
-diff -N a - <&- > out; test $? = 1 || fail=1
+returns_ 1 diff -N a - <&- > out || fail=1
compare exp out || fail=1
-diff --unidirectional-new-file a - <&- > out; test $? = 2 || fail=1
+returns_ 2 diff --unidirectional-new-file a - <&- > out || fail=1
-diff -N - b < a > out; test $? = 1 || fail=1
+returns_ 1 diff -N - b < a > out || fail=1
compare exp out || fail=1
-diff --unidirectional-new-file - b < a > out; test $? = 2 || fail=1
+returns_ 2 diff --unidirectional-new-file - b < a > out || fail=1
Exit $fail
diff --git a/tests/no-dereference b/tests/no-dereference
index 1426beb..3f67bd2 100644
--- a/tests/no-dereference
+++ b/tests/no-dereference
@@ -14,8 +14,7 @@ ln -s regular3 symlink3
# Non-recursive comparisons.
# Test case 3: Compare regular file with regular file.
-diff --no-dereference regular1 regular2 > out
-test $? = 1 || fail=1
+returns_ 1 diff --no-dereference regular1 regular2 > out || fail=1
cat <<EOF > expected || framework_failure_
1c1
< Simple contents
@@ -25,30 +24,26 @@ EOF
compare expected out || fail=1
# Test case 4: Compare regular file with symbolic link.
-diff --no-dereference regular1 symlink1 > out
-test $? = 1 || fail=1
+returns_ 1 diff --no-dereference regular1 symlink1 > out || fail=1
cat <<EOF > expected || framework_failure_
File regular1 is a regular file while file symlink1 is a symbolic link
EOF
compare expected out || fail=1
# Test case 5: Compare symbolic link with regular file.
-diff --no-dereference symlink1 regular1 > out
-test $? = 1 || fail=1
+returns_ 1 diff --no-dereference symlink1 regular1 > out || fail=1
cat <<EOF > expected || framework_failure_
File symlink1 is a symbolic link while file regular1 is a regular file
EOF
compare expected out || fail=1
# Test case 6: Compare symbolic links with same value.
-diff --no-dereference symlink1 symlink1bis > out
-test $? = 0 || fail=1
+diff --no-dereference symlink1 symlink1bis > out || fail=1
compare /dev/null out || fail=1
# Test case 7: Compare symbolic links with different value and different target
# contents.
-diff --no-dereference symlink1 symlink2 > out
-test $? = 1 || fail=1
+returns_ 1 diff --no-dereference symlink1 symlink2 > out || fail=1
cat <<EOF > expected || framework_failure_
Symbolic links symlink1 and symlink2 differ
EOF
@@ -56,8 +51,7 @@ compare expected out || fail=1
# Test case 8: Compare symbolic links with different value and same target
# contents.
-diff --no-dereference symlink2 symlink3 > out
-test $? = 1 || fail=1
+returns_ 1 diff --no-dereference symlink2 symlink3 > out || fail=1
cat <<EOF > expected || framework_failure_
Symbolic links symlink2 and symlink3 differ
EOF
@@ -70,8 +64,7 @@ mkdir subdir1a
mkdir subdir1b
ln -s nonexistent subdir1a/foo
ln -s ../regular1 subdir1a/bar
-diff -r --no-dereference subdir1a subdir1b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir1a subdir1b > out || fail=1
cat <<EOF > expected || framework_failure_
Only in subdir1a: bar
Only in subdir1a: foo
@@ -83,8 +76,7 @@ mkdir subdir2a
mkdir subdir2b
ln -s nonexistent subdir2b/foo
ln -s ../regular1 subdir2b/bar
-diff -r --no-dereference subdir2a subdir2b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir2a subdir2b > out || fail=1
cat <<EOF > expected || framework_failure_
Only in subdir2b: bar
Only in subdir2b: foo
@@ -96,8 +88,7 @@ mkdir subdir3a
mkdir subdir3b
cp regular1 subdir3a/foo
cp regular2 subdir3b/foo
-diff -r --no-dereference subdir3a subdir3b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir3a subdir3b > out || fail=1
cat <<EOF > expected || framework_failure_
diff -r --no-dereference subdir3a/foo subdir3b/foo
1c1
@@ -112,8 +103,7 @@ mkdir subdir4a
mkdir subdir4b
cp regular1 subdir4a/foo
ln -s ../regular1 subdir4b/foo
-diff -r --no-dereference subdir4a subdir4b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir4a subdir4b > out || fail=1
cat <<EOF > expected || framework_failure_
File subdir4a/foo is a regular file while file subdir4b/foo is a symbolic link
EOF
@@ -124,8 +114,7 @@ mkdir subdir5a
mkdir subdir5b
ln -s ../regular1 subdir5a/foo
cp regular1 subdir5b/foo
-diff -r --no-dereference subdir5a subdir5b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir5a subdir5b > out || fail=1
cat <<EOF > expected || framework_failure_
File subdir5a/foo is a symbolic link while file subdir5b/foo is a regular file
EOF
@@ -136,8 +125,7 @@ mkdir subdir6a
mkdir subdir6b
ln -s ../regular1 subdir6a/foo
ln -s ../regular1 subdir6b/foo
-diff -r --no-dereference subdir6a subdir6b > out
-test $? = 0 || fail=1
+diff -r --no-dereference subdir6a subdir6b > out || fail=1
compare /dev/null out || fail=1
# Test case 7: Compare symbolic links with different value and different target
@@ -146,8 +134,7 @@ mkdir subdir7a
mkdir subdir7b
ln -s ../regular1 subdir7a/foo
ln -s ../regular2 subdir7b/foo
-diff -r --no-dereference subdir7a subdir7b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir7a subdir7b > out || fail=1
cat <<EOF > expected || framework_failure_
Symbolic links subdir7a/foo and subdir7b/foo differ
EOF
@@ -159,8 +146,7 @@ mkdir subdir8a
mkdir subdir8b
ln -s ../regular2 subdir8a/foo
ln -s ../regular3 subdir8b/foo
-diff -r --no-dereference subdir8a subdir8b > out
-test $? = 1 || fail=1
+returns_ 1 diff -r --no-dereference subdir8a subdir8b > out || fail=1
cat <<EOF > expected || framework_failure_
Symbolic links subdir8a/foo and subdir8b/foo differ
EOF
diff --git a/tests/no-newline-at-eof b/tests/no-newline-at-eof
index f503718..5f00003 100755
--- a/tests/no-newline-at-eof
+++ b/tests/no-newline-at-eof
@@ -31,8 +31,7 @@ fail=0
# So we don't have to record trailing blanks in expected output above.
opt=--suppress-blank-empty
-diff $opt -U1 a b > out 2> err
-test $? = 1 || fail=1
+returns_ 1 diff $opt -U1 a b > out 2> err || fail=1
sed -n '/^@@/,$p' out > k && mv k out || fail=1
compare exp out || fail=1
@@ -42,8 +41,7 @@ compare /dev/null err || fail=1
# Repeat, but with a newline at the end of "a".
echo >> a
-diff $opt -U1 a b > out 2> err
-test $? = 1 || fail=1
+returns_ 1 diff $opt -U1 a b > out 2> err || fail=1
sed -n '/^@@/,$p' out > k && mv k out || fail=1
compare exp2 out || fail=1
@@ -53,7 +51,6 @@ compare /dev/null err || fail=1
# Test for Bug#18402.
printf a > a
printf b > b
-diff -B a b > out 2>err
-test $? = 1 || fail=1
+returns_ 1 diff -B a b > out 2>err || fail=1
Exit $fail
diff --git a/tests/stdin b/tests/stdin
index 295e98d..94b7542 100755
--- a/tests/stdin
+++ b/tests/stdin
@@ -16,7 +16,7 @@ EOF
echo a > a
echo b > b
-diff -u - b < a > out 2> err; test $? = 1 || fail=1
+returns_ 1 diff -u - b < a > out 2> err || fail=1
# Remove date and time.
sed -e 's/^\([-+*][-+*][-+*] [^ ]*\) .*/\1/' out > k; mv k out
compare exp out || fail=1