Skip to content

Commit

Permalink
#2651 improve tests arguments passing
Browse files Browse the repository at this point in the history
- use `HARNESS_OPTIONS` to pass formatter and jobs number (still can't pass `--merge`, see Perl-Toolchain-Gang/Test-Harness#117)
- use `HARNESS_PERL_SWITCHES` instead of `PassEnv` plugin

We need such approach to be able to use any frontend, besides `prove`, e.g. `make test`

Fixes #2651
  • Loading branch information
hurricup committed Apr 3, 2023
1 parent fe37314 commit 312cd6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,27 @@

import static com.intellij.execution.configurations.GeneralCommandLine.ParentEnvironmentType.CONSOLE;
import static com.intellij.execution.configurations.GeneralCommandLine.ParentEnvironmentType.NONE;
import static com.perl5.lang.perl.util.PerlRunUtil.PERL5OPT;
import static com.perl5.lang.perl.util.PerlRunUtil.getPerlRunIncludeArguments;

@VisibleForTesting
public class PerlTestRunConfiguration extends GenericPerlRunConfiguration {
private static final String PROVE = "prove";
private static final String TEST_HARNESS = "Test::Harness";
private static final String PROVE_PASS_PREFIX = "PROVE_PASS_";
static final int DEFAULT_JOBS_NUMBER = 1;
private static final String PROVE_FORMAT_PARAMETER = "--formatter";
private static final String PROVE_FRAMEWORK_NAME = TEST_HARNESS;
private static final Pattern MISSING_FILTER_PATTERN = Pattern.compile("Can't load module (\\S+) at .+?/prove line");
private static final String PROVE_PLUGIN_NAMESPACE = "App::Prove::Plugin";
private static final List<String> PROVE_DEFAULT_PARAMETERS = Arrays.asList(
"-PPassEnv", PROVE_FORMAT_PARAMETER, "TAP::Formatter::Camelcade", "--merge", "--recurse");
private static final List<String> PROVE_DEFAULT_PARAMETERS = Arrays.asList("--merge", "--recurse");
private static final String PROVE_JOBS_SHORT_PREFIX = "-j";
private static final String PROVE_JOBS_PARAMETER = "--jobs";
private static final String HARNESS_OPTIONS = "HARNESS_OPTIONS";
private static final String HARNESS_OPTIONS_SEPARATOR = ":";
private static final String HARNESS_OPTIONS_JOBS = "j";
private static final String HARNESS_OPTIONS_FORMATTER = "f";
private static final String HARNESS_OPTIONS_FORMATTER_CLASS = "TAP-Formatter-Camelcade";
private static final String HARNESS_PERL_SWITCHES = "HARNESS_PERL_SWITCHES";
private static final Logger LOG = Logger.getInstance(PerlTestRunConfiguration.class);
@Tag("JOBS_NUMBER")
private int myJobsNumber = DEFAULT_JOBS_NUMBER;
Expand Down Expand Up @@ -141,8 +146,7 @@ else if (testsVirtualFiles.size() == 1) {

Set<String> proveParameters = new LinkedHashSet<>(PROVE_DEFAULT_PARAMETERS);
proveParameters.addAll(getScriptParameters());
proveParameters.add(PROVE_JOBS_PARAMETER);
proveParameters.add(Integer.toString(perlRunProfileState.isParallelRunAllowed() ? getJobsNumber() : 1));

VirtualFile workingDirectory = computeExplicitWorkingDirectory();

List<String> testsPaths = new ArrayList<>();
Expand Down Expand Up @@ -188,8 +192,18 @@ else if (testsVirtualFiles.size() == 1) {
Map<String, String> environment = new HashMap<>(getEnvs());
environment.putAll(additionalEnvironmentVariables);
PerlRunUtil.updatePerl5Opt(environment, perlParametersList);
environment.forEach((key, val) -> commandLine.withEnvironment(PROVE_PASS_PREFIX + key, val));

List<String> harnessOptions = new ArrayList<>();
harnessOptions.add(HARNESS_OPTIONS_JOBS + Integer.toString(perlRunProfileState.isParallelRunAllowed() ? getJobsNumber() : 1));
harnessOptions.add(HARNESS_OPTIONS_FORMATTER + HARNESS_OPTIONS_FORMATTER_CLASS);

environment.put(HARNESS_OPTIONS, String.join(HARNESS_OPTIONS_SEPARATOR, harnessOptions));
var perl5Opt = environment.remove(PERL5OPT);
if (StringUtil.isNotEmpty(perl5Opt)) {
environment.put(HARNESS_PERL_SWITCHES, perl5Opt);
}

commandLine.withEnvironment(environment);
commandLine.withParentEnvironmentType(isPassParentEnvs() ? CONSOLE : NONE);
return commandLine;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2021 Alexandr Evstigneev
* Copyright 2015-2023 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.io.FileUtil;
import com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration;
import com.perl5.lang.perl.idea.run.PerlRunProfileState;
import com.perl5.lang.perl.idea.sdk.host.PerlHostData;
Expand Down Expand Up @@ -54,10 +55,11 @@ public PerlCoverageProfileState(ExecutionEnvironment environment) {

Sdk effectiveSdk = perlRunConfiguration.getEffectiveSdk();
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(effectiveSdk);
var remoteDataPath = FileUtil.toSystemIndependentName(hostData.getRemotePath(coverageBasePath));
if (ApplicationManager.getApplication().isUnitTestMode()) {
return Collections.singletonList("-MDevel::Cover=-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
return Collections.singletonList("-MDevel::Cover=-db," + remoteDataPath + ",-dir,.");
}
return Collections.singletonList("-MDevel::Cover=-silent,1,-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
return Collections.singletonList("-MDevel::Cover=-silent,1,-db," + remoteDataPath + ",-dir,.");
}

@Override
Expand Down

0 comments on commit 312cd6e

Please sign in to comment.