experimental UI: when showing the last test, color-code its state The experimental UI also keeps track, in the progress bar, of the last test that completed. When using curses, use colors to indicate whether the test passed or not. -- Change-Id: Iaa01a773c3bbf534692ed21dd420596cb63e2585 Reviewed-on: https://bazel-review.googlesource.com/#/c/3752 MOS_MIGRATED_REVID=123871492
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java index 44e38f0..eee5e0f 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java
@@ -410,10 +410,15 @@ final String prefix = "; last test: "; if (!shortVersion && mostRecentTest != null) { if (terminalWriter != null) { - terminalWriter - .normal() - .append(prefix + shortenedLabelString( - mostRecentTest.getTarget().getLabel(), width - prefix.length())); + terminalWriter.normal().append(prefix); + if (mostRecentTest.getStatus() == BlazeTestStatus.PASSED) { + terminalWriter.okStatus(); + } else { + terminalWriter.failStatus(); + } + terminalWriter.append( + shortenedLabelString(mostRecentTest.getTarget().getLabel(), width - prefix.length())); + terminalWriter.normal(); } return true; } else {
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java index ae6ec13..1da196b 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
@@ -287,7 +287,7 @@ @Test public void testPassedVisible() throws Exception { - // The last test that passed should still be visible in the long status bar. + // The last test should still be visible in the long status bar, and colored as ok if it passed. ManualClock clock = new ManualClock(); ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class); @@ -303,13 +303,43 @@ stateTracker.testFilteringComplete(filteringComplete); stateTracker.testSummary(testSummary); - LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); + LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(); stateTracker.writeProgressBar(terminalWriter); String output = terminalWriter.getTranscript(); + String expected = LoggingTerminalWriter.OK + labelA; assertTrue( - "Label " + labelA.toString() + " should be present in progress bar: " + output, - output.contains(labelA.toString())); + "Sequence '" + expected + "' should be present in colored progress bar: " + output, + output.contains(expected)); + } + + @Test + public void testFailedVisible() throws Exception { + // The last test should still be visible in the long status bar, and colored as fail if it + // did not pass. + ManualClock clock = new ManualClock(); + ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); + TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class); + Label labelA = Label.parseAbsolute("//foo/bar:baz"); + ConfiguredTarget targetA = Mockito.mock(ConfiguredTarget.class); + when(targetA.getLabel()).thenReturn(labelA); + ConfiguredTarget targetB = Mockito.mock(ConfiguredTarget.class); + when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetA, targetB)); + TestSummary testSummary = Mockito.mock(TestSummary.class); + when(testSummary.getStatus()).thenReturn(BlazeTestStatus.FAILED); + when(testSummary.getTarget()).thenReturn(targetA); + + stateTracker.testFilteringComplete(filteringComplete); + stateTracker.testSummary(testSummary); + + LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(); + stateTracker.writeProgressBar(terminalWriter); + String output = terminalWriter.getTranscript(); + + String expected = LoggingTerminalWriter.FAIL + labelA; + assertTrue( + "Sequence '" + expected + "' should be present in colored progress bar: " + output, + output.contains(expected)); } @Test