Skip to content

Commit

Permalink
Using the common testing library
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu committed Feb 16, 2025
1 parent 3ac6b2b commit 0d1d5d2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 73 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ project(LangulusLogger
if (PROJECT_IS_TOP_LEVEL OR NOT LANGULUS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

include(LangulusUtilities.cmake)

# Add Langulus::Core library
fetch_langulus_module(Core GIT_TAG 35756f11d2f9c475f27b094b8d4c82cd453969fc)
fetch_langulus_module(Core GIT_TAG 9b4f33b768295fb5166acc0e21a2ebb8565a64a6)
endif()

# Configure {fmt} library
fetch_external_module(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 22701d5f63fd9ba3ffa35fe94585b5bfcb69238b # master branch
GIT_TAG 94ab51cb8c63c93220f0cdd1733bdeef95e77d60 # master branch
)

# Build and install Logger library
Expand All @@ -44,6 +41,6 @@ target_link_libraries(LangulusLogger
)

if (LANGULUS_TESTING)
enable_testing()
enable_testing()
add_subdirectory(test)
endif()
30 changes: 23 additions & 7 deletions LangulusUtilities.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
include(FetchContent)


# Utility for fetching Langulus libraries using FetchContent
function(fetch_langulus_module NAME GIT_TAG TAG)
if (LANGULUS)
message(FATAL_ERROR "You can't fetch Langulus::${NAME}, because this build \
indicates LANGULUS is being build along your project. The library you're \
trying to fetch should already be available locally.")
endif()

if(NOT DEFINED LANGULUS_EXTERNAL_DIRECTORY)
set(LANGULUS_EXTERNAL_DIRECTORY "${CMAKE_SOURCE_DIR}/external" CACHE PATH
"Place where external dependencies will be downloaded")
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: \
${LANGULUS_EXTERNAL_DIRECTORY}")
endif()

# Completely avoid downloading or updating anything, once the appropriate folder exists
# Completely avoid downloading or updating anything, once the appropriate
# folder exists
string(TOUPPER ${NAME} UPPERCASE_NAME)
if (EXISTS "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src")
set(FETCHCONTENT_SOURCE_DIR_LANGULUS${UPPERCASE_NAME} "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src" CACHE INTERNAL "" FORCE)
message(STATUS "Reusing external library Langulus::${NAME}... (delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
message(STATUS "Reusing external library Langulus::${NAME}... \
(delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
else()
unset(FETCHCONTENT_SOURCE_DIR_LANGULUS${UPPERCASE_NAME} CACHE)
message(STATUS "Downloading external library Langulus::${NAME}...")
Expand All @@ -28,18 +39,23 @@ function(fetch_langulus_module NAME GIT_TAG TAG)
FetchContent_MakeAvailable(Langulus${NAME})
endfunction()


# Utility for fetching external libraries using FetchContent
function(fetch_external_module NAME GIT_REPOSITORY REPO GIT_TAG TAG)
if(NOT DEFINED LANGULUS_EXTERNAL_DIRECTORY)
set(LANGULUS_EXTERNAL_DIRECTORY "${CMAKE_SOURCE_DIR}/external" CACHE PATH
"Place where external dependencies will be downloaded")
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
message(WARNING "LANGULUS_EXTERNAL_DIRECTORY not defined, \
using default: ${LANGULUS_EXTERNAL_DIRECTORY}")
endif()

# Completely avoid downloading or updating anything, once the appropriate folder exists
# Completely avoid downloading or updating anything, once the appropriate
# folder exists
string(TOUPPER ${NAME} UPPERCASE_NAME)
if (EXISTS "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src")
set(FETCHCONTENT_SOURCE_DIR_${UPPERCASE_NAME} "${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src" CACHE INTERNAL "" FORCE)
message(STATUS "Reusing external library ${NAME}... (delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
message(STATUS "Reusing external library ${NAME}... \
(delete ${LANGULUS_EXTERNAL_DIRECTORY}/${NAME}-src manually in order to redownload)")
else()
unset(FETCHCONTENT_SOURCE_DIR_${UPPERCASE_NAME} CACHE)
message(STATUS "Downloading external library ${NAME}...")
Expand All @@ -59,4 +75,4 @@ function(fetch_external_module NAME GIT_REPOSITORY REPO GIT_TAG TAG)
string(TOLOWER ${NAME} LOWERCASE_NAME)
set(${NAME}_SOURCE_DIR "${${LOWERCASE_NAME}_SOURCE_DIR}" CACHE INTERNAL "${NAME} source directory")
set(${NAME}_BINARY_DIR "${${LOWERCASE_NAME}_BINARY_DIR}" CACHE INTERNAL "${NAME} binary directory")
endfunction()
endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
/// SPDX-License-Identifier: MIT
///
#pragma once
#include "../../../source/Logger.hpp"
#include "../../source/Logger.hpp"
18 changes: 7 additions & 11 deletions source/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
/// SPDX-License-Identifier: MIT
///
#pragma once
#include <Langulus/Core/Exceptions.hpp>
#include <Langulus/Core/Common.hpp>
#include <Langulus/Core/Byte.hpp>

#if defined(LANGULUS_EXPORT_ALL) or defined(LANGULUS_EXPORT_LOGGER)
#define LANGULUS_API_LOGGER() LANGULUS_EXPORT()
Expand Down Expand Up @@ -619,23 +620,18 @@ namespace fmt
{

///
/// Extend FMT to be capable of logging any exception
/// Extend FMT to be capable of logging Byte
///
template<::Langulus::CT::Exception T>
struct formatter<T> {
template<>
struct formatter<::Langulus::Byte> {
template<class CONTEXT>
constexpr auto parse(CONTEXT& ctx) {
return ctx.begin();
}

template<class CONTEXT> LANGULUS(INLINED)
auto format(T const& e, CONTEXT& ctx) const {
#if LANGULUS(DEBUG)
return ::fmt::format_to(ctx.out(), "{}({} at {})",
e.GetName(), e.GetMessage(), e.GetLocation());
#else
return ::fmt::format_to(ctx.out(), "{}", e.GetName());
#endif
auto format(::Langulus::Byte const& e, CONTEXT& ctx) const {
return fmt::format_to(ctx.out(), "{:02X}", e.mValue);
}
};

Expand Down
24 changes: 0 additions & 24 deletions test/Main.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions test/Main.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions test/TestLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
///
/// SPDX-License-Identifier: MIT
///
#include "Main.hpp"
#include <catch2/catch.hpp>
#include <Langulus/Logger.hpp>
#include <Langulus/Testing.hpp>


SCENARIO("Logging to console", "[logger]") {
Expand Down

0 comments on commit 0d1d5d2

Please sign in to comment.