Skip to content

Commit 65c6b3e

Browse files
authored
build: Add optional test executable and enable Substrait C API tests (#121)
* Add optional test executable and enable Substrait C API tests * Added an option `ENABLE_TEST_EXE` to build an optional test executable in `test/c/CMakeLists.txt` * Created a new `main.cpp` file to run C tests. * Updated `test_substrait_c_api.cpp` to fix build errors and remove unused includes. * Included the new test directory in the main `CMakeLists.txt`.
1 parent 6ae6557 commit 65c6b3e

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
107107

108108
set(PARAMETERS "-warnings")
109109
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES})
110+
add_subdirectory("test/c")
110111

111112
install(
112113
TARGETS ${EXTENSION_NAME}

test/c/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ add_library_unity(test_substrait OBJECT ${ALL_SOURCES})
1919
set(ALL_OBJECT_FILES
2020
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:test_substrait>
2121
PARENT_SCOPE)
22+
23+
option(SUBSTRAIT_EXTENSION_TEST_EXE "Build the optional test executable" OFF)
24+
if (SUBSTRAIT_EXTENSION_TEST_EXE)
25+
# Add an executable target with main.cpp
26+
add_executable(test_substrait_exe $<TARGET_OBJECTS:test_substrait> main.cpp)
27+
# Link the executable with necessary libraries
28+
target_link_libraries(test_substrait_exe duckdb substrait_extension test_helpers)
29+
endif()

test/c/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define CATCH_CONFIG_RUNNER
2+
#include "catch.hpp"
3+
4+
int main(int argc, char* argv[]) {
5+
// Call Catch2's session to run tests
6+
return Catch::Session().run(argc, argv);
7+
}

test/c/test_substrait_c_api.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "catch.hpp"
22
#include "test_helpers.hpp"
3-
#include "duckdb/parser/parser.hpp"
4-
#include "duckdb/planner/logical_operator.hpp"
53
#include "duckdb/main/connection_manager.hpp"
6-
#include "substrait_extension.hpp"
74

85
#include <chrono>
96
#include <thread>
@@ -13,7 +10,6 @@ using namespace std;
1310

1411
TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") {
1512
DuckDB db(nullptr);
16-
db.LoadExtension<duckdb::DUCKDB_EXTENSION_CLASS>();
1713
Connection con(db);
1814
con.EnableQueryVerification();
1915
// create the database
@@ -33,7 +29,6 @@ TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") {
3329

3430
TEST_CASE("Test C Get and To Json-Substrait API", "[substrait-api]") {
3531
DuckDB db(nullptr);
36-
db.LoadExtension<duckdb::DUCKDB_EXTENSION_CLASS>();
3732
Connection con(db);
3833
con.EnableQueryVerification();
3934
// create the database

0 commit comments

Comments
 (0)