1 ;;;; rnrs-libraries.test --- test library and import forms -*- scheme -*-
2 ;;;; Copyright (C) 2010, 2012 Free Software Foundation, Inc.
4 ;;;; This library is free software; you can redistribute it and/or
5 ;;;; modify it under the terms of the GNU Lesser General Public
6 ;;;; License as published by the Free Software Foundation; either
7 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;; This library is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;;; Lesser General Public License for more details.
14 ;;;; You should have received a copy of the GNU Lesser General Public
15 ;;;; License along with this library; if not, write to the Free Software
16 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 (define-module (tests rnrs-libraries)
19 #:use-module (test-suite lib))
21 ;; First, check that Guile modules are r6rs modules.
23 (with-test-prefix "ice-9 receive"
28 (import (ice-9 receive))
32 (pass-if "resolve-interface"
33 (module? (resolve-interface '(ice-9 receive))))
35 (set! iface (resolve-interface '(ice-9 receive)))
37 (pass-if "resolve-r6rs-interface"
38 (eq? iface (resolve-r6rs-interface '(ice-9 receive))))
40 (pass-if "resolve-r6rs-interface (2)"
41 (eq? iface (resolve-r6rs-interface '(library (ice-9 receive)))))
43 (pass-if "module uses"
44 (and (memq iface (module-uses (current-module))) #t))
46 (pass-if "interface contents"
48 (hash-map->list (lambda (sym var) sym) (module-obarray iface))))
50 (pass-if "interface uses"
51 (null? (module-uses iface)))
54 (or (not (module-version iface))
55 (null? (module-version iface))))
57 (pass-if "calling receive from current env"
58 (equal? (eval '(receive (a b) (values 10 32)
64 ;; And check that r6rs modules are guile modules.
66 (with-test-prefix "rnrs-test-a"
70 (not (module-local-variable (current-module) 'double)))
74 (import (tests rnrs-test-a))
78 (pass-if "still no double"
79 (not (module-local-variable (current-module) 'double)))
81 (pass-if "resolve-interface"
82 (module? (resolve-interface '(tests rnrs-test-a))))
84 (set! iface (resolve-interface '(tests rnrs-test-a)))
86 (pass-if "resolve-interface (2)"
87 (eq? iface (resolve-interface '(tests rnrs-test-a))))
89 (pass-if "resolve-r6rs-interface"
90 (eq? iface (resolve-r6rs-interface '(tests rnrs-test-a))))
92 (pass-if "resolve-r6rs-interface (2)"
93 (eq? iface (resolve-r6rs-interface '(library (tests rnrs-test-a)))))
95 (pass-if "module uses"
96 (and (memq iface (module-uses (current-module))) #t))
98 (pass-if "interface contents"
100 (hash-map->list (lambda (sym var) sym) (module-obarray iface))))
102 (pass-if "interface uses"
103 (null? (module-uses iface)))
106 (or (not (module-version iface))
107 (null? (module-version iface))))
109 (pass-if "calling double"
110 (equal? ((module-ref iface 'double) 10)
113 (pass-if "calling double from current env"
114 (equal? (eval '(double 20) (current-module))
117 ;; Guile should ignore explicit phase specifications
119 (with-test-prefix "implicit phasing"
120 (with-test-prefix "in library form"
121 (pass-if "explicit phasing ignored"
122 (import (for (guile) (meta -1))) #t))
124 (with-test-prefix "in library form"
125 (pass-if "explicit phasing ignored"
126 (save-module-excursion
130 (import (for (guile) (meta -1))))
133 ;; Now import features.
135 (with-test-prefix "import features"
138 (with-test-prefix "only"
142 (lambda (sym var) sym)
143 (module-obarray (resolve-r6rs-interface '(only (guile) +)))))))
145 (with-test-prefix "except"
146 (let ((bindings (hash-map->list
147 (lambda (sym var) sym)
149 (resolve-r6rs-interface '(except (guile) +))))))
151 (equal? (length bindings)
153 (lambda (sym var n) (1+ n))
155 (module-obarray (resolve-interface '(guile)))))))
156 (pass-if "does not contain"
157 (not (memq '+ bindings)))))
159 (with-test-prefix "prefix"
160 (let ((iface (resolve-r6rs-interface '(prefix (ice-9 q) q:))))
162 ((module-ref iface 'q:q?) ((module-ref iface 'q:make-q))))
163 (pass-if "does not contain"
164 (not (module-local-variable iface 'make-q)))))
166 (with-test-prefix "rename"
167 (let ((iface (resolve-r6rs-interface
168 '(rename (only (guile) cons car cdr)
173 (equal? '("rac" "rdc" "snoc")
176 (lambda (sym var) (symbol->string sym))
177 (module-obarray iface))
180 (equal? 3 ((module-ref iface 'rac)
181 ((module-ref iface 'snoc) 3 4))))))
183 (with-test-prefix "srfi"
184 (pass-if "renaming works"
185 (eq? (resolve-interface '(srfi srfi-1))
186 (resolve-r6rs-interface '(srfi :1)))
187 (eq? (resolve-interface '(srfi srfi-1))
188 (resolve-r6rs-interface '(srfi :1 lists)))))
190 (with-test-prefix "macro"
191 (pass-if "multiple clauses"
193 (import (rnrs) (for (rnrs) expand) (rnrs))