test-exceptions.scm 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;;; Copyright (C) 2023, 2024 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. (with-additional-imports
  56. ((hoot exceptions))
  57. (test-call "#(#t \"hey\" (ho))"
  58. (lambda (message irritants)
  59. (let ((exn (make-compound-exception
  60. (list
  61. (make-exception-with-message message)
  62. (make-exception-with-irritants irritants)))))
  63. (vector (error-object? exn)
  64. (error-object-message exn)
  65. (error-object-irritants exn))))
  66. "hey"
  67. '(ho)))
  68. (test-call "42"
  69. (lambda ()
  70. (guard (condition
  71. ((assq 'a condition) => cdr)
  72. ((assq 'b condition)))
  73. (raise (list (cons 'a 42))))))
  74. (test-call "(b . 23)"
  75. (lambda ()
  76. (guard (condition
  77. ((assq 'a condition) => cdr)
  78. ((assq 'b condition)))
  79. (raise (list (cons 'b 23))))))
  80. (test-end* "test-exceptions")