logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

head.sh (1212B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")/../"
  5. target="${WD}/cmd/head"
  6. plans=15
  7. . "${WD}/test-cmd/tap.sh"
  8. t --input="$(seq 1 20)" 20l '' "$(seq 1 10)
  9. "
  10. t --input="$(seq 1 20)" 20l5l '-n 5' "$(seq 1 5)
  11. "
  12. t --input="$(seq 1 20)" 20l-5l '-5' "$(seq 1 5)
  13. "
  14. t --input="$(seq 1 5)" 5l '' "$(seq 1 5)"
  15. t --input="$(seq 1 5)" 5l40l '-n 40' "$(seq 1 5)"
  16. t --input='' empty '' ''
  17. t --input='' empty3l '-n 3' ''
  18. t --input='' empty3c '-c 3' ''
  19. t --input="$(seq 1 2)" devnull+2l "- ${WD}/test-cmd/inputs/empty" "==> - <==
  20. 1
  21. 2
  22. ==> ${WD}/test-cmd/inputs/empty <==
  23. "
  24. t --input="$(seq 1 2)" opt_q "-q - ${WD}/test-cmd/inputs/empty" '1
  25. 2'
  26. t --input='' opt_v '-v -' '==> - <==
  27. '
  28. t z3 "-n 3 -z ${WD}/test-cmd/inputs/strings/length" "$(printf '1\0_2\0__3\0')"
  29. set -o pipefail
  30. head_40c() { "$target" -c 40 /dev/zero | wc -c | tr -d '[:space:]'; }
  31. t_cmd 40c '40' head_40c
  32. head_40kc() { "$target" -c 40k /dev/zero | wc -c | tr -d '[:space:]'; }
  33. t_cmd 40c '40960' head_40kc
  34. head_40d() { "$target" -c 40d /dev/zero | wc -c | tr -d '[:space:]'; }
  35. t_cmd --exit=1 40d "head: error: Unrecognised unit 'd'
  36. 0" head_40d