Skip to content

Commit eee7022

Browse files
authored
13 pre commit (#15)
* track python and cpp changes * shellcheck * add trailing newline * add ability to compile test cases * update build script to configure testing; default off * simple scaffold test case
1 parent f055eb9 commit eee7022

7 files changed

Lines changed: 57 additions & 13 deletions

File tree

.gitmodules

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
[submodule "lib/concurrentqueue"]
2-
path = lib/concurrentqueue
3-
url = https://github.com/cameron314/concurrentqueue.git
4-
[submodule "lib/dlpack"]
5-
path = lib/dlpack
6-
url = https://github.com/dmlc/dlpack.git
7-
[submodule "lib/pybind11"]
8-
path = lib/pybind11
9-
url = https://github.com/pybind/pybind11.git
1+
[submodule "extern/Catch2"]
2+
path = extern/Catch2
3+
url = https://github.com/catchorg/Catch2.git

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ if(BUILD_EXAMPLES)
2424
add_subdirectory(examples)
2525
endif()
2626

27+
# Build test cases
28+
option(BUILD_TESTS "Build test cases" OFF)
29+
if(BUILD_TESTS)
30+
add_subdirectory(extern/Catch2)
31+
enable_testing()
32+
add_subdirectory(tests)
33+
endif()
34+
2735
# Install
2836
include(GNUInstallDirs)
2937
include(CMakePackageConfigHelpers)

configure.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ set -e
66
BUILD_TYPE="Debug"
77
BUILD_DIR="build"
88
BUILD_EXAMPLES=OFF
9+
BUILD_TESTS=OFF
910

1011
# Parse arguments
1112
while [[ "$#" -gt 0 ]]; do
1213
case $1 in
13-
-t | --type)
14+
-m | --mode)
1415
BUILD_TYPE="$2"
1516
shift
1617
;;
@@ -21,11 +22,15 @@ while [[ "$#" -gt 0 ]]; do
2122
-e | --examples)
2223
BUILD_EXAMPLES=ON
2324
;;
25+
-t | --tests)
26+
BUILD_TESTS=ON
27+
;;
2428
-h | --help)
2529
echo "Usage: ./configure.sh [-t Debug|Release|RelWithDebInfo|MinSizeRel] [-d build_dir] [-e]"
26-
echo " -t | --type : Build type (default: Debug)"
30+
echo " -m | --mode : Build type (default: Debug)"
2731
echo " -d | --dir : Build directory (default: build)"
28-
echo " -e | --examples : Enable building examples"
32+
echo " -e | --examples : Enable building examples (default: OFF)"
33+
echo " -t | --tests : Enable building tests (default: OFF)"
2934
exit 0
3035
;;
3136
*)
@@ -40,11 +45,16 @@ echo "Configuring project..."
4045
echo " Build type : $BUILD_TYPE"
4146
echo " Build dir : $BUILD_DIR"
4247
echo " Build examples : $BUILD_EXAMPLES"
48+
echo " Build tests : $BUILD_TESTS"
4349

4450
# Create build directory
4551
mkdir -p "$BUILD_DIR"
4652

4753
# Run CMake configuration
48-
cmake -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DBUILD_EXAMPLES="$BUILD_EXAMPLES" -S .
54+
cmake -B "$BUILD_DIR" \
55+
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
56+
-DBUILD_EXAMPLES="$BUILD_EXAMPLES" \
57+
-DBUILD_TESTS="$BUILD_TESTS" \
58+
-S .
4959

5060
echo "Configuration complete. You can now run: cmake --build $BUILD_DIR"

extern/Catch2

Submodule Catch2 added at 74fcff6

tests/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS *.cpp)
2+
3+
get_target_property(_inc Catch2::Catch2WithMain INTERFACE_INCLUDE_DIRECTORIES)
4+
message(STATUS "Catch2::Catch2WithMain include dirs: ${_inc}")
5+
6+
7+
add_executable(pyscheduler_tests ${TEST_SOURCES})
8+
target_link_libraries(pyscheduler_tests PRIVATE pyscheduler Catch2::Catch2WithMain)
9+
10+
include(CTest)
11+
include(Catch)
12+
catch_discover_tests(pyscheduler_tests)

tests/test_PyManager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "pyscheduler/pyscheduler.hpp"
2+
#include <catch2/catch_all.hpp>
3+
4+
using namespace pyscheduler;
5+
6+
static PyManager manager;
7+
8+
TEST_CASE("Load Standard Module", "[basic]") {
9+
PyManager::InvokeHandler reflect = manager.getPythonModule("tests.test_modules.reflect");
10+
}
11+
12+
TEST_CASE("Reflect Test", "[basic]") {
13+
PyManager::InvokeHandler reflect = manager.getPythonModule("tests.test_modules.reflect");
14+
15+
REQUIRE(reflect.invoke<std::string>("hello") == "hello");
16+
REQUIRE(reflect.invoke<double>(3.1415926535) == 3.1415926535);
17+
}

tests/test_modules/reflect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def invoke(x):
2+
return x

0 commit comments

Comments
 (0)