Search in sources :

Example 6 with ResultType

use of com.facebook.buck.test.result.type.ResultType in project buck by facebook.

the class CxxBoostTest method visitTestSuite.

private void visitTestSuite(ImmutableList.Builder<TestResultSummary> builder, Map<String, String> messages, Map<String, List<String>> stdout, Map<String, Long> times, String prefix, Node testSuite) {
    NamedNodeMap attributes = testSuite.getAttributes();
    String suiteName = attributes.getNamedItem("name").getNodeValue();
    if (!prefix.isEmpty()) {
        suiteName = prefix + "." + suiteName;
    }
    NodeList testCases = testSuite.getChildNodes();
    for (int index = 0; index < testCases.getLength(); index++) {
        Node testCase = testCases.item(index);
        if (!testCase.getNodeName().equals("TestCase")) {
            visitTestSuite(builder, messages, stdout, times, suiteName, testCase);
            continue;
        }
        NamedNodeMap attrs = testCase.getAttributes();
        String caseName = attrs.getNamedItem("name").getNodeValue();
        String test = String.format("%s.%s", suiteName, caseName);
        Long time = Optional.ofNullable(times.get(test)).orElse(0L);
        String resultString = attrs.getNamedItem("result").getNodeValue();
        ResultType result = ResultType.SUCCESS;
        String output = "";
        String message = "";
        if (!"passed".equals(resultString)) {
            result = ResultType.FAILURE;
            message = messages.get(test);
            output = Joiner.on("\n").join(stdout.get(test));
        }
        builder.add(new TestResultSummary(suiteName, caseName, result, time, message, /* stacktrace */
        "", /* stdOut */
        output, /* stdErr */
        ""));
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ResultType(com.facebook.buck.test.result.type.ResultType) TestResultSummary(com.facebook.buck.test.TestResultSummary)

Example 7 with ResultType

use of com.facebook.buck.test.result.type.ResultType in project buck by facebook.

the class RustTest method parseTestResults.

private ImmutableList<TestResultSummary> parseTestResults() throws IOException {
    Map<String, ResultType> testToResult = new HashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(testOutputFile, Charsets.UTF_8)) {
        String line;
        while ((line = reader.readLine()) != null) {
            String[] resultAndTestName = line.split(" ");
            if (resultAndTestName.length != 2) {
                throw new RuntimeException(String.format("Unknown test output format %s", line));
            }
            ResultType result;
            switch(resultAndTestName[0]) {
                case "ok":
                    result = ResultType.SUCCESS;
                    break;
                case "failed":
                    result = ResultType.FAILURE;
                    break;
                case "ignored":
                    result = ResultType.DISABLED;
                    break;
                default:
                    throw new RuntimeException(String.format("Unknown test status %s", line));
            }
            testToResult.put(resultAndTestName[1], result);
        }
    }
    Map<String, String> testToStdout = new HashMap<>();
    try (BufferedReader reader = Files.newBufferedReader(testStdoutFile, Charsets.UTF_8)) {
        StringBuilder stdout = new StringBuilder();
        String currentStdoutTestName = null;
        BiConsumer<String, String> addTestStdout = (key, value) -> {
            testToStdout.put(key, value);
            stdout.setLength(0);
        };
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher;
            if ((matcher = TEST_STDOUT_PATTERN.matcher(line)).matches()) {
                if (currentStdoutTestName != null) {
                    // Start of stdout output for new test
                    // Save current stdout
                    addTestStdout.accept(currentStdoutTestName, stdout.toString());
                }
                currentStdoutTestName = matcher.group("name");
            } else if (FAILURES_LIST_PATTERN.matcher(line).matches()) {
                if (currentStdoutTestName != null) {
                    addTestStdout.accept(currentStdoutTestName, stdout.toString());
                }
            } else if (currentStdoutTestName != null) {
                stdout.append("\n");
                stdout.append(line);
            }
        }
    }
    ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
    for (Map.Entry<String, ResultType> entry : testToResult.entrySet()) {
        summariesBuilder.add(new TestResultSummary("rust_test", entry.getKey(), entry.getValue(), // TODO(StanislavGlebik) time
        0, // message
        "", // stack trace,
        "", testToStdout.get(entry.getKey()), // stderr
        ""));
    }
    return summariesBuilder.build();
}
Also used : BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Step(com.facebook.buck.step.Step) HasRuntimeDeps(com.facebook.buck.rules.HasRuntimeDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ResultType(com.facebook.buck.test.result.type.ResultType) SourcePath(com.facebook.buck.rules.SourcePath) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) Matcher(java.util.regex.Matcher) Label(com.facebook.buck.rules.Label) Tool(com.facebook.buck.rules.Tool) TestResults(com.facebook.buck.test.TestResults) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) TestResultSummary(com.facebook.buck.test.TestResultSummary) TestRule(com.facebook.buck.rules.TestRule) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) MoreCollectors(com.facebook.buck.util.MoreCollectors) Charsets(com.google.common.base.Charsets) ImmutableSet(com.google.common.collect.ImmutableSet) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) ForwardingBuildTargetSourcePath(com.facebook.buck.rules.ForwardingBuildTargetSourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Files(java.nio.file.Files) BuildableContext(com.facebook.buck.rules.BuildableContext) AbstractTestStep(com.facebook.buck.step.AbstractTestStep) IOException(java.io.IOException) BuildTarget(com.facebook.buck.model.BuildTarget) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) Stream(java.util.stream.Stream) BuildContext(com.facebook.buck.rules.BuildContext) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) BuildTargets(com.facebook.buck.model.BuildTargets) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) ResultType(com.facebook.buck.test.result.type.ResultType) TestResultSummary(com.facebook.buck.test.TestResultSummary) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ResultType (com.facebook.buck.test.result.type.ResultType)7 TestResultSummary (com.facebook.buck.test.TestResultSummary)5 NodeList (org.w3c.dom.NodeList)4 ImmutableList (com.google.common.collect.ImmutableList)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 Node (org.w3c.dom.Node)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargets (com.facebook.buck.model.BuildTargets)1 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)1 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)1 BinaryBuildRule (com.facebook.buck.rules.BinaryBuildRule)1 BuildContext (com.facebook.buck.rules.BuildContext)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)1 BuildableContext (com.facebook.buck.rules.BuildableContext)1 ExternalTestRunnerRule (com.facebook.buck.rules.ExternalTestRunnerRule)1 ExternalTestRunnerTestSpec (com.facebook.buck.rules.ExternalTestRunnerTestSpec)1 ForwardingBuildTargetSourcePath (com.facebook.buck.rules.ForwardingBuildTargetSourcePath)1