From 9afcfc3a2b41854a9aac1f11eb6656861291023a Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sun, 2 Apr 2023 19:46:22 +0400 Subject: [PATCH] #2651 improve tests arguments passing - 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 --- .../run/prove/PerlTestRunConfiguration.java | 26 ++++++++++++++----- .../coverage/PerlCoverageProfileState.java | 8 +++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/plugin/core/src/main/java/com/perl5/lang/perl/idea/run/prove/PerlTestRunConfiguration.java b/plugin/core/src/main/java/com/perl5/lang/perl/idea/run/prove/PerlTestRunConfiguration.java index d86b710663..ca91eb0c00 100644 --- a/plugin/core/src/main/java/com/perl5/lang/perl/idea/run/prove/PerlTestRunConfiguration.java +++ b/plugin/core/src/main/java/com/perl5/lang/perl/idea/run/prove/PerlTestRunConfiguration.java @@ -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 PROVE_DEFAULT_PARAMETERS = Arrays.asList( - "-PPassEnv", PROVE_FORMAT_PARAMETER, "TAP::Formatter::Camelcade", "--merge", "--recurse"); + private static final List 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; @@ -141,8 +146,7 @@ else if (testsVirtualFiles.size() == 1) { Set 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 testsPaths = new ArrayList<>(); @@ -188,8 +192,18 @@ else if (testsVirtualFiles.size() == 1) { Map environment = new HashMap<>(getEnvs()); environment.putAll(additionalEnvironmentVariables); PerlRunUtil.updatePerl5Opt(environment, perlParametersList); - environment.forEach((key, val) -> commandLine.withEnvironment(PROVE_PASS_PREFIX + key, val)); + List 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; } diff --git a/plugin/coverage/src/main/java/com/perl5/lang/perl/coverage/PerlCoverageProfileState.java b/plugin/coverage/src/main/java/com/perl5/lang/perl/coverage/PerlCoverageProfileState.java index 8deeb49934..30dfcaeb25 100644 --- a/plugin/coverage/src/main/java/com/perl5/lang/perl/coverage/PerlCoverageProfileState.java +++ b/plugin/coverage/src/main/java/com/perl5/lang/perl/coverage/PerlCoverageProfileState.java @@ -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. @@ -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; @@ -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