2012-10-29 14:55:08 -07:00
|
|
|
#!/bin/bash
|
2012-02-08 22:47:36 -08:00
|
|
|
|
|
|
|
[ -f testing.sh ] && . testing.sh
|
|
|
|
|
2019-03-18 20:37:53 -07:00
|
|
|
# TODO: coreutils cmp uses stdin if only one file is given
|
2019-10-12 16:39:50 -07:00
|
|
|
testing "one argument match" 'cmp input && echo yes' "yes\n" \
|
|
|
|
"one\ntwo\nthree" "one\ntwo\nthree"
|
|
|
|
# posix says ""%s %s differ: char %d, line %d\n" but diffutils says "byte"
|
|
|
|
testing "one argument diff" 'cmp input | sed s/byte/char/' \
|
|
|
|
"input - differ: char 5, line 2\n" "one\ntwo\nthree" "one\nboing\nthree"
|
2019-03-18 20:37:53 -07:00
|
|
|
|
|
|
|
testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "foo" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
|
|
|
#mkdir dir
|
2016-03-02 13:20:04 -08:00
|
|
|
#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
|
2012-02-08 22:47:36 -08:00
|
|
|
#"yes\n" "" ""
|
|
|
|
#rmdir dir
|
|
|
|
|
|
|
|
echo "ab
|
|
|
|
c" > input2
|
|
|
|
|
2016-03-02 13:20:04 -08:00
|
|
|
testing "identical files, stdout" "cmp input input2" "" "ab\nc\n" ""
|
|
|
|
testing "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2016-03-02 13:20:04 -08:00
|
|
|
testing "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
|
|
|
|
testing "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
|
2013-02-04 20:33:27 -08:00
|
|
|
# The gnu/dammit version fails this because posix says "char" and they don't.
|
2019-10-12 16:39:50 -07:00
|
|
|
testing "diff, stdout" "cmp input input2 | sed s/byte/char/" \
|
|
|
|
"input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
|
2016-03-02 13:20:04 -08:00
|
|
|
testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2016-09-04 22:32:38 -07:00
|
|
|
testing "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
|
|
|
|
testing "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2016-03-02 13:20:04 -08:00
|
|
|
testing "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
|
|
|
|
testing "-l diff and EOF, stdout and stderr" "cmp -l input input2 2>&1 | sort" "4 170 143\ncmp: EOF on input2\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2019-10-28 21:47:08 -07:00
|
|
|
testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "x" ""
|
2016-09-04 22:32:38 -07:00
|
|
|
|
2012-02-08 22:47:36 -08:00
|
|
|
rm input2
|
|
|
|
|
2019-10-12 16:39:50 -07:00
|
|
|
testing "stdin and file" "cmp input - | sed s/byte/char/" \
|
|
|
|
"input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
|
2016-03-02 13:20:04 -08:00
|
|
|
#testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n"
|
2012-02-08 22:47:36 -08:00
|
|
|
|