From b7f27912257bc1db3b74adac36482eae45ddeef6 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Tue, 21 Nov 2023 22:44:59 +0200 Subject: [PATCH] re-format --- include/micro-os-plus/detail.h | 78 +++++++++++-------- include/micro-os-plus/inlines.h | 13 ++-- include/micro-os-plus/literals.h | 72 +++++++++++------ include/micro-os-plus/micro-test-plus.h | 66 ++++++++-------- include/micro-os-plus/reflection.h | 10 +-- include/micro-os-plus/test-reporter-inlines.h | 4 +- include/micro-os-plus/test-reporter.h | 9 ++- include/micro-os-plus/type-traits.h | 29 ++++--- src/test-reporter.cpp | 4 +- 9 files changed, 164 insertions(+), 121 deletions(-) diff --git a/include/micro-os-plus/detail.h b/include/micro-os-plus/detail.h index c4a5615..c56f4e8 100644 --- a/include/micro-os-plus/detail.h +++ b/include/micro-os-plus/detail.h @@ -117,16 +117,15 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { // If both types have values (like numeric constants), // compare them directly. return Lhs_T::value == Rhs_T::value; } - else if constexpr ( - type_traits::has_epsilon_v< - Lhs_T> and type_traits::has_epsilon_v) + else if constexpr (type_traits::has_epsilon_v + and type_traits::has_epsilon_v) { // If both values have precision, compare them using // the smalles precision. @@ -156,7 +155,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -201,14 +201,13 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { return Lhs_T::value != Rhs_T::value; } - else if constexpr ( - type_traits::has_epsilon_v< - Lhs_T> and type_traits::has_epsilon_v) + else if constexpr (type_traits::has_epsilon_v + and type_traits::has_epsilon_v) { return math::abs (get (lhs_) - get (rhs_)) > math::min_value (Lhs_T::epsilon, Rhs_T::epsilon); @@ -232,7 +231,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -272,8 +272,8 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { return Lhs_T::value > Rhs_T::value; } @@ -288,7 +288,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -328,8 +329,8 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { return Lhs_T::value >= Rhs_T::value; } @@ -344,7 +345,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -384,8 +386,8 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { return Lhs_T::value < Rhs_T::value; } @@ -400,7 +402,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -441,8 +444,8 @@ namespace micro_os_plus::micro_test_plus #pragma clang diagnostic ignored "-Wpedantic" #endif #endif - if constexpr (type_traits::has_value_v< - Lhs_T> and type_traits::has_value_v) + if constexpr (type_traits::has_value_v + and type_traits::has_value_v) { return Lhs_T::value <= Rhs_T::value; } @@ -457,7 +460,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -486,12 +490,13 @@ namespace micro_os_plus::micro_test_plus struct and_ : type_traits::op { constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {}) - : lhs_{ lhs }, rhs_{ rhs }, value_{ static_cast (lhs) - and static_cast (rhs) } + : lhs_{ lhs }, rhs_{ rhs }, + value_{ static_cast (lhs) and static_cast (rhs) } { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -520,12 +525,13 @@ namespace micro_os_plus::micro_test_plus struct or_ : type_traits::op { constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {}) - : lhs_{ lhs }, rhs_{ rhs }, value_{ static_cast (lhs) - or static_cast (rhs) } + : lhs_{ lhs }, rhs_{ rhs }, + value_{ static_cast (lhs) or static_cast (rhs) } { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -558,7 +564,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -599,7 +606,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -628,7 +636,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } @@ -657,7 +666,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr operator bool () const + [[nodiscard]] constexpr + operator bool () const { return value_; } diff --git a/include/micro-os-plus/inlines.h b/include/micro-os-plus/inlines.h index 9b86a4f..aabb06b 100644 --- a/include/micro-os-plus/inlines.h +++ b/include/micro-os-plus/inlines.h @@ -40,8 +40,8 @@ namespace micro_os_plus::micro_test_plus template test_suite::test_suite (const char* name, Callable_T&& callable, Args_T&&... arguments) - : test_suite_base{ name }, callable_{ std::bind (callable, - arguments...) } + : test_suite_base{ name }, + callable_{ std::bind (callable, arguments...) } { #if defined(MICRO_TEST_PLUS_TRACE) printf ("%s\n", __PRETTY_FUNCTION__); @@ -54,14 +54,14 @@ namespace micro_os_plus::micro_test_plus template void - test_case (const char* name, Callable_T&& func, Args_T&&... arguments) + test_case (const char* name, Callable_T&& callable, Args_T&&... arguments) { #if 0 // defined(MICRO_TEST_PLUS_TRACE) printf ("%s\n", __PRETTY_FUNCTION__); #endif // MICRO_TEST_PLUS_TRACE current_test_suite->begin_test_case (name); - std::invoke (std::forward (func), + std::invoke (std::forward (callable), std::forward (arguments)...); current_test_suite->end_test_case (); } @@ -92,9 +92,8 @@ namespace micro_os_plus::micro_test_plus constexpr deferred_reporter::deferred_reporter ( const Expr_T& expr, bool abort, const reflection::source_location& location) - : deferred_reporter_base{ static_cast (expr), location }, expr_{ - expr - } + : deferred_reporter_base{ static_cast (expr), location }, + expr_{ expr } { #if 0 // defined(MICRO_TEST_PLUS_TRACE) printf ("%s\n", __PRETTY_FUNCTION__); diff --git a/include/micro-os-plus/literals.h b/include/micro-os-plus/literals.h index e1787ba..869dc9b 100644 --- a/include/micro-os-plus/literals.h +++ b/include/micro-os-plus/literals.h @@ -49,134 +49,154 @@ namespace micro_os_plus::micro_test_plus namespace literals { template - [[nodiscard]] constexpr auto operator""_i () + [[nodiscard]] constexpr auto + operator""_i () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_s () + [[nodiscard]] constexpr auto + operator""_s () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_c () + [[nodiscard]] constexpr auto + operator""_c () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_sc () + [[nodiscard]] constexpr auto + operator""_sc () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_l () + [[nodiscard]] constexpr auto + operator""_l () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_ll () + [[nodiscard]] constexpr auto + operator""_ll () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_u () + [[nodiscard]] constexpr auto + operator""_u () { return type_traits::integral_constant ()>{}; } template - [[nodiscard]] constexpr auto operator""_uc () + [[nodiscard]] constexpr auto + operator""_uc () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_us () + [[nodiscard]] constexpr auto + operator""_us () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_ul () + [[nodiscard]] constexpr auto + operator""_ul () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_ull () + [[nodiscard]] constexpr auto + operator""_ull () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_i8 () + [[nodiscard]] constexpr auto + operator""_i8 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_i16 () + [[nodiscard]] constexpr auto + operator""_i16 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_i32 () + [[nodiscard]] constexpr auto + operator""_i32 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_i64 () + [[nodiscard]] constexpr auto + operator""_i64 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_u8 () + [[nodiscard]] constexpr auto + operator""_u8 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_u16 () + [[nodiscard]] constexpr auto + operator""_u16 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_u32 () + [[nodiscard]] constexpr auto + operator""_u32 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_u64 () + [[nodiscard]] constexpr auto + operator""_u64 () { return type_traits::integral_constant< math::num ()>{}; } template - [[nodiscard]] constexpr auto operator""_f () + [[nodiscard]] constexpr auto + operator""_f () { return type_traits::floating_point_constant< float, math::num (), @@ -185,7 +205,8 @@ namespace micro_os_plus::micro_test_plus } template - [[nodiscard]] constexpr auto operator""_d () + [[nodiscard]] constexpr auto + operator""_d () { return type_traits::floating_point_constant< double, math::num (), @@ -194,7 +215,8 @@ namespace micro_os_plus::micro_test_plus } template - [[nodiscard]] constexpr auto operator""_ld () + [[nodiscard]] constexpr auto + operator""_ld () { return type_traits::floating_point_constant< long double, math::num (), @@ -202,12 +224,14 @@ namespace micro_os_plus::micro_test_plus math::den_size ()>{}; } - constexpr auto operator""_b (const char* name, decltype (sizeof ("")) size) + constexpr auto + operator""_b (const char* name, decltype (sizeof ("")) size) { struct named : std::string_view, type_traits::op { using value_type = bool; - [[nodiscard]] constexpr operator value_type () const + [[nodiscard]] constexpr + operator value_type () const { return true; } diff --git a/include/micro-os-plus/micro-test-plus.h b/include/micro-os-plus/micro-test-plus.h index c655f77..56f445d 100644 --- a/include/micro-os-plus/micro-test-plus.h +++ b/include/micro-os-plus/micro-test-plus.h @@ -383,10 +383,10 @@ namespace micro_os_plus::micro_test_plus * @brief Equality operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator== (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -397,10 +397,10 @@ namespace micro_os_plus::micro_test_plus * @brief Non-equality operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator!= (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -411,10 +411,10 @@ namespace micro_os_plus::micro_test_plus * @brief Greater than operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator> (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -425,10 +425,10 @@ namespace micro_os_plus::micro_test_plus * @brief Greater than or equal operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator>= (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -439,10 +439,10 @@ namespace micro_os_plus::micro_test_plus * @brief Less than operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator< (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -453,10 +453,10 @@ namespace micro_os_plus::micro_test_plus * @brief Less than or equal operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator<= (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -467,10 +467,10 @@ namespace micro_os_plus::micro_test_plus * @brief Logical `and` operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator and (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -481,10 +481,10 @@ namespace micro_os_plus::micro_test_plus * @brief Logical `or` operator. It matches only if at least one * operand is of local type (derived from local `op`). */ - template < - class Lhs_T, class Rhs_T, - type_traits::requires_t< - type_traits::is_op_v or type_traits::is_op_v> = 0> + template + or type_traits::is_op_v> + = 0> [[nodiscard]] constexpr auto operator or (const Lhs_T& lhs, const Rhs_T& rhs) { @@ -497,7 +497,7 @@ namespace micro_os_plus::micro_test_plus */ template > = 0> [[nodiscard]] constexpr auto - operator not (const T& t) + operator not(const T& t) { return detail::not_{ t }; } diff --git a/include/micro-os-plus/reflection.h b/include/micro-os-plus/reflection.h index 8bc5607..8b7010d 100644 --- a/include/micro-os-plus/reflection.h +++ b/include/micro-os-plus/reflection.h @@ -59,7 +59,7 @@ namespace micro_os_plus::micro_test_plus [[nodiscard]] static constexpr auto current ( #if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE)) - const char* file = __builtin_FILE(), int line = __builtin_LINE() + const char* file = __builtin_FILE (), int line = __builtin_LINE () #else const char* file = "unknown", int line = {} #endif @@ -105,13 +105,13 @@ namespace micro_os_plus::micro_test_plus #if defined(__clang__) #pragma GCC diagnostic push #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" - // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof (__PRETTY_FUNCTION__)); - // printf("|%s|\n", &__PRETTY_FUNCTION__[78]); + // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof + // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]); return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 }; #pragma GCC diagnostic pop #elif defined(__GNUC__) - // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof (__PRETTY_FUNCTION__)); - // printf("|%s|\n", &__PRETTY_FUNCTION__[93]); + // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof + // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]); return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 }; #else #error "Unsupported compiler" diff --git a/include/micro-os-plus/test-reporter-inlines.h b/include/micro-os-plus/test-reporter-inlines.h index 829de92..7672cd9 100644 --- a/include/micro-os-plus/test-reporter-inlines.h +++ b/include/micro-os-plus/test-reporter-inlines.h @@ -71,8 +71,8 @@ namespace micro_os_plus::micro_test_plus } template and not type_traits::has_npos_v>> + type_traits::requires_t + and not type_traits::has_npos_v>> test_reporter& test_reporter::operator<< (T&& t) { diff --git a/include/micro-os-plus/test-reporter.h b/include/micro-os-plus/test-reporter.h index 9d73d9b..a28fb37 100644 --- a/include/micro-os-plus/test-reporter.h +++ b/include/micro-os-plus/test-reporter.h @@ -23,7 +23,7 @@ // ---------------------------------------------------------------------------- -//#include +// #include #include #include @@ -176,9 +176,10 @@ namespace micro_os_plus::micro_test_plus /** * @brief Output operator to display containers. Iterate all members. */ - template and not type_traits::has_npos_v> = 0> + template + and not type_traits::has_npos_v> + = 0> test_reporter& operator<< (T&& t); diff --git a/include/micro-os-plus/type-traits.h b/include/micro-os-plus/type-traits.h index 264ebb4..976d036 100644 --- a/include/micro-os-plus/type-traits.h +++ b/include/micro-os-plus/type-traits.h @@ -57,7 +57,10 @@ namespace micro_os_plus::micro_test_plus }; #if defined(__DOXYGEN__) - // error: Detected potential recursive class relation between class micro_os_plus::micro_test_plus::type_traits::function_traits and base class micro_os_plus::micro_test_plus::type_traits::function_traits< decltype(&T::operator())>! + // error: Detected potential recursive class relation between class + // micro_os_plus::micro_test_plus::type_traits::function_traits and base + // class micro_os_plus::micro_test_plus::type_traits::function_traits< + // decltype(&T::operator())>! // https://github.com/doxygen/doxygen/issues/9915 #else template @@ -112,9 +115,8 @@ namespace micro_os_plus::micro_test_plus } template - static constexpr auto is_container_v - = is_valid ([] (auto t) -> decltype (t.begin (), t.end (), - void ()) {}); + static constexpr auto is_container_v = is_valid ( + [] (auto t) -> decltype (t.begin (), t.end (), void ()) {}); template static constexpr auto has_npos_v @@ -139,7 +141,7 @@ namespace micro_os_plus::micro_test_plus #if defined(__clang__) or defined(_MSC_VER) template - static constexpr auto is_convertible_v = __is_convertible_to(From, To); + static constexpr auto is_convertible_v = __is_convertible_to (From, To); #else template constexpr auto @@ -194,7 +196,8 @@ namespace micro_os_plus::micro_test_plus return integral_constant<-N>{}; } - [[nodiscard]] constexpr explicit operator value_type () const + [[nodiscard]] constexpr explicit + operator value_type () const { return N; } @@ -226,7 +229,8 @@ namespace micro_os_plus::micro_test_plus return floating_point_constant{}; } - [[nodiscard]] constexpr explicit operator value_type () const + [[nodiscard]] constexpr explicit + operator value_type () const { return value; } @@ -247,7 +251,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr explicit operator T () const + [[nodiscard]] constexpr explicit + operator T () const { return value_; } @@ -262,7 +267,7 @@ namespace micro_os_plus::micro_test_plus }; template - inline constexpr auto is_op_v = __is_base_of(type_traits::op, T); + inline constexpr auto is_op_v = __is_base_of (type_traits::op, T); /** * @brief Class defining a generic value, accessible via a getter. @@ -276,7 +281,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr explicit operator T () const + [[nodiscard]] constexpr explicit + operator T () const { return value_; } @@ -317,7 +323,8 @@ namespace micro_os_plus::micro_test_plus { } - [[nodiscard]] constexpr explicit operator T () const + [[nodiscard]] constexpr explicit + operator T () const { return value_; } diff --git a/src/test-reporter.cpp b/src/test-reporter.cpp index 5093389..bd3b808 100644 --- a/src/test-reporter.cpp +++ b/src/test-reporter.cpp @@ -92,7 +92,9 @@ namespace micro_os_plus::micro_test_plus #pragma GCC diagnostic ignored "-Wsign-conversion" #endif *this << " (" << reflection::short_name (location.file_name ()) << ":" - << type_traits::genuine_integral_value{ location.line () }; + << type_traits::genuine_integral_value{ + location.line () + }; #pragma GCC diagnostic pop }