Commit 3d54d788 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

Create a test framework to remove the tests out of the project

parent ed7cace1
Pipeline #183582 failed with stage
in 0 seconds
......@@ -2,7 +2,13 @@
# file Copyright.txt
macro(autopybind11_fetch_build_pybind11)
set(oneValueArgs "PYBIND11_DIR")
cmake_parse_arguments(APB "" "${oneValueArgs}" "" ${ARGN} )
# if pybind11 source dir is specified add it
if(DEFINED APB_PYBIND11_DIR)
add_subdirectory("${APB_PYBIND11_DIR}" ${CMAKE_CURRENT_BINARY_DIR}/pybind11)
else()
# if pybind11 source dir is not specified download it
include(FetchContent)
FetchContent_Declare(
pybind11
......@@ -11,15 +17,15 @@ macro(autopybind11_fetch_build_pybind11)
)
set(FETCHCONTENT_QUIET OFF)
FetchContent_MakeAvailable(pybind11)
include_directories(${Python_INCLUDE_DIRS})
find_program(CastXML_EXECUTABLE NAMES castxml castxml.exe)
if(NOT CastXML_EXECUTABLE)
message(FATAL_ERROR
"Required program castxml not found set CastXML_EXECUTABLE")
endif()
endif()
include_directories(${Python_INCLUDE_DIRS})
set(AutoPyBind11_generator ${PYTHON_EXECUTABLE} -m autopybind11)
find_program(CastXML_EXECUTABLE NAMES castxml castxml.exe)
if(NOT CastXML_EXECUTABLE)
message(FATAL_ERROR
"Required program castxml not found set CastXML_EXECUTABLE")
endif()
set(AutoPyBind11_generator ${PYTHON_EXECUTABLE} -m autopybind11)
endmacro()
function(_autopybind11_get_compiler_flags)
......@@ -128,4 +134,4 @@ function(autopybind11_add_module)
target_link_libraries(${tgt_helper_name} PUBLIC ${PYBIND_ADD_LIB_LINK_LIBRARIES})
target_include_directories(${tgt_helper_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PYBIND_ADD_LIB_DESTINATION})
# target_compile_definitions(${tgt_helper_name} PUBLIC "${flags}")
endfunction()
\ No newline at end of file
endfunction()
......@@ -11,6 +11,7 @@ configure_file(CTestCustom.cmake.in
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR})
find_package(AutoPyBind11)
add_subdirectory(example)
add_subdirectory(Tests)
add_test(NAME lint_lib COMMAND pycodestyle ${CMAKE_SOURCE_DIR}/autopybind11/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# TODO(someone else?): Fix linting for examples / tests.
# add_test(NAME lint_example COMMAND pycodestyle ${CMAKE_SOURCE_DIR}/example/ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
function(add_autopybind11_test name)
add_test(NAME ${name} COMMAND "${CMAKE_CTEST_COMMAND}"
--build-and-test
${CMAKE_CURRENT_SOURCE_DIR}/${name}
${CMAKE_CURRENT_BINARY_DIR}/${name}
--build-two-config
--build-generator ${CMAKE_GENERATOR}
--build-project ${name}
--build-options "-DPYBIND11_SRC_DIR=${pybind11_SOURCE_DIR}"
"-DAutoPyBind11_DIR=${AutoPyBind11_DIR}"
--test-command ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.py
--build-run-dir ${CMAKE_CURRENT_BINARY_DIR}/${name}
)
set_tests_properties(${name} PROPERTIES
ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/${name})
endfunction()
add_autopybind11_test(simple)
cmake_minimum_required(VERSION 3.15)
project(simple CXX)
find_package(AutoPyBind11)
autopybind11_fetch_build_pybind11(PYBIND11_DIR ${PYBIND11_SRC_DIR})
add_library(simpleLib simple.cxx)
autopybind11_add_module("simpleTest" YAML_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/simple_wrap.yml
# CONFIG_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/config.yml
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
LINK_LIBRARIES simpleLib)
#include <iostream>
#include "simple.h"
simple::simple()
{
}
int simple::hello()
{
std::cout << "hello\n";
return 10;
}
#ifndef simple_h
#define simple_h
class simple
{
public:
simple();
int hello();
};
#endif
import simpleTest
s = simpleTest.simple_py()
r = s.hello()
print("hello returned " + str(r) + "\n")
if r == 10:
exit(0)
else:
exit(-1)
classes:
simple:
file: simple.h
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment