21
21
import com .google .devtools .build .lib .analysis .util .AnalysisMock ;
22
22
import com .google .devtools .build .lib .authandtls .credentialhelper .CredentialModule ;
23
23
import com .google .devtools .build .lib .buildeventservice .BazelBuildEventServiceModule ;
24
- import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos ;
25
24
import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos .BuildEvent ;
26
25
import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos .BuildEventId .IdCase ;
26
+ import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos .TargetSummary ;
27
27
import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos .TestStatus ;
28
+ import com .google .devtools .build .lib .buildeventstream .BuildEventStreamProtos .TestSummary ;
28
29
import com .google .devtools .build .lib .buildtool .util .BuildIntegrationTestCase ;
29
30
import com .google .devtools .build .lib .runtime .BlazeCommandDispatcher ;
30
31
import com .google .devtools .build .lib .runtime .BlazeRuntime ;
@@ -75,7 +76,7 @@ public void plainTarget_buildSuccess() throws Exception {
75
76
76
77
File bep = buildTargetAndCaptureBuildEventProtocol ("//foo:foobin" );
77
78
78
- BuildEventStreamProtos . TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
79
+ TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
79
80
assertThat (summary .getOverallBuildSuccess ()).isTrue ();
80
81
assertThat (summary .getOverallTestStatus ()).isEqualTo (TestStatus .NO_STATUS );
81
82
}
@@ -86,7 +87,7 @@ public void plainTarget_buildFails() throws Exception {
86
87
87
88
File bep = buildFailingTargetAndCaptureBuildEventProtocol ("//foo:foobin" );
88
89
89
- BuildEventStreamProtos . TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
90
+ TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
90
91
assertThat (summary .getOverallBuildSuccess ()).isFalse ();
91
92
assertThat (summary .getOverallTestStatus ()).isEqualTo (TestStatus .NO_STATUS );
92
93
}
@@ -101,9 +102,12 @@ public void test_buildSucceeds_testSucceeds() throws Exception {
101
102
102
103
File bep = testTargetAndCaptureBuildEventProtocol ("//foo:good_test" );
103
104
104
- BuildEventStreamProtos .TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
105
- assertThat (summary .getOverallBuildSuccess ()).isTrue ();
106
- assertThat (summary .getOverallTestStatus ()).isEqualTo (TestStatus .PASSED );
105
+ TargetSummary targetSummary = findTargetSummaryEventInBuildEventStream (bep );
106
+ assertThat (targetSummary .getOverallBuildSuccess ()).isTrue ();
107
+ assertThat (targetSummary .getOverallTestStatus ()).isEqualTo (TestStatus .PASSED );
108
+
109
+ TestSummary testSummary = findTestSummaryEventInBuildEventStream (bep );
110
+ assertThat (testSummary .getOverallStatus ()).isEqualTo (TestStatus .PASSED );
107
111
}
108
112
109
113
@ Test
@@ -116,9 +120,12 @@ public void test_buildSucceeds_testFails() throws Exception {
116
120
117
121
File bep = testTargetAndCaptureBuildEventProtocol ("//foo:bad_test" );
118
122
119
- BuildEventStreamProtos .TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
120
- assertThat (summary .getOverallBuildSuccess ()).isTrue ();
121
- assertThat (summary .getOverallTestStatus ()).isEqualTo (TestStatus .FAILED );
123
+ TargetSummary targetSummary = findTargetSummaryEventInBuildEventStream (bep );
124
+ assertThat (targetSummary .getOverallBuildSuccess ()).isTrue ();
125
+ assertThat (targetSummary .getOverallTestStatus ()).isEqualTo (TestStatus .FAILED );
126
+
127
+ TestSummary testSummary = findTestSummaryEventInBuildEventStream (bep );
128
+ assertThat (testSummary .getOverallStatus ()).isEqualTo (TestStatus .FAILED );
122
129
}
123
130
124
131
@ Test
@@ -147,9 +154,13 @@ public void test_buildSucceeds_testRuntimeFailsToBuild() throws Exception {
147
154
148
155
File bep = testTargetAndCaptureBuildEventProtocol ("//foo:good_test" );
149
156
150
- BuildEventStreamProtos .TargetSummary summary = findTargetSummaryEventInBuildEventStream (bep );
151
- assertThat (summary .getOverallBuildSuccess ()).isTrue ();
152
- assertThat (summary .getOverallTestStatus ()).isEqualTo (TestStatus .FAILED_TO_BUILD );
157
+ TargetSummary targetSummary = findTargetSummaryEventInBuildEventStream (bep );
158
+ assertThat (targetSummary .getOverallBuildSuccess ()).isTrue ();
159
+ assertThat (targetSummary .getOverallTestStatus ()).isEqualTo (TestStatus .FAILED_TO_BUILD );
160
+
161
+ // TODO: b/186996003 - TestSummary is a child of TargetComplete and should be posted.
162
+ TestSummary testSummary = findTestSummaryEventInBuildEventStream (bep );
163
+ assertThat (testSummary ).isNull ();
153
164
}
154
165
155
166
private File buildTargetAndCaptureBuildEventProtocol (String target ) throws Exception {
@@ -217,13 +228,23 @@ private static ImmutableList<BuildEvent> parseBuildEventsFromBuildEventStream(Fi
217
228
}
218
229
219
230
@ Nullable
220
- private static BuildEventStreamProtos . TargetSummary findTargetSummaryEventInBuildEventStream (
221
- File bep ) throws IOException {
231
+ private static TargetSummary findTargetSummaryEventInBuildEventStream (File bep )
232
+ throws IOException {
222
233
for (BuildEvent buildEvent : parseBuildEventsFromBuildEventStream (bep )) {
223
234
if (buildEvent .getId ().getIdCase () == IdCase .TARGET_SUMMARY ) {
224
235
return buildEvent .getTargetSummary ();
225
236
}
226
237
}
227
238
return null ;
228
239
}
240
+
241
+ @ Nullable
242
+ private static TestSummary findTestSummaryEventInBuildEventStream (File bep ) throws IOException {
243
+ for (BuildEvent buildEvent : parseBuildEventsFromBuildEventStream (bep )) {
244
+ if (buildEvent .getId ().getIdCase () == IdCase .TEST_SUMMARY ) {
245
+ return buildEvent .getTestSummary ();
246
+ }
247
+ }
248
+ return null ;
249
+ }
229
250
}
0 commit comments