aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Elliott <tle@holymonkey.com>2012-02-08 22:47:36 -0800
committerTimothy Elliott <tle@holymonkey.com>2012-02-08 22:47:36 -0800
commitd20a2e1b2e4211f00c867e61b23fc3027ab7dd38 (patch)
tree1438c8d222356269799243dc43f01d37dd67b222
parent1aa66ba2084a7e1ad7b0a5bbece58a835c749096 (diff)
downloadtoybox-d20a2e1b2e4211f00c867e61b23fc3027ab7dd38.tar.gz
Add tests for cmp.
Still needs to handle directories properly and needs padding for -l output.
-rw-r--r--scripts/test/cmp.test34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/test/cmp.test b/scripts/test/cmp.test
new file mode 100644
index 00000000..8f6983c5
--- /dev/null
+++ b/scripts/test/cmp.test
@@ -0,0 +1,34 @@
+#/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+testing "cmp not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" ""
+testing "cmp missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" ""
+
+#mkdir dir
+#testing "cmp directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
+ #"yes\n" "" ""
+#rmdir dir
+
+echo "ab
+c" > input2
+
+testing "cmp identical files, stdout" "cmp input input2" "" "ab\nc\n" ""
+testing "cmp identical files, return code" "cmp input input2 && echo yes" "yes\n" "ab\nc\n" ""
+
+testing "cmp EOF, stderr" "cmp input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
+testing "cmp EOF, return code" "cmp input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
+testing "cmp diff, stdout" "cmp input input2" "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
+testing "cmp diff, return code" "cmp input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
+
+testing "cmp -s EOF, return code" "cmp -s input input2 || echo yes" "yes\n" "ab\nc\nx" ""
+testing "cmp -s diff, return code" "cmp -s input input2 || echo yes" "yes\n" "ab\nx\nx" ""
+
+testing "cmp -l EOF, stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
+testing "cmp -l diff and EOF, stdout and stderr" "cmp -l input input2 2>&1" "cmp: EOF on input2\n4 170 143\n" "ab\nx\nx" ""
+
+rm input2
+
+testing "cmp stdin and file" "cmp input -" "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
+#testing "cmp stdin and stdin" "cmp input -" "" "" "ab\nc\n"
+