Skip to content

Commit e18f27f

Browse files
authored
test: switch some unit tests to doctest (#5383)
This change moves some tests from the current unit tests that are compiled into the rippled binary to using the doctest framework.
1 parent df6daf0 commit e18f27f

25 files changed

+908
-927
lines changed

.github/workflows/macos.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ jobs:
9696
run: |
9797
n=$(nproc)
9898
echo "Using $n test jobs"
99-
${build_dir}/rippled --unittest --unittest-jobs $n
99+
100+
cd ${build_dir}
101+
./rippled --unittest --unittest-jobs $n
102+
ctest -j $n --output-on-failure

.github/workflows/nix.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ jobs:
163163
cmake-args: "-Dassert=TRUE -Dwerr=TRUE ${{ matrix.cmake-args }}"
164164
- name: test
165165
run: |
166-
${build_dir}/rippled --unittest --unittest-jobs $(nproc)
166+
cd ${build_dir}
167+
./rippled --unittest --unittest-jobs $(nproc)
168+
ctest -j $(nproc) --output-on-failure
167169
168170
reference-fee-test:
169171
strategy:
@@ -217,8 +219,9 @@ jobs:
217219
cmake-args: "-Dassert=TRUE -Dwerr=TRUE ${{ matrix.cmake-args }}"
218220
- name: test
219221
run: |
220-
${build_dir}/rippled --unittest --unittest-jobs $(nproc)
221-
222+
cd ${build_dir}
223+
./rippled --unittest --unittest-jobs $(nproc)
224+
ctest -j $(nproc) --output-on-failure
222225
coverage:
223226
strategy:
224227
fail-fast: false
@@ -441,3 +444,4 @@ jobs:
441444
run: |
442445
cd ${BUILD_DIR}
443446
./rippled -u --unittest-jobs $(( $(nproc)/4 ))
447+
ctest -j $(nproc) --output-on-failure

.github/workflows/windows.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@ jobs:
9595
shell: bash
9696
if: ${{ matrix.configuration.tests }}
9797
run: |
98-
${build_dir}/${{ matrix.configuration.type }}/rippled --unittest \
99-
--unittest-jobs $(nproc)
98+
cd ${build_dir}/${{ matrix.configuration.type }}
99+
./rippled --unittest --unittest-jobs $(nproc)
100+
ctest -j $(nproc) --output-on-failure

Builds/levelization/results/ordering.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ test.shamap > xrpl.protocol
132132
test.toplevel > test.csf
133133
test.toplevel > xrpl.json
134134
test.unit_test > xrpl.basics
135+
tests.libxrpl > xrpl.basics
135136
xrpl.json > xrpl.basics
136137
xrpl.protocol > xrpl.basics
137138
xrpl.protocol > xrpl.json

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ set_target_properties(OpenSSL::SSL PROPERTIES
9090
INTERFACE_COMPILE_DEFINITIONS OPENSSL_NO_SSL2
9191
)
9292
set(SECP256K1_INSTALL TRUE)
93+
set(SECP256K1_BUILD_BENCHMARK FALSE)
94+
set(SECP256K1_BUILD_TESTS FALSE)
95+
set(SECP256K1_BUILD_EXHAUSTIVE_TESTS FALSE)
96+
set(SECP256K1_BUILD_CTIME_TESTS FALSE)
97+
set(SECP256K1_BUILD_EXAMPLES FALSE)
9398
add_subdirectory(external/secp256k1)
9499
add_library(secp256k1::secp256k1 ALIAS secp256k1)
95100
add_subdirectory(external/ed25519-donna)
@@ -144,3 +149,8 @@ set(PROJECT_EXPORT_SET RippleExports)
144149
include(RippledCore)
145150
include(RippledInstall)
146151
include(RippledValidatorKeys)
152+
153+
if(tests)
154+
include(CTest)
155+
add_subdirectory(src/tests/libxrpl)
156+
endif()

cmake/xrpl_add_test.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
include(isolate_headers)
2+
3+
function(xrpl_add_test name)
4+
set(target ${PROJECT_NAME}.test.${name})
5+
6+
file(GLOB_RECURSE sources CONFIGURE_DEPENDS
7+
"${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.cpp"
8+
"${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp"
9+
)
10+
add_executable(${target} EXCLUDE_FROM_ALL ${ARGN} ${sources})
11+
12+
isolate_headers(
13+
${target}
14+
"${CMAKE_SOURCE_DIR}"
15+
"${CMAKE_SOURCE_DIR}/tests/${name}"
16+
PRIVATE
17+
)
18+
19+
# Make sure the test isn't optimized away in unity builds
20+
set_target_properties(${target} PROPERTIES
21+
UNITY_BUILD_MODE GROUP
22+
UNITY_BUILD_BATCH_SIZE 0) # Adjust as needed
23+
24+
add_test(NAME ${target} COMMAND ${target})
25+
set_tests_properties(
26+
${target} PROPERTIES
27+
FIXTURES_REQUIRED ${target}_fixture
28+
)
29+
30+
add_test(
31+
NAME ${target}.build
32+
COMMAND
33+
${CMAKE_COMMAND}
34+
--build ${CMAKE_BINARY_DIR}
35+
--config $<CONFIG>
36+
--target ${target}
37+
)
38+
set_tests_properties(${target}.build PROPERTIES
39+
FIXTURES_SETUP ${target}_fixture
40+
)
41+
endfunction()

conanfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Xrpl(ConanFile):
2424
}
2525

2626
requires = [
27+
'doctest/2.4.11',
2728
'grpc/1.50.1',
2829
'libarchive/3.7.6',
2930
'nudb/2.0.8',

src/test/basics/RangeSet_test.cpp

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/test/basics/Slice_test.cpp

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)