logo

utils-std

Collection of commonly available Unix tools
commit: d097ffcc3d4523805037c21ed67813deb1591ccd
parent 4718adb2161ae83f670ed13986bc2427d1fcf444
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  9 Jul 2024 20:35:05 +0200

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

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/id164-------------------------------------------------------------------------------
Atest-cmd/id.sh39+++++++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 165 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="id", required_files=basedir.."/cmd/id", timeout=1} atf_test_program{name="link", required_files=basedir.."/cmd/link", 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} @@ -23,6 +22,7 @@ tap_test_program{name="dirname.sh", required_files=basedir.."/cmd/dirname", time tap_test_program{name="echo.sh", required_files=basedir.."/cmd/echo", timeout=1} tap_test_program{name="env.sh", required_files=basedir.."/cmd/env", timeout=1} tap_test_program{name="false.sh", required_files=basedir.."/cmd/false", timeout=1} +tap_test_program{name="id.sh", required_files=basedir.."/cmd/id", timeout=1} 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} diff --git a/test-cmd/id b/test-cmd/id @@ -1,164 +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 cleanup -noargs_body() { - atf_check -o save:noargs.out ../cmd/id - atf_check grep -q "uid=$(id -u)($(id -un)) gid=$(id -g)($(id -gn)) groups=" noargs.out -} -noargs_cleanup() { - rm -f noargs.out -} - -atf_test_case names cleanup -names_body() { - atf_check -o save:names.out ../cmd/id -n - atf_check grep -q "uid=$(id -un) gid=$(id -gn) groups=" names.out -} -names_cleanup() { - rm -f names.out -} - -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 sh -c '../cmd/id >/dev/full' - atf_check -s exit:1 sh -c '../cmd/id -n >/dev/full' - atf_check -s exit:1 sh -c '../cmd/id -u >/dev/full' - atf_check -s exit:1 sh -c '../cmd/id -g >/dev/full' -} - -atf_test_case group -group_body() { - atf_check -o "inline:$(id -g)\n" ../cmd/id -g - atf_check -o "inline:$(id -gr)\n" ../cmd/id -gr - atf_check -o "inline:$(id -gn)\n" ../cmd/id -gn - atf_check -o "inline:$(id -gnr)\n" ../cmd/id -gnr -} - -atf_test_case user -user_body() { - atf_check -o "inline:$(id -u)\n" ../cmd/id -u - atf_check -o "inline:$(id -ur)\n" ../cmd/id -ur - atf_check -o "inline:$(id -un)\n" ../cmd/id -un - atf_check -o "inline:$(id -unr)\n" ../cmd/id -unr -} - -atf_test_case groups -groups_body() { - # sadly GNU coreutils' id(1) sorts it's grouplist - - atf_check -o not-empty ../cmd/id -G - atf_check -o not-empty ../cmd/id -Gr - atf_check -o not-empty ../cmd/id -Gn - atf_check -o not-empty ../cmd/id -Gnr -} - -# Make sure the correct list is returned for different users -# Previously it would only return the runtime list of the current user -atf_test_case regression_groups -regression_groups() { - atf_check -o "not-inline:$(../cmd/id -G root)" ../cmd/id -G nobody - atf_check -o "not-inline:$(../cmd/id -Gr root)" ../cmd/id -Gr nobody - atf_check -o "not-inline:$(../cmd/id -Gn root)" ../cmd/id -Gn nobody - atf_check -o "not-inline:$(../cmd/id -Gnr root)" ../cmd/id -Gnr nobody -} - -atf_test_case noetc -noetc_body() { - bwrap_args="--bind / / --bind /var/empty /etc" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn -} - -atf_test_case nopasswd -nopasswd_body() { - bwrap_args="--bind / / --bind /dev/null /etc/passwd" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -gn)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn -} - -atf_test_case nogroup -nogroup_body() { - bwrap_args="--bind / / --bind /dev/null /etc/group" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -un)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn -} - -atf_test_case badarg -badarg_body() { - atf_check -s exit:1 -e 'inline:Usage: id [-Ggu] [-nr] [user]\n' ../cmd/id -a -} - -atf_test_case root cleanup -root_body() { - atf_check -o save:root.out ../cmd/id root - atf_check grep -q "uid=$(id -u root)($(id -un root)) gid=$(id -g root)($(id -gn root)) groups=" root.out -} -root_cleanup() { - rm -f root.out -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case devfull - atf_add_test_case badarg - - atf_add_test_case noargs - atf_add_test_case names - atf_add_test_case group - atf_add_test_case user - atf_add_test_case groups - - atf_add_test_case noetc - atf_add_test_case nogroup - atf_add_test_case nopasswd - - atf_add_test_case root -} diff --git a/test-cmd/id.sh b/test-cmd/id.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +target="$(dirname "$0")/../cmd/id" +plans=12 +. "$(dirname "$0")/tap.sh" + +usage='Usage: id [-Ggu] [-nr] [user] +' + +t g -g "$(id -g) +" +t gr -gr "$(id -gr) +" +t gn -gn "$(id -gn) +" +t gnr -gnr "$(id -gnr) +" + +t u -u "$(id -u) +" +t ur -ur "$(id -ur) +" +t un -un "$(id -un) +" +t unr -unr "$(id -unr) +" + +t G -G "$(id -G) +" +# Make sure the correct list is returned for different users +# Previously it would only return the runtime list of the current user +t G_nobody '-G nobody' "$(id -G nobody) +" +t G_root '-G root' "$(id -G root) +" + +t --exit=1 badarg '-a' "${usage}"