1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5# TODO: coreutils cmp uses stdin if only one file is given 6SKIP_HOST=1 testing "not enough arguments [fail]" 'cmp input 2>/dev/null || echo $?' "2\n" "foo" "" 7 8testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "foo" "" 9 10#mkdir dir 11#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \ 12 #"yes\n" "" "" 13#rmdir dir 14 15echo "ab 16c" > input2 17 18testing "identical files, stdout" "cmp input input2" "" "ab\nc\n" "" 19testing "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" "" 20 21testing "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" 22testing "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" "" 23# The gnu/dammit version fails this because posix says "char" and they don't. 24testing "diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" "" 25testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" "" 26 27testing "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" "" 28testing "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" "" 29 30testing "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" 31testing "-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" "" 32 33testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" "" 34 35rm input2 36 37testing "stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n" 38#testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n" 39 40