Felix Janda | add77b1 | 2012-10-29 16:55:08 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 2 | |
| 3 | [ -f testing.sh ] && . testing.sh |
| 4 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 5 | testing "not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" "" |
| 6 | testing "missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" "" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 7 | |
| 8 | #mkdir dir |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 9 | #testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \ |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 10 | #"yes\n" "" "" |
| 11 | #rmdir dir |
| 12 | |
| 13 | echo "ab |
| 14 | c" > input2 |
| 15 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 16 | testing "identical files, stdout" "cmp input input2" "" "ab\nc\n" "" |
| 17 | testing "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" "" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 18 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 19 | testing "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" |
| 20 | testing "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" "" |
Rob Landley | d1fcf4f | 2013-02-04 22:33:27 -0600 | [diff] [blame] | 21 | # The gnu/dammit version fails this because posix says "char" and they don't. |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 22 | testing "diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" "" |
| 23 | testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" "" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 24 | |
Rob Landley | 19394fa | 2016-09-05 00:32:38 -0500 | [diff] [blame] | 25 | testing "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" "" |
| 26 | testing "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" "" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 27 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 28 | testing "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" |
| 29 | 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" "" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 30 | |
Rob Landley | 19394fa | 2016-09-05 00:32:38 -0500 | [diff] [blame] | 31 | testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" "" |
| 32 | |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 33 | rm input2 |
| 34 | |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 35 | testing "stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n" |
| 36 | #testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n" |
Timothy Elliott | d20a2e1 | 2012-02-08 22:47:36 -0800 | [diff] [blame] | 37 | |