logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 0a26b32f58a9f21547d4c6289576b8a2529ca6ef
parent ba98fd1075f26db098bdaded02b9598f6bfd5cf2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  1 Mar 2022 14:34:09 +0100

test-bin/tee: Copy tests from test-bin/cat

Diffstat:

Mtest-bin/tee54++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/test-bin/tee b/test-bin/tee @@ -2,6 +2,7 @@ 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 @@ -17,22 +18,71 @@ writefile_cleanup() { atf_test_case appendfile appendfile_body() { echo 'hello' > tmp_tee.log - atf_check -o file:inputs/all_bytes ../bin/tee tmp_tee.log <inputs/all_bytes - atf_check -o file:inputs/all_bytes cat 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() { + if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h + then + atf_expect_fail "glibc ignoring write errors for fputs()" + fi + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for fputs()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for fputs()" + + atf_check -s exit:1 -e 'inline:Error writing: No space left on device\n' sh -c '../bin/tee <inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:Error writing: 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 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 }