Skip to content

Commit bfaf8e8

Browse files
authored
Merge pull request #466 from albestro/fix_catch2
Catch2 fixes
2 parents 1ae57c9 + b16104b commit bfaf8e8

16 files changed

+57
-85
lines changed

appveyor.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ environment:
2020

2121
cache:
2222
- libzmq -> appveyor.yml
23-
- Build/catch -> tests/cmake/catch.cmake
2423

2524
before_build:
2625
- if not exist libzmq (
@@ -35,6 +34,5 @@ build:
3534
verbosity: normal
3635

3736
test_script:
38-
- cp libzmq/bin/libzmq*.dll Build/bin/%configuration%/
3937
- cd Build
4038
- ctest -V -C %configuration%

tests/CMakeLists.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
1+
find_package(Threads)
22

3-
project(cppzmq-test CXX)
3+
find_package(Catch2 QUIET)
44

5-
# place binaries and libraries according to GNU standards
5+
if (NOT Catch2_FOUND)
6+
include(FetchContent)
67

7-
include(GNUInstallDirs)
8-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
9-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
10-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
8+
FetchContent_Declare(
9+
Catch2
10+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
11+
GIT_TAG v2.13.4)
1112

12-
include(CTest)
13-
include(cmake/catch.cmake)
14-
include(${CATCH_MODULE_PATH}/Catch.cmake)
13+
FetchContent_MakeAvailable(Catch2)
1514

16-
find_package(Threads)
15+
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
16+
endif()
1717

1818
add_executable(
1919
unit_tests
@@ -32,11 +32,10 @@ add_executable(
3232
utilities.cpp
3333
)
3434

35-
add_dependencies(unit_tests catch)
36-
3735
target_include_directories(unit_tests PUBLIC ${CATCH_MODULE_PATH})
3836
target_link_libraries(
3937
unit_tests
38+
PRIVATE Catch2::Catch2
4039
PRIVATE cppzmq
4140
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
4241
)
@@ -48,4 +47,6 @@ if (COVERAGE)
4847
target_link_libraries(unit_tests PRIVATE --coverage)
4948
endif()
5049

50+
include(CTest)
51+
include(Catch)
5152
catch_discover_tests(unit_tests)

tests/active_poller.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ TEST_CASE("add null handler fails", "[active_poller]")
9393
zmq::active_poller_t active_poller;
9494
zmq::active_poller_t::handler_type handler;
9595
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler),
96-
const std::invalid_argument &);
96+
std::invalid_argument);
9797
}
9898

9999
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 0)
@@ -107,7 +107,7 @@ TEST_CASE("add handler invalid events type", "[active_poller]")
107107
CHECK_THROWS_AS(
108108
active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type),
109109
no_op_handler),
110-
const zmq::error_t &);
110+
zmq::error_t);
111111
CHECK(active_poller.empty());
112112
CHECK(0u == active_poller.size());
113113
}
@@ -243,7 +243,7 @@ TEST_CASE("add invalid socket throws", "[active_poller]")
243243
zmq::socket_t a{context, zmq::socket_type::router};
244244
zmq::socket_t b{std::move(a)};
245245
CHECK_THROWS_AS(active_poller.add(a, zmq::event_flags::pollin, no_op_handler),
246-
const zmq::error_t &);
246+
zmq::error_t);
247247
}
248248

249249
TEST_CASE("remove invalid socket throws", "[active_poller]")
@@ -256,7 +256,7 @@ TEST_CASE("remove invalid socket throws", "[active_poller]")
256256
CHECK(1u == active_poller.size());
257257
std::vector<zmq::socket_t> sockets;
258258
sockets.emplace_back(std::move(socket));
259-
CHECK_THROWS_AS(active_poller.remove(socket), const zmq::error_t &);
259+
CHECK_THROWS_AS(active_poller.remove(socket), zmq::error_t);
260260
CHECK(1u == active_poller.size());
261261
}
262262

@@ -276,7 +276,7 @@ TEST_CASE("modify empty throws", "[active_poller]")
276276
zmq::socket_t socket{context, zmq::socket_type::push};
277277
zmq::active_poller_t active_poller;
278278
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin),
279-
const zmq::error_t &);
279+
zmq::error_t);
280280
}
281281

282282
TEST_CASE("modify invalid socket throws", "[active_poller]")
@@ -286,7 +286,7 @@ TEST_CASE("modify invalid socket throws", "[active_poller]")
286286
zmq::socket_t b{std::move(a)};
287287
zmq::active_poller_t active_poller;
288288
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin),
289-
const zmq::error_t &);
289+
zmq::error_t);
290290
}
291291

292292
TEST_CASE("modify not added throws", "[active_poller]")
@@ -297,7 +297,7 @@ TEST_CASE("modify not added throws", "[active_poller]")
297297
zmq::active_poller_t active_poller;
298298
CHECK_NOTHROW(active_poller.add(a, zmq::event_flags::pollin, no_op_handler));
299299
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin),
300-
const zmq::error_t &);
300+
zmq::error_t);
301301
}
302302

303303
TEST_CASE("modify simple", "[active_poller]")

tests/buffer.cpp

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

44
#ifdef ZMQ_CPP17

tests/cmake/catch.cmake

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

tests/codec_multipart.cpp

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

44
#ifdef ZMQ_CPP11
@@ -69,7 +69,7 @@ TEST_CASE("multipart codec decode bad data overflow", "[codec_multipart]")
6969

7070
CHECK_THROWS_AS(
7171
multipart_t::decode(wrong_size),
72-
const std::out_of_range&);
72+
std::out_of_range);
7373
}
7474

7575
TEST_CASE("multipart codec decode bad data extra data", "[codec_multipart]")
@@ -83,7 +83,7 @@ TEST_CASE("multipart codec decode bad data extra data", "[codec_multipart]")
8383

8484
CHECK_THROWS_AS(
8585
multipart_t::decode(wrong_size),
86-
const std::out_of_range&);
86+
std::out_of_range);
8787
}
8888

8989

tests/context.cpp

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

44
#if (__cplusplus >= 201703L)
@@ -75,10 +75,10 @@ TEST_CASE("context set/get options", "[context]")
7575

7676
CHECK_THROWS_AS(
7777
context.set(static_cast<zmq::ctxopt>(-42), 5),
78-
const zmq::error_t &);
78+
zmq::error_t);
7979

8080
CHECK_THROWS_AS(
8181
context.get(static_cast<zmq::ctxopt>(-42)),
82-
const zmq::error_t &);
82+
zmq::error_t);
8383
}
8484
#endif

tests/message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define CATCH_CONFIG_MAIN
2-
#include <catch.hpp>
2+
#include <catch2/catch.hpp>
33
#include <zmq.hpp>
44

55
#if defined(ZMQ_CPP11)

tests/multipart.cpp

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

44
#ifdef ZMQ_HAS_RVALUE_REFS

tests/poller.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ TEST_CASE("poller add handler invalid events type", "[poller]")
109109
short invalid_events_type = 2 << 10;
110110
CHECK_THROWS_AS(
111111
poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type)),
112-
const zmq::error_t&);
112+
zmq::error_t);
113113
}
114114
#endif
115115

@@ -121,7 +121,7 @@ TEST_CASE("poller add handler twice throws", "[poller]")
121121
poller.add(socket, zmq::event_flags::pollin);
122122
/// \todo the actual error code should be checked
123123
CHECK_THROWS_AS(poller.add(socket, zmq::event_flags::pollin),
124-
const zmq::error_t&);
124+
zmq::error_t);
125125
}
126126

127127
TEST_CASE("poller wait with no handlers throws", "[poller]")
@@ -130,7 +130,7 @@ TEST_CASE("poller wait with no handlers throws", "[poller]")
130130
std::vector<zmq::poller_event<>> events;
131131
/// \todo the actual error code should be checked
132132
CHECK_THROWS_AS(poller.wait_all(events, std::chrono::milliseconds{10}),
133-
const zmq::error_t&);
133+
zmq::error_t);
134134
}
135135

136136
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3)
@@ -153,7 +153,7 @@ TEST_CASE("poller remove unregistered throws", "[poller]")
153153
zmq::socket_t socket{context, zmq::socket_type::router};
154154
zmq::poller_t<> poller;
155155
/// \todo the actual error code should be checked
156-
CHECK_THROWS_AS(poller.remove(socket), const zmq::error_t&);
156+
CHECK_THROWS_AS(poller.remove(socket), zmq::error_t);
157157
}
158158

159159
TEST_CASE("poller remove registered empty", "[poller]")
@@ -198,7 +198,7 @@ TEST_CASE("poller add invalid socket throws", "[poller]")
198198
zmq::poller_t<> poller;
199199
zmq::socket_t a{context, zmq::socket_type::router};
200200
zmq::socket_t b{std::move(a)};
201-
CHECK_THROWS_AS(poller.add(a, zmq::event_flags::pollin), const zmq::error_t&);
201+
CHECK_THROWS_AS(poller.add(a, zmq::event_flags::pollin), zmq::error_t);
202202
}
203203

204204
TEST_CASE("poller remove invalid socket throws", "[poller]")
@@ -209,7 +209,7 @@ TEST_CASE("poller remove invalid socket throws", "[poller]")
209209
CHECK_NOTHROW(poller.add(socket, zmq::event_flags::pollin));
210210
std::vector<zmq::socket_t> sockets;
211211
sockets.emplace_back(std::move(socket));
212-
CHECK_THROWS_AS(poller.remove(socket), const zmq::error_t&);
212+
CHECK_THROWS_AS(poller.remove(socket), zmq::error_t);
213213
CHECK_NOTHROW(poller.remove(sockets[0]));
214214
}
215215

@@ -219,7 +219,7 @@ TEST_CASE("poller modify empty throws", "[poller]")
219219
zmq::socket_t socket{context, zmq::socket_type::push};
220220
zmq::poller_t<> poller;
221221
CHECK_THROWS_AS(poller.modify(socket, zmq::event_flags::pollin),
222-
const zmq::error_t&);
222+
zmq::error_t);
223223
}
224224

225225
TEST_CASE("poller modify invalid socket throws", "[poller]")
@@ -228,7 +228,7 @@ TEST_CASE("poller modify invalid socket throws", "[poller]")
228228
zmq::socket_t a{context, zmq::socket_type::push};
229229
zmq::socket_t b{std::move(a)};
230230
zmq::poller_t<> poller;
231-
CHECK_THROWS_AS(poller.modify(a, zmq::event_flags::pollin), const zmq::error_t&);
231+
CHECK_THROWS_AS(poller.modify(a, zmq::event_flags::pollin), zmq::error_t);
232232
}
233233

234234
TEST_CASE("poller modify not added throws", "[poller]")
@@ -238,7 +238,7 @@ TEST_CASE("poller modify not added throws", "[poller]")
238238
zmq::socket_t b{context, zmq::socket_type::push};
239239
zmq::poller_t<> poller;
240240
CHECK_NOTHROW(poller.add(a, zmq::event_flags::pollin));
241-
CHECK_THROWS_AS(poller.modify(b, zmq::event_flags::pollin), const zmq::error_t&);
241+
CHECK_THROWS_AS(poller.modify(b, zmq::event_flags::pollin), zmq::error_t);
242242
}
243243

244244
TEST_CASE("poller modify simple", "[poller]")
@@ -304,7 +304,7 @@ TEST_CASE("poller wait on move constructed", "[poller]")
304304
std::vector<zmq::poller_event<>> events(1);
305305
/// \todo the actual error code should be checked
306306
CHECK_THROWS_AS(a.wait_all(events, std::chrono::milliseconds{10}),
307-
const zmq::error_t&);
307+
zmq::error_t);
308308
CHECK(1 == b.wait_all(events, std::chrono::milliseconds{-1}));
309309
}
310310

@@ -319,7 +319,7 @@ TEST_CASE("poller wait on move assigned", "[poller]")
319319
/// \todo the TEST_CASE error code should be checked
320320
std::vector<zmq::poller_event<>> events(1);
321321
CHECK_THROWS_AS(a.wait_all(events, std::chrono::milliseconds{10}),
322-
const zmq::error_t&);
322+
zmq::error_t);
323323
CHECK(1 == b.wait_all(events, std::chrono::milliseconds{-1}));
324324
}
325325

0 commit comments

Comments
 (0)