-
-
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
Open
cfinegan
wants to merge
16
commits into
racket:master
Choose a base branch
from
cfinegan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8371ba1
Added current-check-info procedure.
cfinegan 75576b8
Added filtering upon names, files, and line numbers.
cfinegan b62ee26
Fixed bug in file/line filtering.
cfinegan b37720e
Added tests and fixed bug in arguments-say-to-run.
cfinegan 749a8ae
Added documentation for test filtering.
cfinegan e4412bf
Updated wording in docs.
cfinegan 071ce1d
Now ignores invalid line numbers.
cfinegan 6e18da0
Fixed type in docs.
cfinegan 2952f2a
Merge branch 'master' of https://github.com/racket/rackunit
cfinegan 6fc3e6d
Fixed issue from location info being a struct.
cfinegan 4268e62
Added missing newline at end of file.
cfinegan 9a457d3
parital fix for docs examples.
cfinegan 210431d
Fixed errors thrown in docs examples.
cfinegan 573f97c
Added caching for test filters.
cfinegan 117d26c
Removed unused dependency on sandbox-lib.
cfinegan e9ce0b2
Merge branch 'master' of https://github.com/racket/rackunit
cfinegan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#lang scribble/manual | ||
|
||
@(require (for-label racket/base syntax/srcloc) | ||
scribble/example) | ||
|
||
@(define e (make-base-eval '(require rackunit))) | ||
|
||
@title[#:tag "filtering-tests"]{Filtering Tests with Command-line Arguments} | ||
|
||
RackUnit supports test filtering so that one may run one test or a handful of | ||
tests out of a given set. This can be accomplished by using command-line | ||
arguments. Before each check is run, RackUnit will use the value of | ||
@racket[current-command-line-arguments] to construct a list of names, files, | ||
and lines to run. | ||
|
||
@examples[#:eval e | ||
(parameterize ([current-command-line-arguments (vector "foo")]) | ||
(with-check-info (['name 'foo]) | ||
(check-equal? 1 2)) | ||
(check-equal? 2 3))] | ||
|
||
In the above example, the former test runs because its @racket['name] field | ||
matches with the value specified on the command line. The latter test is | ||
skipped. | ||
|
||
Multiple names can also be specified. Names are treated as regular expressions, | ||
and tests will be run if they match any of the names specified on the command | ||
line. | ||
|
||
@examples[#:eval e | ||
(parameterize ([current-command-line-arguments (vector "foo" "bar")]) | ||
(with-check-info (['name 'foo]) | ||
(check-equal? 1 2)) | ||
(with-check-info (['name 'bar]) | ||
(check-equal? 2 3)))] | ||
|
||
Filtering by file or line number works similarly, and uses the syntax | ||
file:@italic{<file>} or line:@italic{<line>}. | ||
|
||
@examples[#:eval e | ||
(parameterize ([current-command-line-arguments (vector "line:2")]) | ||
(check-equal? 1 2))] | ||
|
||
@examples[#:eval e | ||
(parameterize ([current-command-line-arguments (vector "line:1")]) | ||
(check-equal? 2 3))] | ||
|
||
Name, file, and line specifiers can be combined to create more specific filters. | ||
|
||
@racketblock[(define loc (list (string->path "baz.rkt") 5 0 #f #f)) | ||
(parameterize ([current-command-line-arguments (vector "foo" "file:bar.rkt" "line:5")]) | ||
(with-check-info (['name 'foo] | ||
['location (location-info loc)]) | ||
(check-equal? 1 2)))] | ||
|
||
The above example is not run because, even though the test name and line number | ||
are correct, the file names do not match. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#lang racket/base | ||
|
||
(require rackunit | ||
syntax/parse/define | ||
racket/format | ||
(for-syntax racket/base | ||
syntax/location)) | ||
|
||
(define-syntax (current-file-name stx) | ||
(with-syntax ([file (syntax-source-file-name stx)]) | ||
(syntax-case stx () | ||
[_ #'file]))) | ||
|
||
(define-syntax (current-line-number stx) | ||
(with-syntax ([line (syntax-line stx)]) | ||
(syntax-case stx () | ||
[_ #'line]))) | ||
|
||
(define-simple-macro (with-cmd (args ...) e) | ||
(parameterize ([current-command-line-arguments (vector args ...)]) | ||
(let () e))) | ||
|
||
(define-simple-macro (run-test (args ...) e) | ||
(with-cmd (args ...) | ||
(let ([result (open-output-string)]) | ||
(parameterize ([current-error-port result]) | ||
(begin e (get-output-string result)))))) | ||
|
||
(define-simple-macro (check-error (args ...) e) | ||
(when (zero? (string-length (run-test (args ...) e))) | ||
(eprintf "TEST FAILED: (check-error ~s ~a)\n" | ||
(map ~a (list args ...)) (quote e)))) | ||
|
||
(define-simple-macro (check-no-error (args ...) e) | ||
(let ([result (run-test (args ...) e)]) | ||
(unless (zero? (string-length result)) | ||
(eprintf "TEST FAILED: (check-no-error ~s ~a)\n~a\n" | ||
(map ~a (list args ...)) (quote e) result)))) | ||
|
||
(define FILE-NAME (path->string (current-file-name))) | ||
|
||
(module+ test | ||
;; Define args for correct and incorrect file names. | ||
(define file-name-arg (format "file:~a" FILE-NAME)) | ||
(define wrong-file-name-arg | ||
(format "file:~a" | ||
(list->string (map (compose integer->char add1 char->integer) | ||
(string->list FILE-NAME))))) | ||
;; Define test. | ||
(define (go) | ||
(with-check-info (['name 'foo]) | ||
(check-equal? 1 2))) (define GO-LINE (current-line-number)) ;; Keep this on same line! | ||
;; Define args for correct and incorrect line numbers. | ||
(define go-line-num-arg (format "line:~a" GO-LINE)) | ||
(define wrong-go-line-num-arg (format "line:~a" (+ GO-LINE 100))) | ||
|
||
(check-error ("foo") (go)) | ||
(check-no-error ("baz") (go)) | ||
(check-error ("foo" "baz") (go)) | ||
(check-error ("foo" file-name-arg) (go)) | ||
(check-error ("foo" go-line-num-arg) (go)) | ||
(check-no-error ("foo" wrong-file-name-arg) (go)) | ||
(check-no-error ("foo" wrong-go-line-num-arg) (go)) | ||
(check-no-error ("foo" file-name-arg wrong-go-line-num-arg) (go)) | ||
(check-no-error ("foo" wrong-file-name-arg go-line-num-arg) (go)) | ||
|
||
(define (go2) | ||
(check-equal? 2 3)) | ||
|
||
(check-error () (go2)) | ||
(check-no-error ("foo") (go2)) | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andtest-suite
set the name field?(So, if I have
(test-case "foo" ....)
willraco 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.