File: libtest.sh

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (87 lines) | stat: -rwxr-xr-x 1,929 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh

# Scheme 9 from Empty Space
# By Nils M Holm, 2008-2012
# Generate Library Test Suite

testfile=util/libtest.scm

trap '
	cleanup
	exit 1
' 1 2 3 15

cleanup() {
	rm -f $testfile
}

cat >$testfile <<EOT
; Automatically generated test suite,
; See libtest.sh for details.

(load-from-library "syntax-rules.scm")

(define Errors 0)

(define (check src expr result)
;  (write src) (display " ==> ") (write expr) (newline)
  (if (not (equal? expr result))
      (begin (write src)
             (display " FAILED!")
             (newline)
             (display "Expected: ")
             (write result)
             (newline)
             (display "But got:  ")
             (write expr)
             (newline)
             (set! Errors (+ 1 Errors)))))

(define-syntax %test
  (syntax-rules (==>)
    ((_) #t)
    ((_ expr ==> result)
       (check 'expr expr 'result))
    ((_ expr ==> result . more)
       (begin (check 'expr expr 'result)
              (%test . more)))))

EOT

cases="lib/*.scm contrib/*.scm"
if echo '*extensions*' | ./s9 -i ./test.image | grep sys-unix >/dev/null; then
	cases="$cases ext/unix/*.scm"
fi

for f in $cases; do
	if grep '^; Example: ' $f >/dev/null 2>&1; then
		# echo "(display \"$f\") (newline)" >>$testfile
	  	echo "(load-from-library \"`basename $f`\")" >>$testfile
		if grep '^; Given: ' $f >/dev/null 2>&1; then
			sed -ne '/^; Given: /,/^;$/p' <$f | \
				sed -e '/^$/d' | \
				sed -e 's/^;............//' >>$testfile
			echo "" >>$testfile
		fi
		echo "(%test" >>$testfile
		sed -ne '/^; Example: /,/^$/p' <$f | \
			sed -e '/^$/d' | \
			sed -e 's/^;..........//' >>$testfile
		echo ")" >>$testfile
		echo "" >>$testfile
	fi
done

cat >>$testfile <<EOT
(if (= 0 Errors)
    (begin (display "Everything fine!")
           (newline)))
EOT

trap '
	exit 1
' 1 2 3 15

# Use BUILD_ENV from Makefile here
env S9FES_LIBRARY_PATH=.:lib:ext:contrib \
./s9 -i ./test.image $testfile