-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Allow users to filter tests using command-line arguments #44
base: master
Are you sure you want to change the base?
Conversation
(define new-files (cons (regexp (substring arg 5)) files)) | ||
(values names new-files lines)] | ||
[(regexp-match-exact? #rx"[Ll][Ii][Nn][Ee]:.+" arg) | ||
(define new-lines (cons (string->number (substring arg 5)) lines)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if not numberable string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this so it ignore invalid line numbers.
@jackfirth 's recent changes to the data structures broke your in-development version, so please update your fork and fix it up. See the Travis CI log for the problem. |
(check-equal? 1 2)) | ||
(check-equal? 2 3))] | ||
|
||
In the above example, the former test runs because its @racket['name] field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do test-case
and test-suite
set the name field?
(So, if I have (test-case "foo" ....)
will raco test foo file.rkt
run only that test case?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops just realized I need to write raco test ++arg foo file.rkt
.
It would be good to have an example of raco test ....
in these docs.
['location loc]) | ||
(check-equal? 1 2)))] | ||
|
||
The above example is not run because, even though the test name and file number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file number
line number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed this.
I don't think this feature should be built into rackunit. If you want to conditionally execute parts of your test suite, say so with
The Some other comments: The granularity for selective execution should be test cases, not checks. A check might guard another check or an action that shouldn't be executed if the first check fails. In contrast, test cases are supposed to be independent. A library should probably not be parsing command-line arguments, and especially not with such generic names. An environment variable is more idiomatic for adjusting library behavior. In any case, the command-line arguments (or environment variable) should not be re-parsed/processed each time a check executes. Instead, the library should define another parameter ( If this must be tied into rackunit, it should be implemented via the existing |
I disagree with @rmculpepper here. Handling selective execution is a big part of making a nice-to-use testing system, and command line parsing is a very effective way of doing this. My experience with |
My thoughts, @rmculpepper Re: check vs test-case --- I think that most Rackunit users don't use test-case and just put a bunch of Re: parsing & reparsing --- I think your idea is fine. Personally, I would implement it with a global variable and a cache, rather than a parameter. @cfinegan can you do @rmculpepper 's idea? Re: command line vs env variable --- I think that they are orthogonal and I was looking for something with good mouth feel. My preference was "raco test file --- name" but @mflatt objected so we have "raco test ++arg name file" which feels better to the taste than "PLT_RACKUNIT_FILTER=name raco test file" Are you blocking the change or are you convinced in any way? |
I'm unconvinced. I'll write a more detailed response later tonight. |
I have two main problems with the current design and implementation.
First, because the decision of whether to execute or not happens within individual checks and after the evaluation of their arguments, very little evaluation is actually avoided. Suppose we have the following tests, and suppose the we have indicated that we want to run only the first one:
The second expensive computation still gets run. The resource Second, the use of command-line arguments breaks tests that already use command-line arguments, such as the db tests. I introduced an error into the db tests and ran My recommendation is to build a completely separate filtered execution macro; I don't think it belongs in the rackunit core. (But possibly as a rackunit library.) Wrapping the form around test cases or top-level checks or sequences thereof solves the first problem, and making it opt-in (as opposed to changing the meaning of existing rackunit programs) helps with the second. |
I agree with @rmculpepper. Having said that, @samth could you open an issue describing what sort of test filtering you'd like for the Typed Racket tests (I assume TR is your motivation here?) I think if we had a concrete use case it'd be much easier to work out the right API for this. |
@samth
1. I use rackunit a lot and I don’t understand why a library should parse command-line args. Can you explain?
2. When I ran Hell a couple of years ago, I discovered the Python testing and running facilities. Matthew’s reaction to my write-up from back then was just write: sure we need something like this but let me think about it. — And then he came up with submodules, which are far superior and general to Python’s approach.
I am hoping we can get to a similar place here.
|
This pull request changes the behavior of the
define-check
macro so that it examines thecurrent-command-line-arguments
, which it interprets as a set of names, files, and line numbers to run. More specific information about the filtering behavior is available in the docs under "Filtering Tests with Command-line arguments."