1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

pwd in scanner discovery, bug 237958.

This commit is contained in:
Markus Schorn 2008-07-14 16:00:29 +00:00
parent 0954c9559b
commit 87b69a7f19
2 changed files with 33 additions and 13 deletions

View file

@ -47,6 +47,7 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
super(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
fCProject= CProjectHelper.createCCProject("perfilescdtest", null);
@ -55,6 +56,7 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
fOutputParser.startup(project, project.getLocation(), fCollector, MARKER_GENERATOR);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (fOutputParser != null) {
@ -68,7 +70,7 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
public void testParsingIfStatement_bug197930() throws Exception {
fOutputParser.processLine("if gcc -g -O0 -I\"include abc\" -c impl/testmath.c; then ; fi"); //$NON-NLS-1$
List cmds = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.COMPILER_COMMAND);
List<?> cmds = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.COMPILER_COMMAND);
assertEquals(1, cmds.size());
CCommandDSC command= (CCommandDSC) cmds.get(0);
assertEquals("gcc", command.getCompilerName());
@ -76,16 +78,16 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
public void testResolvingLinkedFolder_Bug213690() throws Exception {
File tempRoot= new File(System.getProperty("java.io.tmpdir"));
File tempDir= new File(tempRoot, "cdttest_213690");
File tempDir= new File(tempRoot, "cdttest_213690").getCanonicalFile();
tempDir.mkdir();
try {
IFolder linkedFolder= fCProject.getProject().getFolder("cdttest");
linkedFolder.createLink(new Path(tempDir.toString()), IResource.ALLOW_MISSING_LOCAL, null);
fOutputParser.processLine("gcc -g -O0 -I\""+ tempDir.toString() + "\"" + "-c test.c"); //$NON-NLS-1$
List cmds = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.COMPILER_COMMAND);
fOutputParser.processLine("gcc -g -O0 -I\""+ tempDir.toString() + "\" -c test.c"); //$NON-NLS-1$
List<?> cmds = fCollector.getCollectedScannerInfo(null, ScannerInfoTypes.COMPILER_COMMAND);
assertEquals(1, cmds.size());
CCommandDSC command= (CCommandDSC) cmds.get(0);
List includes= command.getIncludes();
List<?> includes= command.getIncludes();
assertEquals(1, includes.size());
assertEquals(tempDir.toString(), includes.get(0).toString());
} finally {
@ -105,7 +107,7 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
linkedFolder.createLink(new Path(tempDir.toString()), IResource.ALLOW_MISSING_LOCAL, null);
fOutputParser.processLine("gcc -g -O0 -c \""+ tempFile.toString() + "\""); //$NON-NLS-1$
IFile file= linkedFolder.getFile("test.c");
List cmds = fCollector.getCollectedScannerInfo(file, ScannerInfoTypes.COMPILER_COMMAND);
List<?> cmds = fCollector.getCollectedScannerInfo(file, ScannerInfoTypes.COMPILER_COMMAND);
assertEquals(1, cmds.size());
} finally {
if (tempFile != null) {
@ -114,4 +116,23 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
tempDir.delete();
}
}
public void testPwdInFilePath_Bug237958() throws Exception {
IFile file1= fCProject.getProject().getFile("Bug237958_1.c");
IFile file2= fCProject.getProject().getFile("Bug237958_2.c");
fOutputParser.processLine("gcc -g -DTEST1 -c `pwd`/Bug237958_1.c");
fOutputParser.processLine("gcc -DTEST2=12 -g -ggdb -Wall -c \"`pwd`/./Bug237958_2.c\"");
List<?> cmds = fCollector.getCollectedScannerInfo(file1, ScannerInfoTypes.COMPILER_COMMAND);
CCommandDSC cdsc= (CCommandDSC) cmds.get(0);
List<?> symbols= cdsc.getSymbols();
assertEquals(1, symbols.size());
assertEquals("TEST1=1", symbols.get(0).toString());
cmds = fCollector.getCollectedScannerInfo(file2, ScannerInfoTypes.COMPILER_COMMAND);
cdsc= (CCommandDSC) cmds.get(0);
symbols= cdsc.getSymbols();
assertEquals(1, symbols.size());
assertEquals("TEST2=12", symbols.get(0).toString());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation 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
@ -177,8 +177,8 @@ public abstract class AbstractGCCBOPConsoleParser implements IScannerInfoConsole
* @return array of commands
*/
protected String[][] tokenize(String line, boolean escapeInsideDoubleQuotes) {
ArrayList commands= new ArrayList();
ArrayList tokens= new ArrayList();
ArrayList<String[]> commands= new ArrayList<String[]>();
ArrayList<String> tokens= new ArrayList<String>();
StringBuffer token= new StringBuffer();
final char[] input= line.toCharArray();
@ -197,7 +197,6 @@ public abstract class AbstractGCCBOPConsoleParser implements IScannerInfoConsole
if (c=='`') {
token.append(c); // preserve back-quotes
}
endToken(token, tokens);
currentQuote= 0;
}
}
@ -274,17 +273,17 @@ public abstract class AbstractGCCBOPConsoleParser implements IScannerInfoConsole
}
}
endCommand(token, tokens, commands);
return (String[][]) commands.toArray(new String[commands.size()][]);
return commands.toArray(new String[commands.size()][]);
}
private void endCommand(StringBuffer token, ArrayList tokens, ArrayList commands) {
private void endCommand(StringBuffer token, ArrayList<String> tokens, ArrayList<String[]> commands) {
endToken(token, tokens);
if (!tokens.isEmpty()) {
commands.add(tokens.toArray(new String[tokens.size()]));
tokens.clear();
}
}
private void endToken(StringBuffer token, ArrayList tokens) {
private void endToken(StringBuffer token, ArrayList<String> tokens) {
if (token.length() > 0) {
tokens.add(token.toString());
token.setLength(0);