Skip to content

Commit 87cc92e

Browse files
aehligphilwo
authored andcommitted
BEP: always close stream, even if aborted due to missing tests
If testing is requested, but no tests are found, the build is aborted. Ensure that even in this case the steam of build events is internally closed (i.e., all announced events are reported, the last event is marked as such). Change-Id: I88763ed6ccd7793deedbcb3428df7e8d289efa23 PiperOrigin-RevId: 168364127
1 parent 139543d commit 87cc92e

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.google.devtools.build.lib.events.Event;
5858
import com.google.devtools.build.lib.events.EventHandler;
5959
import com.google.devtools.build.lib.events.Reporter;
60+
import com.google.devtools.build.lib.runtime.commands.NoTestsFound;
6061
import com.google.devtools.build.lib.util.Pair;
6162
import java.util.ArrayList;
6263
import java.util.Collection;
@@ -373,6 +374,11 @@ public void buildInterrupted(BuildInterruptedEvent event) {
373374
abortReason = AbortReason.USER_INTERRUPTED;
374375
}
375376

377+
@Subscribe
378+
public void noTestsFound(NoTestsFound event) {
379+
buildComplete();
380+
}
381+
376382
@Subscribe
377383
public void buildEvent(BuildEvent event) {
378384
if (isActionWithoutError(event)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.devtools.build.lib.runtime.commands;
16+
17+
/** This event is posted by the {@link TestCommand} if no tests were found. */
18+
public class NoTestsFound {}

src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private ExitCode doTest(CommandEnvironment env,
137137
if (testTargets.isEmpty()) {
138138
env.getReporter().handle(Event.error(
139139
null, "No test targets were found, yet testing was requested"));
140+
env.getEventBus().post(new NoTestsFound());
140141
return buildResult.getSuccess() ? ExitCode.NO_TESTS_FOUND : buildResult.getExitCondition();
141142
}
142143

src/test/shell/integration/build_event_stream_test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ filegroup(
101101
name = "outergroup",
102102
srcs = ["sourcefileC", ":innergroup"],
103103
)
104+
genrule(
105+
name = "not_a_test",
106+
outs = ["not_a_test.txt"],
107+
cmd = "touch $@",
108+
)
104109
EOF
105110
cat > simpleaspect.bzl <<EOF
106111
def _simple_aspect_impl(target, ctx):
@@ -616,6 +621,14 @@ function test_test_fails_to_build() {
616621
(bazel test --build_event_text_file=$TEST_log \
617622
pkg:test_that_fails_to_build && fail "test failure expected") || true
618623
expect_not_log '^test_summary'
624+
expect_log 'last_message: true'
625+
}
626+
627+
function test_no_tests_found() {
628+
(bazel test --build_event_text_file=$TEST_log \
629+
pkg:not_a_test && fail "failure expected") || true
630+
expect_not_log '^test_summary'
631+
expect_log 'last_message: true'
619632
}
620633

621634
run_suite "Integration tests for the build event stream"

0 commit comments

Comments
 (0)