Skip to content

Commit 98b8dd8

Browse files
justinhorvitzcopybara-github
authored andcommitted
Add assertions on TestSummary for test command cases in TargetSummaryTest.
PiperOrigin-RevId: 752416711 Change-Id: I04ee9a6a54c1a8256dd52e3d5f09e1f3de15c4e6
1 parent f8c867c commit 98b8dd8

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

src/test/java/com/google/devtools/build/lib/buildtool/TargetSummaryEventTest.java

+35-14
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
2222
import com.google.devtools.build.lib.authandtls.credentialhelper.CredentialModule;
2323
import com.google.devtools.build.lib.buildeventservice.BazelBuildEventServiceModule;
24-
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
2524
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent;
2625
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId.IdCase;
26+
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetSummary;
2727
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TestStatus;
28+
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TestSummary;
2829
import com.google.devtools.build.lib.buildtool.util.BuildIntegrationTestCase;
2930
import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher;
3031
import com.google.devtools.build.lib.runtime.BlazeRuntime;
@@ -75,7 +76,7 @@ public void plainTarget_buildSuccess() throws Exception {
7576

7677
File bep = buildTargetAndCaptureBuildEventProtocol("//foo:foobin");
7778

78-
BuildEventStreamProtos.TargetSummary summary = findTargetSummaryEventInBuildEventStream(bep);
79+
TargetSummary summary = findTargetSummaryEventInBuildEventStream(bep);
7980
assertThat(summary.getOverallBuildSuccess()).isTrue();
8081
assertThat(summary.getOverallTestStatus()).isEqualTo(TestStatus.NO_STATUS);
8182
}
@@ -86,7 +87,7 @@ public void plainTarget_buildFails() throws Exception {
8687

8788
File bep = buildFailingTargetAndCaptureBuildEventProtocol("//foo:foobin");
8889

89-
BuildEventStreamProtos.TargetSummary summary = findTargetSummaryEventInBuildEventStream(bep);
90+
TargetSummary summary = findTargetSummaryEventInBuildEventStream(bep);
9091
assertThat(summary.getOverallBuildSuccess()).isFalse();
9192
assertThat(summary.getOverallTestStatus()).isEqualTo(TestStatus.NO_STATUS);
9293
}
@@ -101,9 +102,12 @@ public void test_buildSucceeds_testSucceeds() throws Exception {
101102

102103
File bep = testTargetAndCaptureBuildEventProtocol("//foo:good_test");
103104

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);
107111
}
108112

109113
@Test
@@ -116,9 +120,12 @@ public void test_buildSucceeds_testFails() throws Exception {
116120

117121
File bep = testTargetAndCaptureBuildEventProtocol("//foo:bad_test");
118122

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);
122129
}
123130

124131
@Test
@@ -147,9 +154,13 @@ public void test_buildSucceeds_testRuntimeFailsToBuild() throws Exception {
147154

148155
File bep = testTargetAndCaptureBuildEventProtocol("//foo:good_test");
149156

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();
153164
}
154165

155166
private File buildTargetAndCaptureBuildEventProtocol(String target) throws Exception {
@@ -217,13 +228,23 @@ private static ImmutableList<BuildEvent> parseBuildEventsFromBuildEventStream(Fi
217228
}
218229

219230
@Nullable
220-
private static BuildEventStreamProtos.TargetSummary findTargetSummaryEventInBuildEventStream(
221-
File bep) throws IOException {
231+
private static TargetSummary findTargetSummaryEventInBuildEventStream(File bep)
232+
throws IOException {
222233
for (BuildEvent buildEvent : parseBuildEventsFromBuildEventStream(bep)) {
223234
if (buildEvent.getId().getIdCase() == IdCase.TARGET_SUMMARY) {
224235
return buildEvent.getTargetSummary();
225236
}
226237
}
227238
return null;
228239
}
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+
}
229250
}

0 commit comments

Comments
 (0)