@@ -54,8 +54,8 @@ private fun String.substringBetween(first: String, second: String): String {
54
54
return substring(startIndex, endIndex)
55
55
}
56
56
57
- private fun String.parseInstrumentationStatusValue (key : String ): String =
58
- substringBetween( " INSTRUMENTATION_STATUS: $key = " , " INSTRUMENTATION_STATUS " ) .trim()
57
+ private fun String.parseInstrumentationStatusValue (key : String ): String = substringBetween( " INSTRUMENTATION_STATUS: $key = " , " INSTRUMENTATION_STATUS " )
58
+ .trim()
59
59
60
60
private fun parseInstrumentationEntry (str : String ): InstrumentationEntry =
61
61
InstrumentationEntry (
@@ -74,7 +74,7 @@ private fun parseInstrumentationEntry(str: String): InstrumentationEntry =
74
74
}
75
75
.let { statusCode ->
76
76
when (statusCode) {
77
- null -> throw IllegalStateException (" Unknown test result status code, please report that to Composer maintainers $str " )
77
+ null -> throw IllegalStateException (" Unknown test result status code [ $statusCode ] , please report that to Composer maintainers $str " )
78
78
else -> statusCode
79
79
}
80
80
},
@@ -86,12 +86,13 @@ fun readInstrumentationOutput(output: File): Observable<InstrumentationEntry> {
86
86
data class result (val buffer : String = " " , val readyForProcessing : Boolean = false )
87
87
88
88
return tail(output)
89
+ .map { it.trim() }
89
90
// `INSTRUMENTATION_CODE: -1` is last line printed by instrumentation, even if 0 tests were run.
90
91
.takeWhile { ! it.startsWith(" INSTRUMENTATION_CODE" ) }
91
92
.scan(result()) { previousResult, newLine ->
92
93
val buffer = when (previousResult.readyForProcessing) {
93
94
true -> newLine
94
- false -> " ${previousResult.buffer} \n $newLine "
95
+ false -> " ${previousResult.buffer}${ System .lineSeparator()} $newLine "
95
96
}
96
97
97
98
result(buffer = buffer, readyForProcessing = newLine.startsWith(" INSTRUMENTATION_STATUS_CODE" ))
@@ -101,7 +102,7 @@ fun readInstrumentationOutput(output: File): Observable<InstrumentationEntry> {
101
102
}
102
103
103
104
fun Observable<InstrumentationEntry>.asTests (): Observable <Test > {
104
- data class result (val entries : List <InstrumentationEntry > = emptyList(), val tests : List <Test > = emptyList())
105
+ data class result (val entries : List <InstrumentationEntry > = emptyList(), val tests : List <Test > = emptyList(), val totalTestsCount : Int = 0 )
105
106
106
107
return this
107
108
.scan(result()) { previousResult, newEntry ->
@@ -110,7 +111,15 @@ fun Observable<InstrumentationEntry>.asTests(): Observable<Test> {
110
111
.mapIndexed { index, first ->
111
112
val second = entries
112
113
.subList(index + 1 , entries.size)
113
- .firstOrNull { first.clazz == it.clazz && first.test == it.test && first.current == it.current }
114
+ .firstOrNull {
115
+ first.clazz == it.clazz
116
+ &&
117
+ first.test == it.test
118
+ &&
119
+ first.current == it.current
120
+ &&
121
+ first.statusCode != it.statusCode
122
+ }
114
123
115
124
if (second == null ) null else first to second
116
125
}
@@ -123,18 +132,29 @@ fun Observable<InstrumentationEntry>.asTests(): Observable<Test> {
123
132
StatusCode .Ok -> Passed
124
133
StatusCode .Ignored -> Ignored
125
134
StatusCode .Failure , StatusCode .AssumptionFailure -> Failed (stacktrace = second.stack)
126
- StatusCode .Start -> throw IllegalStateException (" Unexpected Start code in second entry, please report that to Composer maintainers ($first , $second )" )
135
+ StatusCode .Start -> throw IllegalStateException (" Unexpected status code [ ${second.statusCode} ] in second entry, please report that to Composer maintainers ($first , $second )" )
127
136
},
128
137
durationNanos = second.timestampNanos - first.timestampNanos
129
138
)
130
139
}
131
140
132
141
result(
133
142
entries = entries.filter { entry -> tests.firstOrNull { it.className == entry.clazz && it.testName == entry.test } == null },
134
- tests = tests
143
+ tests = tests,
144
+ totalTestsCount = previousResult.totalTestsCount + tests.size
135
145
)
136
146
}
137
- .takeUntil { it.entries.count { it.current == it.numTests } >= 2 }
147
+ .takeUntil {
148
+ if (it.entries.count { it.current == it.numTests } == 2 ) {
149
+ if (it.totalTestsCount < it.entries.first().numTests) {
150
+ throw IllegalStateException (" Less tests were emitted than Instrumentation reported: $it " )
151
+ }
152
+
153
+ true
154
+ } else {
155
+ false
156
+ }
157
+ }
138
158
.filter { it.tests.isNotEmpty() }
139
159
.flatMap { Observable .from(it.tests) }
140
160
}
0 commit comments