xcd (2191B)
- #!/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 openfile
- openfile_body() {
- atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd inputs/all_bytes
- }
- atf_test_case stdinput
- stdinput_body() {
- atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd <inputs/all_bytes
- atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd - <inputs/all_bytes
- }
- atf_test_case nullfile
- nullfile_body() {
- atf_check -o file:outputs/xcd/null ../cmd/xcd /dev/null
- }
- atf_test_case nullinput
- nullinput_body() {
- atf_check -o file:outputs/xcd/null ../cmd/xcd </dev/null
- }
- 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[0mxcd: Error opening ‘inputs/chmod_000’: Permission denied\n' -o 'inline:[0m' ../cmd/xcd 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 printf()"
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for printf()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for printf()"
- # shellcheck disable=SC1112
- atf_check -s 'exit:1' -e 'inline:\n[0mxcd: Write error: No space left on device\n\n[0mxcd: Error closing ‘inputs/all_bytes’: No space left on device\n' sh -c '../cmd/xcd inputs/all_bytes >/dev/full'
- atf_check -s 'exit:1' -e 'inline:\n[0mxcd: Write error: No space left on device\n' sh -c '../cmd/xcd <inputs/all_bytes >/dev/full'
- atf_check -s 'exit:1' -e 'inline:\n[0mxcd: Write error: No space left on device\n' sh -c '../cmd/xcd - <inputs/all_bytes >/dev/full'
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case openfile
- atf_add_test_case stdinput
- atf_add_test_case nullfile
- atf_add_test_case nullinput
- atf_add_test_case noperm
- atf_add_test_case devfull
- }