logo

utils-std

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

tee.sh (1842B)


  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. plans=17
  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. if [ "x${LOGNAME}" = 'xroot' ]; then
  21. skip noperm:chmod_0000 'ran as root, ignoring'
  22. skip noperm 'ran as root, ignoring'
  23. skip noperm:chmod_0600 'ran as root, ignoring'
  24. skip noperm:rm 'ran as root, ignoring'
  25. else
  26. tmp_noperm="$(mktemp)"
  27. t_cmd noperm:chmod_0000 '' chmod 0000 "${tmp_noperm}"
  28. t --exit=1 noperm "${tmp_noperm}" "tee: error: Failed opening file ‘${tmp_noperm}’: Permission denied
  29. " </dev/null
  30. t_cmd noperm:chmod_0600 '' chmod 0600 "${tmp_noperm}"
  31. t_cmd noperm:rm '' rm "${tmp_noperm}"
  32. fi
  33. t --input='' nullinput
  34. t --exit=1 --input='foo' writeslash './' 'tee: error: Failed opening file ‘./’: Is a directory
  35. '
  36. 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
  37. '
  38. t_file --infile="${WD}/inputs/all_bytes" doubledash "${WD}/inputs/all_bytes" --
  39. t --exit=1 --input='foo' tripledash '---' "tee: error: Unrecognised option: '--'
  40. "