tee (3022B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- atf_test_case allinput
- allinput_body() {
- atf_check -o file:inputs/all_bytes ../bin/tee <inputs/all_bytes
- atf_check -o file:inputs/all_bytes ../bin/tee - <inputs/all_bytes
- }
- atf_test_case writefile
- writefile_body() {
- echo 'hello' > tmp_tee.log
- atf_check -o file:inputs/all_bytes ../bin/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
- appendfile_body() {
- echo 'hello' > tmp_tee.log
- atf_check -o file:inputs/all_bytes ../bin/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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/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_expect_fail "glibc ignoring write errors for fputs()"
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for fputs()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for fputs()"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../bin/tee <inputs/all_bytes >/dev/full'
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../bin/tee - <inputs/all_bytes >/dev/full'
- }
- atf_test_case nullinput
- nullinput_body() {
- atf_check ../bin/tee </dev/null
- }
- atf_test_case writeslash
- writeslash_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:Error opening ‘./’: Is a directory\n' ../bin/tee ./ <inputs/all_bytes
- }
- atf_test_case enoent
- enoent_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../bin/tee /var/empty/e/no/ent <inputs/all_bytes
- }
- atf_test_case doubledash
- doubledash_body() {
- atf_check -o file:inputs/all_bytes -- ../bin/tee -- <inputs/all_bytes
- #atf_check -s exit:1 -e 'inline:Error opening ‘---’: No such file or directory\n' -o empty -- ../bin/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
- }