Browse Source

fix tests in compile_commands for windows and fix a bug in compile_commands.cc

python
parent
commit
cdf8b4548f
  1. 2
      src/compile_commands.cpp
  2. 16
      tests/python_bindings/CompileCommands_tests/compile_commands_test.cc
  3. 34
      tests/python_bindings/CompileCommands_tests/compile_commands_test.py

2
src/compile_commands.cpp

@ -109,7 +109,7 @@ CompileCommands::CompileCommands(const boost::filesystem::path &build_path) {
if(parameter_start_pos != std::string::npos) if(parameter_start_pos != std::string::npos)
add_parameter(); add_parameter();
commands.emplace_back(Command{directory, parameters, boost::filesystem::absolute(file, build_path)}); commands.emplace_back(Command{directory.make_preferred(), parameters, boost::filesystem::absolute(file, build_path).make_preferred()});
} }
} }
catch(...) { catch(...) {

16
tests/python_bindings/CompileCommands_tests/compile_commands_test.cc

@ -5,14 +5,24 @@
int main() { int main() {
auto suite_name = "CompileCommands_tests"; auto suite_name = "CompileCommands_tests";
suite test_suite(suite_name); suite test_suite(suite_name);
auto project_path = (test_suite.test_file_path / "cmake_project"); auto project_path = test_suite.test_file_path / "cmake_project";
auto &config = Config::get(); auto &config = Config::get();
#ifdef _WIN32
config.project.cmake.command = "cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64";
#else
config.project.cmake.command = "cmake"; config.project.cmake.command = "cmake";
#endif
CMake cmake(project_path); CMake cmake(project_path);
cmake.update_default_build(project_path/"build"); cmake.update_default_build(boost::filesystem::path(project_path) / "build");
try { try {
auto module = py::module::import("compile_commands_test"); auto module = py::module::import("compile_commands_test");
module.attr("run")(project_path.string()); std::string slash =
#ifdef _WIN32
"\\";
#else
"/";
#endif
module.attr("run")(project_path.make_preferred().string(), slash);
test_suite.has_assertion = true; test_suite.has_assertion = true;
} }
catch(const py::error_already_set &error) { catch(const py::error_already_set &error) {

34
tests/python_bindings/CompileCommands_tests/compile_commands_test.py

@ -1,32 +1,38 @@
from Jucipp import CompileCommands from Jucipp import CompileCommands
def run(project_path): from os import path
build_path = project_path + "/build"
def assert_equal(expected, actual):
assert actual == expected, "Expected: " + expected + ", got " + actual
def run(project_path, slash):
build_path = project_path + slash + "build"
cc = CompileCommands(build_path) cc = CompileCommands(build_path)
commands = cc.commands commands = cc.commands
assert len(commands) == 1, "Wrong length of compile commands" assert len(commands) == 1, "Wrong length of compile commands"
command = commands.pop() command = commands.pop()
assert command.directory == build_path assert_equal(build_path, command.directory)
assert command.file == project_path + "/main.cpp" assert_equal(project_path + slash + "main.cpp", command.file)
params = command.parameters params = command.parameters
param = params.pop() param = path.basename(params.pop())
assert param == project_path + "/main.cpp" assert_equal("main.cpp", param)
param = params.pop() param = params.pop()
assert param == "-c" assert_equal("-c", param)
param = params.pop() param = params.pop()
param = params.pop() param = params.pop()
assert param == "-o" assert_equal("-o", param)
values = command.parameter_values("-c") values = command.parameter_values("-c")
value = values.pop() value = path.basename(values.pop())
assert value == project_path + "/main.cpp" assert_equal("main.cpp", value)
assert CompileCommands.is_source(project_path + "/main.cpp") == True assert_equal(True, CompileCommands.is_source(project_path + slash + "main.cpp"))
assert CompileCommands.is_header(project_path + "/main.cpp") == False assert_equal(False, CompileCommands.is_header(project_path + slash + "main.cpp"))
arguments = CompileCommands.get_arguments(build_path, project_path + "/main.cpp") arguments = CompileCommands.get_arguments(build_path, project_path + slash + "main.cpp")
argument = arguments.pop() argument = arguments.pop()
assert argument == build_path
assert_equal(build_path, argument)
Loading…
Cancel
Save