summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Ruiz2012-02-23 16:25:46 (EST)
committerSergey Prigogin2012-02-23 16:25:46 (EST)
commit00c29ec7eb32e3120d1023bfc3252d2f80fd7f01 (patch)
tree4f22ae07f637aee35d54fa4eebf8616cbced4253
parentf405944e2d0434f6dd8b7af1aa052ec8de01c7b7 (diff)
downloadorg.eclipse.cdt-00c29ec7eb32e3120d1023bfc3252d2f80fd7f01.zip
org.eclipse.cdt-00c29ec7eb32e3120d1023bfc3252d2f80fd7f01.tar.gz
org.eclipse.cdt-00c29ec7eb32e3120d1023bfc3252d2f80fd7f01.tar.bz2
Added more tests.
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/externaltool/CppcheckOutputParserTest.java111
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java4
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvoker.java11
3 files changed, 120 insertions, 6 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/externaltool/CppcheckOutputParserTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/externaltool/CppcheckOutputParserTest.java
new file mode 100644
index 0000000..aa08d16
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/externaltool/CppcheckOutputParserTest.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alex Ruiz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.checkers.externaltool;
+
+import org.eclipse.cdt.codan.core.externaltool.IProblemDisplay;
+import org.eclipse.cdt.codan.core.externaltool.InvocationParameters;
+import org.eclipse.cdt.codan.core.model.IProblemLocation;
+import org.eclipse.cdt.codan.core.test.CodanTestCase;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Tests for <code>{@link CppcheckOutputParser}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@SuppressWarnings("nls")
+public class CppcheckOutputParserTest extends CodanTestCase {
+ private static final String MATCHING_LINE_FORMAT = "[%s:%d]: (%s) %s";
+
+ private ProblemDisplayStub problemDisplay;
+
+ private CppcheckOutputParser parser;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ problemDisplay = new ProblemDisplayStub();
+ loadcode("void f(int x) {}", "test.cpp");
+ InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile,
+ actualFilePath(), null);
+ parser = new CppcheckOutputParser(parameters, problemDisplay);
+ }
+
+ public void testProblemIsReportedWhenParsingMatchingLine() {
+ int lineNumber = 2;
+ String severity = "warning";
+ String description = "The scope of the variable 'i' can be reduced";
+ boolean parsed = parser.parse(createMatchingLine(lineNumber, severity, description));
+ assertTrue(parsed);
+ problemDisplay.assertThatLocationHasFile(currentIFile);
+ problemDisplay.assertThatLocationHasLineNumber(lineNumber);
+ problemDisplay.assertThatLocationHasNoStartingAndEndingChars();
+ problemDisplay.assertThatReceivedDescription(description);
+ problemDisplay.assertThatReceivedSeverity(severity);
+ }
+
+ private String createMatchingLine(int lineNumber, String severity, String description) {
+ return String.format(MATCHING_LINE_FORMAT, actualFilePath(), lineNumber, severity, description);
+ }
+
+ private String actualFilePath() {
+ return currentIFile.getLocation().toOSString();
+ }
+
+ public void testProblemIsNotReportedWhenLineDoesNotMatch() {
+ boolean parsed = parser.parse("Checking usage of global functions..");
+ assertFalse(parsed);
+ problemDisplay.assertThatProblemWasNotReported();
+ }
+
+ private static class ProblemDisplayStub implements IProblemDisplay {
+ private boolean problemReported;
+ private IProblemLocation location;
+ private String description;
+ private String severity;
+
+ public void reportProblem(IProblemLocation location, String description) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void reportProblem(IProblemLocation location, String description, String severity) {
+ problemReported = true;
+ this.location = location;
+ this.description = description;
+ this.severity = severity;
+ }
+
+ void assertThatLocationHasFile(IResource expected) {
+ assertSame(expected, location.getFile());
+ }
+
+ void assertThatLocationHasLineNumber(int expected) {
+ assertEquals(expected, location.getLineNumber());
+ }
+
+ void assertThatLocationHasNoStartingAndEndingChars() {
+ assertEquals(-1, location.getStartingChar());
+ assertEquals(-1, location.getEndingChar());
+ }
+
+ void assertThatReceivedDescription(String expected) {
+ assertEquals(expected, description);
+ }
+
+ void assertThatReceivedSeverity(String expected) {
+ assertEquals(expected, severity);
+ }
+
+ void assertThatProblemWasNotReported() {
+ assertFalse(problemReported);
+ }
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java
index ef86e72..0aa87c6 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java
@@ -101,7 +101,9 @@ public class ExternalToolInvokerTest extends CodanTestCase {
// class C {
// };
public void testInvokesProcessCorrectly() throws Throwable {
- loadcode(getAboveComment());
+ String aboveComment = getAboveComment();
+ System.out.println(aboveComment);
+ loadcode(aboveComment);
String expectedCommand = expectedCommand();
InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile,
actualFilePath(), workingDirectory);
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvoker.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvoker.java
index 5d7d0ab..1743ed3 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvoker.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvoker.java
@@ -49,7 +49,7 @@ public class ExternalToolInvoker {
}
/**
- * Constructor.
+ * Constructor, for testing purposes only.
* @param consolePrinterProvider creates an Eclipse console that uses the name of an external
* tool as its own.
* @param processInvoker executes a command in a separate process.
@@ -72,8 +72,8 @@ public class ExternalToolInvoker {
* @throws Throwable if the external tool cannot be launched.
*/
public void invoke(InvocationParameters parameters, ConfigurationSettings configurationSettings,
- IArgsSeparator argsSeparator,
- List<AbstractOutputParser> parsers) throws InvocationFailure, Throwable {
+ IArgsSeparator argsSeparator, List<AbstractOutputParser> parsers)
+ throws InvocationFailure, Throwable {
IPath executablePath = executablePath(configurationSettings);
String[] args = argsToPass(parameters, configurationSettings, argsSeparator);
boolean shouldDisplayOutput = configurationSettings.getShouldDisplayOutput().getValue();
@@ -92,9 +92,9 @@ public class ExternalToolInvoker {
private String[] argsToPass(InvocationParameters parameters,
ConfigurationSettings configurationSettings, IArgsSeparator argsSeparator) {
- String[] configuredArgs = configuredArgs(configurationSettings, argsSeparator);
String actualFilePath = parameters.getActualFilePath();
- return addFilePathToArgs(actualFilePath, configuredArgs);
+ String[] args = configuredArgs(configurationSettings, argsSeparator);
+ return addFilePathToArgs(actualFilePath, args);
}
private String[] configuredArgs(ConfigurationSettings configurationSettings,
@@ -168,6 +168,7 @@ public class ExternalToolInvoker {
}
}
}
+
private void reset(List<AbstractOutputParser> parsers) {
for (AbstractOutputParser parser : parsers) {
parser.reset();