tee (2781B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case allinput
- allinput_body() {
- atf_check -o file:inputs/all_bytes ../cmd/tee <inputs/all_bytes
- }
- atf_test_case writefile cleanup
- writefile_body() {
- echo 'hello' > tmp_tee.log
- atf_check -o file:inputs/all_bytes ../cmd/tee tmp_tee.log <inputs/all_bytes
- atf_check -o empty -s exit:1 grep hello tmp_tee.log
- }
- writefile_cleanup() {
- rm tmp_tee.log
- }
- atf_test_case appendfile cleanup
- appendfile_body() {
- echo 'hello' > tmp_tee.log
- atf_check -o file:inputs/all_bytes ../cmd/tee -a tmp_tee.log <inputs/all_bytes
- atf_check -o file:outputs/tee/hello_all_bytes cat tmp_tee.log
- }
- appendfile_cleanup() {
- rm tmp_tee.log
- }
- atf_test_case noperm cleanup
- noperm_body() {
- touch inputs/chmod_000 || atf_fail "touching chmod_000"
- chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:tee: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/tee inputs/chmod_000 </dev/null
- }
- noperm_cleanup() {
- chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
- rm inputs/chmod_000 || atf_fail "rm chmod_000"
- }
- atf_test_case devfull
- devfull_body() {
- has_glibc && atf_skip "glibc ignoring write errors for fputs()"
- [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for fputs()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for fputs()"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:tee: Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee <inputs/all_bytes >/dev/full'
- }
- atf_test_case nullinput
- nullinput_body() {
- atf_check ../cmd/tee </dev/null
- }
- atf_test_case writeslash
- writeslash_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:tee: Error opening ‘./’: Is a directory\n' ../cmd/tee ./ <inputs/all_bytes
- }
- atf_test_case enoent
- enoent_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:tee: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/tee /var/empty/e/no/ent <inputs/all_bytes
- }
- atf_test_case doubledash
- doubledash_body() {
- atf_check -o file:inputs/all_bytes -- ../cmd/tee -- <inputs/all_bytes
- #atf_check -s exit:1 -e 'inline:tee: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/tee --- <inputs/all_bytes
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case allinput
- atf_add_test_case writefile
- atf_add_test_case appendfile
- atf_add_test_case noperm
- atf_add_test_case devfull
- atf_add_test_case nullinput
- atf_add_test_case writeslash
- atf_add_test_case enoent
- atf_add_test_case doubledash
- }