GNU bug report logs - #66776
SRFI-64 test-error doesn't match error types

Previous Next

Package: guile;

Reported by: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Date: Fri, 27 Oct 2023 18:42:01 UTC

Severity: normal

To reply to this bug, email your comments to 66776 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#66776; Package guile. (Fri, 27 Oct 2023 18:42:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Fri, 27 Oct 2023 18:42:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: bug-guile <bug-guile <at> gnu.org>
Subject: SRFI-64 test-error doesn't match error types
Date: Fri, 27 Oct 2023 14:40:31 -0400
Hello,

I've mean meaning to use 'test-error' in test suites, but as a comment
in its source says, it's currently incomplete:

--8<---------------cut here---------------start------------->8---
;; TODO: decide how to specify expected error types for Guile.
--8<---------------cut here---------------end--------------->8---

So, for example, this should fail but passes:

--8<---------------cut here---------------start------------->8---
(use-modules (srfi srfi-64))
(test-begin "test")
(test-error "testing" 'bad (throw 'oops))
(test-end "test")
--8<---------------cut here---------------end--------------->8---

'test-error' report success for any type of exception, which means its 2nd
argument is currently unused.

It'd also be nice if as its second argument it could accept non only a
error symbol key, but an exception type *or* an exception predicate,
e.g.:

--8<---------------cut here---------------start------------->8---
(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")
--8<---------------cut here---------------end--------------->8---

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>.

-- 
Thanks,
Maxim




Information forwarded to bug-guile <at> gnu.org:
bug#66776; Package guile. (Sat, 28 Oct 2023 18:12:01 GMT) Full text and rfc822 format available.

Message #8 received at 66776 <at> debbugs.gnu.org (full text, mbox):

From: Taylan Kammer <taylan.kammer <at> gmail.com>
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, 66776 <at> debbugs.gnu.org
Subject: Re: bug#66776: SRFI-64 test-error doesn't match error types
Date: Sat, 28 Oct 2023 20:10:32 +0200
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

-- 
Taylan


P.S.: The warning on Codeberg re. invisible Unicode characters is from
using ^L to delineate file sections for navigation with Emacs.




Information forwarded to bug-guile <at> gnu.org:
bug#66776; Package guile. (Tue, 12 Dec 2023 04:46:02 GMT) Full text and rfc822 format available.

Message #11 received at 66776 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Taylan Kammer <taylan.kammer <at> gmail.com>
Cc: 66776 <at> debbugs.gnu.org
Subject: Re: bug#66776: SRFI-64 test-error doesn't match error types
Date: Mon, 11 Dec 2023 23:45:20 -0500
Hi Taylan,

Taylan Kammer <taylan.kammer <at> 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




This bug report was last modified 144 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.