Debian Codegraph @

test/r7rs-tests.scm

raw
1 ;;
2 ;; This defines a compatibility module, then include Chibi's r7rs-tests to run.
3 ;;
4
5 (use gauche.test)
6
7 ;; fake (chibi test) used in r7rs-tests
8 (define-module chibi.test
9 (use gauche.test)
10 (export test-begin test-end test-values test-assert
11 (rename x:test test))
12
13 (define *nest-count* 0)
14
15 (define (test-begin msg) (test-section msg))
16 (define (test-end) #f)
17
18 (define-syntax x:test
19 (syntax-rules ()
20 [(_ expected expr)
21 (test (write-to-string 'expr) expected (lambda () expr)
22 (lambda (a b)
23 (if (and (inexact? a) (inexact? b)
24 (finite? a) (finite? b)
25 (not (zero? a)))
26 (< (abs (- a b)) (* 10e-7 (abs (+ a b))))
27 (test-check a b))))]))
28
29 (define-syntax test-assert
30 (syntax-rules ()
31 [(_ str expr)
32 (test str #t (lambda () (boolean expr)))]))
33
34 (define-syntax test-values
35 (syntax-rules ()
36 [(_ expected expr)
37 (receive r expected
38 (test (write-to-string 'expr) r
39 (lambda () (values->list expr))))]))
40 )
41 (provide "chibi/test")
42
43 (define-module adaptor
44 (export include)
45 (define-syntax include (with-module gauche include)))
46 (provide "adaptor")
47
48 (test-start "r7rs-tests")
49
50 (require "r7rs-setup")
51 (with-module r7rs.user
52 (import (adaptor))
53 (include "include/r7rs-tests.scm"))
54
55 ;;
56 ;; Some extra tests
57 ;;
58
59 (test-section "Extra tests")
60
61 ;;
62 ;; https://github.com/shirok/Gauche/issues/221
63 ;;
64 ;; In 0.9.5 and before, expansion of insert-internal-define raises
65 ;; syntax-error, since the binding of 'begin' is replaced by
66 ;; define-library implementation.
67
68 (define-library (insert-internal-define)
69 (import (scheme base))
70 (export insert-internal-define)
71 (begin (define-syntax insert-internal-define
72 (syntax-rules ()
73 ((_ x) (begin (define x 'yo!) x))))))
74
75 (define-module insert-internal-define.user
76 (import insert-internal-define))
77
78 (test* "insert internal define with r7rs library" 'yo!
79 (eval '(let ((a 'duh!)) (insert-internal-define a))
80 (find-module 'insert-internal-define.user)))
81
82 ;; cond-expand in library decl is tricky. see the comment in r7rs.scm
83 (define-module cond-expand-test1.user)
84 (test* "cond-expand in library decl" '(a . b)
85 (begin
86 (eval
87 '(define-library (cond-expand-test1)
88 (import (scheme base))
89 (export gauche:list*)
90 (cond-expand
91 (gauche (import (rename (only (gauche base) list*)
92 (list* gauche:list*))))
93 (else)))
94 (find-module 'user))
95 (eval
96 '(with-module cond-expand-test1.user
97 (import cond-expand-test1)
98 (gauche:list* 'a 'b))
99 (find-module 'user))))
100
101 ;; cond-expand with library form
102 (define-module cond-expand-test2.user)
103 (test* "cond-expand in library decl 2" '(0 1 2 3 4 5 6 7 8 9)
104 (begin
105 (eval
106 '(define-library (cond-expand-test2)
107 (import (scheme base))
108 (export xs)
109 (cond-expand
110 ((library (srfi 42))
111 (import (srfi 42))
112 (begin (define xs (list-ec (: x 10) x))))
113 (else)))
114 (find-module 'user))
115 (eval
116 '(with-module cond-expand-test2.user
117 (import cond-expand-test2)
118 xs)
119 (find-module 'user))))
120
121 ;; This test uses srfi-N as a feature identifier; we deprecate such usage.
122 ;; ;; in this test, cond-expand inserts (use SRFI-42). see we can handle it.
123 ;; (define-module cond-expand-test3.user)
124 ;; (test* "cond-expand in library decl 3" '(0 1 2 3 4 5 6 7 8 9)
125 ;; (begin
126 ;; (eval
127 ;; '(define-library (cond-expand-test3)
128 ;; (import (scheme base))
129 ;; (export xs)
130 ;; (cond-expand
131 ;; (srfi-42 (begin (define xs (list-ec (: x 10) x))))
132 ;; (else)))
133 ;; (find-module 'user))
134 ;; (eval
135 ;; '(with-module cond-expand-test3.user
136 ;; (import cond-expand-test3)
137 ;; xs)
138 ;; (find-module 'user))))
139
140 ;; in this test, cond-expand expands into none
141 (test* "cond-expand in library decl 4" #t
142 (begin
143 (eval
144 '(define-library (cond-expand-test4)
145 (import (scheme base))
146 (cond-expand
147 (gauche)
148 (else)))
149 (find-module 'user))
150 #t))
151
152 ;;
153 ;; Test include-library-declarations
154 ;;
155
156 (test* "include-library-declarations 1" 5
157 (begin
158 (eval
159 '(define-library (include-library-declarations-1)
160 (include-library-declarations "include/include-library-declarations-1.scm")
161 (begin (define bar (+ foo 1))))
162 (find-module 'user))
163 (eval
164 '(begin
165 (import include-library-declarations-1)
166 bar)
167 (make-module #f))))
168
169 (test* "include-library-declarations 2"
170 (test-error <top> #/Invalid library declaration/)
171 (begin
172 (eval
173 '(define-library (include-library-declarations-2)
174 (include-library-declarations "include/include-library-declarations-2.scm")
175 (begin (define bar (+ foo 1))))
176 (find-module 'user))
177 (eval
178 '(begin
179 (import include-library-declarations-2)
180 bar)
181 (make-module #f))))
182
183 (test-end)