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