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)