|
1 | 1 | using ParallelTestRunner |
2 | | -using Test |
| 2 | +using Test, IOCapture |
3 | 3 |
|
4 | 4 | pushfirst!(ARGS, "--verbose") |
5 | 5 |
|
6 | | -runtests(ARGS) |
| 6 | +@testset "ParallelTestRunner" verbose=true begin |
7 | 7 |
|
8 | | -# custom tests, and initialization code |
9 | | -init_code = quote |
10 | | - using Test |
11 | | - should_be_defined() = true |
12 | | - |
13 | | - macro should_also_be_defined() |
14 | | - return :(true) |
| 8 | +@testset "basic test" begin |
| 9 | + c = IOCapture.capture() do |
| 10 | + runtests(ARGS) |
15 | 11 | end |
| 12 | + @test contains(c.output, "SUCCESS") |
| 13 | + @test contains(c.output, r"basic .+ started at") |
16 | 14 | end |
17 | | -custom_tests = Dict( |
18 | | - "custom" => quote |
19 | | - @test should_be_defined() |
20 | | - @test @should_also_be_defined() |
21 | | - end |
22 | | -) |
23 | | -runtests(ARGS; init_code, custom_tests) |
24 | 15 |
|
25 | | -# custom worker |
26 | | -function test_worker(name) |
27 | | - if name == "needs env var" |
28 | | - return addworker(env = ["SPECIAL_ENV_VAR" => "42"]) |
| 16 | +@testset "custom tests and init code" begin |
| 17 | + init_code = quote |
| 18 | + using Test |
| 19 | + should_be_defined() = true |
| 20 | + |
| 21 | + macro should_also_be_defined() |
| 22 | + return :(true) |
| 23 | + end |
29 | 24 | end |
30 | | - return nothing |
| 25 | + custom_tests = Dict( |
| 26 | + "custom" => quote |
| 27 | + @test should_be_defined() |
| 28 | + @test @should_also_be_defined() |
| 29 | + end |
| 30 | + ) |
| 31 | + c = IOCapture.capture() do |
| 32 | + runtests(ARGS; init_code, custom_tests) |
| 33 | + end |
| 34 | + @test contains(c.output, "SUCCESS") |
| 35 | + @test contains(c.output, "basic") |
| 36 | + @test contains(c.output, "custom") |
31 | 37 | end |
32 | | -custom_tests = Dict( |
33 | | - "needs env var" => quote |
34 | | - @test ENV["SPECIAL_ENV_VAR"] == "42" |
35 | | - end, |
36 | | - "doesn't need env var" => quote |
37 | | - @test !haskey(ENV, "SPECIAL_ENV_VAR") |
| 38 | + |
| 39 | +@testset "custom worker" begin |
| 40 | + function test_worker(name) |
| 41 | + if name == "needs env var" |
| 42 | + return addworker(env = ["SPECIAL_ENV_VAR" => "42"]) |
| 43 | + end |
| 44 | + return nothing |
| 45 | + end |
| 46 | + custom_tests = Dict( |
| 47 | + "needs env var" => quote |
| 48 | + @test ENV["SPECIAL_ENV_VAR"] == "42" |
| 49 | + end, |
| 50 | + "doesn't need env var" => quote |
| 51 | + @test !haskey(ENV, "SPECIAL_ENV_VAR") |
| 52 | + end |
| 53 | + ) |
| 54 | + c = IOCapture.capture() do |
| 55 | + runtests(ARGS; test_worker, custom_tests) |
38 | 56 | end |
39 | | -) |
40 | | -runtests(ARGS; test_worker, custom_tests) |
| 57 | + @test contains(c.output, "SUCCESS") |
| 58 | + @test contains(c.output, "basic") |
| 59 | + @test contains(c.output, "needs env var") |
| 60 | + @test contains(c.output, "doesn't need env var") |
| 61 | +end |
41 | 62 |
|
42 | | -# failing test |
43 | | -custom_tests = Dict( |
44 | | - "failing test" => quote |
45 | | - @test 1 == 2 |
| 63 | +@testset "failing test" begin |
| 64 | + custom_tests = Dict( |
| 65 | + "failing test" => quote |
| 66 | + @test 1 == 2 |
| 67 | + end |
| 68 | + ) |
| 69 | + c = IOCapture.capture(rethrow=Union{}) do |
| 70 | + runtests(ARGS; custom_tests) |
46 | 71 | end |
47 | | -) |
48 | | -@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests) |
| 72 | + @test contains(c.output, "FAILURE") |
| 73 | + @test contains(c.output, "basic") |
| 74 | + @test contains(c.output, r"failing test .+ failed at") |
| 75 | + @test contains(c.output, "1 == 2") |
| 76 | + @test c.error |
| 77 | + @test c.value == Test.FallbackTestSetException("Test run finished with errors") |
| 78 | +end |
49 | 79 |
|
50 | | -# throwing test |
51 | | -custom_tests = Dict( |
52 | | - "throwing test" => quote |
53 | | - error("This test throws an error") |
| 80 | +@testset "throwing test" begin |
| 81 | + custom_tests = Dict( |
| 82 | + "throwing test" => quote |
| 83 | + error("This test throws an error") |
| 84 | + end |
| 85 | + ) |
| 86 | + c = IOCapture.capture(rethrow=Union{}) do |
| 87 | + runtests(ARGS; custom_tests) |
54 | 88 | end |
55 | | -) |
56 | | -@test_throws Test.FallbackTestSetException("Test run finished with errors") runtests(ARGS; custom_tests) |
| 89 | + @test contains(c.output, "FAILURE") |
| 90 | + @test contains(c.output, "basic") |
| 91 | + @test contains(c.output, r"throwing test .+ failed at") |
| 92 | + @test contains(c.output, "Got exception outside of a @test") |
| 93 | + @test c.error |
| 94 | + @test c.value == Test.FallbackTestSetException("Test run finished with errors") |
| 95 | +end |
| 96 | + |
| 97 | +end |
0 commit comments