Esempio n. 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();
    };
  }
Esempio n. 2
0
    /**
     * Walks the trie of paths attempting to merge all of the children of the current path into
     * itself. As soon as this fails we know we can't merge the parent path with the current path
     * either.
     *
     * @param currentPath current path
     * @return Optional.of(a successfully merged folder) or absent if merging did not succeed.
     */
    private Optional<IjFolder> walk(Path currentPath) {
      ImmutableList<Optional<IjFolder>> children =
          StreamSupport.stream(tree.getOutgoingNodesFor(currentPath).spliterator(), false)
              .map(this::walk)
              .collect(MoreCollectors.toImmutableList());

      List<IjFolder> presentChildren = new ArrayList<>(children.size());
      for (Optional<IjFolder> folderOptional : children) {
        if (!folderOptional.isPresent()) {
          return Optional.empty();
        }

        IjFolder folder = folderOptional.get();
        // We don't want to merge exclude folders.
        if (folder instanceof ExcludeFolder) {
          continue;
        }
        presentChildren.add(folderOptional.get());
      }

      IjFolder currentFolder = mergePathsMap.get(currentPath);
      if (presentChildren.isEmpty()) {
        return Optional.ofNullable(currentFolder);
      }

      final IjFolder mergeDistination;
      if (currentFolder != null) {
        mergeDistination = currentFolder;
      } else {
        mergeDistination = findBestChildToAggregateTo(presentChildren).createCopyWith(currentPath);
      }

      boolean allChildrenCanBeMerged =
          FluentIterable.from(presentChildren)
              .allMatch(input -> canMerge(mergeDistination, input, packagePathCache));
      if (!allChildrenCanBeMerged) {
        return Optional.empty();
      }

      return attemptMerge(mergeDistination, presentChildren);
    }
Esempio n. 3
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()));
   };
 }