Added Catch v3 support (#2661)

* Added Catch v3 support.

* Removed extra square brackets from some tests.
This commit is contained in:
Vitaly Zaitsev 2023-03-01 12:51:04 +01:00 committed by GitHub
parent 150ba9e6dd
commit 7f09c88817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 41 additions and 18011 deletions

View File

@ -12,12 +12,10 @@ jobs:
fail-fast: false
matrix:
config:
- { compiler: gcc, version: 4.9, build_type: Release, cppstd: 11, examples: OFF, asan: OFF }
- { compiler: gcc, version: 7, build_type: Release, cppstd: 11 }
- { compiler: gcc, version: 9, build_type: Release, cppstd: 17 }
- { compiler: gcc, version: 11, build_type: Debug, cppstd: 20 }
- { compiler: gcc, version: 12, build_type: Release, cppstd: 20 }
- { compiler: clang, version: 3.5, build_type: Release, cppstd: 11, asan: OFF }
- { compiler: clang, version: 10, build_type: Release, cppstd: 11 }
- { compiler: clang, version: 10, build_type: Debug, cppstd: 17, asan: OFF }
- { compiler: clang, version: 12, build_type: Debug, cppstd: 17, asan: OFF }
@ -29,7 +27,7 @@ jobs:
- uses: actions/checkout@main
- name: Setup
run: |
apt-get update && apt-get install -y curl
apt-get update && apt-get install -y curl git
CMAKE_VERSION="3.24.2"
curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh
chmod +x install-cmake.sh

View File

@ -13,6 +13,20 @@ if(PkgConfig_FOUND)
pkg_check_modules(systemd libsystemd)
endif()
find_package(Catch2 3 QUIET)
if (Catch2_FOUND)
message(STATUS "Packaged version of Catch will be used.")
else()
message(STATUS "Bundled version of Catch will be downloaded and used.")
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.3.2
)
FetchContent_MakeAvailable(Catch2)
endif()
set(SPDLOG_UTESTS_SOURCES
test_file_helper.cpp
test_file_logging.cpp
@ -53,6 +67,7 @@ function(spdlog_prepare_test test_target spdlog_lib)
if(systemd_FOUND)
target_link_libraries(${test_target} PRIVATE ${systemd_LIBRARIES})
endif()
target_link_libraries(${test_target} PRIVATE Catch2::Catch2WithMain)
if(SPDLOG_SANITIZE_ADDRESS)
spdlog_enable_sanitizer(${test_target})
endif()

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -4,7 +4,7 @@
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
#endif
#include "catch.hpp"
#include <catch2/catch_all.hpp>
#if defined(__GNUC__) && __GNUC__ == 12
# pragma GCC diagnostic pop
#endif

View File

@ -3,8 +3,7 @@
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
#endif
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <catch2/catch_all.hpp>
#if defined(__GNUC__) && __GNUC__ == 12
# pragma GCC diagnostic pop

View File

@ -7,7 +7,7 @@
#include "spdlog/async.h"
#include "spdlog/common.h"
TEST_CASE("custom_callback_logger", "[custom_callback_logger]]")
TEST_CASE("custom_callback_logger", "[custom_callback_logger]")
{
std::vector<std::string> lines;
spdlog::pattern_formatter formatter;

View File

@ -87,19 +87,19 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
* File name calculations
*/
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]]")
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 3);
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3.txt"));
}
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]]")
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated"), 3);
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3"));
}
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]")
{
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 0);
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.txt"));
@ -110,7 +110,7 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
# include <regex>
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]")
{
// daily_YYYY-MM-DD_hh-mm.txt
auto filename =
@ -123,7 +123,7 @@ TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
}
#endif
TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]]")
TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]")
{
std::tm tm = spdlog::details::os::localtime();
// example-YYYY-MM-DD.log

View File

@ -22,7 +22,7 @@ protected:
}
};
TEST_CASE("default_error_handler", "[errors]]")
TEST_CASE("default_error_handler", "[errors]")
{
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
@ -40,7 +40,7 @@ TEST_CASE("default_error_handler", "[errors]]")
struct custom_ex
{};
TEST_CASE("custom_error_handler", "[errors]]")
TEST_CASE("custom_error_handler", "[errors]")
{
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
@ -54,7 +54,7 @@ TEST_CASE("custom_error_handler", "[errors]]")
require_message_count(SIMPLE_LOG, 2);
}
TEST_CASE("default_error_handler2", "[errors]]")
TEST_CASE("default_error_handler2", "[errors]")
{
spdlog::drop_all();
auto logger = spdlog::create<failing_sink>("failed_logger");
@ -62,7 +62,7 @@ TEST_CASE("default_error_handler2", "[errors]]")
REQUIRE_THROWS_AS(logger->info("Some message"), custom_ex);
}
TEST_CASE("flush_error_handler", "[errors]]")
TEST_CASE("flush_error_handler", "[errors]")
{
spdlog::drop_all();
auto logger = spdlog::create<failing_sink>("failed_logger");
@ -70,7 +70,7 @@ TEST_CASE("flush_error_handler", "[errors]]")
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
}
TEST_CASE("async_error_handler", "[errors]]")
TEST_CASE("async_error_handler", "[errors]")
{
prepare_logdir();
std::string err_msg("log failed with some msg");
@ -98,7 +98,7 @@ TEST_CASE("async_error_handler", "[errors]]")
}
// Make sure async error handler is executed
TEST_CASE("async_error_handler2", "[errors]]")
TEST_CASE("async_error_handler2", "[errors]")
{
prepare_logdir();
std::string err_msg("This is async handler error message");

View File

@ -15,7 +15,7 @@ static void write_with_helper(file_helper &helper, size_t howmany)
helper.flush();
}
TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
TEST_CASE("file_helper_filename", "[file_helper::filename()]")
{
prepare_logdir();
@ -25,7 +25,7 @@ TEST_CASE("file_helper_filename", "[file_helper::filename()]]")
REQUIRE(helper.filename() == target_filename);
}
TEST_CASE("file_helper_size", "[file_helper::size()]]")
TEST_CASE("file_helper_size", "[file_helper::size()]")
{
prepare_logdir();
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
@ -39,7 +39,7 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]")
REQUIRE(get_filesize(TEST_FILENAME) == expected_size);
}
TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
TEST_CASE("file_helper_reopen", "[file_helper::reopen()]")
{
prepare_logdir();
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
@ -51,7 +51,7 @@ TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]")
REQUIRE(helper.size() == 0);
}
TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]")
{
prepare_logdir();
spdlog::filename_t target_filename = SPDLOG_FILENAME_T(TEST_FILENAME);
@ -78,7 +78,7 @@ static void test_split_ext(const spdlog::filename_t::value_type *fname, const sp
REQUIRE(ext == expected_ext);
}
TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()]]")
TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()]")
{
test_split_ext(SPDLOG_FILENAME_T("mylog.txt"), SPDLOG_FILENAME_T("mylog"), SPDLOG_FILENAME_T(".txt"));
test_split_ext(SPDLOG_FILENAME_T(".mylog.txt"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".txt"));

View File

@ -6,7 +6,7 @@
#define SIMPLE_LOG "test_logs/simple_log"
#define ROTATING_LOG "test_logs/rotating_log"
TEST_CASE("simple_file_logger", "[simple_logger]]")
TEST_CASE("simple_file_logger", "[simple_logger]")
{
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
@ -23,7 +23,7 @@ TEST_CASE("simple_file_logger", "[simple_logger]]")
REQUIRE(file_contents(SIMPLE_LOG) == spdlog::fmt_lib::format("Test message 1{}Test message 2{}", default_eol, default_eol));
}
TEST_CASE("flush_on", "[flush_on]]")
TEST_CASE("flush_on", "[flush_on]")
{
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
@ -44,7 +44,7 @@ TEST_CASE("flush_on", "[flush_on]]")
spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}", default_eol, default_eol, default_eol));
}
TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
TEST_CASE("rotating_file_logger1", "[rotating_logger]")
{
prepare_logdir();
size_t max_size = 1024 * 10;
@ -60,7 +60,7 @@ TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
require_message_count(ROTATING_LOG, 10);
}
TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
TEST_CASE("rotating_file_logger2", "[rotating_logger]")
{
prepare_logdir();
size_t max_size = 1024 * 10;
@ -100,7 +100,7 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
}
// test that passing max_size=0 throws
TEST_CASE("rotating_file_logger3", "[rotating_logger]]")
TEST_CASE("rotating_file_logger3", "[rotating_logger]")
{
prepare_logdir();
size_t max_size = 0;

View File

@ -10,7 +10,7 @@
#define TEST_FILENAME "test_logs/simple_log"
TEST_CASE("debug and trace w/o format string", "[macros]]")
TEST_CASE("debug and trace w/o format string", "[macros]")
{
prepare_logdir();