1
1
module InlineTest
2
2
3
- export @addtest , runtests, @testset , @test , @test_throws
3
+ export runtests, @testset , @test , @test_throws , Test
4
4
5
- using Test: @test , @test_throws , @testset
6
- import Test
5
+ using Test: Test, @test , @test_throws
7
6
8
7
const INLINE_TEST = Ref {Symbol} (:__INLINE_TEST__ )
9
8
@@ -17,40 +16,50 @@ function tests(m)
17
16
getfield (m, inline_test)
18
17
end
19
18
19
+ replacetestset (x) = x
20
+
21
+ # replace unqualified `@testset` by Test.@testset
22
+ function replacetestset (x:: Expr )
23
+ x. head === :macrocall && x. args[1 ] === Symbol (" @testset" ) ?
24
+ Expr (:macrocall , Expr (:., :Test , QuoteNode (Symbol (" @testset" ))), map (replacetestset, x. args[2 : end ])... ) :
25
+ Expr (x. head, map (replacetestset, x. args)... )
26
+ end
27
+
20
28
function addtest (args:: Tuple , m:: Module )
21
- push! (tests (m), :(@testset ($ (args... ))))
29
+ args = map (replacetestset, args)
30
+ push! (tests (m), :(InlineTest. Test. @testset ($ (args... ))))
22
31
nothing
23
32
end
24
33
25
34
"""
26
- @addtest args...
35
+ @testset args...
27
36
28
- Similar to `@testset args...`, but the contained tests are not run immediately,
37
+ Similar to `Test. @testset args...`, but the contained tests are not run immediately,
29
38
and are instead stored for later execution, triggered by `runtests()`.
30
- Invocations of `@addtest` should appear only at the top level, and not be nested
31
- (` @testset` can be nested within `@addtest`) .
32
- Internally, `@addtest` is converted to `@testset` at execution time.
39
+ Invocations of `@testset` can be nested, but qualified invocations of
40
+ `InlineTest. @testset` can't .
41
+ Internally, `@testset` invocations are converted to `Test. @testset` at execution time.
33
42
"""
34
- macro addtest (args... )
43
+ macro testset (args... )
35
44
Expr (:call , :addtest , args, __module__)
36
45
end
37
46
38
47
"""
39
48
runtests([m::Module]; [wrap::Bool])
40
49
41
- Run all the tests declared in `@addtest ` blocks, within `m` if specified,
50
+ Run all the tests declared in `@testset ` blocks, within `m` if specified,
42
51
or within all currently loaded modules otherwise.
43
52
The `wrap` keyword specifies whether the collection of `@testset` blocks derived
44
- from `@addtest ` declarations should be grouped within a top-level `@testset`.
53
+ from `@testset ` declarations should be grouped within a top-level `@testset`.
45
54
The default is `wrap=false` when `m` is specified, `true` otherwise.
46
55
47
- Note: this function executes each `@testset` block using `eval` *within* the module
48
- in which the corresponding `@addtest` block was written (e.g. `m`, when specified).
56
+ Note: this function executes each (top-level) `@testset` block using `eval` *within* the module
57
+ in which it was written (e.g. `m`, when specified).
49
58
"""
50
59
function runtests (m:: Module ; wrap:: Bool = false )
51
60
Core. eval (m,
52
61
if wrap
53
- :(@testset $ (" Tests for module $m " ) begin
62
+ :(InlineTest . Test . @testset $ (" Tests for module $m " ) begin
54
63
$ (tests (m)... )
55
64
end )
56
65
else
71
80
module InlineTestTest
72
81
73
82
using .. InlineTest
74
- @addtest " test Test in sub-module" begin
83
+ @testset " test Test in sub-module" begin
75
84
@test 1 == 1
76
85
end
77
86
78
87
end # module InlineTestTest
79
88
80
- @addtest " self test" begin
89
+ @testset " self test" begin
81
90
@assert typeof (@__MODULE__ ) == Module
82
91
@test 1 != 2
83
92
runtests (InlineTestTest)
0 commit comments