aboutsummaryrefslogtreecommitdiff
path: root/tests/cmp.test
blob: 62d4b89db7b393034f4ea4bc58c317c7711dd8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

[ -f testing.sh ] && . testing.sh

# TODO: coreutils cmp uses stdin if only one file is given
SKIP_HOST=1 testing "not enough arguments [fail]" 'cmp input 2>/dev/null || echo $?' "2\n" "foo" ""

testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "foo" ""

#mkdir dir
#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
	#"yes\n" "" ""
#rmdir dir

echo "ab
c" > input2

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" ""

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" ""
# The gnu/dammit version fails this because posix says "char" and they don't.
testing "diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""

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" ""

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" ""

testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" ""

rm input2

testing "stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
#testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n"