mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
[264998] - fixed console parser
This commit is contained in:
parent
c95d03759b
commit
734b002e93
4 changed files with 89 additions and 3 deletions
|
@ -74,9 +74,9 @@ public class GCCSpecsConsoleParser implements IScannerInfoConsoleParser {
|
|||
// i now marks the space between the name and definition
|
||||
if (i > 0) {
|
||||
int start = line.indexOf(defineParts[1]); // start of definition
|
||||
defineParts[1] = line.substring(start, i);
|
||||
defineParts[1] = line.substring(start, i + 1);
|
||||
if (defineParts.length > 2) {
|
||||
defineParts[2] = line.substring(i + 1);
|
||||
defineParts[2] = line.substring(i + 1).trim();
|
||||
}
|
||||
} else {
|
||||
MakeCorePlugin.log(new Exception("GCCSpecsConsoleParser ERROR: Unmatched brackets: ["+ line+ "]")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
|
|
@ -29,6 +29,7 @@ public class TraceUtil {
|
|||
private static LogWriter logger = null;
|
||||
|
||||
static {
|
||||
if (MakeCorePlugin.getDefault()!=null) // in case of running simple junit tests
|
||||
logger = new LogWriter(MakeCorePlugin.getDefault().getStateLocation().append(".log").toFile()); //$NON-NLS-1$
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -16,6 +16,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.CfgScannerConfigProfileManagerTests;
|
||||
import org.eclipse.cdt.build.core.scannerconfig.tests.GCCSpecsConsoleParserTest;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.managedbuilder.core.tests.BuildDescriptionModelTests;
|
||||
|
@ -54,6 +55,7 @@ public class AllManagedBuildTests {
|
|||
//$JUnit-BEGIN$
|
||||
// build.core.scannerconfig.tests
|
||||
suite.addTest(CfgScannerConfigProfileManagerTests.suite());
|
||||
suite.addTestSuite(GCCSpecsConsoleParserTest.class);
|
||||
|
||||
// managedbuilder.core.tests
|
||||
suite.addTest(ManagedBuildCoreTests20.suite());
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package org.eclipse.cdt.build.core.scannerconfig.tests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
|
||||
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
|
||||
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser;
|
||||
|
||||
public class GCCSpecsConsoleParserTest extends TestCase {
|
||||
GCCSpecsConsoleParser parser;
|
||||
private IScannerInfoCollector collector;
|
||||
List<String> includes;
|
||||
List<String> symbols;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
collector = new IScannerInfoCollector() {
|
||||
|
||||
public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public void contributeToScannerConfig(Object resource, Map scannerInfo1) {
|
||||
Map<ScannerInfoTypes, List<String>> scannerInfo = scannerInfo1;
|
||||
includes = scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);
|
||||
symbols = scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||
}
|
||||
};
|
||||
parser = new GCCSpecsConsoleParser();
|
||||
parser.startup(null, null, collector, null);
|
||||
}
|
||||
|
||||
private void enterLine(String line) {
|
||||
parser.processLine(line);
|
||||
parser.shutdown();
|
||||
}
|
||||
|
||||
private void checkMacro(String name, String value) {
|
||||
assertTrue("No symbols", symbols.size() > 0);
|
||||
String string = symbols.get(0);
|
||||
if (string.contains("=")) {
|
||||
String[] val = string.split("=", 2);
|
||||
assertEquals(name, val[0]);
|
||||
assertEquals(value, val[1]);
|
||||
} else {
|
||||
assertEquals(name, string);
|
||||
assertEquals(value, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testProcessLine_NoArgs() {
|
||||
enterLine("#define __MY_MACRO__ __MY_VALUE__");
|
||||
checkMacro("__MY_MACRO__", "__MY_VALUE__");
|
||||
|
||||
}
|
||||
public void testProcessLine_Const() {
|
||||
enterLine("#define A (3)");
|
||||
checkMacro("A", "(3)");
|
||||
}
|
||||
public void testProcessLine_EmptyArgList() {
|
||||
enterLine("#define A() B");
|
||||
checkMacro("A()", "B");
|
||||
}
|
||||
public void testProcessLine_ParamUnused() {
|
||||
enterLine("#define A(X) B");
|
||||
checkMacro("A(X)", "B");
|
||||
}
|
||||
public void testProcessLine_ParamSpace() {
|
||||
enterLine("#define __MY_MACRO__(P1, P2) __MY_VALUE__(P1, P2)");
|
||||
checkMacro("__MY_MACRO__(P1, P2)", "__MY_VALUE__(P1, P2)");
|
||||
}
|
||||
public void testProcessLine_EmptyBody() {
|
||||
enterLine("#define __MY_MACRO__(P1, P2) ");
|
||||
checkMacro("__MY_MACRO__(P1, P2)", "");
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue