1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fixed test broken by accident.

Switched to System.arrayCopy instead of manual array copy.
This commit is contained in:
Alex Ruiz 2012-02-23 13:20:05 -08:00 committed by Sergey Prigogin
parent 55b9874f5d
commit 295466d26f
2 changed files with 32 additions and 29 deletions

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.core.externaltool; package org.eclipse.cdt.codan.internal.core.externaltool;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import java.io.File; import java.io.File;
@ -38,12 +39,10 @@ import org.eclipse.core.runtime.IPath;
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ExternalToolInvokerTest extends CodanTestCase { public class ExternalToolInvokerTest extends CodanTestCase {
private static final String EXTERNAL_TOOL_NAME = "TestTool"; private ConfigurationSettings settings;
private ConfigurationSettings configurationSettings;
private IArgsSeparator argsSeparator; private IArgsSeparator argsSeparator;
private List<AbstractOutputParser> parsers; private List<AbstractOutputParser> parsers;
private CommandLauncherStub commandLauncher; private CommandLauncherStub launcher;
private ExternalToolInvoker externalToolInvoker; private ExternalToolInvoker externalToolInvoker;
@ -53,17 +52,16 @@ public class ExternalToolInvokerTest extends CodanTestCase {
createConfigurationSettings(); createConfigurationSettings();
argsSeparator = new SpaceDelimitedArgsSeparator(); argsSeparator = new SpaceDelimitedArgsSeparator();
parsers = new ArrayList<AbstractOutputParser>(); parsers = new ArrayList<AbstractOutputParser>();
commandLauncher = new CommandLauncherStub(); launcher = new CommandLauncherStub();
externalToolInvoker = new ExternalToolInvoker(commandLauncher); externalToolInvoker = new ExternalToolInvoker(launcher);
} }
private void createConfigurationSettings() { private void createConfigurationSettings() {
configurationSettings = new ConfigurationSettings(EXTERNAL_TOOL_NAME, new File("testtool"), settings = new ConfigurationSettings("TestTool", new File("testtool"), "", false);
"", false);
// Update current value of ConfigurationSettings from preferences. // Update current value of ConfigurationSettings from preferences.
MapProblemPreference preferences = createPreferences(new File("usr/local/testtool"), MapProblemPreference preferences = createPreferences(new File("usr/local/testtool"),
"--debug=true --include=all", true); "--debug=true --include=all", true);
configurationSettings.updateValuesFrom(preferences); settings.updateValuesFrom(preferences);
} }
private MapProblemPreference createPreferences(File path, String args, private MapProblemPreference createPreferences(File path, String args,
@ -71,8 +69,8 @@ public class ExternalToolInvokerTest extends CodanTestCase {
MapProblemPreference preferences = new MapProblemPreference(); MapProblemPreference preferences = new MapProblemPreference();
preferences.addChildDescriptor(createPreference(PathSetting.KEY, path)); preferences.addChildDescriptor(createPreference(PathSetting.KEY, path));
preferences.addChildDescriptor(createPreference(ArgsSetting.KEY, args)); preferences.addChildDescriptor(createPreference(ArgsSetting.KEY, args));
preferences.addChildDescriptor(createPreference(ShouldDisplayOutputSetting.KEY, preferences.addChildDescriptor(
shouldDisplayOutput)); createPreference(ShouldDisplayOutputSetting.KEY, shouldDisplayOutput));
return preferences; return preferences;
} }
@ -93,15 +91,22 @@ public class ExternalToolInvokerTest extends CodanTestCase {
loadcode(getAboveComment()); loadcode(getAboveComment());
InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile, InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile,
currentIFile.getLocation().toOSString(), cproject.getProject().getLocation()); currentIFile.getLocation().toOSString(), cproject.getProject().getLocation());
externalToolInvoker.invoke(parameters, configurationSettings, argsSeparator, parsers); externalToolInvoker.invoke(parameters, settings, argsSeparator, parsers);
commandLauncher.assertThatReceivedProject(cproject.getProject()); launcher.assertThatReceivedProject(cproject.getProject());
commandLauncher.assertThatReceivedExternalToolName(EXTERNAL_TOOL_NAME); launcher.assertThatReceivedExternalToolName(settings.getExternalToolName());
commandLauncher.assertThatReceivedExecutablePath(configurationSettings.getPath()); launcher.assertThatReceivedExecutablePath(settings.getPath());
commandLauncher.assertThatReceivedArgs(configurationSettings.getArgs()); launcher.assertThatReceivedArgs(expectedArgs(parameters));
commandLauncher.assertThatReceivedWorkingDirectory(parameters.getWorkingDirectory()); launcher.assertThatReceivedWorkingDirectory(parameters.getWorkingDirectory());
commandLauncher.assertThatReceivedShouldDisplayOutput( launcher.assertThatReceivedShouldDisplayOutput(
configurationSettings.getShouldDisplayOutput()); settings.getShouldDisplayOutput());
commandLauncher.assetThatReceivedOutputParsers(parsers); launcher.assertThatReceivedOutputParsers(parsers);
}
private List<String> expectedArgs(InvocationParameters parameters) {
String[] originalArgs = settings.getArgs().getValue().split("\\s+");
List<String> expectedArgs = new ArrayList<String>(asList(originalArgs));
expectedArgs.add(0, parameters.getActualFilePath());
return expectedArgs;
} }
private static class CommandLauncherStub implements ICommandLauncher { private static class CommandLauncherStub implements ICommandLauncher {
@ -140,9 +145,8 @@ public class ExternalToolInvokerTest extends CodanTestCase {
assertEquals(expectedPath, executablePath.toOSString()); assertEquals(expectedPath, executablePath.toOSString());
} }
void assertThatReceivedArgs(SingleConfigurationSetting<String> expected) { void assertThatReceivedArgs(List<String> expected) {
String[] expectedArgs = expected.getValue().split("\\s+"); assertArrayEquals(expected.toArray(), args);
assertArrayEquals(expectedArgs, args);
} }
void assertThatReceivedWorkingDirectory(IPath expected) { void assertThatReceivedWorkingDirectory(IPath expected) {
@ -153,7 +157,7 @@ public class ExternalToolInvokerTest extends CodanTestCase {
assertEquals(expected.getValue().booleanValue(), shouldDisplayOutput); assertEquals(expected.getValue().booleanValue(), shouldDisplayOutput);
} }
void assetThatReceivedOutputParsers(List<AbstractOutputParser> expected) { void assertThatReceivedOutputParsers(List<AbstractOutputParser> expected) {
assertSame(expected, parsers); assertSame(expected, parsers);
} }
} }

View file

@ -13,10 +13,10 @@ package org.eclipse.cdt.codan.internal.core.externaltool;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser;
import org.eclipse.cdt.codan.core.externaltool.ConfigurationSettings; import org.eclipse.cdt.codan.core.externaltool.ConfigurationSettings;
import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator; import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator;
import org.eclipse.cdt.codan.core.externaltool.ICommandLauncher; import org.eclipse.cdt.codan.core.externaltool.ICommandLauncher;
import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser;
import org.eclipse.cdt.codan.core.externaltool.InvocationFailure; import org.eclipse.cdt.codan.core.externaltool.InvocationFailure;
import org.eclipse.cdt.codan.core.externaltool.InvocationParameters; import org.eclipse.cdt.codan.core.externaltool.InvocationParameters;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -88,13 +88,12 @@ public class ExternalToolInvoker {
private String[] addFilePathToArgs(String actualFilePath, String[] configuredArgs) { private String[] addFilePathToArgs(String actualFilePath, String[] configuredArgs) {
int argCount = configuredArgs.length; int argCount = configuredArgs.length;
// TODO (alruiz) use array copy.
String[] allArgs = new String[argCount + 1]; String[] allArgs = new String[argCount + 1];
// alruiz: Arrays.copyOf leaves empty cells at the end. We need an empty cell at the
// beginning of the array.
System.arraycopy(configuredArgs, 0, allArgs, 1, argCount);
// add file to process as the first argument // add file to process as the first argument
allArgs[0] = actualFilePath; allArgs[0] = actualFilePath;
for (int i = 0; i < argCount; i++) {
allArgs[i + 1] = configuredArgs[i];
}
return allArgs; return allArgs;
} }