From 987c1dc64b7634ab5c1992553d3c02c7cd09fcdf Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 15 Jan 2025 16:53:43 -0800 Subject: [PATCH 1/2] Use CMake for tests --- .github/workflows/build.yml | 5 +++-- .gitignore | 1 - README.md | 5 +++-- test/CMakeLists.txt | 18 ++++++++++++++++++ test/pqxx_test.cpp | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test/CMakeLists.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 089084b..fc36ef4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,8 +21,9 @@ jobs: CXXFLAGS=-std=c++17 ./configure make sudo make install - - run: g++ -std=c++17 -Wall -Wextra -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq - - run: test/pqxx + - run: cmake -S test -B test/build + - run: cmake --build test/build + - run: test/build/pqxx_test # test install - run: cmake -S . -B build diff --git a/.gitignore b/.gitignore index b9d3146..378eac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ build -/test/pqxx diff --git a/README.md b/README.md index 4dc3569..e245eaf 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,9 @@ To get started with development: git clone https://github.com/pgvector/pgvector-cpp.git cd pgvector-cpp createdb pgvector_cpp_test -g++ -std=c++17 -Wall -Wextra -Wno-unknown-attributes -Werror -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq -test/pqxx +cmake -S test -B test/build +cmake --build test/build +test/build/pqxx_test ``` To run an example: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..dee9474 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.18) + +project(test) + +set(CMAKE_CXX_STANDARD 17) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unknown-attributes -Werror") +set(SKIP_BUILD_TEST ON) + +include(FetchContent) + +FetchContent_Declare(libpqxx GIT_REPOSITORY https://github.com/jtv/libpqxx.git GIT_TAG 7.10.0) +FetchContent_MakeAvailable(libpqxx) + +add_subdirectory("${PROJECT_SOURCE_DIR}/.." pgvector) + +add_executable(pqxx_test pqxx_test.cpp) +target_link_libraries(pqxx_test PRIVATE libpqxx::pqxx pgvector::pgvector) diff --git a/test/pqxx_test.cpp b/test/pqxx_test.cpp index d5004d1..f57b202 100644 --- a/test/pqxx_test.cpp +++ b/test/pqxx_test.cpp @@ -1,6 +1,6 @@ -#include "../include/pgvector/pqxx.hpp" #include #include +#include #include void setup(pqxx::connection &conn) { From de5d34a4a5c4b733ae58e66d6f9097cfe266670f Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 15 Jan 2025 16:59:58 -0800 Subject: [PATCH 2/2] Run tests automatically --- .github/workflows/build.yml | 1 - README.md | 1 - test/CMakeLists.txt | 1 + 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc36ef4..5b8f5c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,6 @@ jobs: sudo make install - run: cmake -S test -B test/build - run: cmake --build test/build - - run: test/build/pqxx_test # test install - run: cmake -S . -B build diff --git a/README.md b/README.md index e245eaf..63b4edd 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,6 @@ cd pgvector-cpp createdb pgvector_cpp_test cmake -S test -B test/build cmake --build test/build -test/build/pqxx_test ``` To run an example: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dee9474..68a0b53 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,3 +16,4 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/.." pgvector) add_executable(pqxx_test pqxx_test.cpp) target_link_libraries(pqxx_test PRIVATE libpqxx::pqxx pgvector::pgvector) +add_custom_command(TARGET pqxx_test POST_BUILD COMMAND "${CMAKE_CURRENT_BINARY_DIR}/pqxx_test")