Merge pull request #466 from albestro/fix_catch2

Catch2 fixes
This commit is contained in:
Gudmundur Adalsteinsson 2021-06-30 11:28:21 +00:00 committed by GitHub
commit bfaf8e884f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 61 additions and 89 deletions

View File

@ -20,7 +20,6 @@ environment:
cache:
- libzmq -> appveyor.yml
- Build/catch -> tests/cmake/catch.cmake
before_build:
- if not exist libzmq (
@ -35,6 +34,5 @@ build:
verbosity: normal
test_script:
- cp libzmq/bin/libzmq*.dll Build/bin/%configuration%/
- cd Build
- ctest -V -C %configuration%

View File

@ -1,20 +1,20 @@
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(cppzmq-test CXX)
# place binaries and libraries according to GNU standards
include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
include(CTest)
include(cmake/catch.cmake)
include(${CATCH_MODULE_PATH}/Catch.cmake)
find_package(Threads)
find_package(Catch2 QUIET)
if (NOT Catch2_FOUND)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.4)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
endif()
add_executable(
unit_tests
buffer.cpp
@ -32,11 +32,10 @@ add_executable(
utilities.cpp
)
add_dependencies(unit_tests catch)
target_include_directories(unit_tests PUBLIC ${CATCH_MODULE_PATH})
target_link_libraries(
unit_tests
PRIVATE Catch2::Catch2
PRIVATE cppzmq
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
)
@ -48,4 +47,6 @@ if (COVERAGE)
target_link_libraries(unit_tests PRIVATE --coverage)
endif()
include(CTest)
include(Catch)
catch_discover_tests(unit_tests)

View File

@ -93,7 +93,7 @@ TEST_CASE("add null handler fails", "[active_poller]")
zmq::active_poller_t active_poller;
zmq::active_poller_t::handler_type handler;
CHECK_THROWS_AS(active_poller.add(socket, zmq::event_flags::pollin, handler),
const std::invalid_argument &);
std::invalid_argument);
}
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 0)
@ -107,7 +107,7 @@ TEST_CASE("add handler invalid events type", "[active_poller]")
CHECK_THROWS_AS(
active_poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type),
no_op_handler),
const zmq::error_t &);
zmq::error_t);
CHECK(active_poller.empty());
CHECK(0u == active_poller.size());
}
@ -243,7 +243,7 @@ TEST_CASE("add invalid socket throws", "[active_poller]")
zmq::socket_t a{context, zmq::socket_type::router};
zmq::socket_t b{std::move(a)};
CHECK_THROWS_AS(active_poller.add(a, zmq::event_flags::pollin, no_op_handler),
const zmq::error_t &);
zmq::error_t);
}
TEST_CASE("remove invalid socket throws", "[active_poller]")
@ -256,7 +256,7 @@ TEST_CASE("remove invalid socket throws", "[active_poller]")
CHECK(1u == active_poller.size());
std::vector<zmq::socket_t> sockets;
sockets.emplace_back(std::move(socket));
CHECK_THROWS_AS(active_poller.remove(socket), const zmq::error_t &);
CHECK_THROWS_AS(active_poller.remove(socket), zmq::error_t);
CHECK(1u == active_poller.size());
}
@ -276,7 +276,7 @@ TEST_CASE("modify empty throws", "[active_poller]")
zmq::socket_t socket{context, zmq::socket_type::push};
zmq::active_poller_t active_poller;
CHECK_THROWS_AS(active_poller.modify(socket, zmq::event_flags::pollin),
const zmq::error_t &);
zmq::error_t);
}
TEST_CASE("modify invalid socket throws", "[active_poller]")
@ -286,7 +286,7 @@ TEST_CASE("modify invalid socket throws", "[active_poller]")
zmq::socket_t b{std::move(a)};
zmq::active_poller_t active_poller;
CHECK_THROWS_AS(active_poller.modify(a, zmq::event_flags::pollin),
const zmq::error_t &);
zmq::error_t);
}
TEST_CASE("modify not added throws", "[active_poller]")
@ -297,7 +297,7 @@ TEST_CASE("modify not added throws", "[active_poller]")
zmq::active_poller_t active_poller;
CHECK_NOTHROW(active_poller.add(a, zmq::event_flags::pollin, no_op_handler));
CHECK_THROWS_AS(active_poller.modify(b, zmq::event_flags::pollin),
const zmq::error_t &);
zmq::error_t);
}
TEST_CASE("modify simple", "[active_poller]")

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#ifdef ZMQ_CPP17

View File

@ -1,27 +0,0 @@
include(ExternalProject)
ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
URL "https://raw.githubusercontent.com/catchorg/Catch2/Catch1.x/single_include/catch.hpp"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
DOWNLOAD_NO_EXTRACT ON
)
# Expose variable CATCH_MODULE_PATH to parent scope
ExternalProject_Get_Property(catch DOWNLOAD_DIR)
set(CATCH_MODULE_PATH ${DOWNLOAD_DIR} CACHE INTERNAL "Path to include catch")
# Download module for CTest integration
if(NOT EXISTS "${CATCH_MODULE_PATH}/Catch.cmake")
file(DOWNLOAD "https://raw.githubusercontent.com/catchorg/Catch2/90e2549cecc2e886d563b7a88e752c9b4104f798/contrib/Catch.cmake"
"${CATCH_MODULE_PATH}/Catch.cmake")
endif()
if(NOT EXISTS "${CATCH_MODULE_PATH}/CatchAddTests.cmake")
file(DOWNLOAD "https://raw.githubusercontent.com/catchorg/Catch2/90e2549cecc2e886d563b7a88e752c9b4104f798/contrib/CatchAddTests.cmake"
"${CATCH_MODULE_PATH}/CatchAddTests.cmake")
endif()

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq_addon.hpp>
#ifdef ZMQ_CPP11
@ -69,7 +69,7 @@ TEST_CASE("multipart codec decode bad data overflow", "[codec_multipart]")
CHECK_THROWS_AS(
multipart_t::decode(wrong_size),
const std::out_of_range&);
std::out_of_range);
}
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]")
CHECK_THROWS_AS(
multipart_t::decode(wrong_size),
const std::out_of_range&);
std::out_of_range);
}

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#if (__cplusplus >= 201703L)
@ -75,10 +75,10 @@ TEST_CASE("context set/get options", "[context]")
CHECK_THROWS_AS(
context.set(static_cast<zmq::ctxopt>(-42), 5),
const zmq::error_t &);
zmq::error_t);
CHECK_THROWS_AS(
context.get(static_cast<zmq::ctxopt>(-42)),
const zmq::error_t &);
zmq::error_t);
}
#endif

View File

@ -1,5 +1,5 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#if defined(ZMQ_CPP11)

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq_addon.hpp>
#ifdef ZMQ_HAS_RVALUE_REFS

View File

@ -109,7 +109,7 @@ TEST_CASE("poller add handler invalid events type", "[poller]")
short invalid_events_type = 2 << 10;
CHECK_THROWS_AS(
poller.add(socket, static_cast<zmq::event_flags>(invalid_events_type)),
const zmq::error_t&);
zmq::error_t);
}
#endif
@ -121,7 +121,7 @@ TEST_CASE("poller add handler twice throws", "[poller]")
poller.add(socket, zmq::event_flags::pollin);
/// \todo the actual error code should be checked
CHECK_THROWS_AS(poller.add(socket, zmq::event_flags::pollin),
const zmq::error_t&);
zmq::error_t);
}
TEST_CASE("poller wait with no handlers throws", "[poller]")
@ -130,7 +130,7 @@ TEST_CASE("poller wait with no handlers throws", "[poller]")
std::vector<zmq::poller_event<>> events;
/// \todo the actual error code should be checked
CHECK_THROWS_AS(poller.wait_all(events, std::chrono::milliseconds{10}),
const zmq::error_t&);
zmq::error_t);
}
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3)
@ -153,7 +153,7 @@ TEST_CASE("poller remove unregistered throws", "[poller]")
zmq::socket_t socket{context, zmq::socket_type::router};
zmq::poller_t<> poller;
/// \todo the actual error code should be checked
CHECK_THROWS_AS(poller.remove(socket), const zmq::error_t&);
CHECK_THROWS_AS(poller.remove(socket), zmq::error_t);
}
TEST_CASE("poller remove registered empty", "[poller]")
@ -198,7 +198,7 @@ TEST_CASE("poller add invalid socket throws", "[poller]")
zmq::poller_t<> poller;
zmq::socket_t a{context, zmq::socket_type::router};
zmq::socket_t b{std::move(a)};
CHECK_THROWS_AS(poller.add(a, zmq::event_flags::pollin), const zmq::error_t&);
CHECK_THROWS_AS(poller.add(a, zmq::event_flags::pollin), zmq::error_t);
}
TEST_CASE("poller remove invalid socket throws", "[poller]")
@ -209,7 +209,7 @@ TEST_CASE("poller remove invalid socket throws", "[poller]")
CHECK_NOTHROW(poller.add(socket, zmq::event_flags::pollin));
std::vector<zmq::socket_t> sockets;
sockets.emplace_back(std::move(socket));
CHECK_THROWS_AS(poller.remove(socket), const zmq::error_t&);
CHECK_THROWS_AS(poller.remove(socket), zmq::error_t);
CHECK_NOTHROW(poller.remove(sockets[0]));
}
@ -219,7 +219,7 @@ TEST_CASE("poller modify empty throws", "[poller]")
zmq::socket_t socket{context, zmq::socket_type::push};
zmq::poller_t<> poller;
CHECK_THROWS_AS(poller.modify(socket, zmq::event_flags::pollin),
const zmq::error_t&);
zmq::error_t);
}
TEST_CASE("poller modify invalid socket throws", "[poller]")
@ -228,7 +228,7 @@ TEST_CASE("poller modify invalid socket throws", "[poller]")
zmq::socket_t a{context, zmq::socket_type::push};
zmq::socket_t b{std::move(a)};
zmq::poller_t<> poller;
CHECK_THROWS_AS(poller.modify(a, zmq::event_flags::pollin), const zmq::error_t&);
CHECK_THROWS_AS(poller.modify(a, zmq::event_flags::pollin), zmq::error_t);
}
TEST_CASE("poller modify not added throws", "[poller]")
@ -238,7 +238,7 @@ TEST_CASE("poller modify not added throws", "[poller]")
zmq::socket_t b{context, zmq::socket_type::push};
zmq::poller_t<> poller;
CHECK_NOTHROW(poller.add(a, zmq::event_flags::pollin));
CHECK_THROWS_AS(poller.modify(b, zmq::event_flags::pollin), const zmq::error_t&);
CHECK_THROWS_AS(poller.modify(b, zmq::event_flags::pollin), zmq::error_t);
}
TEST_CASE("poller modify simple", "[poller]")
@ -304,7 +304,7 @@ TEST_CASE("poller wait on move constructed", "[poller]")
std::vector<zmq::poller_event<>> events(1);
/// \todo the actual error code should be checked
CHECK_THROWS_AS(a.wait_all(events, std::chrono::milliseconds{10}),
const zmq::error_t&);
zmq::error_t);
CHECK(1 == b.wait_all(events, std::chrono::milliseconds{-1}));
}
@ -319,7 +319,7 @@ TEST_CASE("poller wait on move assigned", "[poller]")
/// \todo the TEST_CASE error code should be checked
std::vector<zmq::poller_event<>> events(1);
CHECK_THROWS_AS(a.wait_all(events, std::chrono::milliseconds{10}),
const zmq::error_t&);
zmq::error_t);
CHECK(1 == b.wait_all(events, std::chrono::milliseconds{-1}));
}

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq_addon.hpp>
#ifdef ZMQ_CPP11
@ -52,7 +52,7 @@ TEST_CASE("recv_multipart test", "[recv_multipart]")
std::vector<zmq::message_t> msgs;
CHECK_THROWS_AS(
zmq::recv_multipart(zmq::socket_ref(), std::back_inserter(msgs)),
const zmq::error_t &);
zmq::error_t);
}
}
@ -90,7 +90,7 @@ TEST_CASE("recv_multipart_n test", "[recv_multipart]")
std::array<zmq::message_t, 1> msgs;
CHECK_THROWS_AS(
zmq::recv_multipart_n(output, msgs.data(), msgs.size()),
const std::runtime_error&);
std::runtime_error);
}
SECTION("recv 0") {
input.send(zmq::str_buffer("hello"), zmq::send_flags::sndmore);
@ -99,7 +99,7 @@ TEST_CASE("recv_multipart_n test", "[recv_multipart]")
std::array<zmq::message_t, 1> msgs;
CHECK_THROWS_AS(
zmq::recv_multipart_n(output, msgs.data(), 0),
const std::runtime_error&);
std::runtime_error);
}
SECTION("send 2 messages") {
input.send(zmq::str_buffer("hello"), zmq::send_flags::sndmore);
@ -132,7 +132,7 @@ TEST_CASE("recv_multipart_n test", "[recv_multipart]")
std::array<zmq::message_t, 1> msgs;
CHECK_THROWS_AS(
zmq::recv_multipart_n(zmq::socket_ref(), msgs.data(), msgs.size()),
const zmq::error_t &);
zmq::error_t);
}
}

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq_addon.hpp>
#ifdef ZMQ_CPP11
@ -115,7 +115,7 @@ TEST_CASE("send_multipart test", "[send_multipart]")
SECTION("send with invalid socket") {
std::vector<zmq::message_t> msgs(1);
CHECK_THROWS_AS(zmq::send_multipart(zmq::socket_ref(), msgs),
const zmq::error_t &);
zmq::error_t);
}
}
#endif

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#ifdef ZMQ_CPP11
#include <future>
@ -58,7 +58,7 @@ TEST_CASE("socket options", "[socket]")
socket.set(zmq::sockopt::immediate, false);
CHECK(socket.get(zmq::sockopt::immediate) == false);
// unit out of range
CHECK_THROWS_AS(socket.set(zmq::sockopt::immediate, 80), const zmq::error_t &);
CHECK_THROWS_AS(socket.set(zmq::sockopt::immediate, 80), zmq::error_t);
#endif
#ifdef ZMQ_LINGER
socket.set(zmq::sockopt::linger, 55);
@ -83,7 +83,7 @@ TEST_CASE("socket options", "[socket]")
std::string id_ret_small(3, ' ');
// truncated
CHECK_THROWS_AS(socket.get(zmq::sockopt::routing_id, zmq::buffer(id_ret_small)),
const zmq::error_t &);
zmq::error_t);
#endif
}
@ -543,7 +543,7 @@ TEST_CASE("socket send exception", "[socket]")
s.bind("inproc://test");
std::vector<char> buf(4);
CHECK_THROWS_AS(s.send(zmq::buffer(buf)), const zmq::error_t &);
CHECK_THROWS_AS(s.send(zmq::buffer(buf)), zmq::error_t);
}
TEST_CASE("socket recv none", "[socket]")
@ -631,7 +631,7 @@ TEST_CASE("socket recv dontwait", "[socket]")
zmq::message_t msg;
auto resm = s.recv(msg, flags);
CHECK(!resm);
CHECK_THROWS_AS(resm.value(), const std::exception &);
CHECK_THROWS_AS(resm.value(), std::exception);
CHECK(msg.size() == 0);
}
@ -642,7 +642,7 @@ TEST_CASE("socket recv exception", "[socket]")
s.bind("inproc://test");
std::vector<char> buf(4);
CHECK_THROWS_AS(s.recv(zmq::buffer(buf)), const zmq::error_t &);
CHECK_THROWS_AS(s.recv(zmq::buffer(buf)), zmq::error_t);
}
TEST_CASE("socket proxy", "[socket]")

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#ifdef ZMQ_CPP11

View File

@ -1,6 +1,6 @@
#pragma once
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#if defined(ZMQ_CPP11)

View File

@ -1,4 +1,4 @@
#include <catch.hpp>
#include <catch2/catch.hpp>
#include <zmq.hpp>
#if defined(ZMQ_CPP11) && !defined(ZMQ_CPP11_PARTIAL)