1 ;;;; exceptions.test --- tests for Guile's exception handling -*- scheme -*-
2 ;;;; Copyright (C) 2001, 2003, 2004 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 2.1 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
19 (use-modules (test-suite lib))
21 (with-test-prefix "throw/catch"
23 (with-test-prefix "wrong type argument"
25 (pass-if-exception "(throw 1)"
26 exception:wrong-type-arg
29 (with-test-prefix "wrong number of arguments"
31 (pass-if-exception "(throw)"
32 exception:wrong-num-args
35 (pass-if-exception "throw 1 / catch 0"
36 exception:wrong-num-args
38 (lambda () (throw 'a))
41 (pass-if-exception "throw 2 / catch 1"
42 exception:wrong-num-args
44 (lambda () (throw 'a 2))
47 (pass-if-exception "throw 1 / catch 2"
48 exception:wrong-num-args
50 (lambda () (throw 'a))
53 (pass-if-exception "throw 3 / catch 2"
54 exception:wrong-num-args
56 (lambda () (throw 'a 2 3))
59 (pass-if-exception "throw 1 / catch 2+"
60 exception:wrong-num-args
62 (lambda () (throw 'a))
63 (lambda (x y . rest) #f)))))
65 (with-test-prefix "false-if-exception"
67 (pass-if (false-if-exception #t))
68 (pass-if (not (false-if-exception #f)))
69 (pass-if (not (false-if-exception (error "xxx"))))
73 ;; (with-test-prefix "in empty environment"
74 ;; ;; an environment with no bindings at all
75 ;; (define empty-environment
79 ;; (eval `(,false-if-exception #t)
80 ;; empty-environment))
82 ;; (not (eval `(,false-if-exception #f)
83 ;; empty-environment)))
84 ;; (pass-if "exception"
85 ;; (not (eval `(,false-if-exception (,error "xxx"))
86 ;; empty-environment))))