blob: 3b2dd1b2be49bf6788e321fb1a24a25523991603 [file] [log] [blame]
Felix Jandaadd77b12012-10-29 16:55:08 -05001#!/bin/bash
Timothy Elliottd20a2e12012-02-08 22:47:36 -08002
3[ -f testing.sh ] && . testing.sh
4
Rob Landley336c44a2016-03-02 15:20:04 -06005testing "not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" ""
6testing "missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" ""
Timothy Elliottd20a2e12012-02-08 22:47:36 -08007
8#mkdir dir
Rob Landley336c44a2016-03-02 15:20:04 -06009#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
Timothy Elliottd20a2e12012-02-08 22:47:36 -080010 #"yes\n" "" ""
11#rmdir dir
12
13echo "ab
14c" > input2
15
Rob Landley336c44a2016-03-02 15:20:04 -060016testing "identical files, stdout" "cmp input input2" "" "ab\nc\n" ""
17testing "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" ""
Timothy Elliottd20a2e12012-02-08 22:47:36 -080018
Rob Landley336c44a2016-03-02 15:20:04 -060019testing "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
20testing "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
Rob Landleyd1fcf4f2013-02-04 22:33:27 -060021# The gnu/dammit version fails this because posix says "char" and they don't.
Rob Landley336c44a2016-03-02 15:20:04 -060022testing "diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
23testing "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
Timothy Elliottd20a2e12012-02-08 22:47:36 -080024
Rob Landley19394fa2016-09-05 00:32:38 -050025testing "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
26testing "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
Timothy Elliottd20a2e12012-02-08 22:47:36 -080027
Rob Landley336c44a2016-03-02 15:20:04 -060028testing "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
29testing "-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 Elliottd20a2e12012-02-08 22:47:36 -080030
Rob Landley19394fa2016-09-05 00:32:38 -050031testing "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" ""
32
Timothy Elliottd20a2e12012-02-08 22:47:36 -080033rm input2
34
Rob Landley336c44a2016-03-02 15:20:04 -060035testing "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 Elliottd20a2e12012-02-08 22:47:36 -080037