bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66776: SRFI-64 test-error doesn't match error types


From: Maxim Cournoyer
Subject: bug#66776: SRFI-64 test-error doesn't match error types
Date: Mon, 11 Dec 2023 23:45:20 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

Hi Taylan,

Taylan Kammer <taylan.kammer@gmail.com> writes:

> On 27.10.2023 20:40, Maxim Cournoyer wrote:
>> 
>> There is a more modern implementation of SRFI-64 out there for Guile
>> which may provide clues or be used wholesale, though I haven't tried it:
>> <https://codeberg.org/taylan/scheme-srfis/src/branch/master/srfi/64>.
>> 
>
> FYI, this is how I check whether a caught error matches the 'type':
>
> (define (error-matches? error type)
>   (cond
>    ((eq? type #t)
>     #t)
>    ((condition-type? type)
>     (and (condition? error) (condition-has-type? error type)))
>    ((procedure? type)
>     (type error))
>    (else
>     (let ((runner (test-runner-get)))
>       ((%test-runner-on-bad-error-type runner) runner type error))
>     #f)))
>
> Defined on Line 336 in execution.body.scm:
>
> https://codeberg.org/taylan/scheme-srfis/src/branch/master/srfi/64/execution.body.scm#L336
>
> In summary, other than #t to match anything, 'type' can be:
>
> - A SRFI 35 condition-type object
>
> - A procedure, which will be called as a predicate on the error
>
> The predicate case should cover the Guile and R6RS exception systems,
> which both simply use predicates to detect condition/exception type
> from what I can tell:
>
> https://www.gnu.org/software/guile/manual/html_node/Exception-Objects.html
>
> https://www.gnu.org/software/guile/manual/html_node/rnrs-conditions.html

I've tried your SRFI 64 R7RS implementation, and it passes my earlier
tests:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (use-modules (srfi srfi-64))
scheme@(guile-user)> (test-begin "test")
(test-error "testing" 'bad (throw 'oops))
(test-end "test")
Writing log file: test.srfi64.log
Test suite begin: test
$1 = ("test")
WARNING: unknown error type predicate: bad
         error was: #<&compound-exception components: (#<&error> #<&irritants 
irritants: ()> #<&exception-with-kind-and-args kind: oops args: ()>)>
[FAIL] test: testing
#f:2: (throw (quote oops))
Expected error: bad
Raised error: #<&compound-exception components: (#<&error> #<&irritants 
irritants: ()> #<&exception-with-kind-and-args kind: oops args: ()>)>

Test suite end: test
Passes:            0
Expected failures: 0
Failures:          1
Unexpected passes: 0
Skipped tests:     0
Wrote log file: test.srfi64.log
scheme@(guile-user)> (use-modules (ice-9 exceptions) (srfi srfi-64))

(define-exception-type &my-exception
  &exception                            ;parent
  make-my-exception                     ;constructor
  my-exception?)                        ;predicate

(test-begin "test-error exception types")

;; Passes, but should fail.
(test-error "&my-exception raised"
  &my-exception
  (raise-exception (make-error)))

;; OR

;; Unimplemented, but passes also.
(test-error "&my-exception raised"
  my-exception?
  (raise-exception (make-error)))

(test-begin "test-error exception types")
Writing log file: test.srfi64.log
Test suite begin: test-error exception types
$2 = ("test-error exception types")
[FAIL] test-error exception types: &my-exception raised
#f:14: (raise-exception (make-error))
Expected error: #<record-type &my-exception>
Raised error: #<&error>

[FAIL] test-error exception types: &my-exception raised
#f:21: (raise-exception (make-error))
Expected error: #<procedure 7f0170312900 at ice-9/boot-9.scm:1514:8 (obj)>
Raised error: #<&error>

$3 = ("test-error exception types" "test-error exception types")
--8<---------------cut here---------------end--------------->8---

I'll send the patch upgrading our SRFI 64 implementation to it soon.

-- 
Thanks,
Maxim





reply via email to

[Prev in Thread] Current Thread [Next in Thread]