From cabe08bca4a8aeaaf155b7863e85cb8c6cbc6036 Mon Sep 17 00:00:00 2001 From: DTB Date: Thu, 29 Feb 2024 20:33:09 -0700 Subject: [PATCH 01/25] TESTING: start testing document/script --- TESTING | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 TESTING diff --git a/TESTING b/TESTING new file mode 100755 index 0000000..2f92ece --- /dev/null +++ b/TESTING @@ -0,0 +1,74 @@ +#!/bin/sh + +### Overview +# +# Testing is conducted with this script, in the source tree root, using the +# tests in tests/. +# +# Basically, tests follow the format: +# +# - tests/[utility].[number].test +# Test #[number]. This is an executable file (typically a script). +# - tests/[utility].[number].expected +# This is the expected standard output of test #[number]. +# +# This script runs the executable [utility].[number].test and the following +# file is written during testing: +# +# - tests/[utility].[number].output +# The actual standard output from test #[number]. +# +# If the actual standard output from the test differs from the expected +# standard output, the testing ends, showing the difference. + +set -e + +alias emit="printf '%s: %s\n' '$0' \"\$1\"" + +export PATH="$PATH:./build/bin/" + +if strcmp '' "$1"; then + printf 'Usage: %s [utilities...]\n' "$0" >&2 + exit 64 # sysexits.h(3) EX_USAGE +fi + +### Details + +while ! strcmp '' "$1"; do # $1 refers to the given utility + +# Tests are called [utility].[number].test. Tests are numbered from 1 with no +# leading zeroes in the numbers, so (for example) scrut(1)'s first three tests +# are scrut.1.test, scrut.2.test, and scrut.3.test. Tests are run sequentially +# in the numbered order. + + i=1 + while scrut -e "$1.$i.test"; do # $i refers to the test number + emit "$1.$i.test: Running test..." + +# A test is an executable file. This runs each test for given utilities +# and writes the standard output from the test to [utility].[number].output, +# then uses diff(1p) (with the "-u" option) to highlight differences between +# the actual output and the expected output, which is located at +# [utility].[number].expected. If there are no differences none are shown and +# testing continues. + + # $1.$i.test is the same as [utility].[number].test + ./"$1.$i.test" \ + | mm -o "$1.$i.output" -o - \ + | diff -u - "$1.$i.expected" \ + || emit '$1.$i.test: Test passed.\n' + # "set -e" terminates on an unsuccessful exit + +# The ideal output of this script is no output at all and each +# [utility].[number].output written matching its associated +# [utility].[number].expected. + + i=$(rpn 1 "$i" +) + done + + shift +done + +# -- +# This work © 2024 by DTB is licensed under CC BY-SA 4.0. To view a copy of +# this license, visit -- 2.30.2 From f7a74dc430347ae6bec43a1b08f1ad563670a001 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 11 Mar 2024 21:01:29 -0600 Subject: [PATCH 02/25] Testfile --- Makefile | 2 ++ TESTING | 74 ----------------------------------------------------- Testfile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 74 deletions(-) delete mode 100755 TESTING create mode 100755 Testfile diff --git a/Makefile b/Makefile index f181e20..494f0f7 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ PREFIX=/usr/local CC=cc +MAKE=make RUSTC=rustc .PHONY: all @@ -42,6 +43,7 @@ install: dist test: build tests/posix-compat.sh $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt + $(MAKE) -f Testfile build/o/libsysexits.rlib: build # bandage solution until bindgen(1) gets stdin support diff --git a/TESTING b/TESTING deleted file mode 100755 index 2f92ece..0000000 --- a/TESTING +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh - -### Overview -# -# Testing is conducted with this script, in the source tree root, using the -# tests in tests/. -# -# Basically, tests follow the format: -# -# - tests/[utility].[number].test -# Test #[number]. This is an executable file (typically a script). -# - tests/[utility].[number].expected -# This is the expected standard output of test #[number]. -# -# This script runs the executable [utility].[number].test and the following -# file is written during testing: -# -# - tests/[utility].[number].output -# The actual standard output from test #[number]. -# -# If the actual standard output from the test differs from the expected -# standard output, the testing ends, showing the difference. - -set -e - -alias emit="printf '%s: %s\n' '$0' \"\$1\"" - -export PATH="$PATH:./build/bin/" - -if strcmp '' "$1"; then - printf 'Usage: %s [utilities...]\n' "$0" >&2 - exit 64 # sysexits.h(3) EX_USAGE -fi - -### Details - -while ! strcmp '' "$1"; do # $1 refers to the given utility - -# Tests are called [utility].[number].test. Tests are numbered from 1 with no -# leading zeroes in the numbers, so (for example) scrut(1)'s first three tests -# are scrut.1.test, scrut.2.test, and scrut.3.test. Tests are run sequentially -# in the numbered order. - - i=1 - while scrut -e "$1.$i.test"; do # $i refers to the test number - emit "$1.$i.test: Running test..." - -# A test is an executable file. This runs each test for given utilities -# and writes the standard output from the test to [utility].[number].output, -# then uses diff(1p) (with the "-u" option) to highlight differences between -# the actual output and the expected output, which is located at -# [utility].[number].expected. If there are no differences none are shown and -# testing continues. - - # $1.$i.test is the same as [utility].[number].test - ./"$1.$i.test" \ - | mm -o "$1.$i.output" -o - \ - | diff -u - "$1.$i.expected" \ - || emit '$1.$i.test: Test passed.\n' - # "set -e" terminates on an unsuccessful exit - -# The ideal output of this script is no output at all and each -# [utility].[number].output written matching its associated -# [utility].[number].expected. - - i=$(rpn 1 "$i" +) - done - - shift -done - -# -- -# This work © 2024 by DTB is licensed under CC BY-SA 4.0. To view a copy of -# this license, visit diff --git a/Testfile b/Testfile new file mode 100755 index 0000000..6b0ed42 --- /dev/null +++ b/Testfile @@ -0,0 +1,77 @@ +# Copyright (c) 2024 DTB +# 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. + +BIN = build/bin +MAKE = make -B + +DEFENDANTS = dj false intcmp strcmp true +.PHONY: all $(DEFENDANTS) +all: $(DEFENDANTS) + +$(BIN)/dj: + $(MAKE) dj + +$(BIN)/false: + $(MAKE) false + +$(BIN)/intcmp: + $(MAKE) intcmp + +$(BIN)/strcmp + $(MAKE) strcmp + +$(BIN)/true: + $(MAKE) true + +dj: $(BIN)/dj $(BIN)/strcmp + sh -c "! $(BIN)/dj -h" + # This test is theoretically Linux-dependent; write(2) should return -1 on + # error. + # Right now dj(1) interprets the return value of write(2) as the amount of + # bytes written. This can decrement the stored quantity of bytes written, + # which is an int, so doesn't underflow but goes negative. dj(1) tries to + # again to write(2) if an error occurs in which no bytes are written, so in + # total two write(2)s are attempted and so the written byte quantity is -2. + # This is a bug and will change, but for now is at least documented. + sh -ec "\ + $(BIN)/dj -Hi /dev/zero -o /dev/full \ + | xargs -I out $(BIN)/strcmp '1+0 > 0+0; 1024 > -2' out" + # Read nothing from /dev/null, write nothing to /dev/null. + sh -ec "\ + $(BIN)/dj -Hi /dev/null -o /dev/null \ + | xargs -I out $(BIN)/strcmp '0+0 > 0+0; 0 > 0' out" + +false: $(BIN)/false + sh -c "! $(BIN)/false" + sh -c "! $(BIN)/false -h" + +intcmp: $(BIN)/intcmp + intcmp -e 3 3 3 + intcmp -g 3 2 1 + intcmp -l 1 2 3 + intcmp -ge 3 3 1 + intcmp -le 1 3 3 + intcmp -gl 1 2 3 + intcmp -egl 3 1 1 2 + sh -c "! intcmp -e 1 2 3" + sh -c "! intcmp -g 1 3 3" + sh -c "! intcmp -l 3 3 1" + sh -c "! intcmp -ge 1 2 3" + sh -c "! intcmp -le 3 2 1" + sh -c "! intcmp -gl 3 3 3" + sh -c "! intcmp -egl foo" + +strcmp: $(BIN)/strcmp + $(BIN)/strcmp equals equals + sh -c "! $(BIN)/strcmp inequals equals" + $(BIN)/strcmp - - + sh -c "! $(BIN)/strcmp -h" + sh -c "! $(BIN)/strcmp nocmp" + +true: + $(BIN)/true + $(BIN)/true -h -- 2.30.2 From 417d7ca40555b67f3051bde9e06b653df305eb58 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 11 Mar 2024 21:03:53 -0600 Subject: [PATCH 03/25] Testfile: fix syntax --- Testfile | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Testfile b/Testfile index 6b0ed42..d921451 100755 --- a/Testfile +++ b/Testfile @@ -21,7 +21,7 @@ $(BIN)/false: $(BIN)/intcmp: $(MAKE) intcmp -$(BIN)/strcmp +$(BIN)/strcmp: $(MAKE) strcmp $(BIN)/true: @@ -50,20 +50,20 @@ false: $(BIN)/false sh -c "! $(BIN)/false -h" intcmp: $(BIN)/intcmp - intcmp -e 3 3 3 - intcmp -g 3 2 1 - intcmp -l 1 2 3 - intcmp -ge 3 3 1 - intcmp -le 1 3 3 - intcmp -gl 1 2 3 - intcmp -egl 3 1 1 2 - sh -c "! intcmp -e 1 2 3" - sh -c "! intcmp -g 1 3 3" - sh -c "! intcmp -l 3 3 1" - sh -c "! intcmp -ge 1 2 3" - sh -c "! intcmp -le 3 2 1" - sh -c "! intcmp -gl 3 3 3" - sh -c "! intcmp -egl foo" + $(BIN)/intcmp -e 3 3 3 + $(BIN)/intcmp -g 3 2 1 + $(BIN)/intcmp -l 1 2 3 + $(BIN)/intcmp -ge 3 3 1 + $(BIN)/intcmp -le 1 3 3 + $(BIN)/intcmp -gl 1 2 3 + $(BIN)/intcmp -egl 3 1 1 2 + sh -c "! $(BIN)/intcmp -e 1 2 3" + sh -c "! $(BIN)/intcmp -g 1 3 3" + sh -c "! $(BIN)/intcmp -l 3 3 1" + sh -c "! $(BIN)/intcmp -ge 1 2 3" + sh -c "! $(BIN)/intcmp -le 3 2 1" + sh -c "! $(BIN)/intcmp -gl 3 3 3" + sh -c "! $(BIN)/intcmp -egl foo" strcmp: $(BIN)/strcmp $(BIN)/strcmp equals equals -- 2.30.2 From e7021e127ce1ea456de46a259d9cceed58f684ef Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 13 Mar 2024 18:20:30 -0600 Subject: [PATCH 04/25] Testfile: make non-executable --- Testfile | 1 + 1 file changed, 1 insertion(+) mode change 100755 => 100644 Testfile diff --git a/Testfile b/Testfile old mode 100755 new mode 100644 index d921451..e2cc294 --- a/Testfile +++ b/Testfile @@ -1,3 +1,4 @@ +#!/usr/bin/env make # Copyright (c) 2024 DTB # SPDX-License-Identifier: FSFAP # -- 2.30.2 From 057f5571d6708a964e2b6cc60e10ff76d132cf92 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 14:58:35 -0600 Subject: [PATCH 05/25] moved tests into test directory --- Makefile | 5 +- Testfile | 78 ------------------------------ tests/bonsai/dj.sh | 25 ++++++++++ tests/bonsai/false.sh | 11 +++++ tests/bonsai/intcmp.sh | 23 +++++++++ tests/bonsai/strcmp.sh | 14 ++++++ tests/bonsai/true.sh | 11 +++++ tests/posix/false.sh | 13 +++++ tests/posix/true.sh | 13 +++++ tests/{posix-compat.sh => test.sh} | 23 ++++++++- 10 files changed, 134 insertions(+), 82 deletions(-) delete mode 100644 Testfile create mode 100755 tests/bonsai/dj.sh create mode 100755 tests/bonsai/false.sh create mode 100755 tests/bonsai/intcmp.sh create mode 100755 tests/bonsai/strcmp.sh create mode 100755 tests/bonsai/true.sh create mode 100755 tests/posix/false.sh create mode 100755 tests/posix/true.sh rename tests/{posix-compat.sh => test.sh} (55%) diff --git a/Makefile b/Makefile index 494f0f7..03f68fd 100644 --- a/Makefile +++ b/Makefile @@ -40,10 +40,9 @@ install: dist cp -r dist/* $(PREFIX)/ .PHONY: test -test: build - tests/posix-compat.sh +test: all + tests/test.sh $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt - $(MAKE) -f Testfile build/o/libsysexits.rlib: build # bandage solution until bindgen(1) gets stdin support diff --git a/Testfile b/Testfile deleted file mode 100644 index e2cc294..0000000 --- a/Testfile +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env make -# Copyright (c) 2024 DTB -# 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. - -BIN = build/bin -MAKE = make -B - -DEFENDANTS = dj false intcmp strcmp true -.PHONY: all $(DEFENDANTS) -all: $(DEFENDANTS) - -$(BIN)/dj: - $(MAKE) dj - -$(BIN)/false: - $(MAKE) false - -$(BIN)/intcmp: - $(MAKE) intcmp - -$(BIN)/strcmp: - $(MAKE) strcmp - -$(BIN)/true: - $(MAKE) true - -dj: $(BIN)/dj $(BIN)/strcmp - sh -c "! $(BIN)/dj -h" - # This test is theoretically Linux-dependent; write(2) should return -1 on - # error. - # Right now dj(1) interprets the return value of write(2) as the amount of - # bytes written. This can decrement the stored quantity of bytes written, - # which is an int, so doesn't underflow but goes negative. dj(1) tries to - # again to write(2) if an error occurs in which no bytes are written, so in - # total two write(2)s are attempted and so the written byte quantity is -2. - # This is a bug and will change, but for now is at least documented. - sh -ec "\ - $(BIN)/dj -Hi /dev/zero -o /dev/full \ - | xargs -I out $(BIN)/strcmp '1+0 > 0+0; 1024 > -2' out" - # Read nothing from /dev/null, write nothing to /dev/null. - sh -ec "\ - $(BIN)/dj -Hi /dev/null -o /dev/null \ - | xargs -I out $(BIN)/strcmp '0+0 > 0+0; 0 > 0' out" - -false: $(BIN)/false - sh -c "! $(BIN)/false" - sh -c "! $(BIN)/false -h" - -intcmp: $(BIN)/intcmp - $(BIN)/intcmp -e 3 3 3 - $(BIN)/intcmp -g 3 2 1 - $(BIN)/intcmp -l 1 2 3 - $(BIN)/intcmp -ge 3 3 1 - $(BIN)/intcmp -le 1 3 3 - $(BIN)/intcmp -gl 1 2 3 - $(BIN)/intcmp -egl 3 1 1 2 - sh -c "! $(BIN)/intcmp -e 1 2 3" - sh -c "! $(BIN)/intcmp -g 1 3 3" - sh -c "! $(BIN)/intcmp -l 3 3 1" - sh -c "! $(BIN)/intcmp -ge 1 2 3" - sh -c "! $(BIN)/intcmp -le 3 2 1" - sh -c "! $(BIN)/intcmp -gl 3 3 3" - sh -c "! $(BIN)/intcmp -egl foo" - -strcmp: $(BIN)/strcmp - $(BIN)/strcmp equals equals - sh -c "! $(BIN)/strcmp inequals equals" - $(BIN)/strcmp - - - sh -c "! $(BIN)/strcmp -h" - sh -c "! $(BIN)/strcmp nocmp" - -true: - $(BIN)/true - $(BIN)/true -h diff --git a/tests/bonsai/dj.sh b/tests/bonsai/dj.sh new file mode 100755 index 0000000..be5ca49 --- /dev/null +++ b/tests/bonsai/dj.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +! dj -h + +# This test is theoretically Linux-dependent; write(2) should return -1 on +# error. +# Right now dj(1) interprets the return value of write(2) as the amount of +# bytes written. This can decrement the stored quantity of bytes written, +# which is an int, so doesn't underflow but goes negative. dj(1) tries to +# again to write(2) if an error occurs in which no bytes are written, so in +# total two write(2)s are attempted and so the written byte quantity is -2. +# This is a bug and will change, but for now is at least documented. +dj -Hi /dev/zero -o /dev/full \ + | xargs -I out "$BIN/strcmp" '1+0 > 0+0; 1024 > -2' out + +# Read nothing from /dev/null, write nothing to /dev/null. +dj -Hi /dev/null -o /dev/null \ + | xargs -I out "$BIN/strcmp" '0+0 > 0+0; 0 > 0' out diff --git a/tests/bonsai/false.sh b/tests/bonsai/false.sh new file mode 100755 index 0000000..670feba --- /dev/null +++ b/tests/bonsai/false.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +! false +! false -h diff --git a/tests/bonsai/intcmp.sh b/tests/bonsai/intcmp.sh new file mode 100755 index 0000000..7acb28a --- /dev/null +++ b/tests/bonsai/intcmp.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +intcmp -e 3 3 3 +intcmp -g 3 2 1 +intcmp -l 1 2 3 +intcmp -ge 3 3 1 +intcmp -le 1 3 3 +intcmp -gl 1 2 3 +intcmp -egl 3 1 1 2 +! intcmp -e 1 2 3 +! intcmp -g 1 3 3 +! intcmp -l 3 3 1 +! intcmp -ge 1 2 3 +! intcmp -le 3 2 1 +! intcmp -gl 3 3 3 +! intcmp -egl foo diff --git a/tests/bonsai/strcmp.sh b/tests/bonsai/strcmp.sh new file mode 100755 index 0000000..82f2781 --- /dev/null +++ b/tests/bonsai/strcmp.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +strcmp equals equals +! strcmp inequals equals +strcmp - - +strcmp -h +! strcmp nocmp diff --git a/tests/bonsai/true.sh b/tests/bonsai/true.sh new file mode 100755 index 0000000..e8ed913 --- /dev/null +++ b/tests/bonsai/true.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +true +true -h diff --git a/tests/posix/false.sh b/tests/posix/false.sh new file mode 100755 index 0000000..100b6c1 --- /dev/null +++ b/tests/posix/false.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +alias false="$BIN/false" + +! false +! false -h diff --git a/tests/posix/true.sh b/tests/posix/true.sh new file mode 100755 index 0000000..a7872fb --- /dev/null +++ b/tests/posix/true.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +alias true="$BIN/true" + +true +true -h diff --git a/tests/posix-compat.sh b/tests/test.sh similarity index 55% rename from tests/posix-compat.sh rename to tests/test.sh index 1e98d7b..faaae5e 100755 --- a/tests/posix-compat.sh +++ b/tests/test.sh @@ -9,13 +9,34 @@ set -e +export BIN=build/bin + if ! ls Makefile >/dev/null 2>&1 then printf '%s: Run this script in the root of the project.\n' "$0" 1>&2 exit 1 fi -printf "Starting POSIX compatibility testing.\n" +printf "Starting Bonsai testing.\n\n" + +for script in tests/bonsai/*.sh; do + export UTIL="$(printf '%s\n' "$script" \ + | sed -e 's/\.sh//g' -e 's;tests\/bonsai\/;;g')" + + alias "$UTIL"="$BIN/$UTIL" + + printf '%s: %s: Testing utility.\n' "$0" "$UTIL" + "$script" + printf '\n' +done + +if ! ls Makefile >/dev/null 2>&1 +then + printf '%s: Run this script in the root of the project.\n' "$0" 1>&2 + exit 1 +fi + +printf "Starting POSIX compatibility testing.\n\n" for utility in tests/posix/*; do printf '%s: %s: Testing utility.\n' "$0" "$utility" -- 2.30.2 From aefa87d9e5d3d4daf4544dddb6dfc16796c953d5 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:22:07 -0600 Subject: [PATCH 06/25] tests: fixed aliasing and created mm.sh --- tests/bonsai/aliases | 3 +++ tests/bonsai/dj.sh | 2 ++ tests/bonsai/false.sh | 2 ++ tests/bonsai/intcmp.sh | 2 ++ tests/bonsai/mm.sh | 20 ++++++++++++++++++++ tests/bonsai/strcmp.sh | 2 ++ tests/bonsai/true.sh | 2 ++ tests/test.sh | 2 -- 8 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/bonsai/aliases create mode 100755 tests/bonsai/mm.sh diff --git a/tests/bonsai/aliases b/tests/bonsai/aliases new file mode 100644 index 0000000..f7dfb28 --- /dev/null +++ b/tests/bonsai/aliases @@ -0,0 +1,3 @@ +#!/bin/sh + +alias "$UTIL=$BIN/$UTIL" diff --git a/tests/bonsai/dj.sh b/tests/bonsai/dj.sh index be5ca49..eaefaa9 100755 --- a/tests/bonsai/dj.sh +++ b/tests/bonsai/dj.sh @@ -7,6 +7,8 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +. tests/bonsai/aliases + ! dj -h # This test is theoretically Linux-dependent; write(2) should return -1 on diff --git a/tests/bonsai/false.sh b/tests/bonsai/false.sh index 670feba..6098b4f 100755 --- a/tests/bonsai/false.sh +++ b/tests/bonsai/false.sh @@ -7,5 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +. tests/bonsai/aliases + ! false ! false -h diff --git a/tests/bonsai/intcmp.sh b/tests/bonsai/intcmp.sh index 7acb28a..c566877 100755 --- a/tests/bonsai/intcmp.sh +++ b/tests/bonsai/intcmp.sh @@ -7,6 +7,8 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +. tests/bonsai/aliases + intcmp -e 3 3 3 intcmp -g 3 2 1 intcmp -l 1 2 3 diff --git a/tests/bonsai/mm.sh b/tests/bonsai/mm.sh new file mode 100755 index 0000000..3ef1f99 --- /dev/null +++ b/tests/bonsai/mm.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +. tests/bonsai/aliases + +exec 3>&1 + +! mm -h + +# mm(1) will error if positional arguments are given without -i or -o +! mm argument + +# check if stderr is empty upon specifying -e +! "$BIN/strcmp" "$(printf 'test\n' | mm -i - -e 2>&1 1>&3)" '' diff --git a/tests/bonsai/strcmp.sh b/tests/bonsai/strcmp.sh index 82f2781..9c7ceb0 100755 --- a/tests/bonsai/strcmp.sh +++ b/tests/bonsai/strcmp.sh @@ -7,6 +7,8 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +. tests/bonsai/aliases + strcmp equals equals ! strcmp inequals equals strcmp - - diff --git a/tests/bonsai/true.sh b/tests/bonsai/true.sh index e8ed913..39d3d53 100755 --- a/tests/bonsai/true.sh +++ b/tests/bonsai/true.sh @@ -7,5 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +. tests/bonsai/aliases + true true -h diff --git a/tests/test.sh b/tests/test.sh index faaae5e..b439464 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -23,8 +23,6 @@ for script in tests/bonsai/*.sh; do export UTIL="$(printf '%s\n' "$script" \ | sed -e 's/\.sh//g' -e 's;tests\/bonsai\/;;g')" - alias "$UTIL"="$BIN/$UTIL" - printf '%s: %s: Testing utility.\n' "$0" "$UTIL" "$script" printf '\n' -- 2.30.2 From 28f2d44e2fdd1def42dfaed25660452340451b5c Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:24:35 -0600 Subject: [PATCH 07/25] CONTRIBUTING: updated to include docs and tests requirement --- CONTRIBUTING | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING b/CONTRIBUTING index d7fdc8e..b7ad7a8 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -97,9 +97,10 @@ their editor or terminal. For usage text and help messages, do not implement a -h option. Instead, print usage information when any erroneous option is specified. Follow the NetBSD -style guide for the usage text’s output format [1]. +style guide for the usage text’s output format [0]. -[1] +If committing a new utility, please include tests and documentation (see +tests/ and docs/) for the new tool. If committing a new source file, format the commit message following these guidelines: @@ -128,6 +129,7 @@ $ git commit -m 'tool(1): fix #42 & add feature x' Commit messages should be written in the present tense. +[0] -- This work © 2023–2024 by Emma Tebibyte is licensed under CC BY-SA 4.0. To view a copy of this license, visit -- 2.30.2 From 3398fc372cfaa930dc22d0ac179733c47ae289f4 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:33:17 -0600 Subject: [PATCH 08/25] tests: bonsai: mm.sh: fixed copyright --- tests/bonsai/mm.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bonsai/mm.sh b/tests/bonsai/mm.sh index 3ef1f99..686ad1a 100755 --- a/tests/bonsai/mm.sh +++ b/tests/bonsai/mm.sh @@ -1,5 +1,4 @@ #!/bin/sh -# Copyright (c) 2024 DTB # Copyright (c) 2024 Emma Tebibyte # SPDX-License-Identifier: FSFAP # -- 2.30.2 From c6f30c419581b06099950b952b31d3480b146e52 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 19:25:55 -0600 Subject: [PATCH 09/25] tests: bonsai: fop.sh: added test --- tests/bonsai/fop.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 tests/bonsai/fop.sh diff --git a/tests/bonsai/fop.sh b/tests/bonsai/fop.sh new file mode 100755 index 0000000..2a4e4a9 --- /dev/null +++ b/tests/bonsai/fop.sh @@ -0,0 +1,21 @@ +#!/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. + +. tests/bonsai/aliases + +! fop -h + +"$BIN/strcmp" "$(printf 'test0␞test1␞test2\n' | fop 1 sed 's/1/4/g')" \ + 'test0␞test4␞test2' + +"$BIN/strcmp" "$(printf 'test0 test1 test2\n' | fop -d' ' 2 sed 's/2/4/g')" \ + 'test0 test1 test4' + +! printf 'test\n' | fop 1 cat +! printf 'test\n' | fop 'test' cat +! printf 'test\n' | fop -d'test' cat -- 2.30.2 From 1aa2b596d0003f00b0ea7a7b7c31a2f473696429 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 19:28:33 -0600 Subject: [PATCH 10/25] tests: aliases: added set -x --- tests/bonsai/aliases | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bonsai/aliases b/tests/bonsai/aliases index f7dfb28..a3d07ca 100644 --- a/tests/bonsai/aliases +++ b/tests/bonsai/aliases @@ -1,3 +1,5 @@ #!/bin/sh +set -x + alias "$UTIL=$BIN/$UTIL" -- 2.30.2 From 0113cf793de13298f6ec7986b43cb6a639289e18 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 17:20:55 -0600 Subject: [PATCH 11/25] tests: bonsai: hru.sh: adds test --- tests/bonsai/hru.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/bonsai/hru.sh diff --git a/tests/bonsai/hru.sh b/tests/bonsai/hru.sh new file mode 100755 index 0000000..fd59e69 --- /dev/null +++ b/tests/bonsai/hru.sh @@ -0,0 +1,26 @@ +#!/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. + +. tests/bonsai/aliases + +alias strcmp="$BIN/strcmp" +alias rpn="$BIN/rpn" + +strcmp "$(printf '1234\n' | hru)" '1.2 kB' +strcmp "$(printf '0\n' | hru)" '0 B' + +# doesn’t currently work but would be useful for testing for regressions +#n=1 +#while "$BIN/true"; do +# n="$(rpn "$n" 10 ×)" +# +# printf '%s\n' "$n" | hru || break +#done +#printf 'integer limit: ~%s\n' "$(rpn "$n" 10 ÷)" + +! printf '%s\n' '-1' | hru -- 2.30.2 From 4ad9e0da92cc43f0663dbb36230c06dec8cb8f52 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 18:57:05 -0600 Subject: [PATCH 12/25] tests: bonsai: rename aliases sourced script to test_env --- tests/bonsai/dj.sh | 2 +- tests/bonsai/false.sh | 2 +- tests/bonsai/fop.sh | 2 +- tests/bonsai/hru.sh | 2 +- tests/bonsai/intcmp.sh | 2 +- tests/bonsai/mm.sh | 2 +- tests/bonsai/strcmp.sh | 2 +- tests/bonsai/{aliases => test_env} | 0 tests/bonsai/true.sh | 2 +- 9 files changed, 8 insertions(+), 8 deletions(-) rename tests/bonsai/{aliases => test_env} (100%) diff --git a/tests/bonsai/dj.sh b/tests/bonsai/dj.sh index eaefaa9..8016ec3 100755 --- a/tests/bonsai/dj.sh +++ b/tests/bonsai/dj.sh @@ -7,7 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env ! dj -h diff --git a/tests/bonsai/false.sh b/tests/bonsai/false.sh index 6098b4f..3ad0e94 100755 --- a/tests/bonsai/false.sh +++ b/tests/bonsai/false.sh @@ -7,7 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env ! false ! false -h diff --git a/tests/bonsai/fop.sh b/tests/bonsai/fop.sh index 2a4e4a9..2cb2533 100755 --- a/tests/bonsai/fop.sh +++ b/tests/bonsai/fop.sh @@ -6,7 +6,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env ! fop -h diff --git a/tests/bonsai/hru.sh b/tests/bonsai/hru.sh index fd59e69..51bf7c1 100755 --- a/tests/bonsai/hru.sh +++ b/tests/bonsai/hru.sh @@ -6,7 +6,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env alias strcmp="$BIN/strcmp" alias rpn="$BIN/rpn" diff --git a/tests/bonsai/intcmp.sh b/tests/bonsai/intcmp.sh index c566877..e3cdcb7 100755 --- a/tests/bonsai/intcmp.sh +++ b/tests/bonsai/intcmp.sh @@ -7,7 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env intcmp -e 3 3 3 intcmp -g 3 2 1 diff --git a/tests/bonsai/mm.sh b/tests/bonsai/mm.sh index 686ad1a..43f3a1c 100755 --- a/tests/bonsai/mm.sh +++ b/tests/bonsai/mm.sh @@ -6,7 +6,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env exec 3>&1 diff --git a/tests/bonsai/strcmp.sh b/tests/bonsai/strcmp.sh index 9c7ceb0..018cee2 100755 --- a/tests/bonsai/strcmp.sh +++ b/tests/bonsai/strcmp.sh @@ -7,7 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env strcmp equals equals ! strcmp inequals equals diff --git a/tests/bonsai/aliases b/tests/bonsai/test_env similarity index 100% rename from tests/bonsai/aliases rename to tests/bonsai/test_env diff --git a/tests/bonsai/true.sh b/tests/bonsai/true.sh index 39d3d53..413d758 100755 --- a/tests/bonsai/true.sh +++ b/tests/bonsai/true.sh @@ -7,7 +7,7 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. -. tests/bonsai/aliases +. tests/bonsai/test_env true true -h -- 2.30.2 From e278307dafe4b2cabf37b4b325037acbd8e46afd Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 26 Apr 2024 20:55:16 -0600 Subject: [PATCH 13/25] tests: bonsai: removed redundant code --- tests/test.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index b439464..de03aa6 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -28,12 +28,6 @@ for script in tests/bonsai/*.sh; do printf '\n' done -if ! ls Makefile >/dev/null 2>&1 -then - printf '%s: Run this script in the root of the project.\n' "$0" 1>&2 - exit 1 -fi - printf "Starting POSIX compatibility testing.\n\n" for utility in tests/posix/*; do -- 2.30.2 From f022121436164d6ac4ea7f9f2c75dc39c63914cd Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 27 Apr 2024 15:16:52 -0600 Subject: [PATCH 14/25] 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 -- 2.30.2 From e02884482539cee25d7f2b071f4a1bb2d534f5a6 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 27 Apr 2024 15:18:09 -0600 Subject: [PATCH 15/25] tests: test.sh: utilize $BIN --- tests/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 7db6d61..bec71ff 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -31,7 +31,7 @@ done printf "Starting POSIX compatibility testing.\n\n" for test in tests/posix/*.sh; do - export PATH="build/bin:$PATH" + export PATH="$BIN:$PATH" printf '%s: %s: Testing utility.\n' "$0" "$test" "$utility" printf '\n' -- 2.30.2 From 8508479a5b0e76aee6ce99999dcacaa093dedf10 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:07:17 -0600 Subject: [PATCH 16/25] tests: test.sh: remove superfluous printing of test category --- tests/test.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index bec71ff..43f6eb8 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -17,8 +17,6 @@ then exit 1 fi -printf "Starting Bonsai testing.\n\n" - for script in tests/bonsai/*.sh; do export UTIL="$(printf '%s\n' "$script" \ | sed -e 's/\.sh//g' -e 's;tests\/bonsai\/;;g')" @@ -28,8 +26,6 @@ for script in tests/bonsai/*.sh; do printf '\n' done -printf "Starting POSIX compatibility testing.\n\n" - for test in tests/posix/*.sh; do export PATH="$BIN:$PATH" printf '%s: %s: Testing utility.\n' "$0" "$test" -- 2.30.2 From 9bfc5876238d6808a8a0ed0581c9ff3d0a846571 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:12:54 -0600 Subject: [PATCH 17/25] tests: posix: add environment script for sourcing in tests --- tests/posix/posix_env | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/posix/posix_env diff --git a/tests/posix/posix_env b/tests/posix/posix_env new file mode 100644 index 0000000..56c5701 --- /dev/null +++ b/tests/posix/posix_env @@ -0,0 +1,3 @@ +#!/bin/sh + +PATH="$PWD/bin:$PATH" -- 2.30.2 From 94ada03ce4a6624e3430091a805e131f0f35941b Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:17:30 -0600 Subject: [PATCH 18/25] tests: adds easy localization --- tests/locales/en_US.UTF-8 | 4 ++++ tests/test.sh | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/locales/en_US.UTF-8 diff --git a/tests/locales/en_US.UTF-8 b/tests/locales/en_US.UTF-8 new file mode 100644 index 0000000..95e2efb --- /dev/null +++ b/tests/locales/en_US.UTF-8 @@ -0,0 +1,4 @@ +#!/bin/sh + +export RUN_ERR='Run this script in the root of the project' +export TEST_STR='Testing utility' diff --git a/tests/test.sh b/tests/test.sh index 43f6eb8..47a57a3 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -9,11 +9,13 @@ set -e +. "./locales/$LANG" + export BIN=build/bin if ! ls Makefile >/dev/null 2>&1 then - printf '%s: Run this script in the root of the project.\n' "$0" 1>&2 + printf '%s: %s.\n' "$0" "$RUN_ERR" 1>&2 exit 1 fi @@ -21,7 +23,7 @@ for script in tests/bonsai/*.sh; do export UTIL="$(printf '%s\n' "$script" \ | sed -e 's/\.sh//g' -e 's;tests\/bonsai\/;;g')" - printf '%s: %s: Testing utility.\n' "$0" "$UTIL" + printf '%s: %s: %s\n' "$0" "$UTIL" "$TEST_STR" "$script" printf '\n' done -- 2.30.2 From 787f0dc6e2d6b7cf3318fa22d46b17b8cd6f6a20 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:23:49 -0600 Subject: [PATCH 19/25] tests: test.sh: actually includes localization variables --- tests/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 47a57a3..0d39dff 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -15,7 +15,7 @@ export BIN=build/bin if ! ls Makefile >/dev/null 2>&1 then - printf '%s: %s.\n' "$0" "$RUN_ERR" 1>&2 + printf '%s: %s\n' "$0" "$RUN_ERR" 1>&2 exit 1 fi @@ -30,7 +30,7 @@ done for test in tests/posix/*.sh; do export PATH="$BIN:$PATH" - printf '%s: %s: Testing utility.\n' "$0" "$test" + printf '%s: %s: %s\n' "$0" "$test" "$TEST_STR" "$utility" printf '\n' done -- 2.30.2 From 406feb3dc7bea899da4bcb97846d58bc89d06eb1 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:37:15 -0600 Subject: [PATCH 20/25] tests: test.sh: fixes locales when run from root of project --- tests/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 0d39dff..61bb814 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -9,7 +9,7 @@ set -e -. "./locales/$LANG" +. "tests/locales/$LANG" export BIN=build/bin -- 2.30.2 From c88c41b21370a1866b3a2324a0c79f5bb208e06e Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 20:14:06 -0600 Subject: [PATCH 21/25] tests: adds toki pona locale --- tests/locales/tok | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/locales/tok diff --git a/tests/locales/tok b/tests/locales/tok new file mode 100644 index 0000000..7770742 --- /dev/null +++ b/tests/locales/tok @@ -0,0 +1,5 @@ +#!/bin/sh + +export RUN_ERR="ilo ni li ken ala pali lon ma ni. sina ken kepeken ona lon ma \ +sewi" +export TEST_STR='ilo pali' -- 2.30.2 From 5cfccf75af614ca5838cfa5b889895a89fadccc3 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 7 Jun 2024 23:30:13 -0600 Subject: [PATCH 22/25] tests: bonsai/test_env: set -e; tests: strcmp: -h causes error --- tests/bonsai/strcmp.sh | 2 +- tests/bonsai/test_env | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bonsai/strcmp.sh b/tests/bonsai/strcmp.sh index 018cee2..9d9024e 100755 --- a/tests/bonsai/strcmp.sh +++ b/tests/bonsai/strcmp.sh @@ -12,5 +12,5 @@ strcmp equals equals ! strcmp inequals equals strcmp - - -strcmp -h +! strcmp -h ! strcmp nocmp diff --git a/tests/bonsai/test_env b/tests/bonsai/test_env index a3d07ca..aaf2b50 100644 --- a/tests/bonsai/test_env +++ b/tests/bonsai/test_env @@ -1,5 +1,5 @@ #!/bin/sh -set -x +set -ex alias "$UTIL=$BIN/$UTIL" -- 2.30.2 From 45329ccb8cd9fe1118ec7c4d3854cb584d52ddad Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 7 Jul 2024 19:19:38 -0600 Subject: [PATCH 23/25] tests/README: initial commit; tests/posix_env, tests/test.sh: updated to match README --- tests/README | 60 +++++++++++++++++++++++++++++++++++++++++++ tests/posix/posix_env | 2 ++ tests/test.sh | 6 +++-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/README diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..ee370b8 --- /dev/null +++ b/tests/README @@ -0,0 +1,60 @@ +The testing suite contains two main trees (plus translations for strings used in +the shell scripts): the Bonsai tree and the POSIX tree: + +. +├── bonsai +│   ├── test_env +│   ├── dj.sh +│   ├── false.sh +│   ├── fop.sh +│   ├── hru.sh +│   ├── intcmp.sh +│   ├── mm.sh +│   ├── strcmp.sh +│   └── true.sh +├── locales +│   ├── en_US.UTF-8 +│   └── tok +├── posix +│   ├── bin +│   │   ├── cat +│   │   ├── false +│   │   └── true +│   └── posix_env +├── README +└── test.sh + +The Bonsai tree tests the functionality of Harakit utilities for regressions and +other issues relating to compliance to our standards of practice. + +The POSIX tree tests the use of Harakit utilities in place of the standard usage +of POSIX utilities. These scripts test the ability of Harakit to comply to POSIX +standards using its native utilities in shell scripts as a compatibility shim. +Each shell script in the top directory should contain a set of tests for each +POSIX utility and be named for that utility. The bin directory should contain +a set of shim scripts which will be imported into the path as POSIX utilities. +Each test will compare the behavior of the shim script to the real utility on +the system. + +Currently, due to the limitations of POSIX shell quoting, a subset of argument +parsing is supported: arguments containing characters from POSIX’s Portable +Filename Character Set [0]. + +The bonsai/test_env and posix/posix_env files contain prerequisite shared +environments for each of the tests. These scripts both contain lines which set +the shell to write all commands run in them (-x) and to fail if any command +fails (-e). See set(1p) for more information. + +Both sets of tests also inherit the environment set by the test.sh script, which +sets the $BIN environment variable to the bin directory at the root of the +project for easy and idiomatic access to the built Harakit binaries. When +calling the POSIX test scripts, test.sh also sets the variable $realutil to be +the absolute path to the currently tested utility’s counterpart on the system. + +[0] + +-- +Copyright © 2024 Emma Tebibyte + +This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit +. diff --git a/tests/posix/posix_env b/tests/posix/posix_env index 56c5701..b436601 100644 --- a/tests/posix/posix_env +++ b/tests/posix/posix_env @@ -1,3 +1,5 @@ #!/bin/sh +set -ex + PATH="$PWD/bin:$PATH" diff --git a/tests/test.sh b/tests/test.sh index 61bb814..bc68c65 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -28,9 +28,11 @@ for script in tests/bonsai/*.sh; do printf '\n' done -for test in tests/posix/*.sh; do +for test_util in tests/posix/*.sh; do + realutil="$(command -v "$(printf '%s\n' "$test" | sed 's/\.sh$//g')")" + export realutil export PATH="$BIN:$PATH" printf '%s: %s: %s\n' "$0" "$test" "$TEST_STR" - "$utility" + "$test_util" printf '\n' done -- 2.30.2 From aa819cabc242697fda8bc61ad89bd2c0a1b30396 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 8 Jul 2024 22:24:18 -0600 Subject: [PATCH 24/25] tests: bonsai/npc.sh: initial arg parsing tests --- tests/bonsai/npc.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 tests/bonsai/npc.sh diff --git a/tests/bonsai/npc.sh b/tests/bonsai/npc.sh new file mode 100755 index 0000000..aa66b4f --- /dev/null +++ b/tests/bonsai/npc.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Copyright (c) 2024 DTB +# 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. + +. tests/bonsai/test_env + +! npc -h + +# arg parsing +npc -e /dev/null \ +# | xargs "$BIN"/intcmp -e 8 \ +# && i="$(printf '20 + %s\n' "$i" | bc)" +#done -- 2.30.2 From 94873a2ddca6fab4cf2a89f553f39cecc427f141 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 8 Jul 2024 22:25:18 -0600 Subject: [PATCH 25/25] tests: bonsai/dj.sh: iron out some existing tests --- tests/bonsai/dj.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/bonsai/dj.sh b/tests/bonsai/dj.sh index 8016ec3..9919d60 100755 --- a/tests/bonsai/dj.sh +++ b/tests/bonsai/dj.sh @@ -11,17 +11,19 @@ ! dj -h -# This test is theoretically Linux-dependent; write(2) should return -1 on -# error. -# Right now dj(1) interprets the return value of write(2) as the amount of -# bytes written. This can decrement the stored quantity of bytes written, -# which is an int, so doesn't underflow but goes negative. dj(1) tries to -# again to write(2) if an error occurs in which no bytes are written, so in -# total two write(2)s are attempted and so the written byte quantity is -2. -# This is a bug and will change, but for now is at least documented. -dj -Hi /dev/zero -o /dev/full \ - | xargs -I out "$BIN/strcmp" '1+0 > 0+0; 1024 > -2' out +# Linux has a /dev/full pseudodevice useful for testing errors. +case "$(uname)" in +Linux) + dj -Hi /dev/zero -o /dev/full 2>&1 \ + | xargs -I out "$BIN"/strcmp '1+0 > 0+0; 1024 > 0' out + ;; +esac # Read nothing from /dev/null, write nothing to /dev/null. -dj -Hi /dev/null -o /dev/null \ - | xargs -I out "$BIN/strcmp" '0+0 > 0+0; 0 > 0' out +dj -Hi /dev/null -o /dev/null 2>&1 \ + | xargs -I out "$BIN"/strcmp '0+0 > 0+0; 0 > 0' out + +# Test skipping stdin. +#dd count=1 bs=1024 /dev/null \ +# | dj -H -s 24 -o /dev/null 2>&1 \ +# | xargs -I out "$BIN"/strcmp '1+0 > 1+0; 1024 > 1000' out -- 2.30.2