unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#66776: SRFI-64 test-error doesn't match error types
@ 2023-10-27 18:40 Maxim Cournoyer
  2023-10-28 18:10 ` Taylan Kammer
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Cournoyer @ 2023-10-27 18:40 UTC (permalink / raw)
  To: 66776

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#66776: SRFI-64 test-error doesn't match error types
  2023-10-27 18:40 bug#66776: SRFI-64 test-error doesn't match error types Maxim Cournoyer
@ 2023-10-28 18:10 ` Taylan Kammer
  2023-12-12  4:45   ` Maxim Cournoyer
  0 siblings, 1 reply; 3+ messages in thread
From: Taylan Kammer @ 2023-10-28 18:10 UTC (permalink / raw)
  To: Maxim Cournoyer, 66776

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.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#66776: SRFI-64 test-error doesn't match error types
  2023-10-28 18:10 ` Taylan Kammer
@ 2023-12-12  4:45   ` Maxim Cournoyer
  0 siblings, 0 replies; 3+ messages in thread
From: Maxim Cournoyer @ 2023-12-12  4:45 UTC (permalink / raw)
  To: Taylan Kammer; +Cc: 66776

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-12  4:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-27 18:40 bug#66776: SRFI-64 test-error doesn't match error types Maxim Cournoyer
2023-10-28 18:10 ` Taylan Kammer
2023-12-12  4:45   ` Maxim Cournoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).