-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtestsets.jl
88 lines (71 loc) · 2.4 KB
/
testsets.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
mutable struct ReportingTestSet <: AbstractTestSet
description::AbstractString
results::Vector
end
ReportingTestSet(desc) = ReportingTestSet(desc, [])
record(ts::ReportingTestSet, t) = (push!(ts.results, t); t)
function finish(ts::ReportingTestSet)
# If we are a nested test set, do not print a full summary
# now - let the parent test set do the printing
if get_testset_depth() != 0
# Attach this test set to the parent test set
parent_ts = get_testset()
record(parent_ts, ts)
return ts
end
# We are the top level, lets do this
#to_xml(ts, Val(0))
flatten_results!(ts)
end
#############
"""
any_problems(ts)
Checks a testset to see if there were any problems.
Note that unlike the `DefaultTestSet`, the `ReportingTestSet`
does not throw an exception on a failure.
Thus to set the exit code you should check it using `exit(any_problems(top_level_testset))`
"""
any_problems(ts::AbstractTestSet) = any(any_problems.(ts.results))
any_problems(::Pass) = false
any_problems(::Fail) = true
any_problems(::Broken) = false
any_problems(::Error) = true
######################################
# result flattening
"""
Returns a flat structure 2 deep, of Testset->Result
"""
function flatten_results!(ts::AbstractTestSet)
# Dig down through any singleton levels
while(length(ts.results) == 1 && first(ts.results) isa AbstractTestSet)
ts.description*= "/"*first(ts.results).description
ts.results = first(ts.results).results
end
# Flatten it
ts.results = vcat(_flatten_results!.(ts.results, Val{:top}())...)
ts
end
function _flatten_results!(ts::AbstractTestSet, ::Val) :: Vector{<:AbstractTestSet}
original_results = ts.results
ts.results = Result[]
rets = AbstractTestSet[ts]
function inner!(rs::Result)
push!(ts.results, rs)
end
function inner!(childts::AbstractTestSet)
# make it a sibling
childts.description = ts.description * "/" * childts.description
push!(rets, childts)
end
for res in original_results
childs = _flatten_results!(res, Val{:child}())
for child in childs
inner!(child)
end
end
rets
end
"A result without a parent testset"
_flatten_results!(rs::Result, ::Val{:top})::Vector{AbstractTestSet} = [ReportingTestSet("", [rs])]
"A result with a parent testset"
_flatten_results!(rs::Result, ::Val{:child}) = [rs]