From 58003f68894d4f0c42ca30e3a32fa245db8d8036 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 29 Oct 2026 09:24:10 +0000 Subject: kstd: add Catch2 string makers for printable test output Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 5 +- cspell.json | 1 + libs/kstd/CMakeLists.txt | 4 + libs/kstd/kstd/test_support/os_panic.tests.cpp | 2 +- libs/kstd/kstd/test_support/string_makers.hpp | 180 +++++++++++++++++++++ .../kstd/kstd/test_support/string_makers.tests.cpp | 94 +++++++++++ 6 files changed, 284 insertions(+), 2 deletions(-) create mode 100644 libs/kstd/kstd/test_support/string_makers.hpp create mode 100644 libs/kstd/kstd/test_support/string_makers.tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1323efc3..a6950a3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,10 @@ if (BUILD_TESTING) FetchContent_MakeAvailable("Catch2") - add_compile_definitions("CATCH_CONFIG_NO_COUNTER") + add_compile_definitions( + "CATCH_CONFIG_NO_COUNTER" + "CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS" + ) endif() #[============================================================================[ diff --git a/cspell.json b/cspell.json index e288dfaf..94a85529 100644 --- a/cspell.json +++ b/cspell.json @@ -20,6 +20,7 @@ "hhdm", "idtr", "initializable", + "insertable", "interprocedural", "invlpg", "invokable", diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index 1902d0d9..d7af1952 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -83,6 +83,10 @@ if(BUILD_TESTING) teachos_add_tests("kstd") + target_compile_options("kstd_tests" PRIVATE + "SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kstd/test_support/string_makers.hpp" + ) + if(COMMAND "enable_coverage" AND KSTD_ENABLE_TEST_COVERAGE) enable_coverage("kstd") enable_coverage("kstd_tests") diff --git a/libs/kstd/kstd/test_support/os_panic.tests.cpp b/libs/kstd/kstd/test_support/os_panic.tests.cpp index c30411aa..17af74a7 100644 --- a/libs/kstd/kstd/test_support/os_panic.tests.cpp +++ b/libs/kstd/kstd/test_support/os_panic.tests.cpp @@ -7,7 +7,7 @@ namespace kstd::os { - auto panic(std::string_view message, std::source_location location) + auto panic(std::string_view message, std::source_location location) -> void { throw kstd::tests::os_panic{std::string{message}, location}; } diff --git a/libs/kstd/kstd/test_support/string_makers.hpp b/libs/kstd/kstd/test_support/string_makers.hpp new file mode 100644 index 00000000..c2c6a38a --- /dev/null +++ b/libs/kstd/kstd/test_support/string_makers.hpp @@ -0,0 +1,180 @@ +#ifndef KSTD_TEST_SUPPORT_STRING_MAKERS_HPP +#define KSTD_TEST_SUPPORT_STRING_MAKERS_HPP + +//! Catch2 string conversions for kstd types. +//! +//! Catch2 prints values it does not know how to convert as "{?}". This header teaches Catch2 how to print kstd types, +//! so that failed assertions show the actual values. It is force-included into every test translation unit by the +//! build system and must therefore never be included by kernel code. +//! +//! Any type with a kstd::formatter specialization is printed via kstd::format, so the easiest way to make a type +//! printable in tests is to give it a formatter. Types without a formatter can get a Catch::StringMaker specialization +//! here, or in the test support header of the library they belong to. + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace kstd::tests +{ + + //! A type that can be printed via kstd::format. + template + concept kstd_formattable = std::default_initializable>>; + + //! A type that can be written to a std::ostream. + template + concept stream_insertable = requires(std::ostream & stream, T const & value) { stream << value; }; + + //! A type that Catch2 can not print on its own, but which is printable via kstd::format. + //! + //! Types that are stream insertable, pointers, arrays, and ranges are handled by Catch2 already. They are excluded + //! before checking for a formatter, since probing the formatter of a range with unformattable elements is a hard + //! error. + template + concept catch_printable_via_kstd = + !std::ranges::range && !Catch::is_range::value && !std::is_pointer_v && !std::is_array_v && + !std::is_arithmetic_v && !stream_insertable && kstd_formattable; + + //! Convert a kstd string to a std::string. + inline auto to_std_string(kstd::string const & string) -> std::string + { + return std::string{string.data(), string.size()}; + } + + //! Convert an error code or error condition to its textual representation, e.g. "generic:22:invalid argument". + template + auto error_to_string(ErrorType const & error) -> std::string + { + return std::string{error.category().name()} + ':' + std::to_string(error.value()) + ':' + + std::string{error.message()}; + } + + //! Convert a smart pointer to the same textual representation Catch2 uses for raw pointers. + template + auto pointer_to_string(Pointer const & pointer) -> std::string + { + return Catch::Detail::stringify(pointer.get()); + } + +} // namespace kstd::tests + +namespace Catch +{ + + template + struct StringMaker + { + static auto convert(T const & value) -> std::string + { + return kstd::tests::to_std_string(kstd::format("{}", value)); + } + }; + + template<> + struct StringMaker + { + static auto convert(kstd::string const & value) -> std::string + { + return Catch::Detail::stringify(kstd::tests::to_std_string(value)); + } + }; + + template<> + struct StringMaker + { + static auto convert(kstd::error_category const & category) -> std::string + { + return std::string{category.name()}; + } + }; + + template<> + struct StringMaker + { + static auto convert(kstd::error_condition const & condition) -> std::string + { + return kstd::tests::error_to_string(condition); + } + }; + + template + struct StringMaker + { + static auto convert(Enum value) -> std::string + { + return kstd::tests::error_to_string(kstd::error_code{value}); + } + }; + + template + requires(!kstd::error_code_enum) + struct StringMaker + { + static auto convert(Enum value) -> std::string + { + return kstd::tests::error_to_string(make_error_condition(value)); + } + }; + + template + struct StringMaker> + { + static auto convert(kstd::shared_ptr const & pointer) -> std::string + { + return kstd::tests::pointer_to_string(pointer); + } + }; + + template + struct StringMaker> + { + static auto convert(kstd::unique_ptr const & pointer) -> std::string + { + return kstd::tests::pointer_to_string(pointer); + } + }; + + template + struct StringMaker> + { + static auto convert(kstd::observer_ptr const & pointer) -> std::string + { + return kstd::tests::pointer_to_string(pointer); + } + }; + + template + struct StringMaker> + { + static auto convert(std::expected const & expected) -> std::string + { + if (!expected) + { + return "error(" + Catch::Detail::stringify(expected.error()) + ')'; + } + + if constexpr (std::is_void_v) + { + return "value()"; + } + else + { + return "value(" + Catch::Detail::stringify(*expected) + ')'; + } + } + }; + +} // namespace Catch + +#endif diff --git a/libs/kstd/kstd/test_support/string_makers.tests.cpp b/libs/kstd/kstd/test_support/string_makers.tests.cpp new file mode 100644 index 00000000..887bec37 --- /dev/null +++ b/libs/kstd/kstd/test_support/string_makers.tests.cpp @@ -0,0 +1,94 @@ +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +using namespace kstd::units_literals; + +SCENARIO("Catch2 string conversion of kstd types", "[test_support][string_makers]") +{ + GIVEN("a kstd string") + { + auto const string = kstd::string{"hello"}; + + THEN("it is printed like a std::string") + { + REQUIRE(Catch::Detail::stringify(string) == "\"hello\""); + } + } + + GIVEN("a type with a kstd formatter") + { + THEN("it is printed via kstd::format") + { + REQUIRE(Catch::Detail::stringify(42_B) == "42"); + REQUIRE(Catch::Detail::stringify(std::strong_ordering::less) == "less"); + } + } + + GIVEN("an error code") + { + auto const error = kstd::make_error_code(kstd::errc::invalid_argument); + + THEN("it is printed with its category, value, and message") + { + REQUIRE(Catch::Detail::stringify(error) == kstd::tests::error_to_string(error)); + REQUIRE(Catch::Detail::stringify(error).starts_with(std::string{error.category().name()} + ':')); + } + } + + GIVEN("an error condition enumerator") + { + THEN("it is printed like the matching error condition") + { + REQUIRE(Catch::Detail::stringify(kstd::errc::invalid_argument) == + kstd::tests::error_to_string(kstd::make_error_condition(kstd::errc::invalid_argument))); + } + } + + GIVEN("a successful result") + { + auto const result = kstd::result{42}; + auto const void_result = kstd::result{}; + + THEN("it is printed as value(...)") + { + REQUIRE(Catch::Detail::stringify(result) == "value(42)"); + REQUIRE(Catch::Detail::stringify(void_result) == "value()"); + } + } + + GIVEN("a failed result") + { + auto const error = kstd::make_error_code(kstd::errc::invalid_argument); + auto const result = kstd::result{std::unexpect, error}; + + THEN("it is printed as error(...)") + { + REQUIRE(Catch::Detail::stringify(result) == "error(" + Catch::Detail::stringify(error) + ')'); + } + } + + GIVEN("smart pointers") + { + auto const empty = kstd::shared_ptr{}; + auto const shared = kstd::make_shared(1); + auto const observer = kstd::observer_ptr{shared.get()}; + + THEN("they are printed like raw pointers") + { + REQUIRE(Catch::Detail::stringify(empty) == "nullptr"); + REQUIRE(Catch::Detail::stringify(shared) == Catch::Detail::stringify(shared.get())); + REQUIRE(Catch::Detail::stringify(observer) == Catch::Detail::stringify(shared.get())); + } + } +} -- cgit v1.2.3 From a3efa856d0deba35609aa68656e510c2cf033f26 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 29 Oct 2026 09:24:10 +0000 Subject: kernel: add Catch2 string makers for printable test output Co-Authored-By: Claude Opus 5.5 --- kernel/CMakeLists.txt | 4 + kernel/kernel/test_support/string_makers.hpp | 132 +++++++++++++++++++++ kernel/kernel/test_support/string_makers.tests.cpp | 61 ++++++++++ 3 files changed, 197 insertions(+) create mode 100644 kernel/kernel/test_support/string_makers.hpp create mode 100644 kernel/kernel/test_support/string_makers.tests.cpp diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 341f396a..eb14f619 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -184,6 +184,10 @@ if(BUILD_TESTING) ${KERNEL_TEST_SUPPORT_SOURCES} ) + target_compile_options("${TEST_TARGET}" PRIVATE + "SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kernel/test_support/string_makers.hpp" + ) + target_compile_definitions("${TEST_TARGET}" PRIVATE KERNEL_TEST_ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/kernel/test_support/vfs/test_assets" ) diff --git a/kernel/kernel/test_support/string_makers.hpp b/kernel/kernel/test_support/string_makers.hpp new file mode 100644 index 00000000..98eed3e8 --- /dev/null +++ b/kernel/kernel/test_support/string_makers.hpp @@ -0,0 +1,132 @@ +#ifndef TEACHOS_KERNEL_TEST_SUPPORT_STRING_MAKERS_HPP +#define TEACHOS_KERNEL_TEST_SUPPORT_STRING_MAKERS_HPP + +//! Catch2 string conversions for kapi and kernel types. +//! +//! This header is force-included into every kernel test translation unit by the build system and must therefore never +//! be included by kernel code. See kstd/test_support/string_makers.hpp for the conversions of kstd types. + +#include // IWYU pragma: export + +#include +#include +#include + +#include + +#include + +namespace Catch +{ + + template<> + struct StringMaker + { + static auto convert(kapi::filesystem::device_number number) -> std::string + { + return std::to_string(number.major) + ':' + std::to_string(number.minor); + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::filesystem::directory_cursor cursor) -> std::string + { + return "directory_cursor{" + std::to_string(cursor.value) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::filesystem::file_status const & status) -> std::string + { + return "file_status{mode: " + Catch::Detail::stringify(status.mode) + + ", size: " + Catch::Detail::stringify(status.size) + + ", raw_device: " + Catch::Detail::stringify(status.raw_device) + + ", inode_number: " + Catch::Detail::stringify(status.inode_number) + + ", link_count: " + Catch::Detail::stringify(status.link_count) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::memory::frame frame) -> std::string + { + return "frame{" + std::to_string(frame.number()) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::memory::page page) -> std::string + { + return "page{" + std::to_string(page.number()) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::devices::mmio_range const & range) -> std::string + { + return "mmio{" + Catch::Detail::stringify(range.start) + ", " + Catch::Detail::stringify(range.size) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::devices::io_port const & port) -> std::string + { + return "port{" + std::to_string(port.start) + ", " + std::to_string(port.count) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::devices::interrupt_line const & line) -> std::string + { + return "irq{" + std::to_string(line.number) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::devices::dma_channel const & channel) -> std::string + { + return "dma{" + std::to_string(channel.number) + '}'; + } + }; + + template<> + struct StringMaker + { + static auto convert(kapi::devices::resource const & resource) -> std::string + { + using kapi::devices::resource_type; + + switch (resource.type) + { + case resource_type::mmio: + return Catch::Detail::stringify(resource.get()); + case resource_type::port: + return Catch::Detail::stringify(resource.get()); + case resource_type::irq: + return Catch::Detail::stringify(resource.get()); + case resource_type::dma: + return Catch::Detail::stringify(resource.get()); + } + + return "resource{}"; + } + }; + +} // namespace Catch + +#endif diff --git a/kernel/kernel/test_support/string_makers.tests.cpp b/kernel/kernel/test_support/string_makers.tests.cpp new file mode 100644 index 00000000..1bcb332f --- /dev/null +++ b/kernel/kernel/test_support/string_makers.tests.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include +#include + +#include + +#include +#include + +using namespace kstd::units_literals; + +SCENARIO("Catch2 string conversion of kapi types", "[test_support][string_makers]") +{ + GIVEN("filesystem types") + { + auto const number = kapi::filesystem::device_number{.major = 1, .minor = 2}; + auto const cursor = kapi::filesystem::directory_cursor{3}; + auto const status = kapi::filesystem::file_status{ + .mode = 4, .size = 5_B, .raw_device = number, .inode_number = 6, .link_count = 7}; + + THEN("they are printed with their fields") + { + REQUIRE(Catch::Detail::stringify(number) == "1:2"); + REQUIRE(Catch::Detail::stringify(cursor) == "directory_cursor{3}"); + REQUIRE(Catch::Detail::stringify(status) == + "file_status{mode: 4, size: 5, raw_device: 1:2, inode_number: 6, link_count: 7}"); + } + } + + GIVEN("memory chunks") + { + THEN("they are printed with their number") + { + REQUIRE(Catch::Detail::stringify(kapi::memory::frame{8}) == "frame{8}"); + REQUIRE(Catch::Detail::stringify(kapi::memory::page{9}) == "page{9}"); + } + } + + GIVEN("device resources") + { + auto const port = kapi::devices::io_port{.start = 0x60, .count = 2}; + auto const line = kapi::devices::interrupt_line{.number = 1}; + auto const channel = kapi::devices::dma_channel{.number = 3}; + + THEN("they are printed with their kind and fields") + { + REQUIRE(Catch::Detail::stringify(port) == "port{96, 2}"); + REQUIRE(Catch::Detail::stringify(line) == "irq{1}"); + REQUIRE(Catch::Detail::stringify(channel) == "dma{3}"); + } + + THEN("a resource is printed like the value it holds") + { + REQUIRE(Catch::Detail::stringify(kapi::devices::resource{port}) == "port{96, 2}"); + REQUIRE(Catch::Detail::stringify(kapi::devices::resource{line}) == "irq{1}"); + REQUIRE(Catch::Detail::stringify(kapi::devices::resource{channel}) == "dma{3}"); + } + } +} -- cgit v1.2.3 From 9f8376981c6749b9420e3d319b29e9e78de49423 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 29 Oct 2026 09:24:10 +0000 Subject: doc: describe how to make types printable in test failures Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 2dbd613c..1ea69ee6 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -54,6 +54,16 @@ For thread-safety and race condition analysis under ThreadSanitizer: cmake --build --preset bht-stress-dbg ctest --preset bht-stress-dbg +Printing Values in Test Failures +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Catch2 prints values it cannot convert as ``{?}``. +To avoid that, every test translation unit force-includes ``kstd/test_support/string_makers.hpp`` (kstd tests) or ``kernel/test_support/string_makers.hpp`` (kernel tests), which teach Catch2 how to print our types without touching kernel code. +To make a new type printable in tests, either: + +* give it a ``kstd::formatter`` specialization, which is picked up automatically, or +* add a ``Catch::StringMaker`` specialization to the ``string_makers.hpp`` of the library the type belongs to. + Bootable Kernel Targets ~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From cb05568db24efc9fd0b33e9d0094256e1b678e69 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 31 Oct 2026 09:54:17 +0000 Subject: doc: require StringMaker instead of formatter for test printing --- CONTRIBUTING.rst | 7 +++---- libs/kstd/kstd/test_support/string_makers.hpp | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 1ea69ee6..dabc2552 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -59,10 +59,9 @@ Printing Values in Test Failures Catch2 prints values it cannot convert as ``{?}``. To avoid that, every test translation unit force-includes ``kstd/test_support/string_makers.hpp`` (kstd tests) or ``kernel/test_support/string_makers.hpp`` (kernel tests), which teach Catch2 how to print our types without touching kernel code. -To make a new type printable in tests, either: - -* give it a ``kstd::formatter`` specialization, which is picked up automatically, or -* add a ``Catch::StringMaker`` specialization to the ``string_makers.hpp`` of the library the type belongs to. +To make a new type printable in tests, add a ``Catch::StringMaker`` specialization to the ``string_makers.hpp`` of the library the type belongs to. +Do not add or change anything in kernel code (e.g. a ``kstd::formatter``) just to make a type printable in tests. +Types that already have a ``kstd::formatter`` are printed through it automatically. Bootable Kernel Targets ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/libs/kstd/kstd/test_support/string_makers.hpp b/libs/kstd/kstd/test_support/string_makers.hpp index c2c6a38a..46d270f9 100644 --- a/libs/kstd/kstd/test_support/string_makers.hpp +++ b/libs/kstd/kstd/test_support/string_makers.hpp @@ -7,9 +7,9 @@ //! so that failed assertions show the actual values. It is force-included into every test translation unit by the //! build system and must therefore never be included by kernel code. //! -//! Any type with a kstd::formatter specialization is printed via kstd::format, so the easiest way to make a type -//! printable in tests is to give it a formatter. Types without a formatter can get a Catch::StringMaker specialization -//! here, or in the test support header of the library they belong to. +//! Types that already have a kstd::formatter specialization are printed via kstd::format. All other types get a +//! Catch::StringMaker specialization here, or in the test support header of the library they belong to. Kernel code +//! must never be changed just to make a type printable in tests. #include #include -- cgit v1.2.3 From 1415e1e7e0011b0c9f42978f013a5d79007bf255 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 12 Nov 2026 07:27:58 +0000 Subject: test: apply review feedback for Catch2 string makers - restrict the -include force-include flag to GCC and Clang - drop the redundant explicit include in the kernel string maker tests - apply clang-format Co-Authored-By: Claude Opus 5.5 --- kernel/CMakeLists.txt | 2 +- kernel/kernel/test_support/string_makers.hpp | 24 +++++++++++----------- kernel/kernel/test_support/string_makers.tests.cpp | 6 ++---- libs/kstd/CMakeLists.txt | 2 +- libs/kstd/kstd/test_support/string_makers.hpp | 22 ++++++++++---------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index eb14f619..2ed3ac62 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -185,7 +185,7 @@ if(BUILD_TESTING) ) target_compile_options("${TEST_TARGET}" PRIVATE - "SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kernel/test_support/string_makers.hpp" + "$<$:SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kernel/test_support/string_makers.hpp>" ) target_compile_definitions("${TEST_TARGET}" PRIVATE diff --git a/kernel/kernel/test_support/string_makers.hpp b/kernel/kernel/test_support/string_makers.hpp index 98eed3e8..c158ac3a 100644 --- a/kernel/kernel/test_support/string_makers.hpp +++ b/kernel/kernel/test_support/string_makers.hpp @@ -6,12 +6,12 @@ //! This header is force-included into every kernel test translation unit by the build system and must therefore never //! be included by kernel code. See kstd/test_support/string_makers.hpp for the conversions of kstd types. -#include // IWYU pragma: export - #include #include #include +#include // IWYU pragma: export + #include #include @@ -22,7 +22,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::filesystem::device_number number) -> std::string + auto static convert(kapi::filesystem::device_number number) -> std::string { return std::to_string(number.major) + ':' + std::to_string(number.minor); } @@ -31,7 +31,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::filesystem::directory_cursor cursor) -> std::string + auto static convert(kapi::filesystem::directory_cursor cursor) -> std::string { return "directory_cursor{" + std::to_string(cursor.value) + '}'; } @@ -40,7 +40,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::filesystem::file_status const & status) -> std::string + auto static convert(kapi::filesystem::file_status const & status) -> std::string { return "file_status{mode: " + Catch::Detail::stringify(status.mode) + ", size: " + Catch::Detail::stringify(status.size) + @@ -53,7 +53,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::memory::frame frame) -> std::string + auto static convert(kapi::memory::frame frame) -> std::string { return "frame{" + std::to_string(frame.number()) + '}'; } @@ -62,7 +62,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::memory::page page) -> std::string + auto static convert(kapi::memory::page page) -> std::string { return "page{" + std::to_string(page.number()) + '}'; } @@ -71,7 +71,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::devices::mmio_range const & range) -> std::string + auto static convert(kapi::devices::mmio_range const & range) -> std::string { return "mmio{" + Catch::Detail::stringify(range.start) + ", " + Catch::Detail::stringify(range.size) + '}'; } @@ -80,7 +80,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::devices::io_port const & port) -> std::string + auto static convert(kapi::devices::io_port const & port) -> std::string { return "port{" + std::to_string(port.start) + ", " + std::to_string(port.count) + '}'; } @@ -89,7 +89,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::devices::interrupt_line const & line) -> std::string + auto static convert(kapi::devices::interrupt_line const & line) -> std::string { return "irq{" + std::to_string(line.number) + '}'; } @@ -98,7 +98,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::devices::dma_channel const & channel) -> std::string + auto static convert(kapi::devices::dma_channel const & channel) -> std::string { return "dma{" + std::to_string(channel.number) + '}'; } @@ -107,7 +107,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kapi::devices::resource const & resource) -> std::string + auto static convert(kapi::devices::resource const & resource) -> std::string { using kapi::devices::resource_type; diff --git a/kernel/kernel/test_support/string_makers.tests.cpp b/kernel/kernel/test_support/string_makers.tests.cpp index 1bcb332f..3c3cd791 100644 --- a/kernel/kernel/test_support/string_makers.tests.cpp +++ b/kernel/kernel/test_support/string_makers.tests.cpp @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -17,8 +15,8 @@ SCENARIO("Catch2 string conversion of kapi types", "[test_support][string_makers { auto const number = kapi::filesystem::device_number{.major = 1, .minor = 2}; auto const cursor = kapi::filesystem::directory_cursor{3}; - auto const status = kapi::filesystem::file_status{ - .mode = 4, .size = 5_B, .raw_device = number, .inode_number = 6, .link_count = 7}; + auto const status = + kapi::filesystem::file_status{.mode = 4, .size = 5_B, .raw_device = number, .inode_number = 6, .link_count = 7}; THEN("they are printed with their fields") { diff --git a/libs/kstd/CMakeLists.txt b/libs/kstd/CMakeLists.txt index d7af1952..c6e02223 100644 --- a/libs/kstd/CMakeLists.txt +++ b/libs/kstd/CMakeLists.txt @@ -84,7 +84,7 @@ if(BUILD_TESTING) teachos_add_tests("kstd") target_compile_options("kstd_tests" PRIVATE - "SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kstd/test_support/string_makers.hpp" + "$<$:SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/kstd/test_support/string_makers.hpp>" ) if(COMMAND "enable_coverage" AND KSTD_ENABLE_TEST_COVERAGE) diff --git a/libs/kstd/kstd/test_support/string_makers.hpp b/libs/kstd/kstd/test_support/string_makers.hpp index 46d270f9..03a7f8c8 100644 --- a/libs/kstd/kstd/test_support/string_makers.hpp +++ b/libs/kstd/kstd/test_support/string_makers.hpp @@ -47,7 +47,7 @@ namespace kstd::tests !std::is_arithmetic_v && !stream_insertable && kstd_formattable; //! Convert a kstd string to a std::string. - inline auto to_std_string(kstd::string const & string) -> std::string + auto inline to_std_string(kstd::string const & string) -> std::string { return std::string{string.data(), string.size()}; } @@ -75,7 +75,7 @@ namespace Catch template struct StringMaker { - static auto convert(T const & value) -> std::string + auto static convert(T const & value) -> std::string { return kstd::tests::to_std_string(kstd::format("{}", value)); } @@ -84,7 +84,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kstd::string const & value) -> std::string + auto static convert(kstd::string const & value) -> std::string { return Catch::Detail::stringify(kstd::tests::to_std_string(value)); } @@ -93,7 +93,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kstd::error_category const & category) -> std::string + auto static convert(kstd::error_category const & category) -> std::string { return std::string{category.name()}; } @@ -102,7 +102,7 @@ namespace Catch template<> struct StringMaker { - static auto convert(kstd::error_condition const & condition) -> std::string + auto static convert(kstd::error_condition const & condition) -> std::string { return kstd::tests::error_to_string(condition); } @@ -111,7 +111,7 @@ namespace Catch template struct StringMaker { - static auto convert(Enum value) -> std::string + auto static convert(Enum value) -> std::string { return kstd::tests::error_to_string(kstd::error_code{value}); } @@ -121,7 +121,7 @@ namespace Catch requires(!kstd::error_code_enum) struct StringMaker { - static auto convert(Enum value) -> std::string + auto static convert(Enum value) -> std::string { return kstd::tests::error_to_string(make_error_condition(value)); } @@ -130,7 +130,7 @@ namespace Catch template struct StringMaker> { - static auto convert(kstd::shared_ptr const & pointer) -> std::string + auto static convert(kstd::shared_ptr const & pointer) -> std::string { return kstd::tests::pointer_to_string(pointer); } @@ -139,7 +139,7 @@ namespace Catch template struct StringMaker> { - static auto convert(kstd::unique_ptr const & pointer) -> std::string + auto static convert(kstd::unique_ptr const & pointer) -> std::string { return kstd::tests::pointer_to_string(pointer); } @@ -148,7 +148,7 @@ namespace Catch template struct StringMaker> { - static auto convert(kstd::observer_ptr const & pointer) -> std::string + auto static convert(kstd::observer_ptr const & pointer) -> std::string { return kstd::tests::pointer_to_string(pointer); } @@ -157,7 +157,7 @@ namespace Catch template struct StringMaker> { - static auto convert(std::expected const & expected) -> std::string + auto static convert(std::expected const & expected) -> std::string { if (!expected) { -- cgit v1.2.3