mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Test for agents with external hg config fixed
* ignore all config files except repository config for unit test mode; * hg separated process builder changed to ShellCommand executor in tests
This commit is contained in:
@@ -205,7 +205,7 @@ public class Executor {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
protected static List<String> splitCommandInParameters(String command) {
|
||||
public static List<String> splitCommandInParameters(String command) {
|
||||
List<String> split = new ArrayList<String>();
|
||||
|
||||
boolean insideParam = false;
|
||||
@@ -263,7 +263,7 @@ public class Executor {
|
||||
" executable." : ""));
|
||||
}
|
||||
|
||||
protected static String findEnvValue(String programNameForLog, Collection<String> envs) {
|
||||
public static String findEnvValue(String programNameForLog, Collection<String> envs) {
|
||||
for (String env : envs) {
|
||||
String val = System.getenv(env);
|
||||
if (val != null && new File(val).canExecute()) {
|
||||
@@ -274,7 +274,7 @@ public class Executor {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void debug(String msg) {
|
||||
public static void debug(String msg) {
|
||||
if (!StringUtil.isEmptyOrSpaces(msg)) {
|
||||
LOG.info(msg);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,11 @@ package org.zmlx.hg4idea.execution;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.*;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessListener;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -44,6 +48,10 @@ public final class ShellCommand {
|
||||
if (charset != null) {
|
||||
myCommandLine.setCharset(charset);
|
||||
}
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
//ignore all hg config files except current repository config
|
||||
myCommandLine.getEnvironment().put("HGRCPATH", "");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -3,6 +3,3 @@ username = John Doe <John.Doe@example.com>
|
||||
|
||||
[merge-patterns]
|
||||
** = internal:merge
|
||||
|
||||
[extensions]
|
||||
sparse=!
|
||||
|
||||
@@ -18,14 +18,17 @@ package hg4idea.test;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.Executor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.ShellCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HgExecutor extends Executor {
|
||||
import static com.intellij.openapi.vcs.Executor.*;
|
||||
|
||||
public class HgExecutor {
|
||||
|
||||
private static final String HG_EXECUTABLE_ENV = "IDEA_TEST_HG_EXECUTABLE";
|
||||
|
||||
@@ -35,7 +38,7 @@ public class HgExecutor extends Executor {
|
||||
final String programName = "hg";
|
||||
final String unixExec = "hg";
|
||||
final String winExec = "hg.exe";
|
||||
String exec = findEnvValue(programName, Arrays.asList(HG_EXECUTABLE_ENV));
|
||||
String exec = findEnvValue(programName, Collections.singletonList(HG_EXECUTABLE_ENV));
|
||||
if (exec != null) {
|
||||
return exec;
|
||||
}
|
||||
@@ -57,15 +60,26 @@ public class HgExecutor extends Executor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String hg(String command) {
|
||||
public static String hg(@NotNull String command) {
|
||||
return hg(command, false);
|
||||
}
|
||||
|
||||
public static String hg(String command, boolean ignoreNonZeroExitCode) {
|
||||
public static String hg(@NotNull String command, boolean ignoreNonZeroExitCode) {
|
||||
List<String> split = splitCommandInParameters(command);
|
||||
split.add(0, HG_EXECUTABLE);
|
||||
debug("hg " + command);
|
||||
return run(ourCurrentDir(), split, ignoreNonZeroExitCode);
|
||||
HgCommandResult result;
|
||||
try {
|
||||
result = new ShellCommand(split, pwd(), null).execute(false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
int exitValue = result.getExitValue();
|
||||
if (!ignoreNonZeroExitCode && exitValue != 0) {
|
||||
throw new RuntimeException(result.getRawError());
|
||||
}
|
||||
return result.getRawOutput();
|
||||
}
|
||||
|
||||
public static void updateProject() {
|
||||
|
||||
@@ -27,11 +27,9 @@ import org.zmlx.hg4idea.util.HgUtil;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static hg4idea.test.HgExecutor.*;
|
||||
import static com.intellij.openapi.vcs.Executor.*;
|
||||
import static hg4idea.test.HgExecutor.hg;
|
||||
|
||||
/**
|
||||
* @author Nadya Zabrodina
|
||||
*/
|
||||
public class HgGetDiffForDirTest extends HgPlatformTest {
|
||||
|
||||
private static final String SHORT_TEMPLATE_REVISION = "{rev}:{node|short}";
|
||||
|
||||
Reference in New Issue
Block a user