logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 5dcf42f1e671e75464ad466142abb866f446f0cd
parent 47a7619e85eaa5de068dcc35b8b8aa411bd87a90
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 17 Sep 2024 09:12:52 +0200

test-cmd/head: move last remaining cram cases to tap.sh

Diffstat:

Mtest-cmd/head.sh17++++++++++++++++-
Dtest-cmd/head.t19-------------------
Mtest-cmd/tap.sh22+++++++++++++++++++++-
3 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/test-cmd/head.sh b/test-cmd/head.sh @@ -4,7 +4,7 @@ WD="$(dirname "$0")/../" target="${WD}/cmd/head" -plans=12 +plans=15 . "${WD}/test-cmd/tap.sh" t --input="$(seq 1 20)" 20l '' "$(seq 1 10) @@ -37,3 +37,18 @@ t --input='' opt_v '-v -' '==> - <== ' t z3 "-n 3 -z ${WD}/test-cmd/inputs/strings/length" "$(printf '1\0_2\0__3\0')" + +set -o pipefail + +head_40c() { </dev/zero "$target" -c 40 | wc -c; } +t_cmd 40c '40 +' head_40c + +head_40kc() { </dev/zero "$target" -c 40k | wc -c; } +t_cmd 40c '40960 +' head_40kc + +head_40d() { </dev/zero "$target" -c 40d | wc -c; } +t_cmd --exit=1 40d "head: Unrecognised unit 'd' +0 +" head_40d diff --git a/test-cmd/head.t b/test-cmd/head.t @@ -1,19 +0,0 @@ -#!/usr/bin/env cram -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - - $ export PATH="$TESTDIR/../cmd:$PATH" - - $ test "$(command -v head)" = "$TESTDIR/../cmd/head" - - $ set -o pipefail - - $ </dev/zero head -c 40 | wc -c - 40 - $ </dev/zero head -c 40K | wc -c - 40960 - $ </dev/zero head -c 40d | wc -c - head: Unrecognised unit 'd' - 0 - [1] - diff --git a/test-cmd/tap.sh b/test-cmd/tap.sh @@ -156,9 +156,29 @@ t_file() fi } -# t_cmd <test_name> <expected_output> <command> [arguments] +# t_cmd [--exit=n] <test_name> <expected_output> <command> [arguments] t_cmd() { exp_ret=0 + for i; do + case "$i" in + --exit=*) + exp_ret="${i#*=}" + shift + ;; + --) + shift + break + ;; + # Note: * is still a wildcard, even with a range before + -[a-zA-Z0-9]|--[a-zA-Z0-9]*=*) + printf 'Unknown option: %s\n' "$i" + exit 2 + ;; + *) + break + ;; + esac + done name="$1"; shift exp_out="$1"; shift