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)
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(...) {

16
tests/python_bindings/CompileCommands_tests/compile_commands_test.cc

@ -5,14 +5,24 @@
int main() {
auto suite_name = "CompileCommands_tests";
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();
#ifdef _WIN32
config.project.cmake.command = "cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64";
#else
config.project.cmake.command = "cmake";
#endif
CMake cmake(project_path);
cmake.update_default_build(project_path/"build");
cmake.update_default_build(boost::filesystem::path(project_path) / "build");
try {
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;
}
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
def run(project_path):
build_path = project_path + "/build"
from os import path
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)
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"
assert_equal(build_path, command.directory)
assert_equal(project_path + slash + "main.cpp", command.file)
params = command.parameters
param = params.pop()
assert param == project_path + "/main.cpp"
param = path.basename(params.pop())
assert_equal("main.cpp", param)
param = params.pop()
assert param == "-c"
assert_equal("-c", param)
param = params.pop()
param = params.pop()
assert param == "-o"
assert_equal("-o", param)
values = command.parameter_values("-c")
value = values.pop()
assert value == project_path + "/main.cpp"
value = path.basename(values.pop())
assert_equal("main.cpp", value)
assert CompileCommands.is_source(project_path + "/main.cpp") == True
assert CompileCommands.is_header(project_path + "/main.cpp") == False
assert_equal(True, CompileCommands.is_source(project_path + slash + "main.cpp"))
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()
assert argument == build_path
assert_equal(build_path, argument)
Loading…
Cancel
Save