From cdf8b4548f5a6ad496c4c2885569d3f84e0f93bb Mon Sep 17 00:00:00 2001 From: zalox Date: Sat, 25 May 2019 17:26:11 +0200 Subject: [PATCH] fix tests in compile_commands for windows and fix a bug in compile_commands.cc --- src/compile_commands.cpp | 2 +- .../compile_commands_test.cc | 16 +++++++-- .../compile_commands_test.py | 34 +++++++++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index 2ba6926..d28fa9a 100644 --- a/src/compile_commands.cpp +++ b/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(...) { diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc b/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc index 6753ffb..1e8226e 100644 --- a/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc +++ b/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) { diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.py b/tests/python_bindings/CompileCommands_tests/compile_commands_test.py index 4601f01..9ef2592 100644 --- a/tests/python_bindings/CompileCommands_tests/compile_commands_test.py +++ b/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) \ No newline at end of file