tail.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. BIGTEST="one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n"
  5. echo -ne "$BIGTEST" > file1
  6. testing "tail" "tail && echo yes" "oneyes\n" "" "one"
  7. testing "file" "tail file1" \
  8. "two\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" ""
  9. testing "-n in bounds" "tail -n 3 file1" "nine\nten\neleven\n" "" ""
  10. testing "-n out of bounds" "tail -n 999 file1" "$BIGTEST" "" ""
  11. testing "-n+ in bounds" "tail -n +3 file1" \
  12. "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" ""
  13. testing "-n+ outof bounds" "tail -n +999 file1" "" "" ""
  14. testing "-c in bounds" "tail -c 27 file1" \
  15. "even\neight\nnine\nten\neleven\n" "" ""
  16. testing "-c out of bounds" "tail -c 999 file1" "$BIGTEST" "" ""
  17. testing "-c+ in bounds" "tail -c +27 file1" \
  18. "x\nseven\neight\nnine\nten\neleven\n" "" ""
  19. testing "-c+ out of bonds" "tail -c +999 file1" "" "" ""
  20. testing "-N" "tail -1 file1" "eleven\n" "" ""
  21. rm file1
  22. testing "stdin no trailing newline" "tail -n 1 - " "c" "" "a\nb\nc"
  23. testing "file no trailing newline" "tail -n 1 input" "c" "a\nb\nc" ""
  24. testing "noseek -n in bounds" "tail -n 3" "nine\nten\neleven\n" \
  25. "" "$BIGTEST"
  26. testing "noseek -n out of bounds" "tail -n 999" "$BIGTEST" "" "$BIGTEST"
  27. testing "noseek -n+ in bounds" "tail -n +3" \
  28. "three\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\n" "" \
  29. "$BIGTEST"
  30. testing "noseek -n+ outof bounds" "tail -n +999" "" "" "$BIGTEST"
  31. testing "noseek -c in bounds" "tail -c 27" \
  32. "even\neight\nnine\nten\neleven\n" "" "$BIGTEST"
  33. testing "noseek -c out of bounds" "tail -c 999" "$BIGTEST" "" "$BIGTEST"
  34. testing "noseek -c+ in bounds" "tail -c +27" \
  35. "x\nseven\neight\nnine\nten\neleven\n" "" "$BIGTEST"
  36. testing "noseek -c+ out of bonds" "tail -c +999" "" "" "$BIGTEST"
  37. makebigfile()
  38. {
  39. for j in $(seq 1 100)
  40. do
  41. echo -n "$j "
  42. for i in $(seq 1 100)
  43. do
  44. echo -n 123456789abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  45. done
  46. echo
  47. done
  48. }
  49. makebigfile > bigfile
  50. testing "-c 12345 -n 3 bigfile" "tail -c 12345 -n 3 bigfile | md5sum" \
  51. "347bbdcbad8a313f4dc7bd558c5bfcb8 -\n" "" ""
  52. testing "-n 3 -c 12345 bigfile" "tail -n 3 -c 12345 bigfile | md5sum" \
  53. "1698825a750288284ec3ba7d8a59f302 -\n" "" ""
  54. rm bigfile
  55. echo 111 > one
  56. testing "-f one" \
  57. 'tail -f one & sleep .25 ; echo two >> one; sleep .25; echo three >> one; sleep .25; kill $! >/dev/null' \
  58. "111\ntwo\nthree\n" "" ""
  59. rm one
  60. echo uno > one
  61. echo dos > two
  62. echo tres > three
  63. testing "-f one two three" \
  64. 'tail -f one two three & sleep .25 ; echo more >> three ; echo also >> one; sleep .25; kill $! >/dev/null' \
  65. "==> one <==\nuno\n\n==> two <==\ndos\n\n==> three <==\ntres\nmore\n\n==> one <==\nalso\n" "" ""
  66. rm one two three
  67. testing "-F" "tail -s .1 -F walrus 2>/dev/null & sleep .2; echo hello > walrus;
  68. sleep .2; truncate -s 0 walrus; sleep .2; echo potato >> walrus; sleep .2;
  69. echo hello >> walrus; sleep .2; rm walrus; sleep .2; echo done > walrus;
  70. sleep .5; kill %1" "hello\npotato\nhello\ndone\n" "" ""
  71. rm -f walrus