Explicitly disable TLS on NetBSD 5.0.
[bpt/guile.git] / test-suite / tests / optargs.test
CommitLineData
025f75b4
MV
1;;;; optargs.test --- test suite for optional arg processing -*- scheme -*-
2;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
3;;;;
7ab42fa2 4;;;; Copyright (C) 2001, 2006, 2009 Free Software Foundation, Inc.
025f75b4 5;;;;
53befeb7
NJ
6;;;; This library is free software; you can redistribute it and/or
7;;;; modify it under the terms of the GNU Lesser General Public
8;;;; License as published by the Free Software Foundation; either
9;;;; version 3 of the License, or (at your option) any later version.
025f75b4 10;;;;
53befeb7 11;;;; This library is distributed in the hope that it will be useful,
025f75b4 12;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
53befeb7
NJ
13;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14;;;; Lesser General Public License for more details.
025f75b4 15;;;;
53befeb7
NJ
16;;;; You should have received a copy of the GNU Lesser General Public
17;;;; License along with this library; if not, write to the Free Software
18;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
025f75b4 19
560434b3 20(define-module (test-suite test-optargs)
7ab42fa2
AW
21 #:use-module (test-suite lib)
22 #:use-module (system base compile)
23 #:use-module (ice-9 optargs))
24
25(define-syntax c&e
26 (syntax-rules (pass-if pass-if-exception)
27 ((_ (pass-if test-name exp))
28 (begin (pass-if (string-append test-name " (eval)")
29 (primitive-eval 'exp))
30 (pass-if (string-append test-name " (compile)")
31 (compile 'exp #:to 'value #:env (current-module)))))
32 ((_ (pass-if-exception test-name exc exp))
33 (begin (pass-if-exception (string-append test-name " (eval)")
34 exc (primitive-eval 'exp))
35 (pass-if-exception (string-append test-name " (compile)")
36 exc (compile 'exp #:to 'value
37 #:env (current-module)))))))
38
39(define-syntax with-test-prefix/c&e
40 (syntax-rules ()
41 ((_ section-name exp ...)
42 (with-test-prefix section-name (c&e exp) ...))))
43
44(with-test-prefix/c&e "optional argument processing"
025f75b4 45 (pass-if "local defines work with optional arguments"
560434b3
DH
46 (eval '(begin
47 (define* (test-1 #:optional (x 0))
48 (define d 1) ; local define
49 #t)
50 (false-if-exception (test-1)))
51 (interaction-environment))))
927a122d
KR
52
53;;;
54;;; let-keywords
55;;;
56
7ab42fa2 57(with-test-prefix/c&e "let-keywords"
927a122d
KR
58
59 ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
60 ;; which caused apparently internal defines to "leak" out into the
61 ;; encompasing environment
62 (pass-if-exception "empty bindings internal defines leaking out"
63 exception:unbound-var
64 (let ((rest '()))
65 (let-keywords rest #f ()
66 (define localvar #f)
67 #f)
68 localvar))
69
70 (pass-if "one key"
71 (let-keywords '(#:foo 123) #f (foo)
72 (= foo 123))))
73
74;;;
75;;; let-keywords*
76;;;
77
7ab42fa2 78(with-test-prefix/c&e "let-keywords*"
927a122d
KR
79
80 ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
81 ;; which caused apparently internal defines to "leak" out into the
82 ;; encompasing environment
83 (pass-if-exception "empty bindings internal defines leaking out"
84 exception:unbound-var
85 (let ((rest '()))
86 (let-keywords* rest #f ()
87 (define localvar #f)
88 #f)
89 localvar))
90
91 (pass-if "one key"
92 (let-keywords* '(#:foo 123) #f (foo)
93 (= foo 123))))
94
95;;;
96;;; let-optional
97;;;
98
7ab42fa2 99(with-test-prefix/c&e "let-optional"
927a122d
KR
100
101 ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
102 ;; which caused apparently internal defines to "leak" out into the
103 ;; encompasing environment
104 (pass-if-exception "empty bindings internal defines leaking out"
105 exception:unbound-var
106 (let ((rest '()))
107 (let-optional rest ()
108 (define localvar #f)
109 #f)
110 localvar))
111
112 (pass-if "one var"
113 (let ((rest '(123)))
114 (let-optional rest ((foo 999))
115 (= foo 123)))))
116
117;;;
118;;; let-optional*
119;;;
120
7ab42fa2 121(with-test-prefix/c&e "let-optional*"
927a122d
KR
122
123 ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
124 ;; which caused apparently internal defines to "leak" out into the
125 ;; encompasing environment
126 (pass-if-exception "empty bindings internal defines leaking out"
127 exception:unbound-var
128 (let ((rest '()))
129 (let-optional* rest ()
130 (define localvar #f)
131 #f)
132 localvar))
133
134 (pass-if "one var"
135 (let ((rest '(123)))
136 (let-optional* rest ((foo 999))
137 (= foo 123)))))
7ab42fa2
AW
138
139(define* (foo a b #:optional c (d 1) (e c) f #:key g (h a) (i r) #:rest r)
140 (list a b c d e f g h i r))
141
142;; So we could use lots more tests here, but the fact that lambda* is in
143;; the compiler, and the compiler compiles itself, using the evaluator
144;; (when bootstrapping) and compiled code (when doing a partial rebuild)
145;; makes me a bit complacent.
146(with-test-prefix/c&e "define*"
147 (pass-if "the whole enchilada"
148 (equal? (foo 1 2)
149 '(1 2 #f 1 #f #f #f 1 () ()))))