uniq.tests 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # SUSv3 compliant uniq tests.
  3. # Copyright 2005 by Rob Landley <rob@landley.net>
  4. # Licensed under GPLv2, see file LICENSE in this source tree.
  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. #-w max chars
  34. # Test various command line options
  35. # Leading whitespace is a minor technical violation of the spec,
  36. # but since gnu does it...
  37. testing "uniq -c (occurrence count)" "uniq -c | sed 's/^[ \t]*//'" \
  38. "1 one\n2 two\n3 three\n" "" \
  39. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  40. testing "uniq -d (dups only)" "uniq -d" "two\nthree\n" "" \
  41. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  42. testing "uniq -f -s (skip fields and chars)" "uniq -f2 -s 3" \
  43. "cc dd ee8
  44. aa bb cc9
  45. " "" \
  46. "cc dd ee8
  47. bb cc dd8
  48. aa bb cc9
  49. "
  50. testing "uniq -w (compare max characters)" "uniq -w 2" \
  51. "cc1
  52. " "" \
  53. "cc1
  54. cc2
  55. cc3
  56. "
  57. testing "uniq -s -w (skip fields and compare max chars)" \
  58. "uniq -s 2 -w 2" \
  59. "aaccaa
  60. " "" \
  61. "aaccaa
  62. aaccbb
  63. bbccaa
  64. "
  65. # -d is "Suppress the writing fo lines that are not repeated in the input."
  66. # -u is "Suppress the writing of lines that are repeated in the input."
  67. # Therefore, together this means they should produce no output.
  68. testing "uniq -u and -d produce no output" "uniq -d -u" "" "" \
  69. "one\ntwo\ntwo\nthree\nthree\nthree\n"
  70. exit $FAILCOUNT