Skip to content

Treat exceptions thrown by arguments to check as test failures, without changing function behavior #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2020

Conversation

AlexKnauth
Copy link
Member

Just like #107, this PR has the goal of catching errors thrown by arguments and turning them into check failures. However unlike #107, this one does not change the behavior of checks when used as function-ids.

@AlexKnauth
Copy link
Member Author

What are the errors

instantiate: unknown module
  module name: #<resolved-module-path:"/home/travis/.racket/snapshot/pkgs/scribble-lib/scribble/xref.rkt">
  compilation context...:
   /home/travis/.racket/snapshot/pkgs/racket-index/scribblings/main/local-redirect.scrbl
instantiate: unknown module
  module name: #<resolved-module-path:"/home/travis/racket/collects/syntax/apply-transformer.rkt">
  compilation context...:
   /home/travis/build/racket/rackunit/rackunit-typed/rackunit/main.rkt
   /home/travis/build/racket/rackunit/rackunit-typed/rackunit.rkt

about?

@bennn
Copy link
Contributor

bennn commented May 25, 2019

Good question. I think something's wrong with the Travis configuration but I haven't tried to figure it out.

The last two commits to master have the same CI failures, for example:
https://travis-ci.org/racket/rackunit/builds/537037545?utm_source=github_status&utm_medium=notification

If the rackunit tests pass locally, I'm ok with merging this PR

@AlexKnauth
Copy link
Member Author

AlexKnauth commented May 26, 2019

The rackunit tests do not pass locally. The specific order errors might be because I'm adding the location and expression check-infos before everything else, since those are the two things that it can know before it evaluates the arguments.

I have two ideas for how to fix this, but I'm not sure which one to choose:
(a) Add name before location and expression so that the order happens to remain the same
(b) Evaluate the arguments within a check-info context, and then once we have the values, throw away that check-info context and let the function-call set up its own check-info context from nothing.

raco test: (submod ".../pkgs/rackunit-test/tests/rackunit/check-info-test.rkt" test)
raco test: @(test-responsible '(jay noel))
--------------------
define-check adds certain infos automatically in a specific order
FAILURE
location:   check-info-test.rkt:89:4
name:       check-equal?
actual:     '(location expression name params)
expected:   '(name location expression params)
--------------------
--------------------
define-check infos are added before custom infos
FAILURE
location:   check-info-test.rkt:98:4
name:       check-equal?
actual:     '(location expression name params custom1 custom2)
expected:   '(name location expression params custom1 custom2)
--------------------
--------------------
define-check infos are added before calling current-check-around
FAILURE
location:   check-info-test.rkt:117:4
name:       check-equal?
actual:     '(location expression name params custom)
expected:   '(name location expression params custom)
--------------------

@AlexKnauth AlexKnauth force-pushed the check-fails-on-exn-2 branch from 15bc560 to 5fdd831 Compare May 26, 2019 03:41
@bennn
Copy link
Contributor

bennn commented May 27, 2019

Ok, (a) it is. Tests pass for me. LGTM

@sorawee
Copy link
Contributor

sorawee commented May 7, 2020

Good to merge?

@samth
Copy link
Member

samth commented May 7, 2020

I don't totally understand how well this avoids the concerns raised in #107. @AlexKnauth can you explain a little?

@bennn
Copy link
Contributor

bennn commented May 9, 2020

This PR evaluates args to a check-X form when its used directly (the common case) in the same testing context as the check itself:

Example program:

#lang racket/base
(require rackunit)

(define (f)
  (+ 41 "1"))

(check-eq? (f) 42)

On master the call to f throws a normal error:

+: contract violation
  expected: number?
  given: "1"
  ....

but with this PR, RackUnit catches the exception:

--------------------
ERROR
name:       check-eq?
location:   test.rkt:7:0

+: contract violation
  expected: number?
  given: "1"
--------------------

checks as functions

Using check-eq as a function gives the same answer on master and here:

#lang racket/base
(require rackunit)

(define (f)
  (+ 41 "1"))

(define chk check-eq?)

(chk (f) 42)
;; +: contract violation

@rfindler
Copy link
Member

rfindler commented May 9, 2020

Does the exception printing just call error-display-handler?

And, while we're fixing things in rackunit, can we make something like this be a check failure:

(check-equal? (values 1 2) (values 1 3))

and this be a success?

(check-equal? (values 1 2) (values 1 2))

Robby

@sorawee
Copy link
Contributor

sorawee commented May 9, 2020

The values variant is addressed in #73, I think.

@AlexKnauth
Copy link
Member Author

@samth Re: the concerns raised in #107

I see one main concern voiced by both @bennn and @rmculpepper:

This changes the "checks are functions" idea that the docs suggest.
In rackunit, the check forms are meant to act like functions.

I believe this PR addresses that by leaving make-check-func and the check-impl function alone, and in particular not changing the "calling convention" for how the macro-version of each check calls check-impl, so that no matter whether it's used as a macro or function, there's no difference in how the arguments are passed into the check-impl.

@AlexKnauth AlexKnauth force-pushed the check-fails-on-exn-2 branch from 5fdd831 to 4a14901 Compare May 9, 2020 03:28
@AlexKnauth
Copy link
Member Author

Is that enough to address the concerns?

@samth
Copy link
Member

samth commented May 19, 2020

This looks ok to me.

@AlexKnauth
Copy link
Member Author

Is it okay to merge this weekend if there are no additional concerns raised?

@bennn bennn merged commit ce0ba9f into racket:master May 22, 2020
@AlexKnauth AlexKnauth deleted the check-fails-on-exn-2 branch May 22, 2020 18:53
sorawee added a commit to sorawee/rackunit that referenced this pull request Oct 8, 2020
Sine we "treat exceptions thrown by arguments to check as test
failures", and test failures contain "params" clause, it makes sense
for the reported message to contain the clause as well.
The clause is also useful in itself.

Use procedure-rename to avoid names
like #<procedure:.../path/to/file.rkt:x:y> which is brittle and
especially too sensitive to changes.
samth pushed a commit that referenced this pull request Oct 8, 2020
Sine we "treat exceptions thrown by arguments to check as test
failures", and test failures contain "params" clause, it makes sense
for the reported message to contain the clause as well.
The clause is also useful in itself.

Use procedure-rename to avoid names
like #<procedure:.../path/to/file.rkt:x:y> which is brittle and
especially too sensitive to changes.
sorawee added a commit to sorawee/rackunit that referenced this pull request Mar 27, 2021
This PR corrects the wrong fix in racket#123. It restores the functionality
that racket#109 is meant to implement while correctly reporting test results.
samth pushed a commit that referenced this pull request Apr 12, 2021
This PR corrects the wrong fix in #123. It restores the functionality
that #109 is meant to implement while correctly reporting test results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants