logo

utils-std

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

tee.sh (2185B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. plans=20
  5. WD=$(dirname "$0")
  6. target="${WD}/../cmd/tee"
  7. . "${WD}/tap.sh"
  8. t_file --infile="${WD}/inputs/all_bytes" all_bytes "${WD}/inputs/all_bytes"
  9. tmp_writefile="$(mktemp)"
  10. echo hello > "${tmp_writefile}"
  11. t_cmd writefile:grep '' grep -q hello "${tmp_writefile}"
  12. t_file --infile="${WD}/inputs/all_bytes" writefile "${WD}/inputs/all_bytes" "${tmp_writefile}"
  13. t_cmd writefile:cmp '' cmp "${tmp_writefile}" "${WD}/inputs/all_bytes"
  14. t_cmd writefile:rm '' rm "${tmp_writefile}"
  15. tmp_appendfile="$(mktemp)"
  16. echo hello > "${tmp_appendfile}"
  17. t_file --infile="${WD}/inputs/all_bytes" appendfile "${WD}/inputs/all_bytes" -a "${tmp_appendfile}"
  18. t_cmd writefile:cmp '' cmp "${tmp_appendfile}" "${WD}/outputs/tee/hello_all_bytes"
  19. t_cmd appendfile:rm '' rm "${tmp_appendfile}"
  20. tmp_createfile="${tmp_appendfile}.new"
  21. t_file --infile="${WD}/inputs/all_bytes" createfile "${WD}/inputs/all_bytes" "${tmp_createfile}"
  22. t_cmd createfile:cmp '' cmp "${tmp_createfile}" "${WD}/inputs/all_bytes"
  23. t_cmd createfile:rm '' rm "${tmp_createfile}"
  24. if [ "x${LOGNAME}" = 'xroot' ]; then
  25. skip noperm:chmod_0000 'ran as root, ignoring'
  26. skip noperm 'ran as root, ignoring'
  27. skip noperm:chmod_0600 'ran as root, ignoring'
  28. skip noperm:rm 'ran as root, ignoring'
  29. else
  30. tmp_noperm="$(mktemp)"
  31. t_cmd noperm:chmod_0000 '' chmod 0000 "${tmp_noperm}"
  32. t --exit=1 noperm "${tmp_noperm}" "tee: error: Failed opening file ‘${tmp_noperm}’: Permission denied
  33. " </dev/null
  34. t_cmd noperm:chmod_0600 '' chmod 0600 "${tmp_noperm}"
  35. t_cmd noperm:rm '' rm "${tmp_noperm}"
  36. fi
  37. t --input='' nullinput
  38. t --exit=1 --input='foo' writeslash './' 'tee: error: Failed opening file ‘./’: Is a directory
  39. '
  40. t --exit=1 --input='foo' enoent '/var/empty/e/no/ent' 'tee: error: Failed opening file ‘/var/empty/e/no/ent’: No such file or directory
  41. '
  42. t_file --infile="${WD}/inputs/all_bytes" doubledash "${WD}/inputs/all_bytes" --
  43. if grep -q HAS_GETOPT_LONG "${WD}/../config.h"; then
  44. skip tripledash
  45. else
  46. t --exit=1 --input='foo' tripledash '---' "tee: error: Long options unsupported: '---'
  47. "
  48. fi