test-exceptions.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ;;; Copyright (C) 2023 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Exception tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-exceptions")
  22. (test-call "79" (lambda ()
  23. (with-exception-handler
  24. (lambda (exn) 42)
  25. (lambda () (+ 10 69)))))
  26. (test-call "52" (lambda ()
  27. (with-exception-handler
  28. (lambda (exn) 42)
  29. (lambda () (+ 10 (raise-continuable 69))))))
  30. (test-call "42" (lambda ()
  31. (with-exception-handler
  32. (lambda (exn) 42)
  33. (lambda () (+ 10 (raise-continuable 69)))
  34. #:unwind? #t)))
  35. (test-call "69" (lambda ()
  36. (with-exception-handler
  37. (lambda (exn) exn)
  38. (lambda () (+ 10 (raise-continuable 69)))
  39. #:unwind? #t)))
  40. (test-call "42" (lambda ()
  41. (with-exception-handler
  42. (lambda (exn) 42)
  43. (lambda () (+ 10 (raise 69)))
  44. #:unwind? #t)))
  45. (test-call "69" (lambda ()
  46. (with-exception-handler
  47. (lambda (exn) exn)
  48. (lambda () (+ 10 (raise 69)))
  49. #:unwind? #t)))
  50. (test-call "42" (lambda ()
  51. (with-exception-handler
  52. (lambda (exn) 42)
  53. (lambda () (error "what"))
  54. #:unwind? #t)))
  55. (test-call "#(#t \"hey\" (ho))"
  56. (lambda (message irritants)
  57. (let ((exn (make-compound-exception
  58. (list
  59. (make-exception-with-message message)
  60. (make-exception-with-irritants irritants)))))
  61. (vector (error-object? exn)
  62. (error-object-message exn)
  63. (error-object-irritants exn))))
  64. "hey"
  65. '(ho))
  66. (test-call "42"
  67. (lambda ()
  68. (guard (condition
  69. ((assq 'a condition) => cdr)
  70. ((assq 'b condition)))
  71. (raise (list (cons 'a 42))))))
  72. (test-call "(b . 23)"
  73. (lambda ()
  74. (guard (condition
  75. ((assq 'a condition) => cdr)
  76. ((assq 'b condition)))
  77. (raise (list (cons 'b 23))))))
  78. (test-end* "test-exceptions")