Skip to content

Commit

Permalink
Update Catch2 from 2.13.10 to 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
martinzink committed Jul 21, 2023
1 parent d559764 commit 8e68bed
Show file tree
Hide file tree
Showing 89 changed files with 234 additions and 18,220 deletions.
19 changes: 3 additions & 16 deletions cmake/BuildTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# specific language governing permissions and limitations
# under the License.

include(Catch2)

### test functions
MACRO(GETSOURCEFILES result curdir)
Expand All @@ -31,7 +32,6 @@ ENDMACRO()
set(NANOFI_TEST_DIR "${CMAKE_SOURCE_DIR}/nanofi/tests/")

function(appendIncludes testName)
target_include_directories(${testName} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${testName} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_include_directories(${testName} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/")
target_include_directories(${testName} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/c2/protocols")
Expand Down Expand Up @@ -59,16 +59,9 @@ function(createTests testName)
message(DEBUG "-- Adding test: ${testName}")
appendIncludes("${testName}")

if (Boost_FOUND)
target_include_directories(${testName} BEFORE PRIVATE "${Boost_INCLUDE_DIRS}")
endif()
target_link_libraries(${testName} ${CMAKE_DL_LIBS})
target_wholearchive_library(${testName} ${TEST_BASE_LIB})
target_link_libraries(${testName} core-minifi yaml-cpp spdlog Threads::Threads)
if (Boost_FOUND)
target_link_libraries(${testName} ${Boost_SYSTEM_LIBRARY})
target_link_libraries(${testName} ${Boost_FILESYSTEM_LIBRARY})
endif()
target_compile_definitions(${testName} PRIVATE LOAD_EXTENSIONS)
set_target_properties(${testName} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endfunction()
Expand All @@ -80,19 +73,13 @@ set(TEST_BASE_SOURCES "TestBase.cpp" "RandomServerSocket.cpp" "StatefulProcessor
list(TRANSFORM TEST_BASE_SOURCES PREPEND "${TEST_DIR}/")
add_library(${TEST_BASE_LIB} STATIC "${TEST_BASE_SOURCES}")
target_link_libraries(${TEST_BASE_LIB} core-minifi)
target_include_directories(${TEST_BASE_LIB} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${TEST_BASE_LIB} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/")
if(WIN32)
target_include_directories(${TEST_BASE_LIB} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/opsys/win")
else()
target_include_directories(${TEST_BASE_LIB} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/opsys/posix")
endif()

SET(CATCH_MAIN_LIB catch_main)
add_library(${CATCH_MAIN_LIB} STATIC "${TEST_DIR}/CatchMain.cpp")
target_include_directories(${CATCH_MAIN_LIB} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_link_libraries(${CATCH_MAIN_LIB} spdlog) # for fmt

SET(TEST_RESOURCES ${TEST_DIR}/resources)

GETSOURCEFILES(UNIT_TESTS "${TEST_DIR}/unit/")
Expand All @@ -106,7 +93,7 @@ FOREACH(testfile ${UNIT_TESTS})
add_executable("${testfilename}" "${TEST_DIR}/unit/${testfile}")
target_compile_definitions("${testfilename}" PRIVATE TZ_DATA_DIR="${CMAKE_BINARY_DIR}/tzdata")
createTests("${testfilename}")
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
target_link_libraries(${testfilename} Catch2WithMain)
MATH(EXPR UNIT_TEST_COUNT "${UNIT_TEST_COUNT}+1")
add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR})
ENDFOREACH()
Expand Down Expand Up @@ -134,7 +121,7 @@ if(NOT WIN32 AND ENABLE_NANOFI)
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors/processors/")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")
appendIncludes("${testfilename}")
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB} Threads::Threads)
target_link_libraries(${testfilename} Catch2WithMain Threads::Threads)

target_wholearchive_library(${testfilename} nanofi)

Expand Down
26 changes: 26 additions & 0 deletions cmake/Catch2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
include(FetchContent)

FetchContent_Declare(
Catch2
URL https://github.com/catchorg/Catch2/archive/refs/tags/v3.4.0.tar.gz
URL_HASH SHA256=122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb
)
FetchContent_MakeAvailable(Catch2)
2 changes: 1 addition & 1 deletion controller/MiNiFiController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::shared_ptr<minifi::controllers::SSLContextService> getSSLContextService(con
int main(int argc, char **argv) {
const auto logger = minifi::core::logging::LoggerConfiguration::getConfiguration().getLogger("controller");

const std::string minifi_home = determineMinifiHome(logger);
const auto minifi_home = determineMinifiHome(logger);
if (minifi_home.empty()) {
// determineMinifiHome already logged everything we need
return -1;
Expand Down
3 changes: 1 addition & 2 deletions controller/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ foreach(testfile ${CONTROLLER_TESTS})
get_filename_component(testfilename "${testfile}" NAME_WE)
add_executable(${testfilename} "${testfile}" ${CONTROLLER_SOURCES})

target_include_directories(${testfilename} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/controller")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")

createTests(${testfilename})

target_link_libraries(${testfilename} ${CATCH_MAIN_LIB} ${LIBMINIFI} ${TEST_BASE_LIB})
target_link_libraries(${testfilename} Catch2WithMain ${LIBMINIFI} ${TEST_BASE_LIB})
add_test(NAME ${testfilename} COMMAND ${testfilename} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

math(EXPR CONTROLLER_TEST_COUNT "${CONTROLLER_TEST_COUNT}+1")
Expand Down
3 changes: 1 addition & 2 deletions encrypt-config/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ foreach(testfile ${ENCRYPT_CONFIG_TESTS})
get_filename_component(testfilename "${testfile}" NAME_WE)
add_executable(${testfilename} "${testfile}" ${ENCRYPT_CONFIG_SOURCES})

target_include_directories(${testfilename} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/encrypt-config")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")

createTests(${testfilename})

target_link_libraries(${testfilename} ${CATCH_MAIN_LIB} ${LIBMINIFI} ${TEST_BASE_LIB})
target_link_libraries(${testfilename} Catch2WithMain ${LIBMINIFI} ${TEST_BASE_LIB})
add_test(NAME ${testfilename} COMMAND ${testfilename} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")

math(EXPR ENCRYPT_CONFIG_TEST_COUNT "${ENCRYPT_CONFIG_TEST_COUNT}+1")
Expand Down
2 changes: 1 addition & 1 deletion extensions/aws/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FOREACH(testfile ${AWS_INTEGRATION_TESTS})
target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/expression-language")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")
createTests("${testfilename}")
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
target_link_libraries(${testfilename} Catch2WithMain)
target_link_libraries(${testfilename} minifi-aws)
target_link_libraries(${testfilename} minifi-standard-processors)
target_link_libraries(${testfilename} minifi-expression-language-extensions)
Expand Down
2 changes: 1 addition & 1 deletion extensions/civetweb/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if(NOT DISABLE_CURL)
target_link_libraries(${testfilename} minifi-standard-processors)

createTests("${testfilename}")
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
target_link_libraries(${testfilename} Catch2WithMain)
MATH(EXPR CIVETWEB-EXTENSIONS_TEST_COUNT "${CIVETWEB-EXTENSIONS_TEST_COUNT}+1")
add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR})
# Copy test resources
Expand Down
1 change: 0 additions & 1 deletion extensions/coap/tests/CoapC2VerifyHeartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "BaseHTTPClient.h"
#include "processors/InvokeHTTP.h"
#include "TestBase.h"
#include "Catch.h"
#include "utils/StringUtils.h"
#include "core/Core.h"
#include "core/logging/Logger.h"
Expand Down
2 changes: 1 addition & 1 deletion extensions/elasticsearch/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FOREACH(testfile ${ELASTICSEARCH_TESTS})
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/http-curl/")

createTests("${testfilename}")
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
target_link_libraries(${testfilename} Catch2WithMain)
target_link_libraries(${testfilename} minifi-elasticsearch)
target_link_libraries(${testfilename} minifi-civet-extensions)
target_link_libraries(${testfilename} minifi-http-curl)
Expand Down
4 changes: 1 addition & 3 deletions extensions/expression-language/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ SET(EXTENSIONS_TEST_COUNT 0)
FOREACH(testfile ${EXPRESSION_LANGUAGE_TESTS})
get_filename_component(testfilename "${testfile}" NAME_WE)
add_executable(${testfilename} "${testfile}")
target_include_directories(${testfilename} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors/processors")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/expression-language")
createTests(${testfilename})
target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
target_link_libraries(${testfilename} Catch2WithMain)
if(NOT DISABLE_CURL)
target_link_libraries(${testfilename} CURL::libcurl)
endif()
Expand All @@ -53,7 +52,6 @@ SET(INT_EXTENSIONS_TEST_COUNT 0)
FOREACH(testfile ${INT_EXPRESSION_LANGUAGE_TESTS})
get_filename_component(testfilename "${testfile}" NAME_WE)
add_executable(${testfilename} "${testfile}")
target_include_directories(${testfilename} SYSTEM BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/thirdparty/catch")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/test")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors")
target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors/processors")
Expand Down
28 changes: 15 additions & 13 deletions extensions/expression-language/tests/ExpressionLanguageTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "utils/gsl.h"
#include "TestBase.h"
#include "Catch.h"
#include "catch2/catch_approx.hpp"
#include "unit/ProvenanceTestHelper.h"
#include "date/tz.h"
#include "Utils.h"
Expand Down Expand Up @@ -626,7 +627,7 @@ TEST_CASE("Plus Exponent 2", "[expressionLanguagePlusExponent2]") {

auto flow_file_a = std::make_shared<core::FlowFile>();
flow_file_a->addAttribute("attr", "11.345678901234");
REQUIRE(10000011.345678901234 == Approx(expr(expression::Parameters{ flow_file_a }).asLongDouble()));
REQUIRE(10000011.345678901234 == Catch::Approx(expr(expression::Parameters{ flow_file_a }).asLongDouble()));
}

TEST_CASE("Minus Integer", "[expressionLanguageMinusInteger]") {
Expand Down Expand Up @@ -658,7 +659,7 @@ TEST_CASE("Multiply Decimal", "[expressionLanguageMultiplyDecimal]") {

auto flow_file_a = std::make_shared<core::FlowFile>();
flow_file_a->addAttribute("attr", "11.1");
REQUIRE(-148.136937 == Approx(expr(expression::Parameters{ flow_file_a }).asLongDouble()));
REQUIRE(-148.136937 == Catch::Approx(expr(expression::Parameters{ flow_file_a }).asLongDouble()));
}

TEST_CASE("Divide Integer", "[expressionLanguageDivideInteger]") {
Expand Down Expand Up @@ -910,8 +911,8 @@ TEST_CASE("GT3", "[expressionGT3]") {

// using :gt() to test string to integer parsing code
TEST_CASE("GT4 Value parsing errors", "[expressionGT4][outofrange]") {
const char* test_str;
const char* expected_substr;
const char* test_str = nullptr;
const char* expected_substr = nullptr;
SECTION("integer out of range") {
// 2 ^ 64, the smallest positive integer that's not representable even in uint64_t
test_str = "18446744073709551616";
Expand Down Expand Up @@ -1405,30 +1406,31 @@ TEST_CASE("Reverse DNS lookup with valid ip", "[ExpressionLanguage][reverseDnsLo

auto flow_file_a = std::make_shared<core::FlowFile>();
std::string expected_hostname;
SECTION("dns.google IPv4") {
flow_file_a->addAttribute("ip_addr", "8.8.8.8");
expected_hostname = "dns.google";
}

SECTION("dns.google IPv6") {
if (minifi::test::utils::isIPv6Disabled())
return;
SKIP("IPv6 is disabled");
flow_file_a->addAttribute("ip_addr", "2001:4860:4860::8888");
expected_hostname = "dns.google";
}

SECTION("Unresolvable address IPv4") {
flow_file_a->addAttribute("ip_addr", "192.0.2.0");
expected_hostname = "192.0.2.0";
SECTION("dns.google IPv4") {
flow_file_a->addAttribute("ip_addr", "8.8.8.8");
expected_hostname = "dns.google";
}

SECTION("Unresolvable address IPv6") {
if (minifi::test::utils::isIPv6Disabled())
return;
SKIP("IPv6 is disabled");
flow_file_a->addAttribute("ip_addr", "2001:db8::");
expected_hostname = "2001:db8::";
}

SECTION("Unresolvable address IPv4") {
flow_file_a->addAttribute("ip_addr", "192.0.2.0");
expected_hostname = "192.0.2.0";
}

REQUIRE(expr(expression::Parameters{ flow_file_a }).asString() == expected_hostname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "integration/IntegrationBase.h"
#include "ProcessContextExpr.h"
#include "TestBase.h"
#include "Catch.h"
#include "utils/IntegrationTestUtils.h"

class TestHarness : public IntegrationBase {
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/AbsoluteTimeoutTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <array>

#include "TestBase.h"
#include "Catch.h"
#include "tests/TestServer.h"
#include "HTTPHandlers.h"

Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2CompressTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#undef NDEBUG

#include "TestBase.h"
#include "Catch.h"

#include "c2/C2Agent.h"
#include "c2/HeartbeatLogger.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2DebugBundleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#undef NDEBUG

#include "TestBase.h"
#include "Catch.h"

#include "c2/C2Agent.h"
#include "protocols/RESTProtocol.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#undef NDEBUG
#include <string>
#include "TestBase.h"
#include "Catch.h"
#include "HTTPIntegrationBase.h"
#include "HTTPHandlers.h"
#include "processors/TailFile.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2DescribeManifestTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#undef NDEBUG
#include <string>
#include "Catch.h"
#include "HTTPIntegrationBase.h"
#include "HTTPHandlers.h"
#include "properties/Configuration.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2JstackTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <string>
#include <atomic>
#include "TestBase.h"
#include "Catch.h"
#include "HTTPIntegrationBase.h"
#include "HTTPHandlers.h"
#include "utils/IntegrationTestUtils.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2LogHeartbeatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#undef NDEBUG

#include "TestBase.h"
#include "Catch.h"

#include "c2/C2Agent.h"
#include "c2/HeartbeatLogger.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2MultipleCommandsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <functional>

#include "TestBase.h"
#include "Catch.h"
#include "HTTPIntegrationBase.h"
#include "HTTPHandlers.h"

Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2NullConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <iostream>
#include "InvokeHTTP.h"
#include "TestBase.h"
#include "Catch.h"
#include "core/logging/Logger.h"
#include "core/ProcessGroup.h"
#include "TestServer.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2PauseResumeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <memory>

#include "TestBase.h"
#include "Catch.h"
#include "HTTPIntegrationBase.h"
#include "HTTPHandlers.h"
#include "InvokeHTTP.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2VerifyHeartbeatAndStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#undef NDEBUG
#include "TestBase.h"
#include "Catch.h"
#include "c2/C2Agent.h"
#include "protocols/RESTProtocol.h"
#include "protocols/RESTSender.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <mutex>

#include "TestBase.h"
#include "Catch.h"
#include "c2/C2Agent.h"
#include "protocols/RESTProtocol.h"
#include "protocols/RESTSender.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <utility>

#include "TestBase.h"
#include "Catch.h"
#include "c2/C2Agent.h"
#include "protocols/RESTProtocol.h"
#include "protocols/RESTSender.h"
Expand Down
1 change: 0 additions & 1 deletion extensions/http-curl/tests/C2VerifyServeResults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <sstream>
#include "processors/InvokeHTTP.h"
#include "TestBase.h"
#include "Catch.h"
#include "core/ProcessGroup.h"
#include "properties/Configure.h"
#include "TestServer.h"
Expand Down
Loading

0 comments on commit 8e68bed

Please sign in to comment.