1add77b1dd346aa5e4a02265345f52007166d95a4Felix Janda#!/bin/bash
2d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
3d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott[ -f testing.sh ] && . testing.sh
4d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
5336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" ""
6336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" ""
7d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
8d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott#mkdir dir
9336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landley#testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
10d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott	#"yes\n" "" ""
11d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott#rmdir dir
12d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
13d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliottecho "ab
14d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliottc" > input2
15d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
16336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "identical files, stdout" "cmp input input2" "" "ab\nc\n" ""
17336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" ""
18d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
19336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
20336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
21d1fcf4faf98374d4e24ca2c71e703589d348ee35Rob Landley# The gnu/dammit version fails this because posix says "char" and they don't.
22336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
23336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
24d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
2519394faadb511c6f5ed015d63f6e5ba32c4fc4caRob Landleytesting "-s EOF, return code" "cmp -s input input2 2>&1 || echo yes"  "yes\n" "ab\nc\nx" ""
2619394faadb511c6f5ed015d63f6e5ba32c4fc4caRob Landleytesting "-s diff, return code" "cmp -s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
27d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
28336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "-l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
29336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "-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" ""
30d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
3119394faadb511c6f5ed015d63f6e5ba32c4fc4caRob Landleytesting "-s not exist" "cmp -s input doesnotexist 2>&1 || echo yes" "yes\n" "" ""
3219394faadb511c6f5ed015d63f6e5ba32c4fc4caRob Landley
33d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliottrm input2
34d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
35336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
36336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landley#testing "stdin and stdin" "cmp input -" "" "" "ab\nc\n"
37d20a2e1b2e4211f00c867e61b23fc3027ab7dd38Timothy Elliott
38