diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index e6118b0..2ba6926 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -1,10 +1,12 @@ #include "compile_commands.hpp" #include "clangmm.hpp" #include "config.hpp" +#include "python_type_casters.h" #include "terminal.hpp" #include "utility.hpp" #include #include +#include #include CompileCommands::FindSystemIncludePaths::FindSystemIncludePaths() { @@ -279,13 +281,16 @@ bool CompileCommands::is_source(const boost::filesystem::path &path) { void CompileCommands::init_module(py::module &api) { py::class_ compile_commands(api, "CompileCommands"); - py::class_(compile_commands, "CompileCommands") + py::class_(compile_commands, "Command") .def_readwrite("directory", &CompileCommands::Command::directory) .def_readwrite("parameters", &CompileCommands::Command::parameters) .def_readwrite("file", &CompileCommands::Command::file) + .def("parameter_values", &CompileCommands::Command::parameter_values, + py::arg("parameter_name")) ; compile_commands + .def(py::init()) .def_readwrite("commands", &CompileCommands::commands) .def_static("get_arguments", &CompileCommands::get_arguments, py::arg("build_path"), diff --git a/tests/python_bindings/CMakeLists.txt b/tests/python_bindings/CMakeLists.txt index 559df74..8d2bd54 100644 --- a/tests/python_bindings/CMakeLists.txt +++ b/tests/python_bindings/CMakeLists.txt @@ -12,6 +12,10 @@ add_executable(pb_cmake_test CMake_tests/cmake_test.cc $) +target_link_libraries(pb_compile_commands_test test_suite) +add_test(pb_compile_commands_test pb_compile_commands_test) + add_executable(pb_terminal_test Terminal_tests/terminal_test.cc $) target_link_libraries(pb_terminal_test test_suite) add_test(pb_terminal_test pb_terminal_test) diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc b/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc new file mode 100644 index 0000000..6753ffb --- /dev/null +++ b/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc @@ -0,0 +1,21 @@ +#include "cmake.h" +#include "test_suite.h" +#include + +int main() { + auto suite_name = "CompileCommands_tests"; + suite test_suite(suite_name); + auto project_path = (test_suite.test_file_path / "cmake_project"); + auto &config = Config::get(); + config.project.cmake.command = "cmake"; + CMake cmake(project_path); + cmake.update_default_build(project_path/"build"); + try { + auto module = py::module::import("compile_commands_test"); + module.attr("run")(project_path.string()); + test_suite.has_assertion = true; + } + catch(const py::error_already_set &error) { + std::cout << error.what(); + } +} diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.py b/tests/python_bindings/CompileCommands_tests/compile_commands_test.py new file mode 100644 index 0000000..4601f01 --- /dev/null +++ b/tests/python_bindings/CompileCommands_tests/compile_commands_test.py @@ -0,0 +1,32 @@ +from Jucipp import CompileCommands + +def run(project_path): + build_path = project_path + "/build" + cc = CompileCommands(build_path) + commands = cc.commands + assert len(commands) == 1, "Wrong length of compile commands" + command = commands.pop() + assert command.directory == build_path + assert command.file == project_path + "/main.cpp" + + params = command.parameters + param = params.pop() + assert param == project_path + "/main.cpp" + + param = params.pop() + assert param == "-c" + + param = params.pop() + param = params.pop() + assert param == "-o" + + values = command.parameter_values("-c") + value = values.pop() + assert value == project_path + "/main.cpp" + + assert CompileCommands.is_source(project_path + "/main.cpp") == True + assert CompileCommands.is_header(project_path + "/main.cpp") == False + + arguments = CompileCommands.get_arguments(build_path, project_path + "/main.cpp") + argument = arguments.pop() + assert argument == build_path