From 8371ba19675fec9662496f2a50e9e6ca63f3fda3 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Wed, 14 Jun 2017 23:07:10 -0400 Subject: [PATCH 01/14] Added current-check-info procedure. --- rackunit-lib/rackunit/private/check-info.rkt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rackunit-lib/rackunit/private/check-info.rkt b/rackunit-lib/rackunit/private/check-info.rkt index 837acda..d01e1a6 100644 --- a/rackunit-lib/rackunit/private/check-info.rkt +++ b/rackunit-lib/rackunit/private/check-info.rkt @@ -13,6 +13,7 @@ [info-value->string (-> any/c string?)] [check-info-mark symbol?] [check-info-stack (continuation-mark-set? . -> . (listof check-info?))] + [current-check-info (-> (listof check-info?))] [with-check-info* ((listof check-info?) (-> any) . -> . any)]) with-check-info) @@ -41,6 +42,10 @@ (hash-set! ht (check-info-name x) (cons i x))) (map cdr (sort (hash-map ht (λ (k v) v)) < #:key car)))) +;; Shorthand to get the current check-info. +(define (current-check-info) + (check-info-stack (current-continuation-marks))) + ;; with-check-info* : (list-of check-info) thunk -> any (define (with-check-info* info thunk) (define current-marks From 75576b8ac3834e7d887a5154e048ef8f5d3ad709 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Wed, 14 Jun 2017 23:33:33 -0400 Subject: [PATCH 02/14] Added filtering upon names, files, and line numbers. --- rackunit-lib/rackunit/private/check.rkt | 44 ++++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index 6a86449..e9de973 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -97,6 +97,32 @@ (exn-continuation-marks exn) (exn:test:check-stack exn)))) +(define (get-filters) + (for/fold ([names null] [file #f] [line #f]) + ([arg (vector->list (current-command-line-arguments))]) + (cond [(regexp-match-exact? #rx"[Ff][Ii][Ll][Ee]:.+" arg) + (values names (regexp (substring arg 5)) line)] + [(regexp-match-exact? #px"[Ll][Ii][Nn][Ee]:\\d+" arg) + (values names file (string->number (substring arg 5)))] + [else (values (cons (regexp arg) names) file line)]))) + +(define (arguments-say-to-run) + (define-values (names-to-run file-to-run line-to-run) (get-filters)) + (define name + (symbol->string + (check-info-value + (findf (lambda (info) (eq? (check-info-name info) 'name)) + (current-check-info))))) + (define location + (check-info-value + (findf (lambda (info) (eq? (check-info-name info) 'location)) + (current-check-info)))) + (and (or (not file-to-run) (regexp-match? file-to-run (car location))) + (or (not line-to-run) (= line-to-run (cadr location))) + (or (null? names-to-run) + (ormap (lambda (pat) (regexp-match pat name)) + names-to-run)))) + (define-syntax (define-check stx) (syntax-case stx () ((define-check (name formal ...) body ...) @@ -113,14 +139,16 @@ ((current-check-around) (lambda () (with-check-info* - (list* (make-check-name (quote name)) - (make-check-location location) - (make-check-expression expression) - (make-check-params (list formal ...)) - (if message - (list (make-check-message message)) - null)) - (lambda () (begin0 (let () body ...) (test-log! #t)))))) + (list* (make-check-name (quote name)) + (make-check-location location) + (make-check-expression expression) + (make-check-params (list formal ...)) + (if message + (list (make-check-message message)) + null)) + (lambda () + (when (arguments-say-to-run) + (begin0 (let () body ...) (test-log! #t))))))) ;; All checks should return (void). (void)))] From b62ee26bfac559be02a2771b3b2e22b64ed15c03 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Mon, 19 Jun 2017 12:10:52 -0400 Subject: [PATCH 03/14] Fixed bug in file/line filtering. --- rackunit-lib/rackunit/private/check.rkt | 28 +++++---- .../tests/rackunit/arg-forwarding-test.rkt | 59 +++++++++++++++++++ 2 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 rackunit-test/tests/rackunit/arg-forwarding-test.rkt diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index e9de973..47bbf1d 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -98,16 +98,19 @@ (exn:test:check-stack exn)))) (define (get-filters) - (for/fold ([names null] [file #f] [line #f]) + (for/fold ([names null] [files null] [lines null]) ([arg (vector->list (current-command-line-arguments))]) - (cond [(regexp-match-exact? #rx"[Ff][Ii][Ll][Ee]:.+" arg) - (values names (regexp (substring arg 5)) line)] - [(regexp-match-exact? #px"[Ll][Ii][Nn][Ee]:\\d+" arg) - (values names file (string->number (substring arg 5)))] - [else (values (cons (regexp arg) names) file line)]))) + (cond + [(regexp-match-exact? #rx"[Ff][Ii][Ll][Ee]:.+" arg) + (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)) + (values names files new-lines)] + [else (values (cons regexp arg) names) files lines]))) (define (arguments-say-to-run) - (define-values (names-to-run file-to-run line-to-run) (get-filters)) + (define-values (names-to-run files-to-run lines-to-run) (get-filters)) (define name (symbol->string (check-info-value @@ -117,10 +120,15 @@ (check-info-value (findf (lambda (info) (eq? (check-info-name info) 'location)) (current-check-info)))) - (and (or (not file-to-run) (regexp-match? file-to-run (car location))) - (or (not line-to-run) (= line-to-run (cadr location))) + (define file (if (car location) (path->string (car location)) "")) + (define line (cadr location)) + (and (or (null? files-to-run) + (ormap (lambda (file-rex) (regexp-match? file-rex file)) + files-to-run)) + (or (null? lines-to-run) + (ormap (lambda (ln) (equal? ln line)) lines-to-run)) (or (null? names-to-run) - (ormap (lambda (pat) (regexp-match pat name)) + (ormap (lambda (name-rex) (regexp-match? name-rex name)) names-to-run)))) (define-syntax (define-check stx) diff --git a/rackunit-test/tests/rackunit/arg-forwarding-test.rkt b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt new file mode 100644 index 0000000..0289bbd --- /dev/null +++ b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt @@ -0,0 +1,59 @@ +#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-NUM (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-NUM)) + (define wrong-go-line-num-arg (format "line:~a" (+ GO-LINE-NUM 100))) + + (with-cmd ("foo") (go)) + ) + \ No newline at end of file From b37720eae716238886af0ee0acc9240b6721d65d Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Mon, 19 Jun 2017 16:47:21 -0400 Subject: [PATCH 04/14] Added tests and fixed bug in arguments-say-to-run. --- rackunit-lib/rackunit/private/check.rkt | 2 +- .../tests/rackunit/arg-forwarding-test.rkt | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index 47bbf1d..47a2a84 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -107,7 +107,7 @@ [(regexp-match-exact? #rx"[Ll][Ii][Nn][Ee]:.+" arg) (define new-lines (cons (string->number (substring arg 5)) lines)) (values names files new-lines)] - [else (values (cons regexp arg) names) files lines]))) + [else (values (cons (regexp arg) names) files lines)]))) (define (arguments-say-to-run) (define-values (names-to-run files-to-run lines-to-run) (get-filters)) diff --git a/rackunit-test/tests/rackunit/arg-forwarding-test.rkt b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt index 0289bbd..09a139c 100644 --- a/rackunit-test/tests/rackunit/arg-forwarding-test.rkt +++ b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt @@ -49,11 +49,25 @@ ;; Define test. (define (go) (with-check-info (['name 'foo]) - (check-equal? 1 2))) (define GO-LINE-NUM (current-line-number)) ;; Keep this on same line! + (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-NUM)) - (define wrong-go-line-num-arg (format "line:~a" (+ GO-LINE-NUM 100))) + (define go-line-num-arg (format "line:~a" GO-LINE)) + (define wrong-go-line-num-arg (format "line:~a" (+ GO-LINE 100))) - (with-cmd ("foo") (go)) + (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)) ) \ No newline at end of file From 749a8aed0d97f543ede1d08656d909ecd6e09335 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Tue, 20 Jun 2017 15:04:27 -0400 Subject: [PATCH 05/14] Added documentation for test filtering. --- .../scribblings/filtering-tests.scrbl | 65 +++++++++++++++++++ .../rackunit/scribblings/rackunit.scrbl | 1 + rackunit-lib/rackunit/private/check.rkt | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 rackunit-doc/rackunit/scribblings/filtering-tests.scrbl diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl new file mode 100644 index 0000000..05122c6 --- /dev/null +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -0,0 +1,65 @@ +#lang scribble/manual + +@(require (for-label racket/base syntax/srcloc) + scribble/example + racket/sandbox) + +@(define e (make-base-eval '(require rackunit))) + +@title[#:tag "filtering-tests"]{Filtering Tests with Command-line Arguments} + +Sometimes, you might only want to 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{} or line:@italic{}. + +@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))] + +@examples[#:eval e + (define loc (list (string->path "foo.rkt") 4 0 #f #f)) + (parameterize ([current-command-line-arguments (vector "file:foo.rkt" "line:4")]) + (with-check-info (['location loc]) + (check-equal? 1 2)))] + +Name, file, and line specifiers can be combined to create more specific filters. + +@examples[#:eval e + (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 loc]) + (check-equal? 1 2)))] + +The above example is not run because, even though the test name and file number +are correct, the file names do not match. \ No newline at end of file diff --git a/rackunit-doc/rackunit/scribblings/rackunit.scrbl b/rackunit-doc/rackunit/scribblings/rackunit.scrbl index b4758e1..f3dfc08 100644 --- a/rackunit-doc/rackunit/scribblings/rackunit.scrbl +++ b/rackunit-doc/rackunit/scribblings/rackunit.scrbl @@ -15,6 +15,7 @@ from novices to experts. @include-section["quick-start.scrbl"] @include-section["philosophy.scrbl"] @include-section["api.scrbl"] +@include-section["filtering-tests.scrbl"] @include-section["utils.scrbl"] @include-section["internals.scrbl"] @include-section["release-notes.scrbl"] diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index 47a2a84..e6c372b 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -120,7 +120,7 @@ (check-info-value (findf (lambda (info) (eq? (check-info-name info) 'location)) (current-check-info)))) - (define file (if (car location) (path->string (car location)) "")) + (define file (if (path? (car location)) (path->string (car location)) "")) (define line (cadr location)) (and (or (null? files-to-run) (ormap (lambda (file-rex) (regexp-match? file-rex file)) From e4412bf1ac2f6a3c5046d1aa97458af56da0972b Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Tue, 20 Jun 2017 15:52:14 -0400 Subject: [PATCH 06/14] Updated wording in docs. --- rackunit-doc/rackunit/scribblings/filtering-tests.scrbl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl index 05122c6..466c9a0 100644 --- a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -8,9 +8,9 @@ @title[#:tag "filtering-tests"]{Filtering Tests with Command-line Arguments} -Sometimes, you might only want to 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 +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. From 071ce1d42fc78a28046e9c7f06b3d2ffe9909bc5 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Thu, 22 Jun 2017 12:22:08 -0400 Subject: [PATCH 07/14] Now ignores invalid line numbers. --- rackunit-lib/rackunit/private/check.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index e6c372b..5a2d806 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -105,7 +105,8 @@ (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)) + (define line-num (string->number (substring arg 5))) + (define new-lines (if line-num (cons line-num lines) lines)) (values names files new-lines)] [else (values (cons (regexp arg) names) files lines)]))) From 6e18da035300f77068c34cda71df1648052bac30 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Thu, 22 Jun 2017 12:23:24 -0400 Subject: [PATCH 08/14] Fixed type in docs. --- rackunit-doc/rackunit/scribblings/filtering-tests.scrbl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl index 466c9a0..5455ea4 100644 --- a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -61,5 +61,5 @@ Name, file, and line specifiers can be combined to create more specific filters. ['location loc]) (check-equal? 1 2)))] -The above example is not run because, even though the test name and file number +The above example is not run because, even though the test name and line number are correct, the file names do not match. \ No newline at end of file From 6fc3e6d9a8db698d02ac22885911ce660c97b7f3 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Thu, 22 Jun 2017 12:48:55 -0400 Subject: [PATCH 09/14] Fixed issue from location info being a struct. --- rackunit-lib/rackunit/private/check.rkt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index 5a2d806..8b1b44e 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -118,9 +118,10 @@ (findf (lambda (info) (eq? (check-info-name info) 'name)) (current-check-info))))) (define location - (check-info-value - (findf (lambda (info) (eq? (check-info-name info) 'location)) - (current-check-info)))) + (location-info-value + (check-info-value + (findf (lambda (info) (eq? (check-info-name info) 'location)) + (current-check-info))))) (define file (if (path? (car location)) (path->string (car location)) "")) (define line (cadr location)) (and (or (null? files-to-run) From 4268e629b66cb335c929aee1e96046c9e80585b9 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Thu, 22 Jun 2017 12:50:20 -0400 Subject: [PATCH 10/14] Added missing newline at end of file. --- rackunit-test/tests/rackunit/arg-forwarding-test.rkt | 1 - 1 file changed, 1 deletion(-) diff --git a/rackunit-test/tests/rackunit/arg-forwarding-test.rkt b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt index 09a139c..43d911a 100644 --- a/rackunit-test/tests/rackunit/arg-forwarding-test.rkt +++ b/rackunit-test/tests/rackunit/arg-forwarding-test.rkt @@ -70,4 +70,3 @@ (check-error () (go2)) (check-no-error ("foo") (go2)) ) - \ No newline at end of file From 9a457d3ddb495ec610680cdb02e11fa0e6ac5ee5 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Thu, 22 Jun 2017 14:27:59 -0400 Subject: [PATCH 11/14] parital fix for docs examples. --- rackunit-doc/rackunit/scribblings/filtering-tests.scrbl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl index 5455ea4..8adc3ed 100644 --- a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -49,7 +49,7 @@ file:@italic{} or line:@italic{}. @examples[#:eval e (define loc (list (string->path "foo.rkt") 4 0 #f #f)) (parameterize ([current-command-line-arguments (vector "file:foo.rkt" "line:4")]) - (with-check-info (['location loc]) + (with-check-info (['location (location-info loc)]) (check-equal? 1 2)))] Name, file, and line specifiers can be combined to create more specific filters. @@ -58,8 +58,8 @@ Name, file, and line specifiers can be combined to create more specific filters. (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 loc]) + ['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. \ No newline at end of file +are correct, the file names do not match. From 210431d44f2f749f8ce64f92af77c9ea7486e56b Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Fri, 23 Jun 2017 12:10:52 -0400 Subject: [PATCH 12/14] Fixed errors thrown in docs examples. --- rackunit-doc/rackunit/scribblings/filtering-tests.scrbl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl index 8adc3ed..5625f08 100644 --- a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -46,16 +46,9 @@ file:@italic{} or line:@italic{}. (parameterize ([current-command-line-arguments (vector "line:1")]) (check-equal? 2 3))] -@examples[#:eval e - (define loc (list (string->path "foo.rkt") 4 0 #f #f)) - (parameterize ([current-command-line-arguments (vector "file:foo.rkt" "line:4")]) - (with-check-info (['location (location-info loc)]) - (check-equal? 1 2)))] - Name, file, and line specifiers can be combined to create more specific filters. -@examples[#:eval e - (define loc (list (string->path "baz.rkt") 5 0 #f #f)) +@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)]) From 573f97cd03a6c84145ba902013612be85df2128a Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Fri, 23 Jun 2017 12:11:10 -0400 Subject: [PATCH 13/14] Added caching for test filters. --- rackunit-lib/rackunit/private/check.rkt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rackunit-lib/rackunit/private/check.rkt b/rackunit-lib/rackunit/private/check.rkt index 8b1b44e..de47b94 100644 --- a/rackunit-lib/rackunit/private/check.rkt +++ b/rackunit-lib/rackunit/private/check.rkt @@ -110,8 +110,23 @@ (values names files new-lines)] [else (values (cons (regexp arg) names) files lines)]))) +(struct test-filter (names files lines)) +(define current-filters #f) +(define last-cmd-args #f) + +(define (maybe-load-filters!) + (define cmd-args (current-command-line-arguments)) + (unless (and current-filters (eq? last-cmd-args cmd-args)) + (set! last-cmd-args cmd-args) + (define-values (new-names new-files new-lines) (get-filters)) + (set! current-filters (test-filter new-names new-files new-lines))) + (void)) + (define (arguments-say-to-run) - (define-values (names-to-run files-to-run lines-to-run) (get-filters)) + (maybe-load-filters!) + (define names-to-run (test-filter-names current-filters)) + (define files-to-run (test-filter-files current-filters)) + (define lines-to-run (test-filter-lines current-filters)) (define name (symbol->string (check-info-value From 117d26cfdbb509dc3a8d7b05d60c6efa83713874 Mon Sep 17 00:00:00 2001 From: Conor Finegan Date: Fri, 23 Jun 2017 12:23:04 -0400 Subject: [PATCH 14/14] Removed unused dependency on sandbox-lib. --- rackunit-doc/rackunit/scribblings/filtering-tests.scrbl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl index 5625f08..89e4540 100644 --- a/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl +++ b/rackunit-doc/rackunit/scribblings/filtering-tests.scrbl @@ -1,8 +1,7 @@ #lang scribble/manual @(require (for-label racket/base syntax/srcloc) - scribble/example - racket/sandbox) + scribble/example) @(define e (make-base-eval '(require rackunit)))