use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class SuperConsoleEventBusListenerTest method testSkippedTest.
@Test
public void testSkippedTest() {
Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
ImmutableSet<BuildTarget> testTargets = ImmutableSet.of(testTarget);
Iterable<String> testArgs = Iterables.transform(testTargets, Object::toString);
FakeBuildRule testBuildRule = new FakeBuildRule(testTarget, pathResolver, ImmutableSortedSet.of());
ProjectBuildFileParseEvents.Started parseEventStarted = new ProjectBuildFileParseEvents.Started();
eventBus.postWithoutConfiguring(configureTestEventAtTime(parseEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 0L, ImmutableList.of("[+] PARSING BUCK FILES...0.0s"));
validateConsole(listener, 100L, ImmutableList.of("[+] PARSING BUCK FILES...0.1s"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectBuildFileParseEvents.Finished(parseEventStarted), 200L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 200L, ImmutableList.of("[-] PARSING BUCK FILES...FINISHED 0.2s"));
BuildEvent.Started buildEventStarted = BuildEvent.started(testArgs);
eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
0L));
ParseEvent.Started parseStarted = ParseEvent.started(testTargets);
eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
0L));
ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
0L));
final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s"));
BuildRuleEvent.Started started = BuildRuleEvent.started(testBuildRule, durationTracker);
eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s", " |=> //:test... 0.2s (checking_cache)"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
0L));
final String buildingLine = "[-] BUILDING...FINISHED 0.8s";
validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.started(// isRunAllTests
true, TestSelectorList.empty(), // shouldExplainTestSelectorList
false, ImmutableSet.copyOf(testArgs)), 2500L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 3000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.5s"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRuleEvent.started(testTarget), 3100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 3200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.7s", " |=> //:test... 0.1s"));
UUID stepUuid = new UUID(0, 1);
StepEvent.Started stepEventStarted = StepEvent.started("step_name", "step_desc", stepUuid);
eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 3300L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 3400L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.9s", " |=> //:test... 0.3s (running step_name[0.1s])"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 3500L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 3600L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.1s", " |=> //:test... 0.5s"));
UUID testUUID = new UUID(2, 3);
eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.started(testUUID, "TestClass", "Foo"), 3700L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 3800L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.3s", " |=> //:test... 0.7s (running Foo[0.1s])"));
TestResultSummary testResultSummary = new TestResultSummary("TestClass", "Foo", ResultType.ASSUMPTION_VIOLATION, // time
0L, // message
null, // stacktrace
null, // stdOut
null, // stdErr
null);
eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.finished(testUUID, testResultSummary), 3900L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 4000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.5s (0 PASS/1 SKIP/0 FAIL)", " |=> //:test... 0.9s"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.finished(ImmutableSet.copyOf(testArgs), ImmutableList.of(TestResults.of(testTarget, ImmutableList.of(new TestCaseSummary("TestClass", ImmutableList.of(testResultSummary))), // contacts
ImmutableSet.of(), // labels
ImmutableSet.of()))), 4100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
final String testingLine = "[-] TESTING...FINISHED 1.6s (0 PASS/1 SKIP/0 FAIL)";
validateConsoleWithStdOutAndErr(listener, 4200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, testingLine), ImmutableList.of(), Optional.of(Joiner.on('\n').join("RESULTS FOR ALL TESTS", "ASSUME <100ms 0 Passed 1 Skipped 0 Failed TestClass", "NO TESTS RAN (assumption violations)", "")), // We don't care about stderr, since the last frame will be flushed there.
Optional.empty());
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestResultFormatterTest method allTestsPassingShouldIncludeNonEmptyTestLogs.
@Test
public void allTestsPassingShouldIncludeNonEmptyTestLogs() throws IOException {
Path testLogPath = vfs.getPath("test-log.txt");
Files.write(testLogPath, ImmutableList.of("Hello world"), StandardCharsets.UTF_8);
TestResultFormatter formatter = createSilentFormatter();
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest));
TestResults results = FakeTestResults.withTestLogs(ImmutableList.of(summary), ImmutableList.of(testLogPath));
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.runComplete(builder, ImmutableList.of(results), ImmutableList.of());
assertEquals("Updated test logs: log.txt\nTESTS PASSED", toString(builder));
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestResultFormatterTest method shouldReportTheNumberOfFailingTests.
@Test
public void shouldReportTheNumberOfFailingTests() {
TestResultFormatter formatter = createSilentFormatter();
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(successTest, failingTest));
TestResults results = TestResults.of(BuildTargetFactory.newInstance("//foo:bar"), ImmutableList.of(summary), /* contacts */
ImmutableSet.of(), /* labels */
ImmutableSet.of());
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.runComplete(builder, ImmutableList.of(results), ImmutableList.of());
String expectedOutput = Joiner.on('\n').join("TESTS FAILED: 1 FAILURE", "Failed target: //foo:bar", "FAIL com.example.FooTest");
assertEquals(expectedOutput, toString(builder));
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestCaseSummariesBuildingXctestEventHandler method handleEndXctestEvent.
@Override
public void handleEndXctestEvent(XctestOutputParsing.EndXctestEvent event) {
boolean testsDidEndChangedToTrue = testsDidEnd.compareAndSet(false, true);
Preconditions.checkState(testsDidEndChangedToTrue, "handleEndXctestEvent() should not be called twice");
for (Map.Entry<String, Collection<TestResultSummary>> testCaseSummary : testResultSummariesBuilder.build().asMap().entrySet()) {
testCaseSummariesBuilder.add(new TestCaseSummary(testCaseSummary.getKey(), ImmutableList.copyOf(testCaseSummary.getValue())));
}
testReportingCallback.testsDidEnd(testCaseSummariesBuilder.build());
}
use of com.facebook.buck.test.TestCaseSummary in project buck by facebook.
the class TestCaseSummariesBuildingXctoolEventHandler method handleEndOcunitEvent.
@Override
public void handleEndOcunitEvent(XctoolOutputParsing.EndOcunitEvent event) {
boolean testsDidEndChangedToTrue = testsDidEnd.compareAndSet(false, true);
Preconditions.checkState(testsDidEndChangedToTrue, "handleEndOcunitEvent() should not be called twice");
Optional<TestResultSummary> internalError = XctoolOutputParsing.internalErrorForEndOcunitEvent(event);
if (internalError.isPresent()) {
testResultSummariesBuilder.put("Internal error from test runner", internalError.get());
}
for (Map.Entry<String, Collection<TestResultSummary>> testCaseSummary : testResultSummariesBuilder.build().asMap().entrySet()) {
testCaseSummariesBuilder.add(new TestCaseSummary(testCaseSummary.getKey(), ImmutableList.copyOf(testCaseSummary.getValue())));
}
testReportingCallback.testsDidEnd(testCaseSummariesBuilder.build());
}
Aggregations