Skip to content

Commit

Permalink
BEP: always close stream, even if aborted due to missing tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aehlig authored and philwo committed Sep 12, 2017
1 parent 139543d commit 87cc92e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.runtime.commands.NoTestsFound;
import com.google.devtools.build.lib.util.Pair;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -373,6 +374,11 @@ public void buildInterrupted(BuildInterruptedEvent event) {
abortReason = AbortReason.USER_INTERRUPTED;
}

@Subscribe
public void noTestsFound(NoTestsFound event) {
buildComplete();
}

@Subscribe
public void buildEvent(BuildEvent event) {
if (isActionWithoutError(event)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.runtime.commands;

/** This event is posted by the {@link TestCommand} if no tests were found. */
public class NoTestsFound {}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private ExitCode doTest(CommandEnvironment env,
if (testTargets.isEmpty()) {
env.getReporter().handle(Event.error(
null, "No test targets were found, yet testing was requested"));
env.getEventBus().post(new NoTestsFound());
return buildResult.getSuccess() ? ExitCode.NO_TESTS_FOUND : buildResult.getExitCondition();
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/shell/integration/build_event_stream_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ filegroup(
name = "outergroup",
srcs = ["sourcefileC", ":innergroup"],
)
genrule(
name = "not_a_test",
outs = ["not_a_test.txt"],
cmd = "touch $@",
)
EOF
cat > simpleaspect.bzl <<EOF
def _simple_aspect_impl(target, ctx):
Expand Down Expand Up @@ -616,6 +621,14 @@ function test_test_fails_to_build() {
(bazel test --build_event_text_file=$TEST_log \
pkg:test_that_fails_to_build && fail "test failure expected") || true
expect_not_log '^test_summary'
expect_log 'last_message: true'
}

function test_no_tests_found() {
(bazel test --build_event_text_file=$TEST_log \
pkg:not_a_test && fail "failure expected") || true
expect_not_log '^test_summary'
expect_log 'last_message: true'
}

run_suite "Integration tests for the build event stream"

0 comments on commit 87cc92e

Please sign in to comment.