Skip to content

Commit

Permalink
Migrated to the platform exec method
Browse files Browse the repository at this point in the history
Previously we needed a modified version of this, but now platform is fine
  • Loading branch information
hurricup committed Feb 25, 2024
1 parent 0c10a0a commit b1ece27
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 94 deletions.
7 changes: 4 additions & 3 deletions plugin/src/test/java/run/PerlCoverageTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 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 Down Expand Up @@ -28,6 +28,7 @@
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
Expand All @@ -36,10 +37,10 @@
import com.intellij.rt.coverage.data.ClassData;
import com.intellij.rt.coverage.data.LineData;
import com.intellij.rt.coverage.data.ProjectData;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.perl5.lang.perl.coverage.PerlCoverageSuite;
import com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration;
import com.pty4j.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

Expand Down Expand Up @@ -172,7 +173,7 @@ private void runScriptWithCoverageAndWait(@NotNull String directory, @NotNull St
private @NotNull Pair<ExecutionEnvironment, RunContentDescriptor> runConfigurationWithCoverageAndWait(GenericPerlRunConfiguration runConfiguration) {
Pair<ExecutionEnvironment, RunContentDescriptor> pair;
try {
pair = executeConfiguration(runConfiguration, CoverageExecutor.EXECUTOR_ID);
pair = PlatformTestUtil.executeConfiguration(runConfiguration, CoverageExecutor.EXECUTOR_ID, null);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down
7 changes: 4 additions & 3 deletions plugin/src/test/java/run/PerlDebuggerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 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 @@ -24,6 +24,7 @@
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -53,7 +54,6 @@
import com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration;
import com.perl5.lang.perl.idea.run.debugger.PerlDebugOptionsSets;
import com.perl5.lang.perl.idea.run.prove.PerlTestRunConfiguration;
import com.pty4j.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
Expand Down Expand Up @@ -303,7 +303,8 @@ private void assertStoppedAtLine(XDebugSession debugSession, int expected) {

private @NotNull Trinity<ExecutionEnvironment, RunContentDescriptor, XDebugSession> runConfigurationWithDebugger(@NotNull RunConfiguration runConfiguration) {
try {
Pair<ExecutionEnvironment, RunContentDescriptor> pair = executeConfiguration(runConfiguration, DefaultDebugExecutor.EXECUTOR_ID);
Pair<ExecutionEnvironment, RunContentDescriptor>
pair = PlatformTestUtil.executeConfiguration(runConfiguration, DefaultDebugExecutor.EXECUTOR_ID, null);
XDebugSession debugSession = XDebuggerManager.getInstance(getProject()).getDebugSession(pair.second.getExecutionConsole());
assertNotNull(debugSession);
disposeOnPerlTearDown(() -> {
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/test/java/run/PerlProfilerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 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 @@ -26,6 +26,7 @@
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
Expand All @@ -45,7 +46,6 @@
import com.perl5.lang.perl.profiler.run.PerlProfilerProcess;
import com.perl5.lang.perl.profiler.run.PerlProfilerRunProfileState;
import com.perl5.lang.perl.profiler.run.PerlProfilerStartupMode;
import com.pty4j.util.Pair;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
Expand Down Expand Up @@ -259,7 +259,7 @@ private void checkProfilingResultsWithFile(@NotNull CallTreeBuilder<BaseCallStac
var executorAndSettings = getExecutorAndSettings();
Pair<ExecutionEnvironment, RunContentDescriptor> pair;
try {
pair = executeConfiguration(runConfiguration, executorAndSettings.first);
pair = PlatformTestUtil.executeConfiguration(runConfiguration, executorAndSettings.first, null);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/test/java/run/PerlRunTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 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.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.notification.Notification;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.psi.PsiFile;
Expand All @@ -33,7 +34,6 @@
import com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration;
import com.perl5.lang.perl.idea.sdk.PerlConfig;
import com.perl5.lang.perl.util.PerlRunUtil;
import com.pty4j.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

Expand Down
96 changes: 13 additions & 83 deletions plugin/src/testFixtures/java/base/PerlPlatformTestCase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 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 @@ -17,15 +17,14 @@
package base;

import categories.Integration;
import com.intellij.execution.*;
import com.intellij.execution.actions.ConfigurationContext;
import com.intellij.execution.actions.ConfigurationFromContext;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.execution.process.*;
import com.intellij.execution.process.CapturingProcessAdapter;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.execution.testframework.TestTreeView;
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm;
Expand All @@ -36,18 +35,17 @@
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.PerlSdkTable;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -60,7 +58,6 @@
import com.intellij.util.ObjectUtils;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import com.perl5.lang.perl.adapters.PackageManagerAdapter;
import com.perl5.lang.perl.cpan.adapter.CpanAdapter;
Expand All @@ -74,7 +71,6 @@
import com.perl5.lang.perl.idea.sdk.host.PerlHostData;
import com.perl5.lang.perl.util.PerlPackageUtil;
import com.perl5.lang.perl.util.PerlRunUtil;
import com.pty4j.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.concurrency.Promise;
Expand All @@ -88,8 +84,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
Expand Down Expand Up @@ -321,8 +315,13 @@ else if (LangDataKeys.MODULE.is(dataId)) {

protected @NotNull Pair<ExecutionEnvironment, RunContentDescriptor> runConfigurationAndWait(GenericPerlRunConfiguration runConfiguration) {
Pair<ExecutionEnvironment, RunContentDescriptor> execResult;
CapturingProcessAdapter capturingAdapter = new CapturingProcessAdapter();
try {
execResult = executeConfiguration(runConfiguration, DefaultRunExecutor.EXECUTOR_ID);
execResult = PlatformTestUtil.executeConfiguration(runConfiguration, DefaultRunExecutor.EXECUTOR_ID, descriptor -> {
var processHandler = descriptor.getProcessHandler();
assertNotNull(processHandler);
processHandler.addProcessListener(capturingAdapter);
});
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand All @@ -331,79 +330,10 @@ else if (LangDataKeys.MODULE.is(dataId)) {
ProcessHandler processHandler = contentDescriptor.getProcessHandler();
assertNotNull(processHandler);
waitForProcessFinish(processHandler);
ADAPTER_KEY.set(execResult.getFirst(), capturingAdapter);
return execResult;
}

/**
* Copy of {@link com.intellij.testFramework.PlatformTestUtil#executeConfiguration(RunConfiguration, String)} without waiting
*/
protected Pair<ExecutionEnvironment, RunContentDescriptor> executeConfiguration(@NotNull RunConfiguration runConfiguration,
@NotNull String executorId) throws InterruptedException {
Executor executor = ExecutorRegistry.getInstance().getExecutorById(executorId);
assertNotNull("Unable to find executor: " + executorId, executor);
return executeConfiguration(runConfiguration, executor);
}

protected @NotNull Pair<ExecutionEnvironment, RunContentDescriptor> executeConfiguration(@NotNull RunConfiguration runConfiguration,
Executor executor) throws InterruptedException {
Project project = runConfiguration.getProject();
ConfigurationFactory factory = runConfiguration.getFactory();
if (factory == null) {
fail("No factory found for: " + runConfiguration);
}
RunnerAndConfigurationSettings runnerAndConfigurationSettings =
RunManager.getInstance(project).createConfiguration(runConfiguration, factory);
ProgramRunner<?> runner = ProgramRunner.getRunner(executor.getId(), runConfiguration);
if (runner == null) {
fail("No runner found for: " + executor.getId() + " and " + runConfiguration);
}
Ref<RunContentDescriptor> refRunContentDescriptor = new Ref<>();
ExecutionEnvironment executionEnvironment =
new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, project);
CountDownLatch latch = new CountDownLatch(1);
ProgramRunnerUtil.executeConfigurationAsync(executionEnvironment, false, false, descriptor -> {
LOG.debug("Process started");
refRunContentDescriptor.set(descriptor);
ProcessHandler processHandler = descriptor.getProcessHandler();
assertNotNull(processHandler);
CapturingProcessAdapter capturingAdapter = new CapturingProcessAdapter();
processHandler.addProcessListener(capturingAdapter);
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void startNotified(@NotNull ProcessEvent event) {
LOG.debug("Process notified");
}

@Override
public void processTerminated(@NotNull ProcessEvent event) {
LOG.debug("Process terminated with " + event.getExitCode());
}

@Override
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
LOG.debug(outputType + ": " + event.getText());
}
});
ADAPTER_KEY.set(executionEnvironment, capturingAdapter);
latch.countDown();
});
NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
if (!latch.await(60, TimeUnit.SECONDS)) {
fail("Process failed to start");
}
RunContentDescriptor runContentDescriptor = refRunContentDescriptor.get();
ProcessHandler processHandler = runContentDescriptor.getProcessHandler();
assertNotNull(processHandler);
disposeOnPerlTearDown(runContentDescriptor);
disposeOnPerlTearDown(() -> {
if (!processHandler.isProcessTerminated()) {
processHandler.destroyProcess();
}
UIUtil.dispatchAllInvocationEvents();
});
return Pair.create(executionEnvironment, runContentDescriptor);
}

protected final @Nullable CapturingProcessAdapter getCapturingAdapter(@NotNull ExecutionEnvironment environment) {
return ADAPTER_KEY.get(environment);
}
Expand Down Expand Up @@ -490,7 +420,7 @@ else if (node.isPassed()) {
protected void runTestConfigurationWithExecutorAndCheckResultsWithFile(GenericPerlRunConfiguration runConfiguration, String executorId) {
Pair<ExecutionEnvironment, RunContentDescriptor> execResult;
try {
execResult = executeConfiguration(runConfiguration, executorId);
execResult = PlatformTestUtil.executeConfiguration(runConfiguration, executorId, null);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit b1ece27

Please sign in to comment.