logo

utils-std

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

test-cmd/uname: Switch to simple TAP-style runner

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/uname25-------------------------
Atest-cmd/uname.sh45+++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -7,7 +7,7 @@ test_suite("utils-std commands") basedir = fs.dirname(fs.dirname(current_kyuafile())) -- 9,$|LC_ALL=C.UTF-8 sort -atf_test_program{name="uname", required_files=basedir.."/cmd/uname", timeout=1} +tap_test_program{name="uname.sh", required_files=basedir.."/cmd/uname", timeout=1} atf_test_program{name="base64", required_files=basedir.."/cmd/base64", timeout=1} atf_test_program{name="basename", required_files=basedir.."/cmd/basename", timeout=1} atf_test_program{name="cat", required_files=basedir.."/cmd/cat", timeout=1} diff --git a/test-cmd/uname b/test-cmd/uname @@ -1,25 +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 noargs -noargs_body() { - atf_check -o "inline:$(uname -s)\n" ../cmd/uname -} - -atf_test_case all -all_body() { - atf_check -o "inline:$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m)\n" ../cmd/uname -a -} - -atf_test_case sysname -sysname_body() { - atf_check -o "inline:$(uname -s)\n" ../cmd/uname -s -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case noargs - atf_add_test_case all - atf_add_test_case sysname -} diff --git a/test-cmd/uname.sh b/test-cmd/uname.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +uname="$(dirname "$0")/../cmd/uname" + +t () +{ + # $1 -> arguments + # $2 -> expected output + + count=$((count+1)) + out="$("$uname" $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 +} + +has_cmd () +{ + command -v "$@" >/dev/null +} + +skip () +{ + count=$((count+1)) + name="$1" + shift + printf 'ok %s # skip %s\n' "$count $name" "$*" +} + +count=0 + +echo '1..5' + +t '' "$(uname -s)" +t '-s' "$(uname -s)" +t '-a' "$(uname -s) $(uname -n) $(uname -r) $(uname -v) $(uname -m)" +t '-n' "$(hostname)" +if has_cmd arch; then t '-m' "$(arch)"; else skip '-m' "no arch command"; fi