Skip to content
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

Move test-log logic for checks and tests inside their "around" parameters #75

Merged
merged 5 commits into from
Sep 3, 2017

Conversation

jackfirth
Copy link
Sponsor Collaborator

@jackfirth jackfirth commented Aug 29, 2017

Closes #70
Closes #9
Closes #14
Closes #58

This PR moves the test-log! logic of checks and test cases into the current-check-around and current-test-case-around parameters, respectively. Additionally, checks now parameterize current-check-around inside the body of define-check so that nested checks are evaluated as normal functions. This allows checks to be imperatively composed; they can be chained together in series just like normal exception-throwing validation functions. This involves several subtle changes to the effects and evaluation of checks:

Single nested check

(define-check (check-zero v)
  (check-equal? v 0))

(check-zero 0)

This now reports one test passing, and uses the default check info added by check-zero. Previously, it would report two tests passing.

Multiple nested checks

(define-check (check-zero-twice v)
  (check-equal? v 0)
  (check-equal? v 0))

(check-zero-twice 0)
(check-zero-twice 1)

The passing use reports one test passing, and the failing use reports one test failing with the check failure thrown by the first check-equal? expression. Previously, the passing use reported two tests passing and the failing use reported two tests failing and one test passing, as each of the nested checks would raise and swallow a check failure leading the outer check to believe nothing went wrong.

Multiple nested checks in test case

(test-case "passing test"
  (check-zero-twice 0))
(test-case "failing test"
  (check-zero-twice 1))

The passing test now reports one test passing, and the failing test reports one test failing. The passing test previously reported three tests passing, and the failing test previously reported one test passing and one test failing. It also only evaluated the first check inside check-zero-twice.

Multiple checks in a test case

(test-case "passing test"
  (check-equal? 1 1)
  (check-equal? 2 2))
(test-case "failing test"
  (check-equal? 1 1)
  (check-equal? 2 3))

The passing test now reports one test passing, and the failing test now reports one test failing. Previously the passing test reported two tests passing and the failing test reported one test passing and two tests failing.

Check in a test suite

For all test suites, calling run-tests on a suite now causes test-log! to report the same number of passing and failing tests as run-tests displays in its summary message. Previously, test-log! would report significantly more tests than run-tests claimed.

Other changes

  • Some parameters now use contracts instead of manually checking types
  • Some of rackunit's own tests are now plain test-case expressions instead of test-suite definitions provided and combined in all-rackunit-tests.rkt
  • The rackunit/log tests now have slightly better failure messages
  • Calls to test-log! now need to be explicitly made by the user of fold-test-results or foldts-test-results. This also allows rackunit test suites to be run without interacting with rackunit/log at all (which the GUI runner probably wants to do anyway)

Future work

This doesn't add any documentation of how rackunit checks behave when composed. It now mostly works "as expected", but without docs and tests guaranteeing this behavior it's not safe for users to rely on.

There are corresponding changes that need to be made in Typed Racket's rackunit wrapper code that duplicates rackunit's test case and test suite macros.

Copy link
Contributor

@bennn bennn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

(raise-type-error 'current-check-around "procedure" v)))))
(define handler (current-check-handler))
(with-handlers ([(λ (_) #t) handler]) (thunk))
(void))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Typed Racket not depend on the return type of check-around?
(Or are you going to change TR before merging this?)

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks created with define-check always returned void, so this shouldn't change the types. That's still the case according to the contract so these void expressions can be removed. I'll do that before merging.

(parameterize
([current-check-handler raise]
[current-check-around check-around])
(parameterize ([current-check-around plain-check-around])
(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing it causes some tests to fail because (test-begin) was never a syntax error, but (parameterize ([param v])) is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, maybe change to (void expr ....) ?

Copy link
Sponsor Collaborator Author

@jackfirth jackfirth Sep 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that doesn't work because the expr expressions actually aren't expressions, they could be definitions. I've added a comment and renamed the pattern variable to hopefully make this less confusing.

Test logging is handled exclusively in current-check-around now
@jackfirth
Copy link
Sponsor Collaborator Author

@bennn I'll merge this later today unless you've got any more comments. Thanks for the review!

@jackfirth jackfirth merged commit 1fbc98e into racket:master Sep 3, 2017
@jackfirth jackfirth deleted the test-log-around branch September 3, 2017 04:11
@jackfirth jackfirth mentioned this pull request Sep 3, 2017
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.

None yet

2 participants