Skip to content

Commit

Permalink
maybe fix mac pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Arniiiii committed Jul 24, 2024
1 parent 9153826 commit 05fe79d
Showing 1 changed file with 61 additions and 62 deletions.
123 changes: 61 additions & 62 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export import std;

#include <version>
#if defined(_MSC_VER)
#pragma push_macro("min")
#pragma push_macro("max")
#undef min
#undef max
#pragma push_macro("min")
#pragma push_macro("max")
#undef min
#undef max
#endif
// Before libc++ 17 had experimental support for format and it required a
// special build flag. Currently libc++ has not implemented all C++20 chrono
Expand Down Expand Up @@ -77,6 +77,7 @@ export import std;
#include <chrono>
#include <concepts>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iostream>
#include <memory>
Expand All @@ -89,7 +90,6 @@ export import std;
#include <utility>
#include <variant>
#include <vector>
#include <fstream>
#if __has_include(<unistd.h>) and __has_include(<sys/wait.h>)
#include <sys/wait.h>
#include <unistd.h>
Expand Down Expand Up @@ -183,8 +183,8 @@ class function<R(TArgs...)> {
}

template <class TPattern, class TStr>
[[nodiscard]] constexpr auto match(const TPattern& pattern, const TStr& str)
-> std::vector<TStr> {
[[nodiscard]] constexpr auto match(const TPattern& pattern,
const TStr& str) -> std::vector<TStr> {
std::vector<TStr> groups{};
auto pi = 0u;
auto si = 0u;
Expand Down Expand Up @@ -237,22 +237,22 @@ template <class T = std::string_view, class TDelim>
}
return output;
}
constexpr auto regex_match(const char *str, const char *pattern) -> bool {
constexpr auto regex_match(const char* str, const char* pattern) -> bool {
if (*pattern == '\0' && *str == '\0') return true;
if (*pattern == '\0' && *str != '\0') return false;
if (*str == '\0' && *pattern != '\0') return false;
if (*pattern == '.') {
return regex_match(str+1, pattern+1);
return regex_match(str + 1, pattern + 1);
}
if (*pattern == *str) {
return regex_match(str+1, pattern+1);
return regex_match(str + 1, pattern + 1);
}
return false;
}
} // namespace utility

namespace reflection {
#if defined(__cpp_lib_source_location)
#if defined(__cpp_lib_source_location) && !defined(_LIBCPP_APPLE_CLANG_VER)
using source_location = std::source_location;
#else
class source_location {
Expand Down Expand Up @@ -353,8 +353,9 @@ template <class T>
}

template <class T, class U>
[[nodiscard]] constexpr auto abs_diff(const T t, const U u)
-> decltype(t < u ? u - t : t - u) {
[[nodiscard]] constexpr auto abs_diff(const T t,
const U u) -> decltype(t < u ? u - t
: t - u) {
return t < u ? u - t : t - u;
}

Expand Down Expand Up @@ -463,8 +464,8 @@ struct function_traits<R (T::*)(TArgs...) const> {
template <class T>
T&& declval();
template <class... Ts, class TExpr>
constexpr auto is_valid(TExpr expr)
-> decltype(expr(declval<Ts...>()), bool()) {
constexpr auto is_valid(TExpr expr) -> decltype(expr(declval<Ts...>()),
bool()) {
return true;
}
template <class...>
Expand Down Expand Up @@ -601,7 +602,7 @@ struct suite_end {
template <class Test, class TArg = none>
struct test {
std::string_view type{};
std::string name{}; /// might be dynamic
std::string name{}; /// might be dynamic
std::vector<std::string_view> tag{};
reflection::source_location location{};
TArg arg{};
Expand All @@ -614,8 +615,8 @@ struct test {
static constexpr auto run_impl(Test test, const none&) { test(); }

template <class T>
static constexpr auto run_impl(T test, const TArg& arg)
-> decltype(test(arg), void()) {
static constexpr auto run_impl(T test, const TArg& arg) -> decltype(test(arg),
void()) {
test(arg);
}

Expand Down Expand Up @@ -1569,9 +1570,8 @@ class reporter {
<< printer_.colors().fail << tests_.fail << " failed"
<< printer_.colors().none << '\n'
<< "asserts: " << (asserts_.pass + asserts_.fail) << " | "
<< asserts_.pass << " passed"
<< " | " << printer_.colors().fail << asserts_.fail << " failed"
<< printer_.colors().none << '\n';
<< asserts_.pass << " passed" << " | " << printer_.colors().fail
<< asserts_.fail << " failed" << printer_.colors().none << '\n';
std::cerr << printer_.str() << std::endl;
} else {
std::cout << printer_.colors().pass << "All tests passed"
Expand Down Expand Up @@ -1873,16 +1873,18 @@ class reporter_junit {
std::cout.flush();
std::cout.rdbuf(cout_save);
std::ofstream maybe_of;
if (detail::cfg::output_filename != "") { maybe_of = std::ofstream(detail::cfg::output_filename); }
if (detail::cfg::output_filename != "") {
maybe_of = std::ofstream(detail::cfg::output_filename);
}

if (report_type_ == JUNIT) {
print_junit_summary(detail::cfg::output_filename != "" ? maybe_of : std::cout);
print_junit_summary(detail::cfg::output_filename != "" ? maybe_of
: std::cout);
return;
}
print_console_summary(
detail::cfg::output_filename != "" ? maybe_of : std::cout,
detail::cfg::output_filename != "" ? maybe_of : std::cerr
);
detail::cfg::output_filename != "" ? maybe_of : std::cout,
detail::cfg::output_filename != "" ? maybe_of : std::cerr);
}

protected:
Expand All @@ -1898,25 +1900,25 @@ class reporter_junit {
}
}

void print_console_summary(std::ostream &out_stream, std::ostream &err_stream) {
void print_console_summary(std::ostream& out_stream,
std::ostream& err_stream) {
for (const auto& [suite_name, suite_result] : results_) {
if (suite_result.fails) {
err_stream
<< "\n========================================================"
"=======================\n"
<< "Suite " << suite_name << '\n' //
<< "Suite " << suite_name << '\n' //
<< "tests: " << (suite_result.n_tests) << " | " << color_.fail
<< suite_result.fails << " failed" << color_.none << '\n'
<< "asserts: " << (suite_result.assertions) << " | "
<< suite_result.passed << " passed"
<< " | " << color_.fail << suite_result.fails << " failed"
<< color_.none << '\n';
<< suite_result.passed << " passed" << " | " << color_.fail
<< suite_result.fails << " failed" << color_.none << '\n';
std::cerr << std::endl;
} else {
out_stream << color_.pass << "Suite '" << suite_name
<< "': all tests passed" << color_.none << " ("
<< suite_result.assertions << " asserts in "
<< suite_result.n_tests << " tests)\n";
<< "': all tests passed" << color_.none << " ("
<< suite_result.assertions << " asserts in "
<< suite_result.n_tests << " tests)\n";

if (suite_result.skipped) {
std::cout << suite_result.skipped << " tests skipped\n";
Expand All @@ -1927,9 +1929,9 @@ class reporter_junit {
}
}

void print_junit_summary(std::ostream &stream) {
void print_junit_summary(std::ostream& stream) {
// aggregate results
size_t n_tests=0, n_fails=0;
size_t n_tests = 0, n_fails = 0;
double total_time = 0.0;
auto suite_time = [](auto const& suite_result) {
std::int64_t time_ms =
Expand All @@ -1947,11 +1949,11 @@ class reporter_junit {
// mock junit output:
stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
stream << "<testsuites";
stream << " name=\"all\"";
stream << " tests=\"" << n_tests << '\"';
stream << " failures=\"" << n_fails << '\"';
stream << " time=\"" << total_time << '\"';
stream << ">\n";
stream << " name=\"all\"";
stream << " tests=\"" << n_tests << '\"';
stream << " failures=\"" << n_fails << '\"';
stream << " time=\"" << total_time << '\"';
stream << ">\n";

for (const auto& [suite_name, suite_result] : results_) {
stream << "<testsuite";
Expand All @@ -1969,8 +1971,8 @@ class reporter_junit {
}
stream << "</testsuites>";
}
void print_result(std::ostream &stream, const std::string& suite_name, std::string indent,
const test_result& parent) {
void print_result(std::ostream& stream, const std::string& suite_name,
std::string indent, const test_result& parent) {
for (const auto& [name, result] : *parent.nested_tests) {
stream << indent;
stream << "<testcase classname=\"" << result.suite_name << '\"';
Expand All @@ -1983,8 +1985,7 @@ class reporter_junit {
std::chrono::duration_cast<std::chrono::milliseconds>(
result.run_stop - result.run_start)
.count();
stream << " time=\"" << (static_cast<double>(time_ms) / 1000.0)
<< "\"";
stream << " time=\"" << (static_cast<double>(time_ms) / 1000.0) << "\"";
stream << " status=\"" << result.status << '\"';
if (result.report_string.empty() && result.nested_tests->empty()) {
stream << " />\n";
Expand Down Expand Up @@ -2026,8 +2027,8 @@ class runner {
: path_{utility::split(_filter, delim)} {}

template <class TPath>
constexpr auto operator()(const std::size_t level, const TPath& path) const
-> bool {
constexpr auto operator()(const std::size_t level,
const TPath& path) const -> bool {
for (auto i = 0u; i < math::min_value(level + 1, std::size(path_)); ++i) {
if (not utility::is_match(path[i], path_[i])) {
return false;
Expand Down Expand Up @@ -2156,7 +2157,7 @@ class runner {
}
#endif

if (not --level_) {
if (not--level_) {
reporter_.on(events::test_end{.type = test.type, .name = test.name});
} else { // N.B. prev. only root-level tests were signalled on finish
if constexpr (requires {
Expand Down Expand Up @@ -2742,20 +2743,18 @@ template <class F, class T,
[[nodiscard]] constexpr auto operator|(const F& f, const T& t) {
return [f, t](const auto name) {
for (const auto& arg : t) {
detail::on<F>(events::test<F, decltype(arg)>{
.type = "test",
.name = std::string{name},
.tag = {},
.location = {},
.arg = arg,
.run = f});
detail::on<F>(events::test<F, decltype(arg)>{.type = "test",
.name = std::string{name},
.tag = {},
.location = {},
.arg = arg,
.run = f});
}
};
}

template <
class F, template <class...> class T, class... Ts,
type_traits::requires_t<not type_traits::is_range_v<T<Ts...>>> = 0>
template <class F, template <class...> class T, class... Ts,
type_traits::requires_t<not type_traits::is_range_v<T<Ts...>>> = 0>
[[nodiscard]] constexpr auto operator|(const F& f, const T<Ts...>& t) {
return [f, t](const auto name) {
apply(
Expand Down Expand Up @@ -3329,8 +3328,8 @@ using operators::operator>>;

#if (defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)) && \
!defined(__EMSCRIPTEN__)
__attribute__((constructor(101))) inline void cmd_line_args(int argc,
const char* argv[]) {
__attribute__((constructor(101))) inline void cmd_line_args(
int argc, const char* argv[]) {
::boost::ut::detail::cfg::largc = argc;
::boost::ut::detail::cfg::largv = argv;
}
Expand All @@ -3339,8 +3338,8 @@ __attribute__((constructor(101))) inline void cmd_line_args(int argc,
#endif

#if defined(_MSC_VER)
#pragma pop_macro("min")
#pragma pop_macro("max")
#pragma pop_macro("min")
#pragma pop_macro("max")
#endif

#endif

0 comments on commit 05fe79d

Please sign in to comment.