cmp.test 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. # TODO: coreutils cmp uses stdin if only one file is given
  4. testcmd "one argument match" 'input && echo yes' "yes\n" \
  5. "one\ntwo\nthree" "one\ntwo\nthree"
  6. # posix says ""%s %s differ: char %d, line %d\n" but diffutils says "byte"
  7. testcmd "one argument diff" 'input | sed s/byte/char/' \
  8. "input - differ: char 5, line 2\n" "one\ntwo\nthree" "one\nboing\nthree"
  9. testcmd "missing file1 [fail]" 'file1 input 2>/dev/null || echo $?' "2\n" "foo" ""
  10. #mkdir dir
  11. #testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \
  12. #"yes\n" "" ""
  13. #rmdir dir
  14. echo "ab
  15. c" > input2
  16. testcmd "identical files, stdout" "input input2" "" "ab\nc\n" ""
  17. testcmd "identical files, return code" "input input2 && echo yes" "yes\n" "ab\nc\n" ""
  18. testcmd "EOF, stderr" "input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
  19. testcmd "EOF, return code" "input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
  20. # The gnu/dammit version fails this because posix says "char" and they don't.
  21. testcmd "diff, stdout" "input input2 | sed s/byte/char/" \
  22. "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
  23. testcmd "diff, return code" "input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
  24. testcmd "-s EOF, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
  25. testcmd "-s diff, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
  26. testcmd "-l EOF, stderr" "-l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" ""
  27. testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" "4 170 143\ncmp: EOF on input2\n" "ab\nx\nx" ""
  28. testcmd "-s not exist" "-s input doesnotexist 2>&1 || echo yes" "yes\n" "x" ""
  29. rm input2
  30. testcmd "stdin and file" "input - | sed s/byte/char/" \
  31. "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
  32. testcmd "-n skip1 skip2" "-n 3 input - 3 5 && echo yes" "yes\n" "abcdef123" "vwxyzdef987"