check modules and exit codes with the test egg

Written as shell inside make, a check said only that it failed and left
the reason to rerunning it by hand; now each says what it expected.
This commit is contained in:
2026-10-14 23:22:10 +03:00
parent 952ecd4359
commit a4c32a71d2
5 changed files with 153 additions and 100 deletions

View File

@@ -1,32 +0,0 @@
# The failure paths.
#
# Each needs a process to show itself, so none fits the unit suite:
# sexc has to fail when cc fails -- exiting 0 after a failed compile
# makes every driver, sextest included, read it as success -- it has to
# clean up its temporary .c when its own emission throws, and it has to
# refuse `-o -' for an executable, which cc would write to a file named
# `-'.
#
# Everything is built inside a scratch directory, so nothing is left
# here to clean up.
SEXC ?= ../../sexc
check:
@d=`mktemp -d`; \
TMPDIR=$$d $(SEXC) nested-pointer.sex -o $$d/out >/dev/null 2>&1; \
if [ -n "`find $$d -name '*.c'`" ]; then \
echo "exit code FAILED: the temporary .c survived a failed emission"; \
rm -rf $$d; exit 1; \
fi; \
if $(SEXC) hello.sex -o $$d/out -- -no-such-cc-flag >/dev/null 2>&1; then \
echo "exit code FAILED: sexc reported success after cc failed"; \
rm -rf $$d; exit 1; \
fi; \
if (cd $$d && $(abspath $(SEXC)) $(CURDIR)/hello.sex -o - >/dev/null 2>&1) || [ -e $$d/- ]; then \
echo "exit code FAILED: -o - built an executable"; \
rm -rf $$d; exit 1; \
fi; \
rm -rf $$d; echo "exit code ok"
.PHONY: check

62
tests/exit-code/check.scm Normal file
View File

@@ -0,0 +1,62 @@
;;; The failure paths.
;;;
;;; Each needs a process to show itself, so none fits the unit suite:
;;; sexc has to fail when cc fails -- exiting 0 after a failed compile
;;; makes every driver, sextest included, read it as success -- it has to
;;; clean up its temporary .c when its own emission throws, and it has to
;;; refuse `-o -' for an executable, which cc would write to a file named
;;; `-'.
;;;
;;; Everything is built inside a scratch directory, so nothing is left
;;; here to clean up.
;;;
;;; SEXC=../../sexc csi -s check.scm
(import scheme
(chicken base)
(chicken file)
(chicken io)
(chicken pathname)
(chicken process)
(chicken process-context)
test)
(define sexc
(let ((path (or (get-environment-variable "SEXC") "../../sexc")))
(if (absolute-pathname? path)
path
(make-pathname (current-directory) path))))
(define scratch (create-temporary-directory))
(define out (make-pathname scratch "out"))
(set-environment-variable! "TMPDIR" scratch)
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
(define (sexc-succeeds? . args)
(let ((proc (process* sexc args)))
(read-string #f (process-output-port proc))
(read-string #f (process-error-port proc))
(process-wait proc)
(and (process-returned-normally? proc)
(zero? (process-exit-status proc)))))
(test "a failed emission leaves no temporary .c" '()
(begin
(sexc-succeeds? "nested-pointer.sex" "-o" out)
(glob (make-pathname scratch "*.c"))))
(test "a failed cc fails sexc" #f
(sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))
(define hello (make-pathname (current-directory) "hello.sex"))
(change-directory scratch)
(test "-o - is refused for an executable" #f
(sexc-succeeds? hello "-o" "-"))
(test "and leaves no file named -" #f
(file-exists? "-"))
(delete-directory scratch #t)
(test-exit)