Esempio n. 1
0
  public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand(
      ExecutionContext context,
      TestRunningOptions options,
      TestRule.TestReportingCallback testReportingCallback) {

    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ExternalTestRunnerTestSpec.Builder externalSpec =
        ExternalTestRunnerTestSpec.builder()
            .setTarget(getBuildTarget())
            .setLabels(getLabels())
            .setContacts(getContacts());

    Path resolvedTestBundleDirectory =
        getProjectFilesystem().resolve(Preconditions.checkNotNull(testBundle.getPathToOutput()));

    Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));

    Path resolvedTestLogsPath = getProjectFilesystem().resolve(testLogsPath);
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), resolvedTestLogsPath));

    Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath);

    Optional<Path> testHostAppPath = Optional.empty();
    if (testHostApp.isPresent()) {
      Path resolvedTestHostAppDirectory =
          getProjectFilesystem()
              .resolve(Preconditions.checkNotNull(testHostApp.get().getPathToOutput()));
      testHostAppPath =
          Optional.of(
              resolvedTestHostAppDirectory.resolve(
                  testHostApp.get().getUnzippedOutputFilePathToBinary()));
    }

    if (!useXctest) {
      if (!xctool.isPresent()) {
        throw new HumanReadableException(
            "Set xctool_path = /path/to/xctool or xctool_zip_target = //path/to:xctool-zip "
                + "in the [apple] section of .buckconfig to run this test");
      }

      ImmutableSet.Builder<Path> logicTestPathsBuilder = ImmutableSet.builder();
      ImmutableMap.Builder<Path, Path> appTestPathsToHostAppsBuilder = ImmutableMap.builder();

      if (testHostAppPath.isPresent()) {
        appTestPathsToHostAppsBuilder.put(resolvedTestBundleDirectory, testHostAppPath.get());
      } else {
        logicTestPathsBuilder.add(resolvedTestBundleDirectory);
      }

      xctoolStdoutReader = Optional.of(new AppleTestXctoolStdoutReader(testReportingCallback));
      Optional<String> destinationSpecifierArg;
      if (!destinationSpecifier.get().isEmpty()) {
        destinationSpecifierArg =
            Optional.of(
                Joiner.on(',')
                    .join(
                        Iterables.transform(
                            destinationSpecifier.get().entrySet(),
                            input -> input.getKey() + "=" + input.getValue())));
      } else {
        destinationSpecifierArg = defaultDestinationSpecifier;
      }
      XctoolRunTestsStep xctoolStep =
          new XctoolRunTestsStep(
              getProjectFilesystem(),
              getResolver().getAbsolutePath(xctool.get()),
              options.getEnvironmentOverrides(),
              xctoolStutterTimeout,
              platformName,
              destinationSpecifierArg,
              logicTestPathsBuilder.build(),
              appTestPathsToHostAppsBuilder.build(),
              resolvedTestOutputPath,
              xctoolStdoutReader,
              xcodeDeveloperDirSupplier,
              options.getTestSelectorList(),
              Optional.of(testLogDirectoryEnvironmentVariable),
              Optional.of(resolvedTestLogsPath),
              Optional.of(testLogLevelEnvironmentVariable),
              Optional.of(testLogLevel),
              testRuleTimeoutMs);
      steps.add(xctoolStep);
      externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic"));
      externalSpec.setCommand(xctoolStep.getCommand());
      externalSpec.setEnv(xctoolStep.getEnv(context));
    } else {
      xctestOutputReader = Optional.of(new AppleTestXctestOutputReader(testReportingCallback));

      HashMap<String, String> environment = new HashMap<>();
      environment.putAll(xctest.getEnvironment(getResolver()));
      environment.putAll(options.getEnvironmentOverrides());
      if (testHostAppPath.isPresent()) {
        environment.put("XCInjectBundleInto", testHostAppPath.get().toString());
      }
      XctestRunTestsStep xctestStep =
          new XctestRunTestsStep(
              getProjectFilesystem(),
              ImmutableMap.copyOf(environment),
              xctest.getCommandPrefix(getResolver()),
              resolvedTestBundleDirectory,
              resolvedTestOutputPath,
              xctestOutputReader,
              xcodeDeveloperDirSupplier);
      steps.add(xctestStep);
      externalSpec.setType("xctest");
      externalSpec.setCommand(xctestStep.getCommand());
      externalSpec.setEnv(xctestStep.getEnv(context));
    }

    return new Pair<>(steps.build(), externalSpec.build());
  }
Esempio n. 2
0
  public Pair<ImmutableList<Step>, ExternalTestRunnerTestSpec> getTestCommand(
      ExecutionContext context,
      TestRunningOptions options,
      TestRule.TestReportingCallback testReportingCallback) {

    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ExternalTestRunnerTestSpec.Builder externalSpec =
        ExternalTestRunnerTestSpec.builder()
            .setTarget(getBuildTarget())
            .setLabels(getLabels())
            .setContacts(getContacts());

    Path resolvedTestBundleDirectory =
        getProjectFilesystem().resolve(Preconditions.checkNotNull(testBundle.getPathToOutput()));

    Path pathToTestOutput = getProjectFilesystem().resolve(getPathToTestOutputDirectory());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTestOutput));

    Path resolvedTestOutputPath = getProjectFilesystem().resolve(testOutputPath);

    Optional<Path> testHostAppPath = Optional.absent();
    if (testHostApp.isPresent()) {
      Path resolvedTestHostAppDirectory =
          getProjectFilesystem()
              .resolve(Preconditions.checkNotNull(testHostApp.get().getPathToOutput()));
      testHostAppPath =
          Optional.of(
              resolvedTestHostAppDirectory.resolve(
                  testHostApp.get().getUnzippedOutputFilePathToBinary()));
    }

    if (!useXctest) {
      if (!xctool.isPresent()) {
        throw new HumanReadableException(
            "Set xctool_path = /path/to/xctool or xctool_zip_target = //path/to:xctool-zip "
                + "in the [apple] section of .buckconfig to run this test");
      }

      ImmutableSet.Builder<Path> logicTestPathsBuilder = ImmutableSet.builder();
      ImmutableMap.Builder<Path, Path> appTestPathsToHostAppsBuilder = ImmutableMap.builder();

      if (testHostAppPath.isPresent()) {
        appTestPathsToHostAppsBuilder.put(resolvedTestBundleDirectory, testHostAppPath.get());
      } else {
        logicTestPathsBuilder.add(resolvedTestBundleDirectory);
      }

      xctoolStdoutReader = Optional.of(new AppleTestXctoolStdoutReader(testReportingCallback));
      Optional<String> destinationSpecifierArg;
      if (!destinationSpecifier.get().isEmpty()) {
        destinationSpecifierArg =
            Optional.of(
                Joiner.on(',')
                    .join(
                        Iterables.transform(
                            destinationSpecifier.get().entrySet(),
                            new Function<Map.Entry<String, String>, String>() {
                              @Override
                              public String apply(Map.Entry<String, String> input) {
                                return input.getKey() + "=" + input.getValue();
                              }
                            })));
      } else {
        destinationSpecifierArg = defaultDestinationSpecifier;
      }
      XctoolRunTestsStep xctoolStep =
          new XctoolRunTestsStep(
              getProjectFilesystem(),
              getResolver().getAbsolutePath(xctool.get()),
              xctoolStutterTimeout,
              platformName,
              destinationSpecifierArg,
              logicTestPathsBuilder.build(),
              appTestPathsToHostAppsBuilder.build(),
              resolvedTestOutputPath,
              xctoolStdoutReader,
              xcodeDeveloperDirSupplier,
              options.getTestSelectorList());
      steps.add(xctoolStep);
      externalSpec.setType("xctool-" + (testHostApp.isPresent() ? "application" : "logic"));
      externalSpec.setCommand(xctoolStep.getCommand());
      externalSpec.setEnv(xctoolStep.getEnv(context));
    } else {
      Tool testRunningTool;
      if (testBundleExtension.equals("xctest")) {
        testRunningTool = xctest;
      } else if (otest.isPresent()) {
        testRunningTool = otest.get();
      } else {
        throw new HumanReadableException(
            "Cannot run non-xctest bundle type %s (otest not present)", testBundleExtension);
      }
      XctestRunTestsStep xctestStep =
          new XctestRunTestsStep(
              getProjectFilesystem(),
              testRunningTool.getCommandPrefix(getResolver()),
              (testBundleExtension.equals("xctest") ? "-XCTest" : "-SenTest"),
              resolvedTestBundleDirectory,
              resolvedTestOutputPath,
              xcodeDeveloperDirSupplier);
      steps.add(xctestStep);
      externalSpec.setType("xctest");
      externalSpec.setCommand(xctestStep.getCommand());
      externalSpec.setEnv(xctestStep.getEnv(context));
    }

    return new Pair<>(steps.build(), externalSpec.build());
  }