use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method ignoredTestMethod.
@Test
public void ignoredTestMethod() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
TestObject state = configuration.getState(executor, environment);
JavaParameters parameters = state.getJavaParameters();
parameters.setUseDynamicClasspath(getProject());
GeneralCommandLine commandLine = parameters.toCommandLine();
StringBuffer buf = new StringBuffer();
StringBuffer err = new StringBuffer();
OSProcessHandler process = new OSProcessHandler(commandLine);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
try {
if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
buf.append(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
err.append(text);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
process.startNotify();
process.waitFor();
process.destroyProcess();
String testOutput = buf.toString();
assertEmpty(err.toString());
switch(myJUnitVersion) {
//shouldn't work for old versions
case "4.4":
//shouldn't work for old versions
case "4.5":
break;
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class PyAbstractTestProcessRunner method rerunFailedTests.
/**
* Rerun current tests. Make sure there is at least one failed test.
* <strong>Run in AWT thread only!</strong>
*/
public void rerunFailedTests() {
assert getFailedTestsCount() > 0 : "No failed tests. What you want to rerun?";
assert myLastProcessDescriptor != null : "No last run descriptor. First run tests at least one time";
final List<ProgramRunner<?>> run = getAvailableRunnersForLastRun();
Assert.assertFalse("No runners to rerun", run.isEmpty());
final ProgramRunner<?> runner = run.get(0);
final ExecutionEnvironment restartAction = RerunFailedActionsTestTools.findRestartAction(myLastProcessDescriptor);
Assert.assertNotNull("No restart action", restartAction);
final Ref<ProcessHandler> handlerRef = new Ref<>();
try {
runner.execute(restartAction, descriptor -> handlerRef.set(descriptor.getProcessHandler()));
} catch (final ExecutionException e) {
throw new AssertionError("ExecutionException can't be thrown in tests. Probably, API changed. Got: " + e);
}
final ProcessHandler handler = handlerRef.get();
if (handler == null) {
return;
}
handler.waitFor();
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class RerunFailedActionsTestTools method findRestartActionState.
/**
* Searches for "rerun failed tests" action and fetches state from it
*
* @param descriptor previous run descriptor
* @return state (if found)
*/
@Nullable
public static RunProfileState findRestartActionState(@NotNull final RunContentDescriptor descriptor) {
final ExecutionEnvironment action = findRestartAction(descriptor);
if (action == null) {
return null;
}
final Ref<RunProfileState> stateRef = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
try {
stateRef.set(action.getState());
} catch (final ExecutionException e) {
throw new IllegalStateException("Error obtaining execution state", e);
}
}, ModalityState.NON_MODAL);
return stateRef.get();
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class ConfigurationBasedProcessRunner method runProcess.
@Override
final void runProcess(@NotNull final String sdkPath, @NotNull final Project project, @NotNull final ProcessListener processListener, @NotNull final String tempWorkingPath) throws ExecutionException {
ensureConsoleOk(myConsole);
// Do not create new environment from factory, if child provided environment to rerun
final ExecutionEnvironment executionEnvironment = // TODO: RENAME
(myRerunExecutionEnvironment != null ? myRerunExecutionEnvironment : createExecutionEnvironment(sdkPath, project, tempWorkingPath));
// Engine to be run after process end to post process console
final ProcessListener consolePostprocessor = new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
super.processTerminated(event);
ApplicationManager.getApplication().invokeAndWait(() -> prepareConsoleAfterProcessEnd(), ModalityState.NON_MODAL);
}
};
/// Find all available runners to report them to the test
myAvailableRunnersForLastRun.clear();
for (final ProgramRunner<?> runner : ProgramRunner.PROGRAM_RUNNER_EP.getExtensions()) {
for (final Executor executor : Executor.EXECUTOR_EXTENSION_NAME.getExtensions()) {
if (runner.canRun(executor.getId(), executionEnvironment.getRunProfile())) {
myAvailableRunnersForLastRun.add(runner);
}
}
}
executionEnvironment.getRunner().execute(executionEnvironment, new ProgramRunner.Callback() {
@Override
public void processStarted(final RunContentDescriptor descriptor) {
final ProcessHandler handler = descriptor.getProcessHandler();
assert handler != null : "No process handler";
handler.addProcessListener(consolePostprocessor);
handler.addProcessListener(processListener);
myConsole = null;
fetchConsoleAndSetToField(descriptor);
assert myConsole != null : "fetchConsoleAndSetToField did not set console!";
// Console does not work with out of this method
final JComponent component = myConsole.getComponent();
assert component != null;
myLastProcessDescriptor = descriptor;
}
});
}
use of com.intellij.execution.runners.ExecutionEnvironment in project intellij-community by JetBrains.
the class PyDebuggerTask method runTestOn.
public void runTestOn(String sdkHome) throws Exception {
final Project project = getProject();
final ConfigurationFactory factory = PythonConfigurationType.getInstance().getConfigurationFactories()[0];
final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
myRunConfiguration = (PythonRunConfiguration) settings.getConfiguration();
myRunConfiguration.setSdkHome(sdkHome);
myRunConfiguration.setScriptName(getScriptName());
myRunConfiguration.setWorkingDirectory(myFixture.getTempDirPath());
myRunConfiguration.setScriptParameters(getScriptParameters());
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
}
}.execute();
final PyDebugRunner runner = (PyDebugRunner) ProgramRunnerUtil.getRunner(getExecutorId(), settings);
Assert.assertTrue(runner.canRun(getExecutorId(), myRunConfiguration));
final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, settings, project);
final PythonCommandLineState pyState = (PythonCommandLineState) myRunConfiguration.getState(executor, env);
assert pyState != null;
pyState.setMultiprocessDebug(isMultiprocessDebug());
final ServerSocket serverSocket;
try {
//noinspection SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(0);
} catch (IOException e) {
throw new ExecutionException("Failed to find free socket port", e);
}
final int serverLocalPort = serverSocket.getLocalPort();
final RunProfile profile = env.getRunProfile();
//turn off exception breakpoints by default
PythonDebuggerTest.createExceptionBreak(myFixture, false, false, false);
before();
setProcessCanTerminate(false);
myTerminateSemaphore = new Semaphore(0);
new WriteAction<ExecutionResult>() {
@Override
protected void run(@NotNull Result<ExecutionResult> result) throws Throwable {
myExecutionResult = pyState.execute(executor, runner.createCommandLinePatchers(myFixture.getProject(), pyState, profile, serverLocalPort));
mySession = XDebuggerManager.getInstance(getProject()).startSession(env, new XDebugProcessStarter() {
@NotNull
public XDebugProcess start(@NotNull final XDebugSession session) {
myDebugProcess = new PyDebugProcess(session, serverSocket, myExecutionResult.getExecutionConsole(), myExecutionResult.getProcessHandler(), isMultiprocessDebug());
StringBuilder output = new StringBuilder();
myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
output.append(event.getText());
}
@Override
public void processTerminated(ProcessEvent event) {
myTerminateSemaphore.release();
if (event.getExitCode() != 0 && !myProcessCanTerminate) {
Assert.fail("Process terminated unexpectedly\n" + output.toString());
}
}
});
myDebugProcess.getProcessHandler().startNotify();
return myDebugProcess;
}
});
result.setResult(myExecutionResult);
}
}.execute().getResultObject();
OutputPrinter myOutputPrinter = null;
if (shouldPrintOutput) {
myOutputPrinter = new OutputPrinter();
myOutputPrinter.start();
}
myPausedSemaphore = new Semaphore(0);
mySession.addSessionListener(new XDebugSessionListener() {
@Override
public void sessionPaused() {
if (myPausedSemaphore != null) {
myPausedSemaphore.release();
}
}
});
doTest(myOutputPrinter);
}
Aggregations