Skip to content

Commit fb69e55

Browse files
authored
Fix #lang resyntax/test coverage reports (#648)
1 parent 951df0b commit fb69e55

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
- run: raco pkg install --batch --auto cover cover-coveralls
1515
- run: raco pkg install --batch --auto --link --name resyntax
1616
- run: raco test --package resyntax
17-
- run: raco cover --format coveralls --package resyntax
17+
- run: raco cover --format coveralls --suppress-log-execution --package resyntax
1818
env:
1919
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

default-recommendations/windows-newline-test.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
(module+ test
14+
(clear-suites-under-test!)
15+
(clear-header!)
1416
(test-case "windows-style newlines should be replaced with regular newlines"
1517
(parameterize ([current-suite-under-test default-recommendations])
1618
(define program

test.rkt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
(require (for-syntax racket/base
1515
racket/match
1616
resyntax/test/private/statement)
17+
racket/runtime-path
18+
racket/splicing
1719
rackunit
1820
rebellion/base/comparator
1921
rebellion/base/range
@@ -227,13 +229,29 @@
227229
(define-syntax (resyntax-test-module-begin stx)
228230
(syntax-parse stx
229231
[(_ body ...)
230-
(define has-require? (has-require-statements? (attribute body)))
231-
(if has-require?
232-
#`(racket-module-begin (module+ test body ...))
233-
#`(racket-module-begin
234-
(module+ test
235-
(add-suite-under-test! default-recommendations)
236-
body ...)))]))
232+
#:do [(define has-require? (has-require-statements? (attribute body)))
233+
(define has-src-path? (and (syntax-source stx) (path? (syntax-source stx))))]
234+
#:attr default-require (and (not has-require?) #'(add-suite-under-test! default-recommendations))
235+
#:attr stx-path (and has-src-path? #`'#,(build-path (syntax-source stx) 'up))
236+
#'(racket-module-begin
237+
(module+ test
238+
;; We always clear the suites under test first in case this test file is executing in the
239+
;; same (dynamic) module namespace as another test file. If we didn't do this, because the
240+
;; suites under test are stored in a global parameter, then a test runner that reuses
241+
;; namespaces across files might accidentally run extra refactoring rules that the test file
242+
;; didn't specify. The `raco cover` tool is one such test runner: without this reset,
243+
;; coverage reporting with `raco cover` stops working.
244+
(clear-suites-under-test!)
245+
;; Similarly, we also clear the test header global parameter.
246+
(clear-header!)
247+
(~? (~@ (define-runtime-path here stx-path)
248+
;; We also force the current directory to the module's source location's directory.
249+
;; Cover doesn't do this automatically like raco test does for some reason, and not
250+
;; doing it breaks tests that use relative path imports inside refactored test code.
251+
(splicing-parameterize ([current-directory here])
252+
(~? default-require)
253+
body ...))
254+
(~@ (~? default-require) body ...))))]))
237255

238256

239257
;@----------------------------------------------------------------------------------------------------

test/info.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#lang info
2+
3+
4+
; This test file causes Cover to hang for some reason, likely related to logging.
5+
(define cover-omit-paths
6+
(list "testing-lang-test.rkt"))

test/private/rackunit.rkt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
current-suite-under-test
66
current-header
77
current-line-mask
8+
clear-header!
89
set-header!
10+
clear-suites-under-test!
911
add-suite-under-test!
1012
check-suite-refactors
1113
check-suite-does-not-refactor
@@ -84,6 +86,10 @@
8486
(define current-suite-under-test (make-parameter (refactoring-suite #:rules '())))
8587

8688

89+
(define (clear-suites-under-test!)
90+
(current-suite-under-test (refactoring-suite #:rules '())))
91+
92+
8793
(define (add-suite-under-test! suite)
8894
(define current-rules (refactoring-suite-rules (current-suite-under-test)))
8995
(define new-rules (append current-rules (refactoring-suite-rules suite)))
@@ -93,6 +99,10 @@
9399
(define current-header (make-parameter (code-block "")))
94100

95101

102+
(define (clear-header!)
103+
(current-header (code-block "")))
104+
105+
96106
(define (set-header! header-code)
97107
(unless (equal? (current-header) (code-block ""))
98108
(raise-arguments-error 'header: "the header has already been set"))

0 commit comments

Comments
 (0)