cat.test 976 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. echo "one" > file1
  5. echo "two" > file2
  6. testing "cat" "cat && echo yes" "oneyes\n" "" "one"
  7. testing "-" "cat - && echo yes" "oneyes\n" "" "one"
  8. testing "file1 file2" "cat file1 file2" "one\ntwo\n" "" ""
  9. testing "- file" "cat - file1" "zero\none\n" "" "zero\n"
  10. testing "file -" "cat file1 -" "one\nzero\n" "" "zero\n"
  11. testing "file1 notfound file2" \
  12. "cat file1 notfound file2 2>stderr && echo ok ; cat stderr; rm stderr" \
  13. "one\ntwo\ncat: notfound: No such file or directory\n" "" ""
  14. testing "binary" \
  15. 'cat "$C" > file1 && cmp "$C" file1 && echo yes' "yes\n" "" ""
  16. testing "- file1" \
  17. "cat - file1 | diff -a -U 0 - file1 | tail -n 1" \
  18. "-hello\n" "" "hello\n"
  19. skipnot [ -e /dev/full ]
  20. testing "> /dev/full" \
  21. "cat - > /dev/full 2>/dev/null || echo failed" \
  22. "failed\n" "" "zero\n"
  23. rm file1 file2