Browse Source

add tests for compile commands and fix some bugs

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
3cf14b7841
  1. 7
      src/compile_commands.cpp
  2. 4
      tests/python_bindings/CMakeLists.txt
  3. 21
      tests/python_bindings/CompileCommands_tests/compile_commands_test.cc
  4. 32
      tests/python_bindings/CompileCommands_tests/compile_commands_test.py

7
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 <algorithm>
#include <boost/property_tree/json_parser.hpp>
#include <pybind11/stl.h>
#include <regex>
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_<CompileCommands> compile_commands(api, "CompileCommands");
py::class_<CompileCommands::Command>(compile_commands, "CompileCommands")
py::class_<CompileCommands::Command>(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<const boost::filesystem::path &>())
.def_readwrite("commands", &CompileCommands::commands)
.def_static("get_arguments", &CompileCommands::get_arguments,
py::arg("build_path"),

4
tests/python_bindings/CMakeLists.txt

@ -12,6 +12,10 @@ add_executable(pb_cmake_test CMake_tests/cmake_test.cc $<TARGET_OBJECTS:test_stu
target_link_libraries(pb_cmake_test test_suite)
add_test(pb_cmake_test pb_cmake_test)
add_executable(pb_compile_commands_test CompileCommands_tests/compile_commands_test.cc $<TARGET_OBJECTS:test_stubs>)
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_OBJECTS:test_stubs>)
target_link_libraries(pb_terminal_test test_suite)
add_test(pb_terminal_test pb_terminal_test)

21
tests/python_bindings/CompileCommands_tests/compile_commands_test.cc

@ -0,0 +1,21 @@
#include "cmake.h"
#include "test_suite.h"
#include <iostream>
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();
}
}

32
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
Loading…
Cancel
Save