cmp.test 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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" \
  19. "cmp: EOF on input2 after byte 5, line 2\n" "ab\nc\nx" ""
  20. testcmd "EOF, return code" "input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" ""
  21. # The gnu/dammit version fails this because posix says "char" and they don't.
  22. testcmd "diff, stdout" "input input2 | sed s/byte/char/" \
  23. "input input2 differ: char 4, line 2\n" "ab\nx\nx" ""
  24. testcmd "diff, return code" "input input2 > /dev/null || echo yes" "yes\n" "ab\nx\nx" ""
  25. testcmd "-s EOF, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" ""
  26. testcmd "-s diff, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" ""
  27. testcmd "-l EOF, stderr" "-l input input2 2>&1" \
  28. "cmp: EOF on input2 after byte 5\n" "ab\nc\nx" ""
  29. testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" \
  30. "4 170 143\ncmp: EOF on input2 after byte 5\n" "ab\nx\nx" ""
  31. testcmd "-s not exist" "-s input doesnotexist 2>&1 || echo yes" "yes\n" "x" ""
  32. rm input2
  33. testcmd "stdin and file" "input - | sed s/byte/char/" \
  34. "input - differ: char 4, line 2\n" "ab\nc\n" "ab\nx\n"
  35. testcmd "-n skip1 skip2" "-n 3 input - 3 5 && echo yes" "yes\n" "abcdef123" "vwxyzdef987"