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
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "one argument match" 'input && echo yes' "yes\n" \
|
2019-10-12 16:39:50 -07:00
|
|
|
"one\ntwo\nthree" "one\ntwo\nthree"
|
|
|
|
# posix says ""%s %s differ: char %d, line %d\n" but diffutils says "byte"
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "one argument diff" 'input | sed s/byte/char/' \
|
2019-10-12 16:39:50 -07:00
|
|
|
"input - differ: char 5, line 2\n" "one\ntwo\nthree" "one\nboing\nthree"
|
2019-03-18 20:37:53 -07:00
|
|
|
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "missing file1 [fail]" '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
|
|
|
|
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "identical files, stdout" "input input2" "" "ab\nc\n" ""
|
|
|
|
testcmd "identical files, return code" "input input2 && echo yes" "yes\n" "ab\nc\n" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2022-06-19 01:49:36 -07:00
|
|
|
testcmd "EOF, stderr" "input input2 2>&1" \
|
|
|
|
"cmp: EOF on input2 after byte 5, line 2\n" "ab\nc\nx" ""
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "EOF, return code" "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.
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "diff, stdout" "input input2 | sed s/byte/char/" \
|
2019-10-12 16:39:50 -07:00
|
|
|
"input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "diff, return code" "input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "-s EOF, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
|
|
|
|
testcmd "-s diff, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2022-06-19 01:49:36 -07:00
|
|
|
testcmd "-l EOF, stderr" "-l input input2 2>&1" \
|
|
|
|
"cmp: EOF on input2 after byte 5\n" "ab\nc\nx" ""
|
|
|
|
testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" \
|
|
|
|
"4 170 143\ncmp: EOF on input2 after byte 5\n" "ab\nx\nx" ""
|
2012-02-08 22:47:36 -08:00
|
|
|
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "-s not exist" "-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
|
|
|
|
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "stdin and file" "input - | sed s/byte/char/" \
|
2019-10-12 16:39:50 -07:00
|
|
|
"input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
|
2021-12-26 15:59:44 -08:00
|
|
|
testcmd "-n skip1 skip2" "-n 3 input - 3 5 && echo yes" "yes\n" "abcdef123" "vwxyzdef987"
|
2012-02-08 22:47:36 -08:00
|
|
|
|