use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand in project synopsys-detect by blackducksoftware.
the class CompileCommandParserTest method testGetCompilerArgs.
@Test
public void testGetCompilerArgs() {
CompileCommand sampleCommand = new CompileCommand();
sampleCommand.setCommand("g++ -DDOUBLEQUOTED=\"A value for the compiler\" -DSINGLEQUOTED='Another value for the compiler' file.c -o file.o");
Map<String, String> optionOverrides = new HashMap<>();
optionOverrides.put("-o", "/dev/null");
CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
List<String> result = commandParser.parseCommand(sampleCommand, optionOverrides);
for (String part : result) {
System.out.printf("compiler arg: %s\n", part);
}
assertEquals(6, result.size());
int i = 0;
assertEquals("g++", result.get(i++));
assertEquals("-DDOUBLEQUOTED=\"A value for the compiler\"", result.get(i++));
assertEquals("-DSINGLEQUOTED='Another value for the compiler'", result.get(i++));
assertEquals("file.c", result.get(i++));
assertEquals("-o", result.get(i++));
assertEquals("/dev/null", result.get(i++));
}
use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand in project synopsys-detect by blackducksoftware.
the class CompileCommandParserTest method testEscapedDoubleQuotedTerm.
@Test
public void testEscapedDoubleQuotedTerm() {
CompileCommand command = new CompileCommand();
command.setDirectory("dir");
command.setCommand("X=\\\"'a' 'b'\\\"");
command.setFile("test.cc");
CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
List<String> result = commandParser.parseCommand(command, Collections.emptyMap());
assertEquals(1, result.size());
assertEquals("X=\\\"'a' 'b'\\\"", result.get(0));
}
use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand in project synopsys-detect by blackducksoftware.
the class CompileCommandParserTest method testCrazyNestedQuoting.
@Test
public void testCrazyNestedQuoting() {
CompileCommand command = new CompileCommand();
command.setCommand("X=\"\\\" a b\\\"\"");
CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
List<String> result = commandParser.parseCommand(command, Collections.emptyMap());
assertEquals(1, result.size());
int i = 0;
assertEquals("X=\"\\\" a b\\\"\"", result.get(i++));
}
use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand in project synopsys-detect by blackducksoftware.
the class CompileCommandParserTest method testComplexCompileCommand.
@Test
public void testComplexCompileCommand() {
CompileCommand command = new CompileCommand();
command.setCommand("/usr/bin/clang++-3.6 -DCMAKE_BUILD_TYPE=\\\"Debug\\\" -DCMAKE_CC_FLAGS=\"\\\" -ggdb -Wstrict-aliasing=2 -pedantic -fPIC --std=c11\\\"\" -c ./pb.cc");
CompileCommandParser commandParser = new CompileCommandParser(new CommandParser());
List<String> result = commandParser.parseCommand(command, Collections.emptyMap());
assertEquals(5, result.size());
int i = 0;
assertEquals("/usr/bin/clang++-3.6", result.get(i++));
assertEquals("-DCMAKE_BUILD_TYPE=\\\"Debug\\\"", result.get(i++));
assertEquals("-DCMAKE_CC_FLAGS=\"\\\" -ggdb -Wstrict-aliasing=2 -pedantic -fPIC --std=c11\\\"\"", result.get(i++));
assertEquals("-c", result.get(i++));
assertEquals("./pb.cc", result.get(i++));
}
use of com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand in project synopsys-detect by blackducksoftware.
the class DependencyFileDetailGeneratorTest method testFileThatDoesNotExistIsSkipped.
@Test
public void testFileThatDoesNotExistIsSkipped() {
File mockFile = Mockito.mock(File.class);
Mockito.when(mockFile.toString()).thenReturn("Example");
FilePathGenerator filePathGenerator = Mockito.mock(FilePathGenerator.class);
Mockito.when(filePathGenerator.fromCompileCommand(mockFile, null, true)).thenReturn(Collections.singletonList("does_not_exist.h"));
DependencyFileDetailGenerator dependencyFileDetailGenerator = new DependencyFileDetailGenerator(filePathGenerator);
Set<File> fileDetailsSet = dependencyFileDetailGenerator.fromCompileCommands(Collections.singletonList(new CompileCommand()), null, true);
Assertions.assertEquals(0, fileDetailsSet.size());
}
Aggregations