unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Taylan Kammer <taylan.kammer@gmail.com>
Cc: 66776@debbugs.gnu.org
Subject: bug#66776: SRFI-64 test-error doesn't match error types
Date: Mon, 11 Dec 2023 23:45:20 -0500	[thread overview]
Message-ID: <878r60c9lr.fsf@gmail.com> (raw)
In-Reply-To: <39291d90-04d8-4b2f-89db-b059ebc5733f@gmail.com> (Taylan Kammer's message of "Sat, 28 Oct 2023 20:10:32 +0200")

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	other threads:[~2023-12-12  4:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878r60c9lr.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=66776@debbugs.gnu.org \
    --cc=taylan.kammer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).