Skip to content

Commit 001b67f

Browse files
cboulaytstenner
authored andcommitted
Upgrade Catch2, use FetchContent
1 parent 731bb96 commit 001b67f

24 files changed

+79
-18013
lines changed

testing/CMakeLists.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@ enable_testing()
88

99
option(LSL_BENCHMARKS "Enable benchmarks in unit tests" OFF)
1010

11+
12+
Include(FetchContent)
13+
FetchContent_Declare(
14+
Catch2
15+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
16+
GIT_TAG v3.0.1 # or a later release
17+
)
18+
FetchContent_MakeAvailable(Catch2)
19+
20+
1121
add_library(catch_main OBJECT catch_main.cpp)
1222
target_compile_features(catch_main PUBLIC cxx_std_14)
1323
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
1424
target_link_libraries(catch_main PUBLIC log)
1525
endif()
1626
find_package(Threads REQUIRED)
17-
target_link_libraries(catch_main PUBLIC Threads::Threads)
27+
target_link_libraries(catch_main
28+
PUBLIC
29+
Threads::Threads
30+
Catch2::Catch2
31+
)
1832

1933
target_compile_definitions(catch_main PRIVATE LSL_VERSION_INFO="${LSL_VERSION_INFO}")
20-
target_include_directories(catch_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty)
2134
if(LSL_BENCHMARKS)
2235
target_compile_definitions(catch_main PUBLIC CATCH_CONFIG_ENABLE_BENCHMARKING)
2336
endif()
@@ -30,9 +43,9 @@ add_library(common OBJECT
3043
)
3144
target_compile_features(common PUBLIC cxx_std_14)
3245
target_include_directories(common PUBLIC
33-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty>
3446
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src>
3547
)
48+
target_link_libraries(common PUBLIC Catch2::Catch2)
3649

3750

3851
add_executable(lsl_test_exported
@@ -58,6 +71,7 @@ add_executable(lsl_test_internal
5871
)
5972
target_link_libraries(lsl_test_internal PRIVATE lslobj lslboost common catch_main)
6073

74+
6175
if(LSL_BENCHMARKS)
6276
# to get somewhat reproducible performance numbers:
6377
# /usr/bin/time -v testing/lsl_test_exported --benchmark-samples 100 bounce
@@ -77,6 +91,18 @@ set(LSL_TESTS lsl_test_exported lsl_test_internal)
7791
foreach(lsltest ${LSL_TESTS})
7892
add_test(NAME ${lsltest} COMMAND ${lsltest} --wait-for-keypress never)
7993
installLSLApp(${lsltest})
94+
95+
if(WIN32)
96+
# Copy dependencies into build directory to enable debugging builds in Windows.
97+
add_custom_command(TARGET ${lsltest}
98+
POST_BUILD
99+
COMMAND
100+
${CMAKE_COMMAND} -E copy_if_different
101+
$<TARGET_RUNTIME_DLLS:${lsltest}>
102+
$<TARGET_FILE_DIR:${lsltest}>
103+
COMMAND_EXPAND_LISTS
104+
)
105+
endif(WIN32)
80106
endforeach()
81107

82108
installLSLAuxFiles(lsl_test_exported directory lslcfgs)

testing/catch_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define CATCH_CONFIG_RUNNER
2-
#include <catch2/catch.hpp>
2+
#include <catch2/catch_all.hpp>
33

44
extern "C" {
55
const char *lsl_library_info() { return LSL_VERSION_INFO; }
@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) {
1010
#ifdef _WIN32
1111
session.configData().waitForKeypress = Catch::WaitForKeypress::BeforeExit;
1212
#endif
13-
session.configData().runOrder = Catch::RunTests::InRandomOrder;
13+
session.configData().runOrder = Catch::TestRunOrder::Randomized;
1414
int returnCode = session.applyCommandLine(argc, argv);
1515
if (returnCode != 0) return returnCode;
1616
return session.run();

testing/common/bytecmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "bytecmp.hpp"
22
#include <algorithm>
3-
#include <catch2/catch.hpp>
3+
#include <catch2/catch_all.hpp>
44
#include <cctype>
55
#include <iomanip>
66
#include <map>
@@ -42,7 +42,7 @@ void cmp_binstr(const std::string &a, const std::string b) {
4242
REQUIRE(bytes_to_hexstr(a.substr(0, context_bytes)) ==
4343
bytes_to_hexstr(b.substr(0, context_bytes)));
4444
else {
45-
INFO("First mismatch offset: " << pos)
45+
INFO("First mismatch offset: " << pos);
4646
std::string cmp_a = bytes_to_hexstr(a.substr(0, context_bytes)) + " ... " +
4747
bytes_to_hexstr(a.substr(pos - context_bytes, 2 * context_bytes));
4848
std::string cmp_b = bytes_to_hexstr(b.substr(0, context_bytes)) + " ... " +

testing/ext/DataType.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../common/create_streampair.hpp"
22
#include "../common/lsltypes.hpp"
3-
#include <catch2/catch.hpp>
3+
#include <catch2/catch_all.hpp>
44
#include <cstdint>
55
#include <lsl_cpp.h>
66
#include <thread>
@@ -32,8 +32,8 @@ TEMPLATE_TEST_CASE(
3232
CHECK(inlet.pull_sample(received_data, 2, .5) != 0.0);
3333

3434
timestamps[counter][1] = lsl::local_clock();
35-
CHECK(received_data[0] == Approx(sent_data[0]));
36-
CHECK(received_data[1] == Approx(sent_data[1]));
35+
CHECK(received_data[0] == Catch::Approx(sent_data[0]));
36+
CHECK(received_data[1] == Catch::Approx(sent_data[1]));
3737
sent_data[0] = static_cast<TestType>(static_cast<int64_t>(sent_data[0]) << 1);
3838
}
3939
}
@@ -92,14 +92,14 @@ TEST_CASE("Flush", "[datatransfer][basic]") {
9292

9393
double data_in;
9494
double ts_in = sp.in_.pull_sample(&data_in, 1);
95-
REQUIRE(ts_in == Approx(data_in));
95+
REQUIRE(ts_in == Catch::Approx(data_in));
9696
std::this_thread::sleep_for(std::chrono::milliseconds(700));
9797
auto pulled = sp.in_.flush() + 1;
9898

9999
for(; pulled < n; ++pulled) {
100100
INFO(pulled);
101101
ts_in = sp.in_.pull_sample(&data_in, 1);
102-
REQUIRE(ts_in == Approx(data_in));
102+
REQUIRE(ts_in == Catch::Approx(data_in));
103103
}
104104

105105
pusher.join();

testing/ext/bench_bounce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../common/create_streampair.hpp"
22
#include "../common/lsltypes.hpp"
3-
#include <catch2/catch.hpp>
3+
#include <catch2/catch_all.hpp>
44
#include <lsl_cpp.h>
55

66
// clazy:excludeall=non-pod-global-static

testing/ext/bench_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <catch2/catch.hpp>
1+
#include <catch2/catch_all.hpp>
22
#include <lsl_c.h>
33

44
// clazy:excludeall=non-pod-global-static

testing/ext/bench_pushpull.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../common/create_streampair.hpp"
22
#include "../common/lsltypes.hpp"
33
#include <atomic>
4-
#include <catch2/catch.hpp>
4+
#include <catch2/catch_all.hpp>
55
#include <list>
66
#include <lsl_cpp.h>
77
#include <string>

testing/ext/discovery.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <catch2/catch.hpp>
1+
#include <catch2/catch_all.hpp>
22
#include <lsl_cpp.h>
33
#include <thread>
44

@@ -36,10 +36,10 @@ TEST_CASE("fullinfo", "[inlet][fullinfo][basic]") {
3636
lsl::stream_outlet outlet(info);
3737
auto found_streams = lsl::resolve_stream("name", info.name(), 1, 2);
3838
REQUIRE(!found_streams.empty());
39-
INFO(found_streams[0].as_xml())
39+
INFO(found_streams[0].as_xml());
4040
CHECK(found_streams[0].desc().first_child().empty());
4141
auto fullinfo = lsl::stream_inlet(found_streams[0]).info(2);
42-
INFO(fullinfo.as_xml())
42+
INFO(fullinfo.as_xml());
4343
CHECK(fullinfo.desc().child_value("info") == extinfo);
4444
}
4545

testing/ext/move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <catch2/catch.hpp>
1+
#include <catch2/catch_all.hpp>
22
#include <lsl_cpp.h>
33
#include <thread>
44

testing/ext/streaminfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <catch2/catch.hpp>
1+
#include <catch2/catch_all.hpp>
22
#include <lsl_cpp.h>
33
#include <thread>
44

0 commit comments

Comments
 (0)