Search in sources :

Example 1 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class TestCaseSummariesBuildingXctoolEventHandler method handleEndTestEvent.

@Override
public void handleEndTestEvent(XctoolOutputParsing.EndTestEvent event) {
    TestResultSummary testResultSummary = XctoolOutputParsing.testResultSummaryForEndTestEvent(event);
    testResultSummariesBuilder.put(Preconditions.checkNotNull(event.className), testResultSummary);
    testReportingCallback.testDidEnd(testResultSummary);
}
Also used : TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 2 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class XctestOutputParsing method testResultSummaryForEndTestCaseEvent.

public static TestResultSummary testResultSummaryForEndTestCaseEvent(EndTestCaseEvent event) {
    long timeMillis = (long) (event.totalDuration * TimeUnit.SECONDS.toMillis(1));
    TestResultSummary testResultSummary = new TestResultSummary(Optional.ofNullable(event.className).orElse(Preconditions.checkNotNull(event.test)), Optional.ofNullable(event.methodName).orElse(Preconditions.checkNotNull(event.test)), event.succeeded ? ResultType.SUCCESS : ResultType.FAILURE, timeMillis, formatTestMessage(event), // stackTrace,
    null, formatTestOutput(event), // stderr
    null);
    LOG.debug("Test result summary: %s", testResultSummary);
    return testResultSummary;
}
Also used : TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 3 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class XctoolOutputParsing method internalErrorForEndOcunitEvent.

public static Optional<TestResultSummary> internalErrorForEndOcunitEvent(EndOcunitEvent endOcunitEvent) {
    if (endOcunitEvent.succeeded || endOcunitEvent.message == null) {
        // happen with any random test failure.)
        return Optional.empty();
    }
    TestResultSummary testResultSummary = new TestResultSummary("Internal error from test runner", "main", ResultType.FAILURE, 0L, endOcunitEvent.message, // stackTrace,
    null, // stdOut
    null, // stdErr
    null);
    LOG.debug("OCUnit/XCTest internal failure: %s", testResultSummary);
    return Optional.of(testResultSummary);
}
Also used : TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 4 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class XctoolOutputParsing method testResultSummaryForEndTestEvent.

public static TestResultSummary testResultSummaryForEndTestEvent(EndTestEvent endTestEvent) {
    long timeMillis = (long) (endTestEvent.totalDuration * TimeUnit.SECONDS.toMillis(1));
    TestResultSummary testResultSummary = new TestResultSummary(Preconditions.checkNotNull(endTestEvent.className), Preconditions.checkNotNull(endTestEvent.test), endTestEvent.succeeded ? ResultType.SUCCESS : ResultType.FAILURE, timeMillis, formatTestMessage(endTestEvent), // stackTrace,
    null, formatTestStdout(endTestEvent), // stdErr
    null);
    LOG.debug("Test result summary: %s", testResultSummary);
    return testResultSummary;
}
Also used : TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 5 with TestResultSummary

use of com.facebook.buck.test.TestResultSummary in project buck by facebook.

the class CxxBoostTest method parseResults.

@Override
protected ImmutableList<TestResultSummary> parseResults(Path exitCode, Path output, Path results) throws Exception {
    ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
    // Process the test run output to grab the individual test stdout/stderr and
    // test run times.
    Map<String, String> messages = Maps.newHashMap();
    Map<String, List<String>> stdout = Maps.newHashMap();
    Map<String, Long> times = Maps.newHashMap();
    try (BufferedReader reader = Files.newBufferedReader(output, Charsets.US_ASCII)) {
        Stack<String> testSuite = new Stack<>();
        Optional<String> currentTest = Optional.empty();
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher;
            if ((matcher = SUITE_START.matcher(line)).matches()) {
                String suite = matcher.group(1);
                testSuite.push(suite);
            } else if ((matcher = SUITE_END.matcher(line)).matches()) {
                String suite = matcher.group(1);
                Preconditions.checkState(testSuite.peek().equals(suite));
                testSuite.pop();
            } else if ((matcher = CASE_START.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                currentTest = Optional.of(test);
                stdout.put(test, Lists.newArrayList());
            } else if ((matcher = CASE_END.matcher(line)).matches()) {
                String test = Joiner.on(".").join(testSuite) + "." + matcher.group(1);
                Preconditions.checkState(currentTest.isPresent() && currentTest.get().equals(test));
                String time = matcher.group(2);
                times.put(test, time == null ? 0 : Long.valueOf(time));
                currentTest = Optional.empty();
            } else if (currentTest.isPresent()) {
                if (ERROR.matcher(line).matches()) {
                    messages.put(currentTest.get(), line);
                } else {
                    Preconditions.checkNotNull(stdout.get(currentTest.get())).add(line);
                }
            }
        }
    }
    // Parse the XML result file for the actual test result summaries.
    Document doc = XmlDomParser.parse(results);
    Node testResult = doc.getElementsByTagName("TestResult").item(0);
    Node testSuite = testResult.getFirstChild();
    visitTestSuite(summariesBuilder, messages, stdout, times, "", testSuite);
    return summariesBuilder.build();
}
Also used : Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) Node(org.w3c.dom.Node) TestResultSummary(com.facebook.buck.test.TestResultSummary) Document(org.w3c.dom.Document) Stack(java.util.Stack) BufferedReader(java.io.BufferedReader) ImmutableList(com.google.common.collect.ImmutableList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

TestResultSummary (com.facebook.buck.test.TestResultSummary)34 TestCaseSummary (com.facebook.buck.test.TestCaseSummary)17 Test (org.junit.Test)16 TestResults (com.facebook.buck.test.TestResults)11 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 BuildTarget (com.facebook.buck.model.BuildTarget)9 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 Path (java.nio.file.Path)8 ExecutionContext (com.facebook.buck.step.ExecutionContext)7 FakeTestResults (com.facebook.buck.test.FakeTestResults)7 ImmutableList (com.google.common.collect.ImmutableList)7 RuleKey (com.facebook.buck.rules.RuleKey)6 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)5 ResultType (com.facebook.buck.test.result.type.ResultType)5 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 BufferedReader (java.io.BufferedReader)4 Matcher (java.util.regex.Matcher)4 Document (org.w3c.dom.Document)4