diff --git a/src/test/java/com/google/devtools/build/lib/runtime/UiEventHandlerStdOutAndStdErrTest.java b/src/test/java/com/google/devtools/build/lib/runtime/UiEventHandlerStdOutAndStdErrTest.java index 6ac27f1861cc6b..0edcbdc7c77947 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/UiEventHandlerStdOutAndStdErrTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/UiEventHandlerStdOutAndStdErrTest.java @@ -64,6 +64,12 @@ enum TestedOutput { @Before public void createUiEventHandler() { + UiOptions uiOptions = new UiOptions(); + uiOptions.eventFilters = ImmutableList.of(); + createUiEventHandler(uiOptions); + } + + private void createUiEventHandler(UiOptions uiOptions) { output = new FlushCollectingOutputStream(); OutErr outErr = null; @@ -78,8 +84,6 @@ public void createUiEventHandler() { break; } - UiOptions uiOptions = new UiOptions(); - uiOptions.eventFilters = ImmutableList.of(); uiEventHandler = new UiEventHandler(outErr, uiOptions, new ManualClock(), /*workspacePathFragment=*/ null); uiEventHandler.buildStarted(new BuildStartingEvent(/*env=*/ null, mock(BuildRequest.class))); @@ -154,6 +158,24 @@ public void handleOutputEvent_concatenatesBufferBeforeFlushingOnNewline() { output.assertFlushed("hello there!\n"); } + // This test only exercises progress bar code when testing stderr output, since we don't make + // any assertions on stderr (where the progress bar is written) when testing stdout. + @Test + public void noChangeOnUnflushedWrite() { + UiOptions uiOptions = new UiOptions(); + uiOptions.showProgress = true; + uiOptions.useCursesEnum = UiOptions.UseCurses.YES; + uiOptions.eventFilters = ImmutableList.of(); + createUiEventHandler(uiOptions); + if (testedOutput == TestedOutput.STDERR) { + assertThat(output.flushed).hasSize(1); + output.flushed.clear(); + } + // Unterminated strings are saved in memory and not pushed out at all. + assertThat(output.flushed).isEmpty(); + assertThat(output.writtenSinceFlush).isEmpty(); + } + private Event output(String message) { return Event.of(eventKind, message); } diff --git a/src/test/shell/integration/ui_test.sh b/src/test/shell/integration/ui_test.sh index 55b5920aafbbd8..74afd1561ab7d0 100755 --- a/src/test/shell/integration/ui_test.sh +++ b/src/test/shell/integration/ui_test.sh @@ -632,4 +632,22 @@ EOF bazel info server_pid >& "$TEST_log" || fail "Couldn't use server" } +function test_progress_bar_after_stderr() { + mkdir -p foo + cat > foo/BUILD <<'EOF' +genrule(name = 'fail', outs = ['fail.out'], cmd = 'false') +sh_test(name = 'foo', data = [':fail'], srcs = ['foo.sh']) +EOF + touch foo/foo.sh + chmod +x foo/foo.sh + # Build event file needed so UI considers build to continue after failure. + ! bazel test --build_event_json_file=bep.json --curses=yes --color=yes \ + //foo:foo &> "$TEST_log" || fail "Expected failure" + # Expect to see a failure message with an "erase line" control code prepended. + expect_log $'\e'"\[K"$'\e'"\[31m"$'\e'"\[1mFAILED:"$'\e'"\[0m Build did NOT complete successfully" + # We should not see a build failure message without an "erase line" to start. + # TODO(janakr): Fix the excessive printing of this failure message. + expect_log_n "^"$'\e'"\[31m"$'\e'"\[1mFAILED:"$'\e'"\[0m Build did NOT complete successfully" 4 +} + run_suite "Integration tests for ${PRODUCT_NAME}'s UI"