in mps-execution-deprecated/unitTests/source_gen/jetbrains/mps/baseLanguage/unitTest/execution/tool/UnitTestRunner.java [82:170]
private Process runTestWithParameters(final Tuples._3<String, List<String>, List<String>> parameters, final List<ITestNodeWrapper> tests) throws ProcessNotCreatedException {
final List<String> params = ListSequence.fromList(new ArrayList<String>());
final Wrappers._T<String> workingDir = new Wrappers._T<String>(null);
final Wrappers._T<String> programParams = new Wrappers._T<String>(null);
final Wrappers._T<String> vmParams = new Wrappers._T<String>(null);
final Wrappers._T<String> classpathString = new Wrappers._T<String>();
final Wrappers._T<List<String>> testsCommandLine = new Wrappers._T<List<String>>();
final Wrappers._long testCommandLineLength = new Wrappers._long(0);
ModelAccess.instance().runReadAction(new Runnable() {
public void run() {
if (myRunParameters != null) {
workingDir.value = myRunParameters.getWorkingDirectory();
programParams.value = myRunParameters.getProgramParameters();
vmParams.value = myRunParameters.getVMParameters();
}
addJavaCommand(params);
ListSequence.fromList(params).addSequence(ListSequence.fromList(parameters._1()));
if (vmParams.value != null && isNotEmptyString(vmParams.value)) {
String[] paramList = splitParams(vmParams.value);
ListSequence.fromList(params).addSequence(Sequence.fromIterable(Sequence.fromArray(paramList)));
}
classpathString.value = getClasspathString(tests, parameters._2());
addClassPath(params, classpathString.value);
ListSequence.fromList(params).addElement(parameters._0());
testsCommandLine.value = ListSequence.fromList(new ArrayList<String>(ListSequence.fromList(tests).count()));
for (ITestNodeWrapper test : ListSequence.fromList(tests)) {
List<String> parametersPart = ListSequence.fromListAndArray(new ArrayList<String>(), (test.isTestCase() ? "-c" : "-m"), test.getFqName());
testCommandLineLength.value = ListSequence.fromList(parametersPart).foldLeft(testCommandLineLength.value, new ILeftCombinator<String, Long>() {
public Long combine(Long s, String it) {
return s + it.length();
}
});
ListSequence.fromList(testsCommandLine.value).addSequence(ListSequence.fromList(parametersPart));
}
}
});
// on win command line length is restricted to 32767=2**15-1 symbols
// according to http://blogs.msdn.com/b/oldnewthing/archive/2003/12/10/56028.aspx
// so I use nice and round number 16384=2**14-1 as an upper bound
if (classpathString.value.length() + testCommandLineLength.value < MAX_COMMAND_LINE) {
ListSequence.fromList(params).addSequence(ListSequence.fromList(testsCommandLine.value));
} else {
// if we are to long, we have to write everything into the tmp file
File tmpFile = FileUtil.createTmpFile();
// we want to be sure that file is deleted, even when process is not started
tmpFile.deleteOnExit();
try {
PrintWriter writer = new PrintWriter(tmpFile);
for (String commandLinePiece : testsCommandLine.value) {
writer.append(commandLinePiece);
writer.append("\n");
}
writer.flush();
writer.close();
ListSequence.fromList(params).addElement("-f");
ListSequence.fromList(params).addElement(tmpFile.getAbsolutePath());
} catch (FileNotFoundException e) {
throw new ProcessNotCreatedException("Could not output run parameters to file " + tmpFile, getCommandLine(myRunParameters.getWorkingDirectory()));
}
}
if (programParams.value != null && isNotEmptyString(programParams.value)) {
String[] paramList = splitParams(programParams.value);
ListSequence.fromList(params).addSequence(Sequence.fromIterable(Sequence.fromArray(paramList)));
}
myProcessBuilder = new ProcessBuilder(params);
if (workingDir.value != null && isNotEmptyString(workingDir.value)) {
myProcessBuilder.directory(new File(workingDir.value));
}
try {
return myProcessBuilder.start();
} catch (Throwable e) {
if (LOG.isEnabledFor(Level.ERROR)) {
LOG.error("Can't run tests: " + e.getMessage(), e);
}
throw new ProcessNotCreatedException(e.getMessage(), e, getCommandLine(myRunParameters.getWorkingDirectory()));
}
}