Skip to content

Commit d783232

Browse files
committed
Switched to CMake for tests
1 parent 834a725 commit d783232

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@ jobs:
1515
cd pgvector
1616
make
1717
sudo make install
18-
- run: |
19-
git clone --branch 7.10.0 https://github.com/jtv/libpqxx.git
20-
cd libpqxx
21-
CXXFLAGS=-std=c++17 ./configure
22-
make
23-
sudo make install
2418
25-
- run: g++ -std=c++17 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
26-
- run: test/main
19+
- run: cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=17
20+
- run: cmake --build build
21+
- run: build/test
2722

28-
- run: g++ -std=c++20 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
29-
- run: test/main
23+
- run: cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=20
24+
- run: cmake --build build
25+
- run: build/test
3026

31-
- run: g++ -std=c++23 -Wall -Wextra -Werror -o test/main test/main.cpp test/pqxx_test.cpp -lpqxx -lpq
32-
- run: test/main
27+
- run: cmake -S . -B build -DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=23
28+
- run: cmake --build build
29+
- run: build/test
3330

3431
- run: |
3532
sudo apt-get install valgrind
36-
valgrind --leak-check=yes test/main
33+
valgrind --leak-check=yes build/test
3734
38-
# test install
39-
- run: cmake -S . -B build
40-
- run: cmake --build build
4135
- run: sudo cmake --install build

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
build
2-
/test/main

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,24 @@ install(
1919
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
2020
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
2121
)
22+
23+
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
24+
option(BUILD_TESTING "" OFF)
25+
26+
if(BUILD_TESTING)
27+
include(FetchContent)
28+
29+
# for libpqxx
30+
set(CMAKE_CXX_FLAGS "-Wno-unknown-attributes")
31+
set(SKIP_BUILD_TEST ON)
32+
33+
FetchContent_Declare(libpqxx GIT_REPOSITORY https://github.com/jtv/libpqxx.git GIT_TAG 7.10.0)
34+
FetchContent_MakeAvailable(libpqxx)
35+
36+
add_executable(test test/halfvec_test.cpp test/main.cpp test/pqxx_test.cpp test/sparsevec_test.cpp test/vector_test.cpp)
37+
target_link_libraries(test PRIVATE libpqxx::pqxx pgvector::pgvector)
38+
if(NOT MSVC)
39+
target_compile_options(test PRIVATE -Wall -Wextra -Wpedantic -Werror)
40+
endif()
41+
endif()
42+
endif()

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ To get started with development:
162162
git clone https://github.com/pgvector/pgvector-cpp.git
163163
cd pgvector-cpp
164164
createdb pgvector_cpp_test
165-
g++ -std=c++17 -Wall -Wextra -Wno-unknown-attributes -Werror -o test/main test/main.cpp test/vector_test.cpp test/halfvec_test.cpp test/sparsevec_test.cpp test/pqxx_test.cpp -lpqxx -lpq
166-
test/main
165+
cmake -S . -B build -DBUILD_TESTING=ON
166+
cmake --build build
167+
build/test
167168
```
168169

169170
To run an example:

0 commit comments

Comments
 (0)