From cabe08bca4a8aeaaf155b7863e85cb8c6cbc6036 Mon Sep 17 00:00:00 2001 From: DTB Date: Thu, 29 Feb 2024 20:33:09 -0700 Subject: [PATCH 01/42] 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 From f7a74dc430347ae6bec43a1b08f1ad563670a001 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 11 Mar 2024 21:01:29 -0600 Subject: [PATCH 02/42] 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 From 417d7ca40555b67f3051bde9e06b653df305eb58 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 11 Mar 2024 21:03:53 -0600 Subject: [PATCH 03/42] 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 From e7021e127ce1ea456de46a259d9cceed58f684ef Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 13 Mar 2024 18:20:30 -0600 Subject: [PATCH 04/42] 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 # From 057f5571d6708a964e2b6cc60e10ff76d132cf92 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 14:58:35 -0600 Subject: [PATCH 05/42] 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" From aefa87d9e5d3d4daf4544dddb6dfc16796c953d5 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:22:07 -0600 Subject: [PATCH 06/42] 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' From 28f2d44e2fdd1def42dfaed25660452340451b5c Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:24:35 -0600 Subject: [PATCH 07/42] 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 From 3398fc372cfaa930dc22d0ac179733c47ae289f4 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 15:33:17 -0600 Subject: [PATCH 08/42] 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 # From c6f30c419581b06099950b952b31d3480b146e52 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 19:25:55 -0600 Subject: [PATCH 09/42] 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 From 1aa2b596d0003f00b0ea7a7b7c31a2f473696429 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 19:28:33 -0600 Subject: [PATCH 10/42] 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" From 0113cf793de13298f6ec7986b43cb6a639289e18 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 17:20:55 -0600 Subject: [PATCH 11/42] 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 From 4ad9e0da92cc43f0663dbb36230c06dec8cb8f52 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 18:57:05 -0600 Subject: [PATCH 12/42] 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 From e278307dafe4b2cabf37b4b325037acbd8e46afd Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 26 Apr 2024 20:55:16 -0600 Subject: [PATCH 13/42] 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 From f022121436164d6ac4ea7f9f2c75dc39c63914cd Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 27 Apr 2024 15:16:52 -0600 Subject: [PATCH 14/42] 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 From e02884482539cee25d7f2b071f4a1bb2d534f5a6 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 27 Apr 2024 15:18:09 -0600 Subject: [PATCH 15/42] 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' From 8508479a5b0e76aee6ce99999dcacaa093dedf10 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:07:17 -0600 Subject: [PATCH 16/42] 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" From 9bfc5876238d6808a8a0ed0581c9ff3d0a846571 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:12:54 -0600 Subject: [PATCH 17/42] 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" From 94ada03ce4a6624e3430091a805e131f0f35941b Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:17:30 -0600 Subject: [PATCH 18/42] 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 From 787f0dc6e2d6b7cf3318fa22d46b17b8cd6f6a20 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:23:49 -0600 Subject: [PATCH 19/42] 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 From 406feb3dc7bea899da4bcb97846d58bc89d06eb1 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 27 May 2024 22:37:15 -0600 Subject: [PATCH 20/42] 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 From c88c41b21370a1866b3a2324a0c79f5bb208e06e Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 20:14:06 -0600 Subject: [PATCH 21/42] 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' From 5cfccf75af614ca5838cfa5b889895a89fadccc3 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 7 Jun 2024 23:30:13 -0600 Subject: [PATCH 22/42] 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" From 45329ccb8cd9fe1118ec7c4d3854cb584d52ddad Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 7 Jul 2024 19:19:38 -0600 Subject: [PATCH 23/42] 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 From aa819cabc242697fda8bc61ad89bd2c0a1b30396 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 8 Jul 2024 22:24:18 -0600 Subject: [PATCH 24/42] 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 From 94873a2ddca6fab4cf2a89f553f39cecc427f141 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 8 Jul 2024 22:25:18 -0600 Subject: [PATCH 25/42] 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 From ce8a0a5be38957ec76d75c64b34b51ae8b877217 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 2 Aug 2024 17:29:30 -0600 Subject: [PATCH 26/42] tests: converted to Makefiles --- Makefile | 11 ++++++-- tests/bonsai/dj.mk | 42 +++++++++++++++++++++++++++++ tests/bonsai/dj.sh | 29 -------------------- tests/bonsai/{false.sh => false.mk} | 13 ++++++--- tests/bonsai/fop.mk | 31 +++++++++++++++++++++ tests/bonsai/fop.sh | 21 --------------- tests/bonsai/hru.mk | 35 ++++++++++++++++++++++++ tests/bonsai/hru.sh | 26 ------------------ tests/bonsai/intcmp.mk | 36 +++++++++++++++++++++++++ tests/bonsai/intcmp.sh | 25 ----------------- tests/bonsai/mm.mk | 27 +++++++++++++++++++ tests/bonsai/{npc.sh => npc.mk} | 20 +++++++++----- tests/bonsai/strcmp.mk | 31 +++++++++++++++++++++ tests/bonsai/strcmp.sh | 16 ----------- tests/bonsai/test_env | 5 ---- tests/bonsai/{true.sh => true.mk} | 12 ++++++--- tests/locales/en_US.UTF-8 | 4 --- tests/locales/tok | 5 ---- tests/test.sh | 38 -------------------------- tests/{bonsai/mm.sh => tests.mk} | 16 +++++------ 20 files changed, 249 insertions(+), 194 deletions(-) create mode 100755 tests/bonsai/dj.mk delete mode 100755 tests/bonsai/dj.sh rename tests/bonsai/{false.sh => false.mk} (68%) create mode 100755 tests/bonsai/fop.mk delete mode 100755 tests/bonsai/fop.sh create mode 100755 tests/bonsai/hru.mk delete mode 100755 tests/bonsai/hru.sh create mode 100755 tests/bonsai/intcmp.mk delete mode 100755 tests/bonsai/intcmp.sh create mode 100755 tests/bonsai/mm.mk rename tests/bonsai/{npc.sh => npc.mk} (70%) create mode 100755 tests/bonsai/strcmp.mk delete mode 100755 tests/bonsai/strcmp.sh delete mode 100644 tests/bonsai/test_env rename tests/bonsai/{true.sh => true.mk} (71%) delete mode 100644 tests/locales/en_US.UTF-8 delete mode 100644 tests/locales/tok delete mode 100755 tests/test.sh rename tests/{bonsai/mm.sh => tests.mk} (51%) mode change 100755 => 100644 diff --git a/Makefile b/Makefile index 6e554a4..6c6d555 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,13 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \ --extern strerror=build/o/libstrerror.rlib CFLAGS += -I$(SYSEXITS) +# testing requires the absolute path to the bin directory set +BIN = build/bin +include tests/tests.mk + +.PHONY: default +default: all test + .PHONY: all all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true @@ -53,8 +60,8 @@ install: dist cp -r $(DESTDIR)/* / .PHONY: test -test: all build /tmp/getopt - tests/test.sh +test: all $(TESTS) /tmp/getopt + @echo $(TESTS) /tmp/getopt /tmp/getopt: src/libgetopt.rs diff --git a/tests/bonsai/dj.mk b/tests/bonsai/dj.mk new file mode 100755 index 0000000..9c27927 --- /dev/null +++ b/tests/bonsai/dj.mk @@ -0,0 +1,42 @@ +# 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. + +.PRAGMA: command_comment + +/dev/full: +/dev/null: + +.PHONY: dj_tests +dj_tests: dj_full dj_help dj_null # dj_skip_stdin + +.PHONY: dj_full +# Linux has a /dev/full pseudodevice useful for testing errors. +dj_full: $(BIN)/dj /dev/full + case "$$(uname)" in \ + Linux) \ + $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \ + | xargs -I out test '1+0 > 0+0; 1024 > 0' = out \ + ;; \ + esac + +.PHONY: dj_help +dj_help: $(BIN)/dj + ! $(BIN)/dj -h + +.PHONY: dj_null +# Read nothing from /dev/null, write nothing to /dev/null. +dj_null: $(BIN)/dj /dev/null + $(BIN)/dj -Hi /dev/null -o /dev/null 2>&1 \ + | xargs -I out test '0+0 > 0+0; 0 > 0' = out + +# .PHONY: dj_skip_stdin +# dj_skip_stdin: $(BIN)/dj + # Test skipping stdin. + #dd count=1 bs=1024 /dev/null \ + # | $(BIN)/dj -H -s 24 -o /dev/null 2>&1 \ + # | xargs -I out test '1+0 > 1+0; 1024 > 1000' = out diff --git a/tests/bonsai/dj.sh b/tests/bonsai/dj.sh deleted file mode 100755 index 9919d60..0000000 --- a/tests/bonsai/dj.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/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/test_env - -! dj -h - -# 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 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 diff --git a/tests/bonsai/false.sh b/tests/bonsai/false.mk similarity index 68% rename from tests/bonsai/false.sh rename to tests/bonsai/false.mk index 3ad0e94..e3d19ae 100755 --- a/tests/bonsai/false.sh +++ b/tests/bonsai/false.mk @@ -1,4 +1,3 @@ -#!/bin/sh # Copyright (c) 2024 DTB # Copyright (c) 2024 Emma Tebibyte # SPDX-License-Identifier: FSFAP @@ -7,7 +6,13 @@ # 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 +.PHONY: false_tests +false_tests: false_test false_help -! false -! false -h +.PHONY: false +false_test: $(BIN)/false + ! $(BIN)/false + +.PHONY: false_help +false_help: $(BIN)/false + ! $(BIN)/false -h diff --git a/tests/bonsai/fop.mk b/tests/bonsai/fop.mk new file mode 100755 index 0000000..a22ca46 --- /dev/null +++ b/tests/bonsai/fop.mk @@ -0,0 +1,31 @@ +# 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. + +.PHONY: fop_tests +fop_tests: fop_help fop_functionality fop_delimiter fop_fail + +.PHONY: fop_delimiter +fop_delimiter: $(BIN)/fop + test "$$(printf 'test0 test1 test2\n' | $(BIN)/fop -d' ' 2 sed 's/2/4/g')" \ + = 'test0 test1 test4' + test "$$(printf 'meowsetwoofsetribbit\n' \ + | $(BIN)/fop -d 'set' 1 sed 's/woof/meow/g')" = 'meowsetmeowsetribbit' + +.PHONY: fop_fail +fop_fail: $(BIN)/fop + ! printf 'test\n' | $(BIN)/fop 1 cat + ! printf 'test\n' | $(BIN)/fop 'test' cat + ! printf 'test\n' | $(BIN)/fop -d'test' cat + +.PHONY: fop_functionality +fop_functionality: $(BIN)/fop + test "$$(printf 'test0␞test1␞test2\n' | $(BIN)/fop 1 sed 's/1/4/g')" \ + = 'test0␞test4␞test2' + +.PHONY: fop_help +fop_help: $(BIN)/fop + ! $(BIN)/fop -h diff --git a/tests/bonsai/fop.sh b/tests/bonsai/fop.sh deleted file mode 100755 index 2cb2533..0000000 --- a/tests/bonsai/fop.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/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/test_env - -! 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 diff --git a/tests/bonsai/hru.mk b/tests/bonsai/hru.mk new file mode 100755 index 0000000..9d200e5 --- /dev/null +++ b/tests/bonsai/hru.mk @@ -0,0 +1,35 @@ +# 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. + +NAME = hru +TARGET = $(NAME)_tests +BINARY = $(BIN)/$(NAME) + +.PHONY: hru_tests +hru_tests: $(BIN)/hru + +.PHONY: hru_functionality +hru_functionality: $(BIN)/hru + test "$(printf '1234\n' | $(BIN)/hru)" = '1.2 kB' + test "$(printf '0\n' | $(BIN)/hru)" = '0 B' + +.PHONY: $(NAME_help) +hru_help: $(BIN)/hru + ! $(BIN)/hru -h + +.PHONY: hru_negative +hru_negative: $(BIN)/hru + ! printf '%s\n' '-1' | $(BIN)/hru + +.PHONY: hru_regressions +hru_regressions: $(BIN)/hru + n=1; \ + while true; \ + do n="$$(($$n * 10))"; \ + printf '%s\n' "$$n" | $(BIN)/hru || break; \ + done; \ + printf 'Max float: %s\n' "$$n" diff --git a/tests/bonsai/hru.sh b/tests/bonsai/hru.sh deleted file mode 100755 index 51bf7c1..0000000 --- a/tests/bonsai/hru.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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/test_env - -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 diff --git a/tests/bonsai/intcmp.mk b/tests/bonsai/intcmp.mk new file mode 100755 index 0000000..53f4282 --- /dev/null +++ b/tests/bonsai/intcmp.mk @@ -0,0 +1,36 @@ +# 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. + +.PHONY: intcmp_tests +intcmp_tests: intcmp_e intcmp_g intcmp_l + +.PHONY: intcmp_e +intcmp_e: $(BIN)/intcmp + $(BIN)/intcmp -e 3 3 3 + ! $(BIN)/intcmp -e 1 2 3 + +.PHONY: intcmp_g +intcmp_g: $(BIN)/intcmp + $(BIN)/intcmp -g 3 2 1 + ! $(BIN)/intcmp -g 1 3 3 + $(BIN)/intcmp -ge 3 3 1 + ! $(BIN)/intcmp -ge 1 2 3 + +.PHONY: intcmp_l +intcmp_l: $(BIN)/intcmp + $(BIN)/intcmp -l 1 2 3 + ! $(BIN)/intcmp -l 3 3 1 + $(BIN)/intcmp -le 1 3 3 + ! $(BIN)/intcmp -le 3 2 1 + +.PHONY: intcmp_combined +intcmp_combined: $(BIN)/intcmp + $(BINARY) -gl 1 2 3 + ! $(BINARY) -gl 3 3 3 + $(BINARY) -egl 3 1 1 2 + ! $(BINARY) -egl foo diff --git a/tests/bonsai/intcmp.sh b/tests/bonsai/intcmp.sh deleted file mode 100755 index e3cdcb7..0000000 --- a/tests/bonsai/intcmp.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/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/test_env - -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/mm.mk b/tests/bonsai/mm.mk new file mode 100755 index 0000000..6117330 --- /dev/null +++ b/tests/bonsai/mm.mk @@ -0,0 +1,27 @@ +# Copyright (c) 2024 E$(NAME)a 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. + +NAME = mm +TARGET = $(NAME)_tests +BINARY = $(BIN)/$(NAME) + +.PHONY: mm_tests +mm_tests: mm_args mm_help mm_stderr + +.PHONY: mm_args +# mm(1) will error if positional arguments are given without -i or -o +mm_args: $(BIN)/mm + ! $(BIN)/mm argument + +.PHONY: mm_help +mm_help: $(BIN)/mm + ! $(BIN)/mm -h + +.PHONY: mm_stderr +# check if stderr is empty upon specifying -e +mm_stderr: $(BIN)/mm + ! test "$$(printf 'test\n' | $(BIN)/mm -i - -e 2>&1 >/dev/null)" = "test" diff --git a/tests/bonsai/npc.sh b/tests/bonsai/npc.mk similarity index 70% rename from tests/bonsai/npc.sh rename to tests/bonsai/npc.mk index aa66b4f..5f110de 100755 --- a/tests/bonsai/npc.sh +++ b/tests/bonsai/npc.mk @@ -1,20 +1,28 @@ #!/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/test_env +.PRAGMA: command_comment -! npc -h +.PHONY: npc_tests +npc_tests: npc_args npc_help +.PHONY: npc_args # arg parsing -npc -e +# 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. + +NAME = strcmp +TARGET = $(NAME)_tests +BINARY = $(BIN)/$(NAME) + +.PHONY: strcmp_tests +strcmp_tests: strcmp_equals strcmp_help strcmp_nocmp strcmp_unequals + +.PHONY: strcmp_equals +strcmp_equals: $(BIN)/strcmp + $(BIN)/strcmp equals equals + $(BIN)/strcmp - - + +.PHONY: strcmp_help +strcmp_help: $(BIN)/strcmp + ! $(BIN)/strcmp -h + +.PHONY: strcmp_nocmp +strcmp_nocmp: $(BIN)/strcmp + ! $(BIN)/strcmp nocmp + +.PHONY: strcmp_unequals +strcmp_unequals: $(BIN)/strcmp + ! $(BIN)/strcmp unequals equals diff --git a/tests/bonsai/strcmp.sh b/tests/bonsai/strcmp.sh deleted file mode 100755 index 9d9024e..0000000 --- a/tests/bonsai/strcmp.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/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/test_env - -strcmp equals equals -! strcmp inequals equals -strcmp - - -! strcmp -h -! strcmp nocmp diff --git a/tests/bonsai/test_env b/tests/bonsai/test_env deleted file mode 100644 index aaf2b50..0000000 --- a/tests/bonsai/test_env +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -ex - -alias "$UTIL=$BIN/$UTIL" diff --git a/tests/bonsai/true.sh b/tests/bonsai/true.mk similarity index 71% rename from tests/bonsai/true.sh rename to tests/bonsai/true.mk index 413d758..fb6e82c 100755 --- a/tests/bonsai/true.sh +++ b/tests/bonsai/true.mk @@ -7,7 +7,13 @@ # 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 +.PHONY: true_tests +true_tests: true_test -true -true -h +.PHONY: true_help +true_help: $(BIN)/true + $(BIN)/true -h + +.PHONY: true_test +true_test: $(BIN)/true + $(BIN)/true diff --git a/tests/locales/en_US.UTF-8 b/tests/locales/en_US.UTF-8 deleted file mode 100644 index 95e2efb..0000000 --- a/tests/locales/en_US.UTF-8 +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -export RUN_ERR='Run this script in the root of the project' -export TEST_STR='Testing utility' diff --git a/tests/locales/tok b/tests/locales/tok deleted file mode 100644 index 7770742..0000000 --- a/tests/locales/tok +++ /dev/null @@ -1,5 +0,0 @@ -#!/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' diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index bc68c65..0000000 --- a/tests/test.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2023–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. - -set -e - -. "tests/locales/$LANG" - -export BIN=build/bin - -if ! ls Makefile >/dev/null 2>&1 -then - printf '%s: %s\n' "$0" "$RUN_ERR" 1>&2 - exit 1 -fi - -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: %s\n' "$0" "$UTIL" "$TEST_STR" - "$script" - printf '\n' -done - -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" - "$test_util" - printf '\n' -done diff --git a/tests/bonsai/mm.sh b/tests/tests.mk old mode 100755 new mode 100644 similarity index 51% rename from tests/bonsai/mm.sh rename to tests/tests.mk index 43f3a1c..04f3680 --- a/tests/bonsai/mm.sh +++ b/tests/tests.mk @@ -1,19 +1,15 @@ -#!/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 +# 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 -exec 3>&1 +#TESTFILES != for file in tests/bonsai/*.mk tests/posix/*.mk; do printf '%s ' "$$file"; done; +TESTFILES != for file in tests/bonsai/*.mk; do printf '%s ' "$$file"; done; -! mm -h +TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \ + | sed 's/\.mk/_tests/g' -# 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)" '' +include $(TESTFILES) From bd09d169496a972606ed88701ee9505ee1f6b5fa Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 2 Aug 2024 18:22:45 -0600 Subject: [PATCH 27/42] tests: bonsai/dj.mk: comment more --- tests/bonsai/dj.mk | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/bonsai/dj.mk b/tests/bonsai/dj.mk index 9c27927..402abd6 100755 --- a/tests/bonsai/dj.mk +++ b/tests/bonsai/dj.mk @@ -12,7 +12,7 @@ /dev/null: .PHONY: dj_tests -dj_tests: dj_full dj_help dj_null # dj_skip_stdin +dj_tests: dj_help dj_full dj_null # dj_skip_stdin .PHONY: dj_full # Linux has a /dev/full pseudodevice useful for testing errors. @@ -20,7 +20,8 @@ dj_full: $(BIN)/dj /dev/full case "$$(uname)" in \ Linux) \ $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \ - | xargs -I out test '1+0 > 0+0; 1024 > 0' = out \ + | tee /dev/tty \ + | xargs -I out test '1+0 > 0+0; 1024 > 0' = out \ ;; \ esac @@ -32,11 +33,16 @@ dj_help: $(BIN)/dj # Read nothing from /dev/null, write nothing to /dev/null. dj_null: $(BIN)/dj /dev/null $(BIN)/dj -Hi /dev/null -o /dev/null 2>&1 \ + | tee /dev/tty \ | xargs -I out test '0+0 > 0+0; 0 > 0' = out +# This test currently fails. This is probably due to dj(1) being stale relative +# to the main harakit branch. TODO: Reassess once the testing branch is merged. # .PHONY: dj_skip_stdin +# # Test skipping stdin. # dj_skip_stdin: $(BIN)/dj - # Test skipping stdin. - #dd count=1 bs=1024 /dev/null \ - # | $(BIN)/dj -H -s 24 -o /dev/null 2>&1 \ - # | xargs -I out test '1+0 > 1+0; 1024 > 1000' = out +# # Pipe 1024B of '\0' into dj(1); skip the first 24B; expect 1000B written. +# dd count=1 bs=1024 /dev/null \ +# | $(BIN)/dj -H -s 24 -o /dev/null 2>&1 \ +# | tee /dev/tty \ +# | xargs -I out test '1+0 > 1+0; 1024 > 1000' = out From 91de98cea3025ca3e2a65d4298f910ab0e1d8f6d Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 2 Aug 2024 18:28:24 -0600 Subject: [PATCH 28/42] tests: bonsai/intcmp.mk: make tests more relevant to failure cases --- tests/bonsai/intcmp.mk | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/tests/bonsai/intcmp.mk b/tests/bonsai/intcmp.mk index 53f4282..57afae0 100755 --- a/tests/bonsai/intcmp.mk +++ b/tests/bonsai/intcmp.mk @@ -7,30 +7,39 @@ # notice are preserved. This file is offered as-is, without any warranty. .PHONY: intcmp_tests -intcmp_tests: intcmp_e intcmp_g intcmp_l +intcmp_tests: intcmp_help intcmp_e intcmp_g intcmp_l intcmp_combined + +.PHONY: intcmp_help +intcmp_help: $(BIN)/intcmp + ! $(BIN)/intcmp -h .PHONY: intcmp_e intcmp_e: $(BIN)/intcmp - $(BIN)/intcmp -e 3 3 3 - ! $(BIN)/intcmp -e 1 2 3 + $(BIN)/intcmp -e 3 3 3 # == + ! $(BIN)/intcmp -e 1 2 3 # < + ! $(BIN)/intcmp -e 3 2 1 # > .PHONY: intcmp_g intcmp_g: $(BIN)/intcmp - $(BIN)/intcmp -g 3 2 1 - ! $(BIN)/intcmp -g 1 3 3 - $(BIN)/intcmp -ge 3 3 1 - ! $(BIN)/intcmp -ge 1 2 3 + $(BIN)/intcmp -g 3 2 1 # > + ! $(BIN)/intcmp -g 3 3 3 # == + ! $(BIN)/intcmp -g 1 2 3 # < + $(BIN)/intcmp -ge 3 3 1 # >= + ! $(BIN)/intcmp -ge 1 2 3 # < .PHONY: intcmp_l intcmp_l: $(BIN)/intcmp - $(BIN)/intcmp -l 1 2 3 - ! $(BIN)/intcmp -l 3 3 1 - $(BIN)/intcmp -le 1 3 3 - ! $(BIN)/intcmp -le 3 2 1 + $(BIN)/intcmp -l 1 2 3 # < + ! $(BIN)/intcmp -l 3 3 3 # == + ! $(BIN)/intcmp -l 3 2 1 # > + $(BIN)/intcmp -le 1 3 3 # <= + ! $(BIN)/intcmp -le 3 2 1 # > .PHONY: intcmp_combined intcmp_combined: $(BIN)/intcmp - $(BINARY) -gl 1 2 3 - ! $(BINARY) -gl 3 3 3 - $(BINARY) -egl 3 1 1 2 - ! $(BINARY) -egl foo + $(BIN)/intcmp -gl 1 2 3 # < + $(BIN)/intcmp -gl 3 2 1 # > + $(BIN)/intcmp -gl 1 3 1 # != + ! $(BIN)/intcmp -gl 3 3 3 # == + $(BIN)/intcmp -egl 3 1 1 3 # >, ==, < + ! $(BIN)/intcmp -egl foo # huh? From ee7b7e89b2396eb3c330e0212326031558d75de9 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 2 Aug 2024 19:37:36 -0600 Subject: [PATCH 29/42] tests: bonsai/fop.mk: fixes record separators --- tests/bonsai/fop.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/bonsai/fop.mk b/tests/bonsai/fop.mk index a22ca46..9013308 100755 --- a/tests/bonsai/fop.mk +++ b/tests/bonsai/fop.mk @@ -6,12 +6,16 @@ # notice are preserved. This file is offered as-is, without any warranty. .PHONY: fop_tests -fop_tests: fop_help fop_functionality fop_delimiter fop_fail +fop_tests: fop_functionality fop_delimiter fop_help fop_fail + +.PHONY: fop_help +fop_help: $(BIN)/fop + ! $(BIN)/fop -h .PHONY: fop_delimiter fop_delimiter: $(BIN)/fop - test "$$(printf 'test0 test1 test2\n' | $(BIN)/fop -d' ' 2 sed 's/2/4/g')" \ - = 'test0 test1 test4' + test "$$(printf 'test1 test1 test1\n' | $(BIN)/fop -d' ' 2 sed 's/2/4/g')" \ + = 'test1 test1 test4' test "$$(printf 'meowsetwoofsetribbit\n' \ | $(BIN)/fop -d 'set' 1 sed 's/woof/meow/g')" = 'meowsetmeowsetribbit' @@ -23,9 +27,5 @@ fop_fail: $(BIN)/fop .PHONY: fop_functionality fop_functionality: $(BIN)/fop - test "$$(printf 'test0␞test1␞test2\n' | $(BIN)/fop 1 sed 's/1/4/g')" \ - = 'test0␞test4␞test2' - -.PHONY: fop_help -fop_help: $(BIN)/fop - ! $(BIN)/fop -h + test "$$(printf 'test1\036test1\036test1\n' | $(BIN)/fop 1 sed 's/1/4/g')" \ + = "$$(printf 'test1\036test4\036test1\n')" From 588680406a8e08fae6a645ee2a63b99827fd185f Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 3 Aug 2024 07:29:04 -0600 Subject: [PATCH 30/42] tests: bonsai/npc.mk: full ASCII test coverage --- tests/bonsai/npc.mk | 70 ++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/tests/bonsai/npc.mk b/tests/bonsai/npc.mk index 5f110de..8b10fdf 100755 --- a/tests/bonsai/npc.mk +++ b/tests/bonsai/npc.mk @@ -10,7 +10,11 @@ .PRAGMA: command_comment .PHONY: npc_tests -npc_tests: npc_args npc_help +npc_tests: npc_help npc_args npc_ascii + +.PHONY: npc_help +npc_help: $(BIN)/npc + ! $(BIN)/npc -h .PHONY: npc_args # arg parsing @@ -20,23 +24,49 @@ npc_args: $(BIN)/npc -et /dev/null \ -# | xargs "$BIN"/intcmp -e 8 \ -# && i="$(printf '20 + %s\n' "$i" | bc)" -#done +.PHONY: npc_ascii_controls +# (control characters) +npc_ascii_controls: + # ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues) + awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \ + | $(BIN)/npc \ + | head -n 1 \ + | xargs -I out test "^@^A^B^C^D^E^F^G^H" = out + + # ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f + awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \ + | $(BIN)/npc \ + | head -n 2 \ + | tail -n 1 \ + | xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_" + +.PHONY: npc_ascii_symbols +# ASCII 0x1f to 0x3f (^_ and symbols) +npc_ascii_symbols: + # shell quoting olympics + awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }' \ + | $(BIN)/npc \ + | sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \ + | xargs -I out test "^_ !\"#$$%&'()*+,-./0123456789:;<=>?" = out + +.PHONY: npc_ascii_uppers +# ASCII 0x40 to 0x5f (uppercases) +npc_ascii_uppers: + awk 'BEGIN{ for (i = 64; i < 96; ++i) printf("%c", i); print }' \ + | $(BIN)/npc \ + | sed 's/\\/\\\\/' \ + | xargs -I out test @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ = out + +# This test is broken and will need closer inspection along with the npc(1) +# source. +# .PHONY: npc_ascii_lowers +# # ASCII 0x60 to 0x7f (lowercases) +# npc_ascii_lowers: +# awk 'BEGIN{ for (i = 96; i < 128; ++i) printf("%c", i); print }' \ +# | $(BIN)/npc \ +# | xargs -I out test "\`abcdefghijklmnopqrstuvwxyz{|}~^?" = out From 0f2d357476f1c3809a7641bd58d9b9691f6483f5 Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 3 Aug 2024 07:33:46 -0600 Subject: [PATCH 31/42] tests/bonsai: dj.mk: tee diagnostics to stderr instead of tty --- tests/bonsai/dj.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bonsai/dj.mk b/tests/bonsai/dj.mk index 402abd6..bf8adf3 100755 --- a/tests/bonsai/dj.mk +++ b/tests/bonsai/dj.mk @@ -20,7 +20,7 @@ dj_full: $(BIN)/dj /dev/full case "$$(uname)" in \ Linux) \ $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \ - | tee /dev/tty \ + | tee /dev/stderr \ | xargs -I out test '1+0 > 0+0; 1024 > 0' = out \ ;; \ esac @@ -33,7 +33,7 @@ dj_help: $(BIN)/dj # Read nothing from /dev/null, write nothing to /dev/null. dj_null: $(BIN)/dj /dev/null $(BIN)/dj -Hi /dev/null -o /dev/null 2>&1 \ - | tee /dev/tty \ + | tee /dev/stderr \ | xargs -I out test '0+0 > 0+0; 0 > 0' = out # This test currently fails. This is probably due to dj(1) being stale relative @@ -44,5 +44,5 @@ dj_null: $(BIN)/dj /dev/null # # Pipe 1024B of '\0' into dj(1); skip the first 24B; expect 1000B written. # dd count=1 bs=1024 /dev/null \ # | $(BIN)/dj -H -s 24 -o /dev/null 2>&1 \ -# | tee /dev/tty \ +# | tee /dev/stderr \ # | xargs -I out test '1+0 > 1+0; 1024 > 1000' = out From acdbecf1786180c7e6b01462d685e5c543d7c057 Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 3 Aug 2024 21:36:53 -0600 Subject: [PATCH 32/42] tests: bonsai/scrut.mk: add tests --- tests/bonsai/scrut.mk | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 tests/bonsai/scrut.mk diff --git a/tests/bonsai/scrut.mk b/tests/bonsai/scrut.mk new file mode 100755 index 0000000..e7f421e --- /dev/null +++ b/tests/bonsai/scrut.mk @@ -0,0 +1,46 @@ +#!/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. + +.PRAGMA: command_comment + +.PHONY: scrut_tests +scrut_tests: scrut_help scrut_options + +.PHONY: scrut_help +scrut_help: $(BIN)/scrut + ! $(BIN)/scrut -h + +.PHONY: scrut_options +# scrut tests file attributes, but files of a certain attribute aren't +# guaranteed to be present on a system. This test checks all of the files in +# harakit and, if test(1p) says a file matches a certain attribute, then checks +# scrut. +# opts are space-delimited (for command splitting), sel is not +scrut_options: $(BIN)/scrut + set -e; \ + opts="b c d e f g k p r s u w x L S"; \ + sel=; \ + find . -name .git -prune -o -print \ + | while read -r f; do \ + for opt in $$opts; \ + do if ! printf "%s\n" $$sel | grep $$opt >/dev/null; then \ + if test -$$opt "$$f"; then \ + if ! $(BIN)/scrut -$$opt "$$f"; \ + then printf "[!!] scrut -%s failed on %s.\n" \ + $$opt "$$f"; \ + fi; \ + sel="$$sel$$opt"; \ + printf "[OK] Tested scrut -%s using %s\n" \ + $$opt "$$f"; \ + fi; \ + fi; \ + done; \ + if printf "%s\n" "$$opts" | sed 's/ //g' | xargs test "$$sel" =; \ + then break; \ + fi; \ + done From cd5983b10b4dc32455a9d8a23919863136c3d537 Mon Sep 17 00:00:00 2001 From: DTB Date: Sun, 4 Aug 2024 09:05:20 -0600 Subject: [PATCH 33/42] tests/bonsai: intcmp.mk: add a comment --- tests/bonsai/intcmp.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/bonsai/intcmp.mk b/tests/bonsai/intcmp.mk index 57afae0..e3c559e 100755 --- a/tests/bonsai/intcmp.mk +++ b/tests/bonsai/intcmp.mk @@ -13,6 +13,24 @@ intcmp_tests: intcmp_help intcmp_e intcmp_g intcmp_l intcmp_combined intcmp_help: $(BIN)/intcmp ! $(BIN)/intcmp -h +# These test that integer comparisons are working as they should. For the sake +# of readability (to facilitate faster skimming) these recipes follow a +# columned format: +# $binary -flags d d d d # op +# For flag meanings reference intcmp(1) (though they are somewhat self +# explanatory). d here refers to a decimal number; a mixture of 1s, 2s, and 3s +# (a particularly lovely number) arranged to demonstrate easily the operation +# under scrutiny. The commented op is the operation that is true for the given +# numbers. For example: +# $(BIN)/intcmp -e 3 3 3 3 # == +# op here is ==; 3 == 3 == 3 == 3. The flag being used is -e, to test for +# equality, so this test should succeed. +# ! $(BIN)/intcmp -l 3 2 1 # > +# op here is >; 3 > 2 > 1. The flag being used is -l, to test for each integer +# being less than the next, so intcmp should fail - hence the ! at the start of +# the invocation. If this test failed, intcmp(1) would be confusing -l for -g, +# so that would be a good place to start looking for bugs. + .PHONY: intcmp_e intcmp_e: $(BIN)/intcmp $(BIN)/intcmp -e 3 3 3 # == From e93d218b877990770e5d7ddfcb2b07afa9fbd7f5 Mon Sep 17 00:00:00 2001 From: DTB Date: Sun, 4 Aug 2024 09:14:19 -0600 Subject: [PATCH 34/42] tests/bonsai: str.mk: -h test --- tests/bonsai/str.mk | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 tests/bonsai/str.mk diff --git a/tests/bonsai/str.mk b/tests/bonsai/str.mk new file mode 100755 index 0000000..fac642e --- /dev/null +++ b/tests/bonsai/str.mk @@ -0,0 +1,15 @@ +# 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. + +.PRAGMA: command_comment + +.PHONY: str_tests +str_tests: str_help + +.PHONY: str_help +str_help: $(BIN)/str + ! $(BIN)/str -h From 3880abaa4fc4d0d3771bbfd8dd6ab226eebd6ee0 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 5 Aug 2024 13:47:12 -0600 Subject: [PATCH 35/42] tests: bonsai/rpn.mk: added rpn(1) test --- tests/bonsai/rpn.mk | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 tests/bonsai/rpn.mk diff --git a/tests/bonsai/rpn.mk b/tests/bonsai/rpn.mk new file mode 100755 index 0000000..2ac1243 --- /dev/null +++ b/tests/bonsai/rpn.mk @@ -0,0 +1,43 @@ +# 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. + +.PHONY: rpn_tests +rpn_tests: rpn_help rpn_add + +.PHONY: rpn_help +rpn_help: $(BIN)/rpn + ! $(BIN)/rpn -h + +.PHONY: rpn_add +rpn_add: $(BIN)/rpn + test "$$($(BIN)/rpn 1 2 +)" -eq 3 + test "$$($(BIN)/rpn 0.2 0.1 +)" = 0.3 + +.PHONY: rpn_sub +rpn_sub: $(BIN)/rpn + test "$$($(BIN)/rpn 23 5 -)" -eq 18 + test "$$($(BIN)/rpn 0.3 0.1)" = 0.2 + +.PHONY: rpn_mul +rpn_mul: $(BIN)/rpn + test "$$($(BIN)/rpn 1.2 3 '*')" = 3.6 + test "$$($(BIN)/rpn 0 3 '*')" -eq 0 + +.PHONY: rpn_div +rpn_div: $(BIN)/rpn + test "$$($(BIN)/rpn 12 5 /)" = 2.4 + test "$$($(BIN)/rpn 3 0 /)" -eq inf + +.PHONY: rpn_mod +rpn_mod: $(BIN)/rpn + test "$$($(BIN)/rpn 12 5 %)" -eq 2 + test "$$($(BIN)/rpn 9 4 %)" -eq 1 + +.PHONY: rpn_flr +rpn_flr: $(BIN)/rpn + test "$$($(BIN)/rpn 12 5 //)" -eq 2 + test "$$($(BIN)/rpn 9 4 //)" -eq 2 From 9412f95cb1414876e718cdbab4b65eff7ae36d6e Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 5 Aug 2024 21:16:18 -0600 Subject: [PATCH 36/42] tests: bonsai/str.mk: add str_isalpha test --- tests/bonsai/str.mk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/bonsai/str.mk b/tests/bonsai/str.mk index fac642e..38ad9ca 100755 --- a/tests/bonsai/str.mk +++ b/tests/bonsai/str.mk @@ -8,8 +8,13 @@ .PRAGMA: command_comment .PHONY: str_tests -str_tests: str_help +str_tests: str_help str_isalpha .PHONY: str_help str_help: $(BIN)/str ! $(BIN)/str -h + +.PHONY: str_isalpha +str_isalpha: $(BIN)/str + $(BIN)/str isalpha c + ! $(BIN)/str isalpha 3 From a94884cc2ade776a86056bfa7e7716aa2674bf50 Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 7 Aug 2024 08:34:29 -0600 Subject: [PATCH 37/42] tests: bonsai/swab.mk: add example from tha man page --- tests/bonsai/swab.mk | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tests/bonsai/swab.mk diff --git a/tests/bonsai/swab.mk b/tests/bonsai/swab.mk new file mode 100755 index 0000000..ff64c17 --- /dev/null +++ b/tests/bonsai/swab.mk @@ -0,0 +1,22 @@ +# 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. + +.PRAGMA: command_comment + +.PHONY: swab_tests +swab_tests: swab_help swab_examples + +.PHONY: swab_help +swab_help: $(BIN)/swab + ! $(BIN)/swab -h + +.PHONY: swab_examples +# These are the examples present in the man page. +swab_examples: $(BIN)/swab + printf 'hello world!\n' \ + | $(BIN)/swab \ + | xargs -I out test 'ehll oowlr!d' = out From a7f16b5a7e331fcbe3b64a75474f5fb877354d76 Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 7 Aug 2024 08:35:24 -0600 Subject: [PATCH 38/42] swab.1: Add note to keep example in tests --- docs/swab.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/swab.1 b/docs/swab.1 index 42eef95..89cebb2 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -36,6 +36,7 @@ line: .RS printf 'hello world!\(rsn' | swab .RE +.\" If you change this, make sure to change it in tests/bonsai/swab.mk too. Produces the following output: From 0bc0ffa0a51401f11673b57da2062b26821d4ae5 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 7 Aug 2024 20:38:03 -0600 Subject: [PATCH 39/42] tests: bonsai/hru.mk: updates to not use old variables --- tests/bonsai/hru.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/bonsai/hru.mk b/tests/bonsai/hru.mk index 9d200e5..618acb8 100755 --- a/tests/bonsai/hru.mk +++ b/tests/bonsai/hru.mk @@ -5,10 +5,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. -NAME = hru -TARGET = $(NAME)_tests -BINARY = $(BIN)/$(NAME) - .PHONY: hru_tests hru_tests: $(BIN)/hru From eb821715f7fdfda38900c5dd10ca91efedabd2e3 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 7 Aug 2024 20:45:26 -0600 Subject: [PATCH 40/42] tests: bonsai/hru.mk: fixes hru.mk more --- tests/bonsai/hru.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/bonsai/hru.mk b/tests/bonsai/hru.mk index 618acb8..6f3a05f 100755 --- a/tests/bonsai/hru.mk +++ b/tests/bonsai/hru.mk @@ -6,17 +6,17 @@ # notice are preserved. This file is offered as-is, without any warranty. .PHONY: hru_tests -hru_tests: $(BIN)/hru +hru_tests: hru_help hru_functionality hru_negative hru_regression + +.PHONY: hru_help +hru_help: $(BIN)/hru + ! $(BIN)/hru -h .PHONY: hru_functionality hru_functionality: $(BIN)/hru test "$(printf '1234\n' | $(BIN)/hru)" = '1.2 kB' test "$(printf '0\n' | $(BIN)/hru)" = '0 B' -.PHONY: $(NAME_help) -hru_help: $(BIN)/hru - ! $(BIN)/hru -h - .PHONY: hru_negative hru_negative: $(BIN)/hru ! printf '%s\n' '-1' | $(BIN)/hru From 8e5090d13dcd56feddef261a8adcda10f9149c25 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 7 Aug 2024 22:03:32 -0600 Subject: [PATCH 41/42] tests: README: updates README --- tests/README | 64 ++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/tests/README b/tests/README index ee370b8..7e7508c 100644 --- a/tests/README +++ b/tests/README @@ -1,57 +1,33 @@ -The testing suite contains two main trees (plus translations for strings used in -the shell scripts): the Bonsai tree and the POSIX tree: +The testing suite contains two trees: 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 +├── bonsai/ +│   ├── dj.mk +│   ├── false.mk +│   ├── fop.mk +│   └── ... +├── posix/ +└── tests.mk 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. +The POSIX tests are currently a work-in-progress. Their status in this +repository is uncertain. -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]. +Both sets of tests also inherit the environment set by the top-level Makefile, +which sets the BIN variable to the build/bin directory at the root of the +project; therefore, each binary is located at $(BIN)/tool for idiomatic access. -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. +Each test contains a set of PHONY targets which are prefixed with the name of +the tool being tested and an underscore. The first target is tests, which +depends on all the other targets in the test file. These test files are each +included in the top Makefile, so they can be called from the root of the +repository. This also means that BIN can be set manually so that tests can be +run using make(1) inside of the tests directory: -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] + $ make -f tests.mk BIN=../build/bin dj_tests -- Copyright © 2024 Emma Tebibyte From 7278a8fc41c7784074676851bab97762b364bc70 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 9 Aug 2024 18:00:25 -0600 Subject: [PATCH 42/42] Makefile: fixes testing import --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6c6d555..1b9b9bd 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,6 @@ CFLAGS += -I$(SYSEXITS) # testing requires the absolute path to the bin directory set BIN = build/bin -include tests/tests.mk .PHONY: default default: all test @@ -158,3 +157,5 @@ build/bin/swab: src/swab.rs build rustlibs true: build/bin/true build/bin/true: src/true.c build $(CC) $(CFLAGS) -o $@ src/true.c + +include tests/tests.mk