Search in sources :

Example 6 with CompileCommand

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++));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) HashMap(java.util.HashMap) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 7 with CompileCommand

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));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 8 with CompileCommand

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++));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 9 with CompileCommand

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++));
}
Also used : CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) CommandParser(com.synopsys.integration.common.util.parse.CommandParser) CompileCommandParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 10 with CompileCommand

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());
}
Also used : DependencyFileDetailGenerator(com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) File(java.io.File) FilePathGenerator(com.synopsys.integration.detectable.detectables.clang.dependencyfile.FilePathGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

CompileCommand (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand)10 Test (org.junit.jupiter.api.Test)9 CommandParser (com.synopsys.integration.common.util.parse.CommandParser)7 CompileCommandParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandParser)7 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)5 CompileCommandDatabaseParser (com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser)4 Gson (com.google.gson.Gson)3 FunctionalTest (com.synopsys.integration.detectable.annotations.FunctionalTest)3 DependencyFileDetailGenerator (com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator)2 File (java.io.File)2 Forge (com.synopsys.integration.bdio.model.Forge)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)1 ClangPackageDetailsTransformer (com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer)1 FilePathGenerator (com.synopsys.integration.detectable.detectables.clang.dependencyfile.FilePathGenerator)1 ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)1 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)1 PackageDetailsResult (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 IOException (java.io.IOException)1