Exemple #1
0
  @Override
  public Callable<TestResults> interpretTestResults(
      final ExecutionContext executionContext, boolean isUsingTestSelectors, boolean isDryRun) {
    return () -> {
      List<TestCaseSummary> testCaseSummaries;
      if (xctoolStdoutReader.isPresent()) {
        // We've already run the tests with 'xctool' and parsed
        // their output; no need to parse the same output again.
        testCaseSummaries = xctoolStdoutReader.get().getTestCaseSummaries();
      } else if (xctestOutputReader.isPresent()) {
        // We've already run the tests with 'xctest' and parsed
        // their output; no need to parse the same output again.
        testCaseSummaries = xctestOutputReader.get().getTestCaseSummaries();
      } else if (isUiTest()) {
        TestCaseSummary noTestsSummary =
            new TestCaseSummary(
                "XCUITest runs not supported with buck test", Collections.emptyList());
        testCaseSummaries = Collections.singletonList(noTestsSummary);
      } else {
        Path resolvedOutputPath = getProjectFilesystem().resolve(testOutputPath);
        try (BufferedReader reader =
            Files.newBufferedReader(resolvedOutputPath, StandardCharsets.UTF_8)) {
          if (useXctest) {
            TestCaseSummariesBuildingXctestEventHandler xctestEventHandler =
                new TestCaseSummariesBuildingXctestEventHandler(NOOP_REPORTING_CALLBACK);
            XctestOutputParsing.streamOutput(reader, xctestEventHandler);
            testCaseSummaries = xctestEventHandler.getTestCaseSummaries();
          } else {
            TestCaseSummariesBuildingXctoolEventHandler xctoolEventHandler =
                new TestCaseSummariesBuildingXctoolEventHandler(NOOP_REPORTING_CALLBACK);
            XctoolOutputParsing.streamOutputFromReader(reader, xctoolEventHandler);
            testCaseSummaries = xctoolEventHandler.getTestCaseSummaries();
          }
        }
      }
      TestResults.Builder testResultsBuilder =
          TestResults.builder()
              .setBuildTarget(getBuildTarget())
              .setTestCases(testCaseSummaries)
              .setContacts(contacts)
              .setLabels(
                  labels.stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
      if (getProjectFilesystem().isDirectory(testLogsPath)) {
        for (Path testLogPath : getProjectFilesystem().getDirectoryContents(testLogsPath)) {
          testResultsBuilder.addTestLogPaths(testLogPath);
        }
      }

      return testResultsBuilder.build();
    };
  }
Exemple #2
0
 @Override
 public Callable<TestResults> interpretTestResults(
     final ExecutionContext executionContext,
     boolean isUsingTestSelectors,
     final boolean isDryRun) {
   return () -> {
     ImmutableList.Builder<TestCaseSummary> summaries = ImmutableList.builder();
     if (!isDryRun) {
       ImmutableList<TestResultSummary> resultSummaries =
           parseResults(getPathToTestExitCode(), getPathToTestOutput(), getPathToTestResults());
       TestCaseSummary summary =
           new TestCaseSummary(getBuildTarget().getFullyQualifiedName(), resultSummaries);
       summaries.add(summary);
     }
     return TestResults.of(
         getBuildTarget(),
         summaries.build(),
         contacts,
         labels.stream().map(Object::toString).collect(MoreCollectors.toImmutableSet()));
   };
 }