logo

utils-std

Collection of commonly available Unix tools
commit: eda746388e41126853fc99a03040eafadaaf8b10
parent 284ba88778232bee4d35c214d15e8e445f75abe0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 21 Apr 2024 12:43:14 +0200

test-cmd/seq: Switch to simpler TAP-style runner

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/seq104-------------------------------------------------------------------------------
Atest-cmd/seq.sh56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 57 insertions(+), 105 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -22,7 +22,7 @@ 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="logname", required_files=basedir.."/cmd/logname", timeout=1} atf_test_program{name="pwd", required_files=basedir.."/cmd/pwd", timeout=1} -atf_test_program{name="seq", required_files=basedir.."/cmd/seq", timeout=1} +tap_test_program{name="seq.sh", required_files=basedir.."/cmd/seq", 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} tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2} diff --git a/test-cmd/seq b/test-cmd/seq @@ -1,104 +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 one -one_body() { - atf_check -o "inline:1\n" ../cmd/seq 1 - atf_check -o "inline:1\n2\n3\n4\n5\n" ../cmd/seq 5 - - atf_check -o "inline:1\n0\n-1\n" -- ../cmd/seq -- -1 - atf_check -o "inline:1\n0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq -- -5 -} - -atf_test_case two -two_body() { - atf_check -o "inline:0\n1\n" ../cmd/seq 0 1 - atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../cmd/seq 0 5 - atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../cmd/seq 10 15 - - atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 -1 - atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq 0 -5 - atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../cmd/seq -- -10 -15 - atf_check -o "inline:2\n1\n0\n-1\n-2\n" -- ../cmd/seq 2 -2 - atf_check -o "inline:-2\n-1\n0\n1\n2\n" -- ../cmd/seq -- -2 2 -} - -atf_test_case three -three_body() { - atf_check -o "inline:0\n1\n" ../cmd/seq 0 1 1 - atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../cmd/seq 0 1 5 - atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../cmd/seq 10 1 15 - - atf_check -o "inline:0\n2\n4\n" ../cmd/seq 0 2 5 - atf_check -o "inline:10\n12\n14\n" ../cmd/seq 10 2 15 - - atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 1 -1 - atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq 0 1 -5 - atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../cmd/seq -- -10 1 -15 - - atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 -1 -1 - - atf_check -o "inline:0\n-2\n-4\n" -- ../cmd/seq 0 2 -5 - atf_check -o "inline:-10\n-12\n-14\n" -- ../cmd/seq -- -10 2 -15 -} - -atf_test_case sep -sep_body() { - atf_check -o "inline:1-2-3\n" ../cmd/seq -s - 3 -} - -atf_test_case term -term_body() { - atf_check -o "inline:1-2-3:" ../cmd/seq -s - -t: 3 -} - -atf_test_case noarg -noarg_body() { - atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../cmd/seq -} - -atf_test_case badflag -badflag_body() { - atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../cmd/seq -f -} - -atf_test_case limits -limits_body() { - atf_check ../cmd/seq 9223372036854775806 9223372036854775807 - atf_check -s exit:1 ../cmd/seq 9223372036854775806 9223372036854775808 - - atf_check ../cmd/seq -- -9223372036854775807 -9223372036854775808 - atf_check -s exit:1 ../cmd/seq -- -9223372036854775807 -9223372036854775809 -} - -atf_test_case initial_d -initial_d_body() { - atf_check -e "inline:seq: Warning: Pass -- if the first non-option argument starts with a dash(-)\n" -o "inline:-3\n-2\n-1\n0\n" ../cmd/seq -3 0 -} - -atf_test_case width -width_body() { - atf_check -o "inline:-1\n04\n09\n14\n" ../cmd/seq -w -- -1 5 15 - atf_check -o "inline:-3\n-2\n-1\n00\n" ../cmd/seq -w -- -3 1 0 - atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" ../cmd/seq -w -- -10 1 -15 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case one - atf_add_test_case two - atf_add_test_case three - - atf_add_test_case sep - atf_add_test_case term - - atf_add_test_case noarg - atf_add_test_case badflag - #atf_add_test_case limits - - atf_add_test_case initial_d - - atf_add_test_case width -} diff --git a/test-cmd/seq.sh b/test-cmd/seq.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +seq="$(dirname "$0")/../cmd/seq" + +t () +{ + # $1 -> $test expression + # $2 -> expected output + + count=$((count+1)) + out="$("$seq" -s, -- $1 2>&1)" + ret="$?" + if [ "$?" != 0 ]; then + printf 'not ok %s - %s\n' "$count $1" "$out" + elif [ "$out" != "$2" ]; then + printf 'not ok %s - (%s != %s)\n' "$count $1" "$out" "$2" + else + printf 'ok %s\n' "$count $1" + fi +} + +count=0 + +echo '1..20' + +# One arg +t 1 '1' +t 5 '1,2,3,4,5' +t -1 '1,0,-1' +t -5 '1,0,-1,-2,-3,-4,-5' + +# Two args +t '0 1' '0,1' +t '0 5' '0,1,2,3,4,5' +t '10 15' '10,11,12,13,14,15' +t '2 -2' '2,1,0,-1,-2' +t '-2 2' '-2,-1,0,1,2' + +# Three args +t '0 1 1' '0,1' +t '0 1 5' '0,1,2,3,4,5' +t '10 1 15' '10,11,12,13,14,15' + +t '0 2 5' '0,2,4' +t '10 2 15' '10,12,14' + +t '0 1 -1' '0,-1' +t '0 1 -5' '0,-1,-2,-3,-4,-5' +t '-10 1 -15' '-10,-11,-12,-13,-14,-15' + +t '0 -1 -1' '0,-1' + +t '0 2 -5' '0,-2,-4' +t '-10 2 -15' '-10,-12,-14'