logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 7fffe77b911ba82834257d7c61b60db073419969
parent 907b6082ff1356dbb8b60f83a705897f192ed6dc
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 19 Sep 2024 08:51:08 +0200

test-cmd/tee: Change from atf-sh to tap.sh

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/tee90-------------------------------------------------------------------------------
Atest-cmd/tee.sh42++++++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 91 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -8,7 +8,6 @@ basedir = fs.dirname(fs.dirname(current_kyuafile())) -- 9,$|LC_ALL=C.UTF-8 sort atf_test_program{name="df", required_files=basedir.."/cmd/df", timeout=1} -atf_test_program{name="tee", required_files=basedir.."/cmd/tee", timeout=1} atf_test_program{name="touch", required_files=basedir.."/cmd/touch", timeout=3} 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} @@ -42,6 +41,7 @@ tap_test_program{name="sha1sum.sh", required_files=basedir.."/cmd/sha1sum", time tap_test_program{name="sleep.sh", required_files=basedir.."/cmd/sleep", timeout=1} tap_test_program{name="split.sh", required_files=basedir.."/cmd/split", timeout=1} tap_test_program{name="strings.sh", required_files=basedir.."/cmd/strings", timeout=1} +tap_test_program{name="tee.sh", required_files=basedir.."/cmd/tee", timeout=1} tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2} tap_test_program{name="true.sh", required_files=basedir.."/cmd/true", timeout=1} tap_test_program{name="tty.sh", required_files=basedir.."/cmd/tty", timeout=1} diff --git a/test-cmd/tee b/test-cmd/tee @@ -1,90 +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 allinput -allinput_body() { - atf_check -o file:inputs/all_bytes ../cmd/tee <inputs/all_bytes -} - -atf_test_case writefile cleanup -writefile_body() { - echo 'hello' > tmp_tee.log - atf_check -o file:inputs/all_bytes ../cmd/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 cleanup -appendfile_body() { - echo 'hello' > tmp_tee.log - atf_check -o file:inputs/all_bytes ../cmd/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:tee: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/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_skip "glibc ignoring write errors for fputs()" - [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for fputs()" - [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for fputs()" - - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:tee: Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee <inputs/all_bytes >/dev/full' -} - -atf_test_case nullinput -nullinput_body() { - atf_check ../cmd/tee </dev/null -} - -atf_test_case writeslash -writeslash_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:tee: Error opening ‘./’: Is a directory\n' ../cmd/tee ./ <inputs/all_bytes -} - -atf_test_case enoent -enoent_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:tee: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/tee /var/empty/e/no/ent <inputs/all_bytes -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o file:inputs/all_bytes -- ../cmd/tee -- <inputs/all_bytes - #atf_check -s exit:1 -e 'inline:tee: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/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 -} diff --git a/test-cmd/tee.sh b/test-cmd/tee.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 +WD=$(dirname "$0") +plans=17 +target="${WD}/../cmd/tee" +. "${WD}/tap.sh" + +t_file --infile="${WD}/inputs/all_bytes" all_bytes "${WD}/inputs/all_bytes" + +tmp_writefile="$(mktemp)" +echo hello > "${tmp_writefile}" +t_cmd writefile:grep '' grep -q hello "${tmp_writefile}" +t_file --infile="${WD}/inputs/all_bytes" writefile "${WD}/inputs/all_bytes" "${tmp_writefile}" +t_cmd writefile:cmp '' cmp "${tmp_writefile}" "${WD}/inputs/all_bytes" +t_cmd writefile:rm '' rm "${tmp_writefile}" + +tmp_appendfile="$(mktemp)" +echo hello > "${tmp_appendfile}" +t_file --infile="${WD}/inputs/all_bytes" appendfile "${WD}/inputs/all_bytes" -a "${tmp_appendfile}" +t_cmd writefile:cmp '' cmp "${tmp_appendfile}" "${WD}/outputs/tee/hello_all_bytes" +t_cmd appendfile:rm '' rm "${tmp_appendfile}" + +tmp_noperm="$(mktemp)" +t_cmd noperm:chmod_0000 '' chmod 0000 "${tmp_noperm}" +t --exit=1 noperm "${tmp_noperm}" "tee: Error opening ‘${tmp_noperm}’: Permission denied +" </dev/null +t_cmd noperm:chmod_0600 '' chmod 0600 "${tmp_noperm}" +t_cmd noperm:rm '' rm "${tmp_noperm}" + +t --input='' nullinput + +t --exit=1 --input='foo' writeslash './' 'tee: Error opening ‘./’: Is a directory +' + +t --exit=1 --input='foo' enoent '/var/empty/e/no/ent' 'tee: Error opening ‘/var/empty/e/no/ent’: No such file or directory +' + +t_file --infile="${WD}/inputs/all_bytes" doubledash "${WD}/inputs/all_bytes" -- + +t --exit=1 --input='foo' tripledash '---' "tee: Error: Unrecognised option: '--' +"