Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Gcc Error Parser

Hi,

Since we moved from CDT 3.1 to CDT 4.0 RC2, I noticed
that outputs from gcc can be wrongly parsed.

Here is a JUnit test. It uses EasyMock.
The second test passes. Test 1 and 3 do not. The
error description is truncated.

Adding "Error: " between the line number and the description
makes the parser to work. A problem in the regexp?

Regards
Olivier Corbun
Ericsson, Sweden

import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.junit.Assert.fail;

import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.internal.errorparsers.GCCErrorParser;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.junit.Test;

/**
 * Test processing gcc errors
 * 
 * Tested outputs from gcc:
 * /tmp/src/PersUsage.cc:13: `ssd' undeclared (first use this function)
 * /tmp/src/PersUsage.cc:13:45: Error: undeclared first use this function
 * /tmp/src/PersUsage.cc:13: syntax error before `delete'
 * 
 * @author Olivier Corbun
 */
public class TestGccParser {

	private static final String filename = "/tmp/src/PersUsage.cc";
	
	// /tmp/src/PersUsage.cc:13: `ssd' undeclared (first use this function)
	private static int lineNumber1 = 13;
	private static String desc1 = "`ssd' undeclared (first use this function)";
	private static String line1 = filename+":"+lineNumber1+": "+desc1;

	// /tmp/src/PersUsage.cc:13:45: Error: undeclared first use this function
	private static int lineNumber2 = 13;
	private static String desc2 = "undeclared first use this function";
	private static String line2 = filename+":"+lineNumber2+":45: Error: "+desc2;

	// /tmp/src/PersUsage.cc:13: syntax error before `delete'
	private static int lineNumber3 = 13;
	private static String desc3 = "syntax error before `delete'";
	private static String line3 = filename+":"+lineNumber3+": "+desc3;
	
	private static GCCErrorParser parser = new GCCErrorParser();
	private static IFile ifile = createMock(IFile.class);
		
	@Test
	public void testProcessLine1() {
		// Mock ErrorParserManager
		ErrorParserManager epm = createMock(ErrorParserManager.class);
		expect(epm.findFileName(filename)).andReturn(ifile);
		expect(epm.isConflictingName(filename)).andReturn(false);
		epm.generateExternalMarker((IResource)ifile, lineNumber1, desc1, 2, null, null);
		replay(epm);		
		// Test
		System.out.println("\nparse: "+line1);
		try {
			parser.processLine(line1, epm);
		} catch (AssertionError ae) {
			System.out.println(ae.getMessage());
			fail("bad parsing: "+ae.getMessage());
		}
		System.out.println("correctly parsed");
	}

	@Test
	public void testProcessLine2() {
		// Mock ErrorParserManager
		ErrorParserManager epm = createMock(ErrorParserManager.class);
		expect(epm.findFileName(filename)).andReturn(ifile);
		expect(epm.isConflictingName(filename)).andReturn(false);
		epm.generateExternalMarker((IResource)ifile, lineNumber2, desc2, 2, null, null);
		replay(epm);		
		// Test
		System.out.println("\nparse: "+line2);
		try {
			parser.processLine(line2, epm);
		} catch (AssertionError ae) {
			System.out.println(ae.getMessage());
			fail("bad parsing: "+ae.getMessage());
		}
		System.out.println("correctly parsed");		
	}

	@Test
	public void testProcessLine3() {
		// Mock ErrorParserManager
		ErrorParserManager epm = createMock(ErrorParserManager.class);
		expect(epm.findFileName(filename)).andReturn(ifile);
		expect(epm.isConflictingName(filename)).andReturn(false);
		epm.generateExternalMarker((IResource)ifile, lineNumber3, desc3, 2, null, null);
		replay(epm);		
		// Test
		System.out.println("\nparse: "+line3);
		try {
			parser.processLine(line3, epm);
		} catch (AssertionError ae) {
			System.out.println(ae.getMessage());
			fail("bad parsing: "+ae.getMessage());
		}
		System.out.println("correctly parsed");	
	}

}

Back to the top