From f022121436164d6ac4ea7f9f2c75dc39c63914cd Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 27 Apr 2024 15:16:52 -0600 Subject: [PATCH] tests: posix: cat(1p): added POSIX-compliant cat --- tests/posix/bin/cat | 22 ++++++++++++++++++++++ tests/posix/{true.sh => bin/false} | 5 ++--- tests/posix/{false.sh => bin/true} | 6 ++---- tests/test.sh | 5 +++-- 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100755 tests/posix/bin/cat rename tests/posix/{true.sh => bin/false} (83%) rename tests/posix/{false.sh => bin/true} (83%) diff --git a/tests/posix/bin/cat b/tests/posix/bin/cat new file mode 100755 index 0000000..e123d7c --- /dev/null +++ b/tests/posix/bin/cat @@ -0,0 +1,22 @@ +#!/bin/sh +# Copyright (c) 2024 Emma Tebibyte +# SPDX-License-Identifier: FSFAP +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice and this +# notice are preserved. This file is offered as-is, without any warranty. + +# Strictly POSIX-compliant cat(1) implementation. See cat(1p) + +for arg in "$@"; do + case "$arg" in + -u) args="$(printf '%s %s\n' "$args" "$arg")" ;; + *) args="$(printf -- '%s -i %s\n' "$args" "$arg")" ;; + esac +done + +# See IEEE Std 1003.1-2017 3.282 +# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282 +IFS=' ' + +mm $args diff --git a/tests/posix/true.sh b/tests/posix/bin/false similarity index 83% rename from tests/posix/true.sh rename to tests/posix/bin/false index a7872fb..62a10c9 100755 --- a/tests/posix/true.sh +++ b/tests/posix/bin/false @@ -7,7 +7,6 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -alias true="$BIN/true" +# Strictly POSIX-compliant false(1) implementation. See false(1p) -true -true -h +false "$@" diff --git a/tests/posix/false.sh b/tests/posix/bin/true similarity index 83% rename from tests/posix/false.sh rename to tests/posix/bin/true index 100b6c1..aed1b86 100755 --- a/tests/posix/false.sh +++ b/tests/posix/bin/true @@ -7,7 +7,5 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -alias false="$BIN/false" - -! false -! false -h +# Strictly POSIX-compliant true(1) implementation. See true(1p) +true "$@" diff --git a/tests/test.sh b/tests/test.sh index de03aa6..7db6d61 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -30,8 +30,9 @@ done printf "Starting POSIX compatibility testing.\n\n" -for utility in tests/posix/*; do - printf '%s: %s: Testing utility.\n' "$0" "$utility" +for test in tests/posix/*.sh; do + export PATH="build/bin:$PATH" + printf '%s: %s: Testing utility.\n' "$0" "$test" "$utility" printf '\n' done