/
SpecData.groovy
100 lines (84 loc) · 2.57 KB
/
SpecData.groovy
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
89
90
91
92
93
94
95
96
97
98
99
100
package com.athaydes.spockframework.report.internal
import groovy.transform.CompileStatic
import org.spockframework.runtime.model.ErrorInfo
import org.spockframework.runtime.model.FeatureInfo
import org.spockframework.runtime.model.IterationInfo
import org.spockframework.runtime.model.SpecInfo
import java.util.function.Function
/**
* Data collected for a Spock Specification.
*/
@CompileStatic
class SpecData {
private final List<FeatureRun> featureRuns = [ ].asSynchronized() as List<FeatureRun>
final SpecInfo info
final long startTime
long totalTime
ErrorInfo initializationError
ErrorInfo cleanupSpecError
SpecData( SpecInfo info ) {
this.info = info
this.startTime = System.currentTimeMillis()
}
def <T> T withFeatureRuns( Function<List<FeatureRun>, T> action ) {
synchronized ( featureRuns ) {
return action.apply( featureRuns )
}
}
}
/**
* Data related to a single feature run in a Specification.
*/
@CompileStatic
class FeatureRun {
final FeatureInfo feature
final Map<IterationInfo, List<SpecProblem>> failuresByIteration = [ : ].asSynchronized()
final Map<IterationInfo, Long> timeByIteration = [ : ].asSynchronized()
FeatureRun( FeatureInfo feature ) {
this.feature = feature
}
int iterationCount() {
failuresByIteration.size()
}
/**
* Copy the failuresByIteration Map.
* Use this method to be able to safely iterate over the Map.
* @return a copy of the failuresByIteration.
*/
Map<IterationInfo, List<SpecProblem>> copyFailuresByIteration() {
synchronized ( failuresByIteration ) {
return new LinkedHashMap<>( failuresByIteration )
}
}
/**
* Copy the timeByIteration Map.
* Use this method to be able to safely iterate over the Map.
* @return a copy of the timeByIteration.
*/
Map<IterationInfo, Long> copyTimeByIteration() {
synchronized ( timeByIteration ) {
return new LinkedHashMap<>( timeByIteration )
}
}
}
/**
* Information about an error that occurred within a feature run.
*/
@CompileStatic
class SpecProblem {
final ErrorInfo failure
SpecProblem( ErrorInfo failure ) {
this.failure = failure
}
FailureKind getKind() {
failure.exception instanceof AssertionError ? FailureKind.FAILURE : FailureKind.ERROR
}
}
/**
* Kind of failure for a feature run.
*
* An ERROR means an unexpected {@link Throwable} was thrown, while FAILURE means a test assertion failure.
*/
enum FailureKind {
FAILURE, ERROR
}