From 057f5571d6708a964e2b6cc60e10ff76d132cf92 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 24 Apr 2024 14:58:35 -0600 Subject: [PATCH] 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"