Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flattening retains empty testsets with new properties #102

Merged
merged 11 commits into from
Apr 29, 2024
5 changes: 3 additions & 2 deletions src/testsets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Recursively flatten `ts` to a vector of `TestSet`s.
"""
function _flatten_results!(ts::AbstractTestSet)::Vector{<:AbstractTestSet}
original_results = ts.results
has_new_properties = !isempty(something(properties(ts), Dict()))
omus marked this conversation as resolved.
Show resolved Hide resolved
flattened_results = AbstractTestSet[]
# Track results that are a Result so that if there are any, they can be added
# in their own testset to flattened_results
Expand All @@ -256,8 +257,8 @@ function _flatten_results!(ts::AbstractTestSet)::Vector{<:AbstractTestSet}
end
end

# results will be empty if ts.results only contains testsets
if !isempty(results)
# Skip testsets which contain no results or new properties
if !isempty(results) || has_new_properties
# Use same ts to preserve description
ts.results = results
push!(flattened_results, ts)
Expand Down
13 changes: 4 additions & 9 deletions test/recordproperty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@

# Test nested testset
ts = @testset ReportingTestSet "" begin
recordproperty("ID", "TopLevel")
recordproperty("ID", "TopLevel")
@testset begin
recordproperty("Prop", "Inner 1")
@test 1 == 1
end
@testset begin
recordproperty("Prop", "Inner 2")
@test 2 == 2
end
end
@test ts.properties["ID"] == "TopLevel"
Expand All @@ -35,11 +33,9 @@
recordproperty("ID", "TopLevel")
@testset begin
recordproperty("Prop", "Inner 1")
@test 1 == 1
end
@testset begin
recordproperty("Prop", "Inner 2")
@test 2 == 2
end
end
end
Expand Down Expand Up @@ -86,7 +82,6 @@
recordproperty("ID", "42")
@testset ReportingTestSet "Inner" begin
recordproperty("ID", "0")
@test 1==1
end
end
end
Expand All @@ -100,7 +95,7 @@
@testset ReportingTestSet "Outer" begin
recordproperty("ID", "42")
@testset TestReportingTestSet "Inner" begin
@test 1==1
@test 1 == 1
end
end
end
Expand All @@ -113,7 +108,7 @@
@testset TestReportingTestSet "Custom" begin
ts = @testset ReportingTestSet "Inner" begin
recordproperty("ID", "42")
@test 1==1
@test 1 == 1
end
end
end
Expand All @@ -130,4 +125,4 @@
@testset "Check no interference with default test set" begin
recordproperty("Nothing", "WillHappen")
end
end
end
2 changes: 1 addition & 1 deletion test/references/test_with_properties.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="5" failures="0" errors="0"><testsuite name="Outer/Middle 1" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="true" id="1" classname="Outer/Middle 1" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Outer/Middle 2/Inner" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><testcase name="true" id="1" classname="Outer/Middle 2/Inner" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer/Middle 2" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="true" id="1" classname="Outer/Middle 2" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="true" id="1" classname="Outer" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="true" id="1" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>
<testsuites tests="4" failures="0" errors="0"><testsuite name="Outer/Middle 1" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="true" id="1" classname="Outer/Middle 1" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Outer/Middle 2/Inner" tests="0" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer/Middle 2" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="true" id="1" classname="Outer/Middle 2" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="true" id="1" classname="Outer" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="true" id="1" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>
2 changes: 1 addition & 1 deletion test/references/test_with_properties_pre_1_7.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="5" failures="0" errors="0"><testsuite name="Outer/Middle 1" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer/Middle 1" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Outer/Middle 2/Inner" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer/Middle 2/Inner" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer/Middle 2" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer/Middle 2" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="pass (info lost) (Test 1)" id="1" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>
<testsuites tests="4" failures="0" errors="0"><testsuite name="Outer/Middle 1" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="0"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer/Middle 1" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="1"/></properties></testsuite><testsuite name="Outer/Middle 2/Inner" tests="0" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="1"><properties><property name="File" value="runtests.jl"/><property name="AdditionalNest" value="true"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer/Middle 2" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="2"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer/Middle 2" time="0.0"/><properties><property name="File" value="runtests.jl"/><property name="ID" value="2"/></properties></testsuite><testsuite name="Outer" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="3"><testcase name="pass (info lost) (Test 1)" id="1" classname="Outer" time="0.0"/><properties><property name="File" value="runtests.jl"/></properties></testsuite><testsuite name="Types" tests="1" failures="0" errors="0" time="0.0" timestamp="0" hostname="localhost" id="4"><testcase name="pass (info lost) (Test 1)" id="1" classname="Types" time="0.0"/><properties><property name="Float" value="0.5"/><property name="Int" value="1"/><property name="String" value="TextTests"/><property name="List" value="[&quot;1&quot;]"/><property name="Symbol" value="asymbol"/></properties></testsuite></testsuites>
3 changes: 1 addition & 2 deletions test/test_packages/TestsWithProperties/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using Base.Threads

@testset "Inner" begin
recordproperty("AdditionalNest", true)
@test true
end
end
end
Expand All @@ -30,4 +29,4 @@ end
recordproperty("List", ["1"])
recordproperty("Symbol", :asymbol)
@test true
end
end
Loading