* 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; 2+ 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] 2+ 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
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2023-10-28 18:10 UTC | newest]
Thread overview: 2+ 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
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).