3
0

uniq.tests 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. # SUSv3 compliant uniq tests.
  3. # Copyright 2005 by Rob Landley <rob@landley.net>
  4. # Licensed under GPL v2, see file LICENSE for details.
  5. # AUDIT: Full SUSv3 coverage (except internationalization).
  6. . testing.sh
  7. # testing "test name" "options" "expected result" "file input" "stdin"
  8. # file input will be file called "input"
  9. # test can create a file "actual" instead of writing to stdout
  10. # Test exit status
  11. testing "uniq (exit with error)" "uniq nonexistent 2> /dev/null || echo yes" \
  12. "yes\n" "" ""
  13. testing "uniq (exit success)" "uniq /dev/null && echo yes" "yes\n" "" ""
  14. # Test various data sources and destinations
  15. testing "uniq (default to stdin)" "uniq" "one\ntwo\nthree\n" "" \
  16. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  17. testing "uniq - (specify stdin)" "uniq -" "one\ntwo\nthree\n" "" \
  18. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  19. testing "uniq input (specify file)" "uniq input" "one\ntwo\nthree\n" \
  20. "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
  21. testing "uniq input outfile (two files)" "uniq input actual > /dev/null" \
  22. "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
  23. testing "uniq (stdin) outfile" "uniq - actual" \
  24. "one\ntwo\nthree\n" "" "one\ntwo\ntwo\nthree\nthree\nthree\n"
  25. # Note: SUSv3 doesn't seem to require support for "-" output, but we do anyway.
  26. testing "uniq input - (specify stdout)" "uniq input -" \
  27. "one\ntwo\nthree\n" "one\ntwo\ntwo\nthree\nthree\nthree\n" ""
  28. #-f skip fields
  29. #-s skip chars
  30. #-c occurrences
  31. #-d dups only
  32. #-u
  33. # Test various command line options
  34. # Leading whitespace is a minor technical violation of the spec,
  35. # but since gnu does it...
  36. testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
  37. "1 one\n2 two\n3 three\n" "" \
  38. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  39. testing "uniq -d (dups only) " "uniq -d" "two\nthree\n" "" \
  40. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  41. testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
  42. "cc dd ee8
  43. aa bb cc9
  44. " "" \
  45. "cc dd ee8
  46. bb cc dd8
  47. aa bb cc9
  48. "
  49. # -d is "Suppress the writing fo lines that are not repeated in the input."
  50. # -u is "Suppress the writing of lines that are repeated in the input."
  51. # Therefore, together this means they should produce no output.
  52. testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
  53. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  54. exit $FAILCOUNT