diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/GenericErrorParserTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/GenericErrorParserTests.java index 74f4accc7e6..15c64cc9651 100644 --- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/GenericErrorParserTests.java +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/GenericErrorParserTests.java @@ -36,6 +36,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; public abstract class GenericErrorParserTests extends TestCase { public static final String GCC_ERROR_PARSER_ID = "org.eclipse.cdt.core.GCCErrorParser"; public static final String GLD_ERROR_PARSER_ID = "org.eclipse.cdt.core.GLDErrorParser"; + public static final String GMAKE_ERROR_PARSER_ID = "org.eclipse.cdt.core.GmakeErrorParser"; protected IProject fTempProject; @@ -105,6 +106,11 @@ public abstract class GenericErrorParserTests extends TestCase { protected void runParserTest(InputStream inputStream, int expectedErrorCount, int expectedWarningCount, String[] expectedFileNames, String[] expectedDescriptions, String[] parserID) throws IOException { + runParserTest(inputStream, expectedErrorCount, expectedWarningCount, 0, expectedFileNames, expectedDescriptions, parserID); + } + + protected void runParserTest(InputStream inputStream, int expectedErrorCount, int expectedWarningCount, int expectedInfoCount, + String[] expectedFileNames, String[] expectedDescriptions, String[] parserID) throws IOException { assertNotNull(inputStream); @@ -126,6 +132,9 @@ public abstract class GenericErrorParserTests extends TestCase { if (expectedWarningCount >= 0) { assertEquals(expectedWarningCount, markerGenerator.numWarnings); } + if (expectedInfoCount >= 0) { + assertEquals(expectedInfoCount, markerGenerator.numInfos); + } if (expectedFileNames != null) { assertEquals(expectedFileNames.length, markerGenerator.uniqFiles.size()); for (int i = 0; i < expectedFileNames.length; i++) { @@ -142,13 +151,18 @@ public abstract class GenericErrorParserTests extends TestCase { } } - protected void runParserTest(String[] dataStream, int expectedErrorCount, int expectedWarningCount, String[] expectedFileNames, - String[] expectedDescriptions, String[] parserID) throws IOException { + protected void runParserTest(String[] dataStream, int expectedErrorCount, int expectedWarningCount, + String[] expectedFileNames, String[] expectedDescriptions, String[] parserID) throws IOException { + runParserTest(dataStream, expectedErrorCount, expectedWarningCount, 0, expectedFileNames, expectedDescriptions, parserID); + } + + protected void runParserTest(String[] dataStream, int expectedErrorCount, int expectedWarningCount, int expectedInfoCount, + String[] expectedFileNames, String[] expectedDescriptions, String[] parserID) throws IOException { String errorStream = makeStringFromArray(dataStream, "\n"); ByteArrayInputStream inputStream = new ByteArrayInputStream(errorStream.getBytes()); - runParserTest(inputStream, expectedErrorCount, expectedWarningCount, expectedFileNames, expectedDescriptions, parserID); + runParserTest(inputStream, expectedErrorCount, expectedWarningCount, expectedInfoCount, expectedFileNames, expectedDescriptions, parserID); } class FileNameComparator implements Comparator { @@ -177,6 +191,7 @@ public abstract class GenericErrorParserTests extends TestCase { public int numErrors; public int numWarnings; + public int numInfos; public int numMarkers; public ArrayList uniqFiles; public String lastDescription; @@ -197,10 +212,12 @@ public abstract class GenericErrorParserTests extends TestCase { uniqFiles.add(-1 * (index + 1), problemMarkerInfo.file); } - if (problemMarkerInfo.severity == SEVERITY_WARNING) { - numWarnings++; - } else if (problemMarkerInfo.severity == SEVERITY_ERROR_BUILD || problemMarkerInfo.severity == SEVERITY_ERROR_RESOURCE) { + if (problemMarkerInfo.severity == SEVERITY_ERROR_BUILD || problemMarkerInfo.severity == SEVERITY_ERROR_RESOURCE) { numErrors++; + } else if (problemMarkerInfo.severity == SEVERITY_WARNING) { + numWarnings++; + } else if (problemMarkerInfo.severity == SEVERITY_INFO) { + numInfos++; } lastDescription = problemMarkerInfo.description; @@ -211,6 +228,7 @@ public abstract class GenericErrorParserTests extends TestCase { public CountingMarkerGenerator() { numErrors = 0; numWarnings = 0; + numInfos = 0; uniqFiles = new ArrayList(0); fFileNameComparator = new FileNameComparator(); } @@ -230,11 +248,14 @@ public abstract class GenericErrorParserTests extends TestCase { } public IFile findFileName(String fileName) { + if (fileName==null || fileName.trim().length()==0) { + return null; + } if (fileName.lastIndexOf('/') != -1) { fileName = fileName.substring(fileName.lastIndexOf('/') + 1); } IFile file = fProject.getFile(fileName); - if (!file.exists()) { + if (file!=null && !file.exists()) { try { InputStream stream = new ByteArrayInputStream("TestFile".getBytes()); file.create(stream, true, new NullProgressMonitor()); diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/MakeErrorParserTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/MakeErrorParserTests.java new file mode 100644 index 00000000000..87f424fb994 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/internal/errorparsers/tests/MakeErrorParserTests.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2010 Andrew Gvozdev (Quoin Inc.) and others. + * 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: + * Andrew Gvozdev (Quoin Inc.) - initial API and implementation, based on GCCErrorParserTests + *******************************************************************************/ +package org.eclipse.cdt.core.internal.errorparsers.tests; + + +import java.io.IOException; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.ErrorParserManager; + + +/** + * This test is designed to exercise the error parser capabilities for GNU make. + */ +public class MakeErrorParserTests extends GenericErrorParserTests { + + private static final String[] GMAKE_ERROR_STREAM0 = { + // Infos + "make: [Hello.o] Error 1 (ignored)", + "make[2]: [all] Error 2 (ignored)", + // Warnings + "make: [Hello.o] Error 1", + "make: Circular .folder/file.h <- .folder/file2.h dependency dropped.", + "make[1]: Circular folder/file.h <- Makefile dependency dropped.", + // Errors + "make: *** [Hello.o] Error 1", + "make[3]: *** [Hello.o] Error 1", + "make: *** No rule to make target `one', needed by `all'. Stop.", + "make: *** No rule to make target `all'. Stop.", + "make: *** missing.mk: No such file or directory. Stop.", + "make: Target `all' not remade because of errors.", + // Ignored + "make[3]: Nothing to be done for `all'.", + "make[2]: `all' is up to date.", + + }; + private static final int GMAKE_ERROR_STREAM0_INFOS = 2; + private static final int GMAKE_ERROR_STREAM0_WARNINGS = 3; + private static final int GMAKE_ERROR_STREAM0_ERRORS = 6; + + private static final String[] GMAKE_ERROR_STREAM1 = { + // Warning + "Makefile1:10: include.mk: No such file or directory", + // Errors + "Makefile2:10: *** missing separator. Stop.", + "Makefile3:10: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.", + "Makefile4:10: *** commands commence before first target. Stop.", + "Makefile5:10: *** Recursive variable 'VAR' references itself (eventually). Stop.", + "Makefile6:10: *** target pattern contains no `%'. Stop.", + }; + private static final int GMAKE_ERROR_STREAM1_WARNINGS = 1; + private static final int GMAKE_ERROR_STREAM1_ERRORS = 5; + private static final String[] GMAKE_ERROR_STREAM1_FILENAMES = {"Makefile1", "Makefile2", + "Makefile3", "Makefile4", "Makefile5", "Makefile6"}; + + public MakeErrorParserTests() { + super(); + } + + public static Test suite() { + TestSuite suite = new TestSuite(MakeErrorParserTests.class); + return suite; + } + + public void testGmakeSanity() throws Exception { + assertNotNull(ErrorParserManager.getErrorParserCopy(GMAKE_ERROR_PARSER_ID)); + } + + public void testGmakeMessages0() throws IOException { + runParserTest(GMAKE_ERROR_STREAM0, GMAKE_ERROR_STREAM0_ERRORS, GMAKE_ERROR_STREAM0_WARNINGS, GMAKE_ERROR_STREAM0_INFOS, + null, null, new String[]{GMAKE_ERROR_PARSER_ID}); + } + + public void testGMakeMessages1() throws IOException { + runParserTest(GMAKE_ERROR_STREAM1, GMAKE_ERROR_STREAM1_ERRORS, GMAKE_ERROR_STREAM1_WARNINGS, + GMAKE_ERROR_STREAM1_FILENAMES, null, new String[]{GMAKE_ERROR_PARSER_ID}); + } +}