From f8a607a8ab48c8561e84559a3938cb18c54c3abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 31 May 2019 16:09:36 +0200 Subject: [PATCH] fix some formatting and check for errors in suite --- .../CompileCommands_tests/compile_commands_test.cc | 8 ++------ tests/python_bindings/jucipp_test.py | 2 +- tests/python_bindings/test_suite.cc | 12 ++++++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc b/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc index 1e8226e..1e5ff6d 100644 --- a/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc +++ b/tests/python_bindings/CompileCommands_tests/compile_commands_test.cc @@ -8,20 +8,16 @@ int main() { auto project_path = test_suite.test_file_path / "cmake_project"; auto &config = Config::get(); #ifdef _WIN32 + std::string slash = "\\"; config.project.cmake.command = "cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64"; #else + std::string slash = "/"; config.project.cmake.command = "cmake"; #endif CMake cmake(project_path); cmake.update_default_build(boost::filesystem::path(project_path) / "build"); try { auto module = py::module::import("compile_commands_test"); - std::string slash = -#ifdef _WIN32 - "\\"; -#else - "/"; -#endif module.attr("run")(project_path.make_preferred().string(), slash); test_suite.has_assertion = true; } diff --git a/tests/python_bindings/jucipp_test.py b/tests/python_bindings/jucipp_test.py index 5584728..fdf9b59 100644 --- a/tests/python_bindings/jucipp_test.py +++ b/tests/python_bindings/jucipp_test.py @@ -2,4 +2,4 @@ def assert_equal(expected, actual): """ Assert two variables for equality with an useful error message """ - assert actual == expected, "Expected: " + expected + ", got " + actual + assert actual == expected, "Expected: " + str(expected) + ", got " + str(actual) diff --git a/tests/python_bindings/test_suite.cc b/tests/python_bindings/test_suite.cc index 670b3f2..c9c3666 100644 --- a/tests/python_bindings/test_suite.cc +++ b/tests/python_bindings/test_suite.cc @@ -4,11 +4,19 @@ suite::suite(const boost::filesystem::path &path) { py::initialize_interpreter(); + if(!Py_IsInitialized()) { + throw std::runtime_error("Unable to initialize interpreter"); + } auto sys = py::module::import("sys"); + if(!sys) { + throw std::runtime_error("Unable to append sys path"); + } sys.attr("path").cast().append((test_file_path / path).string()); config.terminal.history_size = 100; } suite::~suite() { - py::finalize_interpreter(); - g_assert_true(has_assertion); + if(Py_IsInitialized()) { + py::finalize_interpreter(); + g_assert_true(has_assertion); + } }