use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testTestCaseNamesOrdered.
@Test
public void testTestCaseNamesOrdered() throws Exception {
TestCase[] details = { newDetail("apple", TestCase.Status.FAILED, 1000L), newDetail("banana", TestCase.Status.FAILED, 1000L), newDetail("cranberry", TestCase.Status.FAILED, 1000L) };
// The exceedingly dumb approach: writing all the permutations down manually
// is simply easier than any way of generating them.
int[][] permutations = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 }, { 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } };
for (int[] permutation : permutations) {
List<TestCase> permutatedDetails = new ArrayList<>();
for (int element : permutation) {
permutatedDetails.add(details[element]);
}
TestSummary summary = createTestSummaryWithDetails(BlazeTestStatus.FAILED, permutatedDetails);
// A mock that checks the ordering of method calls
AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summary, printer, true, true);
InOrder order = Mockito.inOrder(printer);
order.verify(printer).print(contains("//package:name"));
order.verify(printer).print(find("FAILED.*apple"));
order.verify(printer).print(find("FAILED.*banana"));
order.verify(printer).print(find("FAILED.*cranberry"));
}
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class StandaloneTestStrategy method executeTest.
protected TestResultData executeTest(TestRunnerAction action, Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException, IOException {
Executor executor = actionExecutionContext.getExecutor();
Closeable streamed = null;
Path testLogPath = action.getTestLog().getPath();
TestResultData.Builder builder = TestResultData.newBuilder();
long startTime = executor.getClock().currentTimeMillis();
SpawnActionContext spawnActionContext = executor.getSpawnActionContext(action.getMnemonic());
try {
try {
if (executionOptions.testOutput.equals(TestOutputFormat.STREAMED)) {
streamed = new StreamedTestOutput(Reporter.outErrForReporter(actionExecutionContext.getExecutor().getEventHandler()), testLogPath);
}
spawnActionContext.exec(spawn, actionExecutionContext);
builder.setTestPassed(true).setStatus(BlazeTestStatus.PASSED).setCachable(true).setPassedLog(testLogPath.getPathString());
} catch (ExecException e) {
// Execution failed, which we consider a test failure.
// TODO(bazel-team): set cachable==true for relevant statuses (failure, but not for
// timeout, etc.)
builder.setTestPassed(false).setStatus(e.hasTimedOut() ? BlazeTestStatus.TIMEOUT : BlazeTestStatus.FAILED).addFailedLogs(testLogPath.getPathString());
if (spawnActionContext.shouldPropagateExecException()) {
throw e;
}
} finally {
long duration = executor.getClock().currentTimeMillis() - startTime;
builder.addTestTimes(duration);
builder.addTestProcessTimes(duration);
builder.setRunDurationMillis(duration);
if (streamed != null) {
streamed.close();
}
}
TestCase details = parseTestResult(action.resolve(actionExecutionContext.getExecutor().getExecRoot()).getXmlOutputPath());
if (details != null) {
builder.setTestCase(details);
}
if (action.isCoverageMode()) {
builder.setHasCoverage(true);
}
return builder.build();
} catch (IOException e) {
throw new TestExecException(e.getMessage());
}
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryPrinter method print.
/**
* Prints summary status for a single test.
* @param terminalPrinter The printer to print to
*/
public static void print(TestSummary summary, AnsiTerminalPrinter terminalPrinter, boolean verboseSummary, boolean printFailedTestCases) {
BlazeTestStatus status = summary.getStatus();
// Skip output for tests that failed to build.
if (status == BlazeTestStatus.FAILED_TO_BUILD || status == BlazeTestStatus.BLAZE_HALTED_BEFORE_TESTING) {
return;
}
String message = getCacheMessage(summary) + statusString(summary.getStatus());
terminalPrinter.print(Strings.padEnd(summary.getTarget().getLabel().toString(), 78 - message.length(), ' ') + " " + TestSummary.getStatusMode(summary.getStatus()) + message + Mode.DEFAULT + (verboseSummary ? getAttemptSummary(summary) + getTimeSummary(summary) : "") + "\n");
if (printFailedTestCases && summary.getStatus() == BlazeTestStatus.FAILED) {
if (summary.getFailedTestCasesStatus() == FailedTestCasesStatus.NOT_AVAILABLE) {
terminalPrinter.print(Mode.WARNING + " (individual test case information not available) " + Mode.DEFAULT + "\n");
} else {
for (TestCase testCase : summary.getFailedTestCases()) {
if (testCase.getStatus() != TestCase.Status.PASSED) {
TestSummaryPrinter.printTestCase(terminalPrinter, testCase);
}
}
if (summary.getFailedTestCasesStatus() != FailedTestCasesStatus.FULL) {
terminalPrinter.print(Mode.WARNING + " (some shards did not report details, list of failed test" + " cases incomplete)\n" + Mode.DEFAULT);
}
}
}
if (!printFailedTestCases) {
for (String warning : summary.getWarnings()) {
terminalPrinter.print(" " + AnsiTerminalPrinter.Mode.WARNING + "WARNING: " + AnsiTerminalPrinter.Mode.DEFAULT + warning + "\n");
}
for (Path path : summary.getFailedLogs()) {
if (path.exists()) {
// Don't use getPrettyPath() here - we want to print the absolute path,
// so that it cut and paste into a different terminal, and we don't
// want to use the blaze-bin etc. symbolic links because they could be changed
// by a subsequent build with different options.
terminalPrinter.print(" " + path.getPathString() + "\n");
}
}
}
for (Path path : summary.getCoverageFiles()) {
// Print only non-trivial coverage files.
try {
if (path.exists() && path.getFileSize() > 0) {
terminalPrinter.print(" " + path.getPathString() + "\n");
}
} catch (IOException e) {
LoggingUtil.logToRemote(Level.WARNING, "Error while reading coverage data file size", e);
}
}
}
use of com.google.devtools.build.lib.view.test.TestStatus.TestCase in project bazel by bazelbuild.
the class TestSummaryTest method testCollectingFailedDetails.
@Test
public void testCollectingFailedDetails() throws Exception {
TestCase rootCase = TestCase.newBuilder().setName("tests").setRunDurationMillis(5000L).addChild(newDetail("apple", TestCase.Status.FAILED, 1000L)).addChild(newDetail("banana", TestCase.Status.PASSED, 1000L)).addChild(newDetail("cherry", TestCase.Status.ERROR, 1000L)).build();
TestSummary summary = getTemplateBuilder().collectFailedTests(rootCase).setStatus(BlazeTestStatus.FAILED).build();
AnsiTerminalPrinter printer = Mockito.mock(AnsiTerminalPrinter.class);
TestSummaryPrinter.print(summary, printer, true, true);
verify(printer).print(contains("//package:name"));
verify(printer).print(find("FAILED.*apple"));
verify(printer).print(find("ERROR.*cherry"));
}
Aggregations