logo

utils-std

Collection of commonly available Unix tools
commit: 5b3a5784d836e01230e35a52bb103f0a7dbaf800
parent 2ae981824b512e0550a695c4b36ad27f4d68c254
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  8 Jul 2024 04:14:11 +0200

test-cmd/cat: Change from ATF to tap.sh

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/cat78------------------------------------------------------------------------------
Atest-cmd/cat.sh47+++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 79 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -7,7 +7,6 @@ test_suite("utils-std commands") basedir = fs.dirname(fs.dirname(current_kyuafile())) -- 9,$|LC_ALL=C.UTF-8 sort -atf_test_program{name="cat", required_files=basedir.."/cmd/cat", timeout=1} atf_test_program{name="df", required_files=basedir.."/cmd/df", timeout=1} atf_test_program{name="id", required_files=basedir.."/cmd/id", timeout=1} atf_test_program{name="link", required_files=basedir.."/cmd/link", timeout=1} @@ -19,6 +18,7 @@ atf_test_program{name="tty", required_files=basedir.."/cmd/tty", timeout=1} tap_test_program{name="arch.sh", required_files=basedir.."/cmd/arch", timeout=1} tap_test_program{name="base64.sh", required_files=basedir.."/cmd/base64", timeout=1} tap_test_program{name="basename.sh", required_files=basedir.."/cmd/basename", timeout=1} +tap_test_program{name="cat.sh", required_files=basedir.."/cmd/cat", timeout=1} tap_test_program{name="chmod.sh", required_files=basedir.."/cmd/chmod", timeout=1} tap_test_program{name="date.sh", required_files=basedir.."/cmd/date", timeout=1} tap_test_program{name="dirname.sh", required_files=basedir.."/cmd/dirname", timeout=1} diff --git a/test-cmd/cat b/test-cmd/cat @@ -1,78 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -atf_test_case allfile -allfile_body() { - atf_check -o file:inputs/all_bytes ../cmd/cat inputs/all_bytes -} - -atf_test_case allinput -allinput_body() { - atf_check -o file:inputs/all_bytes ../cmd/cat <inputs/all_bytes -} - -atf_test_case alldashinput -alldashinput_body() { - atf_check -o file:inputs/all_bytes ../cmd/cat - <inputs/all_bytes -} - -atf_test_case devnull -devnull_body() { - atf_check ../cmd/cat /dev/null - atf_check ../cmd/cat </dev/null - atf_check ../cmd/cat - </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:cat: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/cat 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() { - atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat - <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:cat: Error reading ‘/’: Is a directory\n' ../cmd/cat / -} - -atf_test_case enoent -enoent_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/cat /var/empty/e/no/ent -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o file:inputs/all_bytes -- ../cmd/cat -- inputs/all_bytes - # shellcheck disable=SC1112 - atf_check -s exit:1 -e "inline:cat: Error: Unrecognised option: '--'\nUsage: cat [-u] [files ...]\n" -o empty -- ../cmd/cat --- inputs/all_bytes -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - 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 -} diff --git a/test-cmd/cat.sh b/test-cmd/cat.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +WD="$(dirname "$0")" +target="${WD}/../cmd/cat" +plans=10 +. "$(dirname "$0")/tap.sh" + +t --input='' noargs '' '' + +t --input='foo' stdin '' 'foo' +t --input='foo' stdin_dash '-' 'foo' + +t devnull '/dev/null' '' + +t_file all_bytes "$WD/inputs/all_bytes" "$WD/inputs/all_bytes" + +touch "$WD/inputs/chmod_000" +chmod 0000 "$WD/inputs/chmod_000" +t --exit=1 'noperm' "$WD/inputs/chmod_000" "cat: Error opening ‘$WD/inputs/chmod_000’: Permission denied +" +chmod 0600 "$WD/inputs/chmod_000" +rm "$WD/inputs/chmod_000" + +#atf_test_case devfull +#devfull_body() { +# atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full' +# atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full' +# atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat - <inputs/all_bytes >/dev/full' +#} + +if [ "$(uname -s)" = "NetBSD" ]; then + skip readslash "NetBSD allows to read directories" +else + t --exit=1 readslash / 'cat: Error reading ‘/’: Is a directory +' +fi + +t --exit=1 enoent /var/empty/e/no/ent 'cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory +' + +t_file doubledash "-- $WD/inputs/all_bytes" "$WD/inputs/all_bytes" + +t --exit=1 tripledash "--- $WD/inputs/all_bytes" "cat: Error: Unrecognised option: '--' +Usage: cat [-u] [files ...] +"