diff --git a/src/cmake.cpp b/src/cmake.cpp index 2befb21..7a485db 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -351,17 +351,18 @@ void CMake::parse_file(const std::string &src, std::map(api, "CMake") - .def_readwrite("project_path", &CMake::project_path) - .def("update_default_build", &CMake::update_default_build, - py::arg("default_build_path"), - py::arg("force") = false) - .def("update_debug_build", &CMake::update_debug_build, - py::arg("debug_build_path"), - py::arg("force") = false) - .def("get_executable", &CMake::get_executable, - py::arg("build_path"), - py::arg("file_path")) + py::class_(api, "CMake") + .def(py::init()) + .def_readwrite("project_path", &CMake::project_path) + .def("update_default_build", &CMake::update_default_build, + py::arg("default_build_path"), + py::arg("force") = false) + .def("update_debug_build", &CMake::update_debug_build, + py::arg("debug_build_path"), + py::arg("force") = false) + .def("get_executable", &CMake::get_executable, + py::arg("build_path"), + py::arg("file_path")) - ; + ; } diff --git a/tests/python_bindings/CMake_tests/cmake_project/CMakeLists.txt b/tests/python_bindings/CMake_tests/cmake_project/CMakeLists.txt new file mode 100644 index 0000000..6400f28 --- /dev/null +++ b/tests/python_bindings/CMake_tests/cmake_project/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) + +project(cmake_project) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra") + +add_executable(cmake_project main.cpp) diff --git a/tests/python_bindings/CMake_tests/cmake_test.cc b/tests/python_bindings/CMake_tests/cmake_test.cc index cf0cd58..89d45df 100644 --- a/tests/python_bindings/CMake_tests/cmake_test.cc +++ b/tests/python_bindings/CMake_tests/cmake_test.cc @@ -1,7 +1,17 @@ #include "test_suite.h" +#include int main() { - suite test_suite("CMake_tests"); - py::module::import("cmake_test"); - test_suite.has_assertion = true; -} \ No newline at end of file + auto &config = Config::get(); + config.project.cmake.command = "cmake"; + auto suite_name = "CMake_tests"; + suite test_suite(suite_name); + auto module = py::module::import("cmake_test"); + + try { + module.attr("run")((test_suite.test_file_path / suite_name / "cmake_project").string()); + test_suite.has_assertion = true; + } catch(const py::error_already_set &error){ + std::cout << error.what(); + } +} diff --git a/tests/python_bindings/CMake_tests/cmake_test.py b/tests/python_bindings/CMake_tests/cmake_test.py index c20e897..f413afb 100644 --- a/tests/python_bindings/CMake_tests/cmake_test.py +++ b/tests/python_bindings/CMake_tests/cmake_test.py @@ -1 +1,12 @@ from Jucipp import CMake + +def run(project_path): + cmake = CMake(project_path) + assert project_path == cmake.project_path, "Construction of CMake failed" + default_build_path = project_path + "/build" + assert cmake.update_default_build(default_build_path) == True, "Update of default build failed" + executable = cmake.get_executable(default_build_path, project_path) + assert executable == default_build_path + "/cmake_project", "Invalid executable" + default_debug_path = project_path + "/debug" + assert cmake.update_debug_build(default_debug_path), "Update of debug build failed" + executable = cmake.get_executable(default_debug_path, project_path)