lolcat (3556B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case allfile
- allfile_body() {
- atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat inputs/all_bytes
- }
- atf_test_case allinput
- allinput_body() {
- atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat <inputs/all_bytes
- }
- atf_test_case alldashinput
- alldashinput_body() {
- atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat - <inputs/all_bytes
- }
- atf_test_case devnull
- devnull_body() {
- if [ "$(uname -s)" = "FreeBSD" ] || [ "$(uname -s)" = "NetBSD" ]; then
- # FIXME
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Read error: Inappropriate ioctl for device\n' -o 'inline:[0m' ../cmd/lolcat /dev/null
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Read error: Inappropriate ioctl for device\n' -o 'inline:[0m' ../cmd/lolcat </dev/null
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Read error: Inappropriate ioctl for device\n' -o 'inline:[0m' ../cmd/lolcat - </dev/null
- else
- atf_check -o 'inline:[0m' ../cmd/lolcat /dev/null
- atf_check -o 'inline:[0m' ../cmd/lolcat </dev/null
- atf_check -o 'inline:[0m' ../cmd/lolcat - </dev/null
- fi
- }
- 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:\n[0mlolcat: Error opening ‘inputs/chmod_000’: Permission denied\n' -o 'inline:[0m' ../cmd/lolcat inputs/chmod_000
- }
- 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 fputc()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD badly handling write errors"
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD badly handling write errors"
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Write error: No space left on device\n' sh -c '../cmd/lolcat inputs/all_bytes >/dev/full'
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Write error: No space left on device\n' sh -c '../cmd/lolcat <inputs/all_bytes >/dev/full'
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Write error: No space left on device\n' sh -c '../cmd/lolcat - <inputs/all_bytes >/dev/full'
- }
- atf_test_case readslash
- readslash_body() {
- [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Read error: Is a directory\n' -o 'inline:[0m' ../cmd/lolcat ./
- }
- atf_test_case enoent
- enoent_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' -o 'inline:[0m' ../cmd/lolcat /var/empty/e/no/ent
- }
- atf_test_case doubledash
- doubledash_body() {
- atf_check -o file:outputs/lolcat/all_bytes -- ../cmd/lolcat -- inputs/all_bytes
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:\n[0mlolcat: Error opening ‘---’: No such file or directory\n' -o 'inline:[0m' -- ../cmd/lolcat --- inputs/all_bytes
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case allfile
- atf_add_test_case allinput
- atf_add_test_case alldashinput
- atf_add_test_case devnull
- atf_add_test_case noperm
- atf_add_test_case devfull
- atf_add_test_case readslash
- atf_add_test_case enoent
- atf_add_test_case doubledash
- }