Asserts rework to be nice with code coverage
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m14s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 44s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 51s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m20s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 35s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m21s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 59s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m4s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 55s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 46s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Clang Format Checks (push) Successful in 12s
Bigfoot / Sonarqube (pull_request) Failing after 2m42s
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m14s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 44s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 30s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 51s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m20s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 35s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 1m21s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 59s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 1m4s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 30s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 55s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 57s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 46s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m0s
Bigfoot / Clang Format Checks (push) Successful in 12s
Bigfoot / Sonarqube (pull_request) Failing after 2m42s
This commit is contained in:
@@ -41,7 +41,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd ./build-toolmode/Debug
|
cd ./build-toolmode/Debug
|
||||||
. ../../build-toolmode/build/Debug/generators/conanbuild.sh
|
. ../../build-toolmode/build/Debug/generators/conanbuild.sh
|
||||||
LLVM_PROFILE_FILE="%p.profraw" xvfb-run ctest --output-on-failure
|
LLVM_PROFILE_FILE="%p.profraw%c" xvfb-run ctest --output-on-failure
|
||||||
. ../../build-toolmode/build/Debug/generators/deactivate_conanbuild.sh
|
. ../../build-toolmode/build/Debug/generators/deactivate_conanbuild.sh
|
||||||
|
|
||||||
- name: Clang-Tidy
|
- name: Clang-Tidy
|
||||||
|
|||||||
@@ -7,25 +7,21 @@
|
|||||||
#ifndef BIGFOOT_UTILS_ASSERT_HPP
|
#ifndef BIGFOOT_UTILS_ASSERT_HPP
|
||||||
#define BIGFOOT_UTILS_ASSERT_HPP
|
#define BIGFOOT_UTILS_ASSERT_HPP
|
||||||
#include <Utils/Log/LogMacros.hpp>
|
#include <Utils/Log/LogMacros.hpp>
|
||||||
|
#include <Utils/TargetMacros.h>
|
||||||
|
|
||||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||||
|
|
||||||
|
#include <EASTL/fixed_function.h>
|
||||||
|
#include <EASTL/string.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
#include <source_location>
|
#include <source_location>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#if defined BIGFOOT_LINUX
|
#if defined BIGFOOT_LINUX
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BIGFOOT_FLUSH_LOG \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if (Bigfoot::Singleton<Bigfoot::Log>::HasInstance()) \
|
|
||||||
{ \
|
|
||||||
Bigfoot::Singleton<Bigfoot::Log>::GetInstance().Flush(); \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
#if defined BIGFOOT_WINDOWS
|
#if defined BIGFOOT_WINDOWS
|
||||||
#define BREAK \
|
#define BREAK \
|
||||||
do \
|
do \
|
||||||
@@ -42,39 +38,71 @@
|
|||||||
} while (false)
|
} while (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Assert then break
|
||||||
|
*
|
||||||
|
* \param p_condition The condition to check
|
||||||
|
* \param p_message A function that will return the formatting string describing the issue
|
||||||
|
* \param p_location The location the assert originates from
|
||||||
|
*/
|
||||||
|
template<typename HANDLER>
|
||||||
|
BIGFOOT_ALWAYS_INLINE void AssertCheck(const bool p_condition,
|
||||||
|
const eastl::fixed_function<32, eastl::string()>& p_messageFn,
|
||||||
|
const std::source_location p_location = std::source_location::current())
|
||||||
|
{
|
||||||
|
if (!p_condition) [[unlikely]]
|
||||||
|
{
|
||||||
|
HANDLER::Handle(p_location, p_messageFn());
|
||||||
|
BREAK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert then break then kill
|
||||||
|
*
|
||||||
|
* \param p_condition The condition to check
|
||||||
|
* \param p_message A function that will return the formatting string describing the issue
|
||||||
|
* \param p_location The location the assert originates from
|
||||||
|
*/
|
||||||
|
template<typename HANDLER>
|
||||||
|
BIGFOOT_ALWAYS_INLINE void CriticalAssertCheck(const bool p_condition,
|
||||||
|
const eastl::fixed_function<32, eastl::string()>& p_messageFn,
|
||||||
|
const std::source_location p_location = std::source_location::current())
|
||||||
|
{
|
||||||
|
if (!p_condition) [[unlikely]]
|
||||||
|
{
|
||||||
|
HANDLER::Handle(p_location, p_messageFn());
|
||||||
|
BREAK;
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot
|
||||||
|
|
||||||
#define ASSERT(HANDLER, p_assert, p_message, ...) \
|
#define ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||||
do \
|
::Bigfoot::AssertCheck<HANDLER>((p_assert), \
|
||||||
{ \
|
[&] \
|
||||||
constexpr std::source_location location = std::source_location::current(); \
|
{ \
|
||||||
if (!(p_assert)) [[unlikely]] \
|
return eastl::string { \
|
||||||
{ \
|
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
|
||||||
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
|
})
|
||||||
BREAK; \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \
|
#define SOFT_ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||||
do \
|
::Bigfoot::AssertCheck<HANDLER>((p_assert), \
|
||||||
{ \
|
[&] \
|
||||||
constexpr std::source_location location = std::source_location::current(); \
|
{ \
|
||||||
if (!(p_assert)) [[unlikely]] \
|
return eastl::string { \
|
||||||
{ \
|
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
|
||||||
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
|
})
|
||||||
BREAK; \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \
|
#define CRITICAL_ASSERT(HANDLER, p_assert, p_message, ...) \
|
||||||
do \
|
::Bigfoot::CriticalAssertCheck<HANDLER>((p_assert), \
|
||||||
{ \
|
[&] \
|
||||||
constexpr std::source_location location = std::source_location::current(); \
|
{ \
|
||||||
if (!(p_assert)) [[unlikely]] \
|
return eastl::string { \
|
||||||
{ \
|
fmt::format(p_message __VA_OPT__(, ) __VA_ARGS__).c_str()}; \
|
||||||
HANDLER::Handle(location, p_message __VA_OPT__(, ) __VA_ARGS__); \
|
})
|
||||||
BREAK; \
|
|
||||||
std::abort(); \
|
|
||||||
} \
|
|
||||||
} while (false)
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define ASSERT(HANDLER, p_assert, p_message, ...)
|
#define ASSERT(HANDLER, p_assert, p_message, ...)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <EASTL/string.h>
|
||||||
|
|
||||||
#include <source_location>
|
#include <source_location>
|
||||||
|
|
||||||
@@ -32,15 +32,13 @@ class AssertHandler
|
|||||||
* Handle an assertion.
|
* Handle an assertion.
|
||||||
*
|
*
|
||||||
* \param p_location Location of the assertion.
|
* \param p_location Location of the assertion.
|
||||||
* \param p_format Format string for the assertion message.
|
* \param p_message Message describing the assertion failure.
|
||||||
* \param p_args Arguments for the format string.
|
|
||||||
*/
|
*/
|
||||||
template<typename... ARGS>
|
static void Handle(const std::source_location& p_location, const eastl::string& p_message)
|
||||||
static void Handle(const std::source_location& p_location, fmt::format_string<ARGS...> p_format, ARGS&&... p_args)
|
|
||||||
{
|
{
|
||||||
BIGFOOT_LOG_FATAL(LOGGER,
|
BIGFOOT_LOG_FATAL(LOGGER,
|
||||||
"Assert: {} (File:{}, Line:{}, Function:{}\n",
|
"Assert: {} (File:{}, Line:{}, Function:{}\n",
|
||||||
fmt::format(p_format, std::forward<ARGS>(p_args)...),
|
p_message,
|
||||||
p_location.file_name(),
|
p_location.file_name(),
|
||||||
p_location.line(),
|
p_location.line(),
|
||||||
p_location.function_name());
|
p_location.function_name());
|
||||||
|
|||||||
@@ -10,6 +10,15 @@
|
|||||||
#include <Utils/Singleton.hpp>
|
#include <Utils/Singleton.hpp>
|
||||||
|
|
||||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||||
|
#define BIGFOOT_FLUSH_LOG \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (Bigfoot::Singleton<Bigfoot::Log>::HasInstance()) \
|
||||||
|
{ \
|
||||||
|
Bigfoot::Singleton<Bigfoot::Log>::GetInstance().Flush(); \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \
|
#define BIGFOOT_LOG_DEBUG(loggerName, fmt, ...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
#define BIGFOOT_WINDOWS_OR_LINUX(p_windows, p_linux) p_linux
|
#define BIGFOOT_WINDOWS_OR_LINUX(p_windows, p_linux) p_linux
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined BIGFOOT_WINDOWS
|
||||||
|
#define BIGFOOT_ALWAYS_INLINE [[msvc::forceinline]]
|
||||||
|
#elif defined BIGFOOT_LINUX
|
||||||
|
#define BIGFOOT_ALWAYS_INLINE [[gnu::always_inline]] inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined BIGFOOT_OPTIMIZED
|
#if defined BIGFOOT_OPTIMIZED
|
||||||
#define BIGFOOT_OPTIMIZED_ONLY(...) __VA_ARGS__
|
#define BIGFOOT_OPTIMIZED_ONLY(...) __VA_ARGS__
|
||||||
#define BIGFOOT_NOT_OPTIMIZED_ONLY(...)
|
#define BIGFOOT_NOT_OPTIMIZED_ONLY(...)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
GTEST_FLAG_SET(death_test_style, "threadsafe");
|
||||||
|
|
||||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
GTEST_FLAG_SET(death_test_style, "threadsafe");
|
||||||
|
|
||||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
GTEST_FLAG_SET(death_test_style, "threadsafe");
|
||||||
|
|
||||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file Assert.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <Utils/Assert/AssertHandler.hpp>
|
||||||
|
|
||||||
|
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
|
||||||
|
|
||||||
|
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
using TestAssertHandler = AssertHandler<UTILSTESTS_LOGGER>;
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST(AssertDeathTest, Assert_ShouldTerminateTheProcessWhenTheConditionIsFalse)
|
||||||
|
{
|
||||||
|
EXPECT_DEATH({ ASSERT(TestAssertHandler, false, "Something went wrong: {}", 42); }, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST(AssertDeathTest, CriticalAssert_ShouldTerminateTheProcessWhenTheConditionIsFalse)
|
||||||
|
{
|
||||||
|
EXPECT_DEATH({ CRITICAL_ASSERT(TestAssertHandler, false, "Something critical went wrong: {}", 42); }, "");
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*********************************************************************
|
||||||
|
* \file AssertHandler.cpp
|
||||||
|
*
|
||||||
|
* \author Romain BOULLARD
|
||||||
|
* \date September 2026
|
||||||
|
*********************************************************************/
|
||||||
|
#include <Utils/Assert/AssertHandler.hpp>
|
||||||
|
|
||||||
|
#include <Utils/Singleton.hpp>
|
||||||
|
|
||||||
|
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
|
||||||
|
|
||||||
|
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||||
|
|
||||||
|
#include <EASTL/string.h>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <source_location>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace Bigfoot
|
||||||
|
{
|
||||||
|
class AssertHandlerFixture: public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
eastl::string ReadFileSinkContent()
|
||||||
|
{
|
||||||
|
Singleton<Log>::GetInstance().Flush();
|
||||||
|
|
||||||
|
std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}};
|
||||||
|
std::stringstream buffer;
|
||||||
|
buffer << file.rdbuf();
|
||||||
|
return eastl::string {buffer.str().c_str()};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheGivenMessage)
|
||||||
|
{
|
||||||
|
constexpr std::source_location location = std::source_location::current();
|
||||||
|
AssertHandler<UTILSTESTS_LOGGER>::Handle(location,
|
||||||
|
eastl::string {fmt::format("Something went wrong: {}", 42).c_str()});
|
||||||
|
|
||||||
|
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Something went wrong: 42"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************************/
|
||||||
|
|
||||||
|
TEST_F(AssertHandlerFixture, Handle_ShouldLogAFatalMessageContainingTheSourceLocation)
|
||||||
|
{
|
||||||
|
constexpr std::source_location location = std::source_location::current();
|
||||||
|
AssertHandler<UTILSTESTS_LOGGER>::Handle(location, "Doesn't matter");
|
||||||
|
|
||||||
|
const std::string content {ReadFileSinkContent().c_str()};
|
||||||
|
EXPECT_THAT(content, ::testing::HasSubstr(location.file_name()));
|
||||||
|
EXPECT_THAT(content, ::testing::HasSubstr(location.function_name()));
|
||||||
|
}
|
||||||
|
} // namespace Bigfoot
|
||||||
|
#endif
|
||||||
@@ -13,6 +13,8 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
GTEST_FLAG_SET(death_test_style, "threadsafe");
|
||||||
|
|
||||||
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
BIGFOOT_NOT_OPTIMIZED_ONLY(::Bigfoot::Singleton<::Bigfoot::Log>::Lifetime m_lifetime);
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ add_library(BigfootCompileAndLinkFlags INTERFACE)
|
|||||||
target_compile_options(BigfootCompileAndLinkFlags INTERFACE
|
target_compile_options(BigfootCompileAndLinkFlags INTERFACE
|
||||||
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
||||||
$<$<CXX_COMPILER_ID:Clang,GNU>:-Wall -Wextra -Wpedantic -Werror>
|
$<$<CXX_COMPILER_ID:Clang,GNU>:-Wall -Wextra -Wpedantic -Werror>
|
||||||
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fcoverage-mapping>
|
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fcoverage-mapping -fprofile-continuous>
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_options(BigfootCompileAndLinkFlags INTERFACE
|
target_link_options(BigfootCompileAndLinkFlags INTERFACE
|
||||||
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate>
|
$<$<AND:$<BOOL:${COVERAGE}>,$<CXX_COMPILER_ID:Clang>>:-fprofile-instr-generate -fprofile-continuous>
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(BigfootCompileAndLinkFlags INTERFACE
|
target_compile_definitions(BigfootCompileAndLinkFlags INTERFACE
|
||||||
|
|||||||
Reference in New Issue
Block a user