Skip to content

Commit 5cb90bc

Browse files
omusphilbitoxinabox
authored
Runner code checks for problems against flattened testsets (#119)
* Simplify tests for `any_problems` * Support `any_problems` on vectors * Test that `flatten_results!` returns a vector * Runner code checks for problems against flattened testsets * Set project version to 1.1.1 * warn about flatten_results! behavior in docs --------- Co-authored-by: Philip Bittihn <[email protected]> Co-authored-by: Frames White <[email protected]>
1 parent b3d92d9 commit 5cb90bc

File tree

8 files changed

+63
-29
lines changed

8 files changed

+63
-29
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TestReports"
22
uuid = "dcd651b4-b50a-5b6b-8f22-87e9f253a252"
3-
version = "1.1.0"
3+
version = "1.1.1"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

Diff for: src/runner.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ function gen_runner_code(testfilename, logfilename, test_args)
151151
end
152152
153153
# Flatten before calling `report` to avoid a `deepcopy`.
154+
flattened_testsets = TestReports.flatten_results!(ts)
154155
open($(repr(logfilename)), "w") do io
155-
prettyprint(io, report(TestReports.flatten_results!(ts)))
156+
prettyprint(io, report(flattened_testsets))
156157
end
157-
any_problems(ts) && exit(TestReports.TESTS_FAILED)
158+
any_problems(flattened_testsets) && exit(TestReports.TESTS_FAILED)
158159
"""
159160
return runner_code
160161
end

Diff for: src/testsets.jl

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ does not throw an exception on a failure. Thus to set the exit code from
238238
the runner code, we check it using `exit(any_problems(top_level_testset))`.
239239
"""
240240
any_problems(ts::AbstractTestSet) = any(any_problems.(ts.results))
241+
any_problems(v::AbstractVector{<:AbstractTestSet}) = any(any_problems.(v))
241242
any_problems(rs::ReportingResult) = any_problems(rs.result)
242243
any_problems(::Pass) = false
243244
any_problems(::Fail) = true
@@ -262,6 +263,9 @@ end
262263
263264
Returns a flat vector of `TestSet`s which only contain `Result`s. This is necessary for
264265
writing a JUnit XML report the schema does not allow nested XML `testsuite` elements.
266+
267+
Warning: Alters the original hierarchy inside `ts` and potentially removes testsets
268+
from it. Be sure to rely only on the returned vector after usage.
265269
"""
266270
flatten_results!(ts::AbstractTestSet) = _flatten_results!(ts, 0)
267271

Diff for: test/reportgeneration.jl

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ end
9090
@testset "Test packages" begin
9191
# Errors
9292
test_package_expected_fail("FailedTest")
93+
test_package_expected_fail("FailedNestedTest")
9394
test_package_expected_fail("ErroredTest")
9495
test_package_expected_fail("NoTestFile")
9596

Diff for: test/test_packages/FailedNestedTest/Project.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "FailedNestedTest"
2+
uuid = "ab7034c0-1419-4241-b1b9-b226c1793904"
3+
version = "0.1.0"
4+
5+
[extras]
6+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
8+
[targets]
9+
test = ["Test"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module FailedNestedTest
2+
3+
end # module

Diff for: test/test_packages/FailedNestedTest/test/runtests.jl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using FailedNestedTest, Test
2+
3+
@testset "FailedNestedTest" begin
4+
@test true
5+
6+
@testset "nested" begin
7+
@test false
8+
end
9+
end

Diff for: test/testsets.jl

+33-26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ end
1111
@test 2 == 2
1212
end
1313
flattened_testsets = TestReports.flatten_results!(ts)
14+
@test flattened_testsets isa Vector
1415
@test length(flattened_testsets) == 1
1516
@test all(ts -> ts isa AbstractTestSet, flattened_testsets)
1617
@test flattened_testsets[1].description == "Top-Level"
@@ -135,32 +136,38 @@ end
135136
end
136137

137138
@testset "any_problems" begin
138-
@test any_problems(Pass(Symbol(), nothing, nothing, nothing)) == false
139-
@test any_problems(Fail(Symbol(), nothing, nothing, nothing, LineNumberNode(1))) == true
140-
@test any_problems(Broken(Symbol(1), nothing)) == false
141-
@test any_problems(Error(Symbol(), nothing, nothing, nothing, LineNumberNode(1))) == true
142-
143-
fail_code = """
144-
using Test
145-
using TestReports
146-
ts = @testset ReportingTestSet "eg" begin
147-
@test false == true
148-
end;
149-
exit(any_problems(ts))
150-
"""
151-
152-
@test_throws Exception run(`$(Base.julia_cmd()) -e $(fail_code)`)
153-
154-
pass_code = """
155-
using Test
156-
using TestReports
157-
ts = @testset ReportingTestSet "eg" begin
158-
@test true == true
159-
end;
160-
exit(any_problems(ts))
161-
"""
162-
163-
@test run(`$(Base.julia_cmd()) -e $(pass_code)`) isa Any #this line would error if fail
139+
pass = Pass(Symbol(), nothing, nothing, nothing)
140+
fail = Fail(Symbol(), "false", nothing, nothing, LineNumberNode(1))
141+
142+
@testset "results" begin
143+
@test any_problems(pass) === false
144+
@test any_problems(fail) === true
145+
@test any_problems(Broken(Symbol(1), nothing)) === false
146+
@test any_problems(Error(Symbol(), nothing, nothing, nothing, LineNumberNode(1))) === true
147+
end
148+
149+
@testset "testsets" begin
150+
ts = DefaultTestSet("")
151+
Test.record(ts, pass)
152+
@test any_problems(ts) === false
153+
Test.record(ts, fail)
154+
@test any_problems(ts) === true
155+
156+
ts = ReportingTestSet("")
157+
Test.record(ts, pass)
158+
@test any_problems(ts) === false
159+
Test.record(ts, fail)
160+
@test any_problems(ts) === true
161+
end
162+
163+
@testset "vector" begin
164+
ts = [ReportingTestSet("first"), ReportingTestSet("second")]
165+
Test.record(ts[1], pass)
166+
Test.record(ts[2], pass)
167+
@test any_problems(ts) === false
168+
Test.record(ts[2], fail)
169+
@test any_problems(ts) === true
170+
end
164171
end
165172

166173
@testset "Timing" begin

0 commit comments

Comments
 (0)