logo

utils-std

Collection of commonly available Unix tools
commit: 3c8f7cfac8d96bf51d8caaa445ebd95a54fd85bc
parent ee20ad4bb26661b721d2c758aba535a2c6300ce0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  8 Jul 2024 05:01:05 +0200

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

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/strings123-------------------------------------------------------------------------------
Atest-cmd/strings.sh63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 124 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -10,7 +10,6 @@ basedir = fs.dirname(fs.dirname(current_kyuafile())) 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} -atf_test_program{name="strings", required_files=basedir.."/cmd/strings", 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} atf_test_program{name="tty", required_files=basedir.."/cmd/tty", timeout=1} @@ -27,6 +26,7 @@ tap_test_program{name="false.sh", required_files=basedir.."/cmd/false", timeout= tap_test_program{name="logname.sh", required_files=basedir.."/cmd/logname", timeout=1} tap_test_program{name="pwd.sh", required_files=basedir.."/cmd/pwd", timeout=1} tap_test_program{name="seq.sh", required_files=basedir.."/cmd/seq", timeout=1} +tap_test_program{name="strings.sh", required_files=basedir.."/cmd/strings", 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="uname.sh", required_files=basedir.."/cmd/uname", timeout=1} diff --git a/test-cmd/strings b/test-cmd/strings @@ -1,123 +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 allbytes -allbytes_body() { - atf_check -o file:outputs/strings/all_bytes ../cmd/strings inputs/all_bytes - atf_check -o file:outputs/strings/all_bytes ../cmd/strings <inputs/all_bytes - atf_check -o file:outputs/strings/all_bytes ../cmd/strings - <inputs/all_bytes -} - -atf_test_case trueelf -trueelf_body() { - atf_check -o file:outputs/strings/true ../cmd/strings inputs/strings/true - atf_check -o file:outputs/strings/true ../cmd/strings <inputs/strings/true - atf_check -o file:outputs/strings/true ../cmd/strings - <inputs/strings/true -} - -atf_test_case true8elf -true8elf_body() { - atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 inputs/strings/true - atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 <inputs/strings/true - atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 - <inputs/strings/true -} - -atf_test_case devnull -devnull_body() { - atf_check ../cmd/strings /dev/null - atf_check ../cmd/strings </dev/null - atf_check ../cmd/strings - </dev/null -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_skip "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:strings: Error writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full' -} - -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:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings 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 octalformat -octalformat_body() { - atf_check -o file:outputs/strings/all_bytes_to ../cmd/strings -to inputs/all_bytes - atf_check ../cmd/strings -to /dev/null - atf_check -o file:outputs/strings/true_to ../cmd/strings -to inputs/strings/true - atf_check -o file:outputs/strings/true_8_to ../cmd/strings -to -n 8 inputs/strings/true -} - -atf_test_case hexformat -hexformat_body() { - atf_check -o file:outputs/strings/all_bytes_tx ../cmd/strings -tx inputs/all_bytes - atf_check ../cmd/strings -tx /dev/null - atf_check -o file:outputs/strings/true_tx ../cmd/strings -tx inputs/strings/true - atf_check -o file:outputs/strings/true_8_tx ../cmd/strings -tx -n 8 inputs/strings/true -} - -atf_test_case decformat -decformat_body() { - atf_check -o file:outputs/strings/all_bytes_td ../cmd/strings -td inputs/all_bytes - atf_check ../cmd/strings -td /dev/null - atf_check -o file:outputs/strings/true_td ../cmd/strings -td inputs/strings/true - atf_check -o file:outputs/strings/true_8_td ../cmd/strings -td -n 8 inputs/strings/true -} - -atf_test_case badformat -badformat_body() { - usage="strings: [-a] [-t format] [-n number] [file...]\n" - - atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes - atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null - atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true - atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true -} - -atf_test_case erange_n -erange_n_body() { - usage="strings: [-a] [-t format] [-n number] [file...]\n" - - atf_check -s exit:1 -e "inline:strings: Option \`-n 0\` is too small\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes - atf_check -s exit:1 -e "inline:strings: Option \`-n 4097\` is too large\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes - atf_check -s exit:1 -e "inline:strings: Option \`-n f\`: Invalid argument\n${usage}" -- ../cmd/strings -n f inputs/all_bytes - atf_check -s exit:1 -e "inline:strings: Option \`-n 42f\`: Invalid argument\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes -} - -atf_test_case usage -usage_body() { - atf_check -s exit:1 -e 'inline:strings: [-a] [-t format] [-n number] [file...]\n' ../cmd/strings -t aa inputs/all_bytes -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case allbytes - atf_add_test_case trueelf - atf_add_test_case true8elf - atf_add_test_case devnull - - atf_add_test_case devfull - atf_add_test_case noperm - atf_add_test_case erange_n - - atf_add_test_case octalformat - atf_add_test_case hexformat - atf_add_test_case decformat - atf_add_test_case badformat - - atf_add_test_case usage -} diff --git a/test-cmd/strings.sh b/test-cmd/strings.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +WD="$(dirname "$0")" +target="${WD}/../cmd/strings" +plans=25 +. "$(dirname "$0")/tap.sh" + +usage="strings: [-a] [-t format] [-n number] [file...] +" + +t --exit=1 usage "-t aa $WD/inputs/all_bytes" "${usage}" + +t devnull /dev/null '' + +t_file all_bytes "$WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes" + +t_file trueelf "$WD/inputs/strings/true" "$WD/outputs/strings/true" +t_file true8elf "-n 8 $WD/inputs/strings/true" "$WD/outputs/strings/true_8" + +#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:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings 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" +#} + +t octal:devnull '-to /dev/null' '' +t_file octal:all_bytes "-to $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_to" +t_file octal:trueelf "-to $WD/inputs/strings/true" "$WD/outputs/strings/true_to" +t_file octal:true8elf "-to -n 8 $WD/inputs/strings/true" "$WD/outputs/strings/true_8_to" + +t hex:devnull '-tx /dev/null' '' +t_file hex:all_bytes "-tx $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_tx" +t_file hex:trueelf "-tx $WD/inputs/strings/true" "$WD/outputs/strings/true_tx" +t_file hex:true8elf "-tx -n 8 $WD/inputs/strings/true" "$WD/outputs/strings/true_8_tx" + +t dec:devnull '-td /dev/null' '' +t_file dec:all_bytes "-td $WD/inputs/all_bytes" "$WD/outputs/strings/all_bytes_td" +t_file dec:trueelf "-td $WD/inputs/strings/true" "$WD/outputs/strings/true_td" +t_file dec:true8elf "-td -n 8 $WD/inputs/strings/true" "$WD/outputs/strings/true_8_td" + +fmt_t="strings: Unknown format: t +${usage}" +t --exit=1 fmt_t:devnull '-tt /dev/null' "${fmt_t}" +t --exit=1 fmt_t:all_bytes "-tt $WD/inputs/all_bytes" "${fmt_t}" +t --exit=1 fmt_t:trueelf "-tt $WD/inputs/strings/true" "${fmt_t}" +t --exit=1 fmt_t:true8elf "-tt -n 8 $WD/inputs/strings/true" "${fmt_t}" + +t --exit=1 erange_n:0 "-n 0 $WD/inputs/all_bytes" "strings: Option \`-n 0\` is too small +${usage}" +t --exit=1 erange_n:4097 "-n 4097 $WD/inputs/all_bytes" "strings: Option \`-n 4097\` is too large +${usage}" +t --exit=1 erange_n:f "-n f $WD/inputs/all_bytes" "strings: Option \`-n f\`: Invalid argument +${usage}" +t --exit=1 erange_n:42f "-n 42f $WD/inputs/all_bytes" "strings: Option \`-n 42f\`: Invalid argument +${usage}"