1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 296904: [Error Parser] Make error parser should report non-fatal errors as Warnings instead of Errors

This commit is contained in:
Andrew Gvozdev 2010-01-30 04:32:53 +00:00
parent eb3dbb78f0
commit a4f9cfe9cc
2 changed files with 116 additions and 7 deletions

View file

@ -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());

View file

@ -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});
}
}