Search in sources :

Example 1 with TestStatus

use of com.google.idea.blaze.base.run.testlogs.BlazeTestResult.TestStatus in project intellij by bazelbuild.

the class BlazeXmlToTestEventsConverter method processTestSuites.

/**
 * Process all test XML files from a single test target.
 */
private void processTestSuites(Label label, Collection<BlazeTestResult> results) {
    List<File> outputFiles = new ArrayList<>();
    results.forEach(result -> outputFiles.addAll(result.getOutputXmlFiles()));
    if (noUsefulOutput(results, outputFiles)) {
        Optional<TestStatus> status = results.stream().map(BlazeTestResult::getTestStatus).findFirst();
        status.ifPresent(testStatus -> reportTargetWithoutOutputFiles(label, testStatus));
        return;
    }
    List<TestSuite> targetSuites = new ArrayList<>();
    for (File file : outputFiles) {
        try (InputStream input = new FileInputStream(file)) {
            targetSuites.add(BlazeXmlSchema.parse(input));
        } catch (Exception e) {
        // ignore parsing errors -- most common cause is user cancellation, which we can't easily
        // recognize.
        }
    }
    if (targetSuites.isEmpty()) {
        return;
    }
    Kind kind = results.stream().map(BlazeTestResult::getTargetKind).filter(Objects::nonNull).findFirst().orElse(null);
    BlazeTestEventsHandler eventsHandler = BlazeTestEventsHandler.getHandlerForTargetKindOrFallback(kind);
    TestSuite suite = targetSuites.size() == 1 ? targetSuites.get(0) : BlazeXmlSchema.mergeSuites(targetSuites);
    processTestSuite(getProcessor(), eventsHandler, kind, suite);
}
Also used : TestStatus(com.google.idea.blaze.base.run.testlogs.BlazeTestResult.TestStatus) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) TestSuite(com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite) Kind(com.google.idea.blaze.base.model.primitives.Kind) Objects(java.util.Objects) File(java.io.File)

Aggregations

Kind (com.google.idea.blaze.base.model.primitives.Kind)1 TestSuite (com.google.idea.blaze.base.run.smrunner.BlazeXmlSchema.TestSuite)1 TestStatus (com.google.idea.blaze.base.run.testlogs.BlazeTestResult.TestStatus)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1