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:
@@ -1,55 +0,0 @@
|
||||
# Multi-module linking.
|
||||
#
|
||||
# Modules are only testable end to end, and nothing else in the suite
|
||||
# links more than one translation unit. Three things have to hold at
|
||||
# once: an imported `pub fn' comes out as a prototype with external
|
||||
# linkage, an imported `pub var' as an extern declaration, and the
|
||||
# module's object survives being passed after `--'. Get any of them
|
||||
# wrong and this fails to link -- or, in the `pub var' case, links and
|
||||
# quietly counts into a private copy.
|
||||
#
|
||||
# It also checks what only a second translation unit can check: that an
|
||||
# imported type reaches the type database, by expanding a macro that
|
||||
# reads the imported struct's fields; and that a closure type crossing
|
||||
# the boundary works both ways -- one built in the module and called
|
||||
# here, one built here and called there, through a code pointer that is
|
||||
# static in the other object. And that a record can cross as a handle
|
||||
# alone, its fields left behind and its methods still found.
|
||||
#
|
||||
# The public forms carry comments in their headers, which the reduction
|
||||
# to a prototype and to an extern both have to look past. And a type the
|
||||
# app cannot see -- private to greet, or from a module greet imports
|
||||
# without `pub' -- crosses behind a pointer, declared and no more.
|
||||
#
|
||||
# The interface prints as importers get it: the declarations first, then
|
||||
# the pub forms in the order they were written.
|
||||
#
|
||||
# The app's dependency rule names both modules: greet, which it imports,
|
||||
# and ledger, which only greet does but which decides what the app is
|
||||
# told of it.
|
||||
|
||||
SEXC ?= ../../sexc
|
||||
|
||||
EXPECTED = hello, world\nhello, sex\n2 greetings\ntext times \ntext times \nmood 1\nclosure 15 21 201\nvec2 7 7\nvec2(3 4)\ntally 2\nboard 42\nledger 2\ncolour 123
|
||||
|
||||
check:
|
||||
@if [ "`$(SEXC) --public-interface greet.sex | head -3`" != "`printf '(record cell)\n(record ledger)\n(include stdio.h)'`" ]; then \
|
||||
echo "modules FAILED, the interface begins:"; $(SEXC) --public-interface greet.sex | head -3; exit 1; \
|
||||
fi
|
||||
@$(SEXC) ledger.sex -c -o ledger.o
|
||||
@$(SEXC) greet.sex -c -o greet.o
|
||||
@$(SEXC) greet-app.sex -o greet-app --depfile=greet-app.d -- greet.o ledger.o
|
||||
@if ! head -1 greet-app.d | grep -q '^greet-app: greet-app.sex .*/greet.sex .*/ledger.sex$$'; then \
|
||||
echo "modules FAILED, the dependency rule is:"; cat greet-app.d; $(MAKE) clean; exit 1; \
|
||||
fi
|
||||
@if [ "`./greet-app`" = "`printf '$(EXPECTED)\n'`" ]; then \
|
||||
echo "modules ok"; \
|
||||
else \
|
||||
echo "modules FAILED, got:"; ./greet-app; $(MAKE) clean; exit 1; \
|
||||
fi
|
||||
@$(MAKE) --no-print-directory clean
|
||||
|
||||
clean:
|
||||
@rm -f greet.o ledger.o greet-app greet-app.d
|
||||
|
||||
.PHONY: check clean
|
||||
86
tests/modules/check.scm
Normal file
86
tests/modules/check.scm
Normal file
@@ -0,0 +1,86 @@
|
||||
;;; Multi-module linking.
|
||||
;;;
|
||||
;;; Modules are only testable end to end, and nothing else in the suite
|
||||
;;; links more than one translation unit. Three things have to hold at
|
||||
;;; once: an imported `pub fn' comes out as a prototype with external
|
||||
;;; linkage, an imported `pub var' as an extern declaration, and the
|
||||
;;; module's object survives being passed after `--'. Get any of them
|
||||
;;; wrong and this fails to link -- or, in the `pub var' case, links and
|
||||
;;; quietly counts into a private copy.
|
||||
;;;
|
||||
;;; It also checks what only a second translation unit can check: that an
|
||||
;;; imported type reaches the type database, by expanding a macro that
|
||||
;;; reads the imported struct's fields; and that a closure type crossing
|
||||
;;; the boundary works both ways -- one built in the module and called
|
||||
;;; here, one built here and called there, through a code pointer that is
|
||||
;;; static in the other object. And that a record can cross as a handle
|
||||
;;; alone, its fields left behind and its methods still found.
|
||||
;;;
|
||||
;;; The public forms carry comments in their headers, which the reduction
|
||||
;;; to a prototype and to an extern both have to look past. And a type the
|
||||
;;; app cannot see -- private to greet, or from a module greet imports
|
||||
;;; without `pub' -- crosses behind a pointer, declared and no more.
|
||||
;;;
|
||||
;;; The interface prints as importers get it: the declarations first, then
|
||||
;;; the pub forms in the order they were written.
|
||||
;;;
|
||||
;;; The app's dependency rule names both modules: greet, which it imports,
|
||||
;;; and ledger, which only greet does but which decides what the app is
|
||||
;;; told of it.
|
||||
;;;
|
||||
;;; SEXC=../../sexc csi -s check.scm
|
||||
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken file)
|
||||
(chicken io)
|
||||
(chicken irregex)
|
||||
(chicken process)
|
||||
(chicken process-context)
|
||||
srfi-1
|
||||
test)
|
||||
|
||||
(define sexc (or (get-environment-variable "SEXC") "../../sexc"))
|
||||
|
||||
;;; The lines PROGRAM prints when run with ARGS, or #f when it fails
|
||||
(define (output-of program . args)
|
||||
(let* ((proc (process program args))
|
||||
(lines (read-lines (process-output-port proc))))
|
||||
(process-wait proc)
|
||||
(and (process-returned-normally? proc)
|
||||
(zero? (process-exit-status proc))
|
||||
lines)))
|
||||
|
||||
(test "the interface begins with the declarations"
|
||||
'("(record cell)" "(record ledger)" "(include stdio.h)")
|
||||
(take (or (output-of sexc "--public-interface" "greet.sex") '()) 3))
|
||||
|
||||
(test-assert "the app links with both modules"
|
||||
(and (output-of sexc "ledger.sex" "-c" "-o" "ledger.o")
|
||||
(output-of sexc "greet.sex" "-c" "-o" "greet.o")
|
||||
(output-of sexc "greet-app.sex" "-o" "greet-app" "--depfile=greet-app.d"
|
||||
"--" "greet.o" "ledger.o")))
|
||||
|
||||
(test-assert "the dependency rule names both modules"
|
||||
(irregex-match "greet-app: greet-app\\.sex .*/greet\\.sex .*/ledger\\.sex"
|
||||
(call-with-input-file "greet-app.d" read-line)))
|
||||
|
||||
(test "the app runs through both"
|
||||
'("hello, world"
|
||||
"hello, sex"
|
||||
"2 greetings"
|
||||
"text times "
|
||||
"text times "
|
||||
"mood 1"
|
||||
"closure 15 21 201"
|
||||
"vec2 7 7"
|
||||
"vec2(3 4)"
|
||||
"tally 2"
|
||||
"board 42"
|
||||
"ledger 2"
|
||||
"colour 123")
|
||||
(output-of "./greet-app"))
|
||||
|
||||
(for-each delete-file* '("greet.o" "ledger.o" "greet-app" "greet-app.d"))
|
||||
|
||||
(test-exit)
|
||||
Reference in New Issue
Block a user