Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement SNITCH_DISABLE feature #192

Merged
merged 21 commits into from
Nov 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
indentation clang-format-18
  • Loading branch information
NMuleo committed Nov 18, 2024
commit 692382f1f30d744fa61e60c20f1d84a12c39e589
2 changes: 1 addition & 1 deletion include/snitch/snitch_expression.hpp
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ struct extracted_unary_expression {
// Operators we want to decompose.
#define EXPR_OPERATOR(OP, OP_TYPE) \
template<typename U> \
constexpr extracted_binary_expression<Expected, T, OP_TYPE, U> operator OP(const U& rhs) \
constexpr extracted_binary_expression<Expected, T, OP_TYPE, U> operator OP(const U & rhs) \
const noexcept { \
return {type, expected, lhs, rhs}; \
}
30 changes: 16 additions & 14 deletions include/snitch/snitch_macros_test_case.hpp
Original file line number Diff line number Diff line change
@@ -15,26 +15,28 @@
# define SNITCH_TEST_CASE(...) \
SNITCH_TEST_CASE_IMPL(SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), __VA_ARGS__)

# define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \
template<typename TestType> \
static void ID(); \
static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \
snitch::tests.add_with_type_list<TYPES>( \
{NAME, TAGS}, SNITCH_CURRENT_LOCATION, []<typename TestType>() { ID<TestType>(); });\
template<typename TestType> \
# define SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL(ID, NAME, TAGS, TYPES) \
template<typename TestType> \
static void ID(); \
static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \
snitch::tests.add_with_type_list<TYPES>( \
{NAME, TAGS}, SNITCH_CURRENT_LOCATION, \
[]<typename TestType>() { ID<TestType>(); }); \
template<typename TestType> \
void ID()

# define SNITCH_TEMPLATE_LIST_TEST_CASE(NAME, TAGS, TYPES) \
SNITCH_TEMPLATE_LIST_TEST_CASE_IMPL( \
SNITCH_MACRO_CONCAT(test_fun_, __COUNTER__), NAME, TAGS, TYPES)

# define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \
template<typename TestType> \
static void ID(); \
static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \
snitch::tests.add_with_types<__VA_ARGS__>( \
{NAME, TAGS}, SNITCH_CURRENT_LOCATION, []<typename TestType>() { ID<TestType>(); });\
template<typename TestType> \
# define SNITCH_TEMPLATE_TEST_CASE_IMPL(ID, NAME, TAGS, ...) \
template<typename TestType> \
static void ID(); \
static const char* SNITCH_MACRO_CONCAT(test_id_, __COUNTER__) [[maybe_unused]] = \
snitch::tests.add_with_types<__VA_ARGS__>( \
{NAME, TAGS}, SNITCH_CURRENT_LOCATION, \
[]<typename TestType>() { ID<TestType>(); }); \
template<typename TestType> \
void ID()

# define SNITCH_TEMPLATE_TEST_CASE(NAME, TAGS, ...) \
12 changes: 5 additions & 7 deletions include/snitch/snitch_matcher.hpp
Original file line number Diff line number Diff line change
@@ -16,18 +16,16 @@ enum class match_status { failed, matched };
namespace snitch {
template<typename T, typename U>
concept matcher_for = requires(const T& m, const U& value) {
{ m.match(value) } -> convertible_to<bool>;
{
m.describe_match(value, matchers::match_status{})
} -> convertible_to<std::string_view>;
};
{ m.match(value) } -> convertible_to<bool>;
{ m.describe_match(value, matchers::match_status{}) } -> convertible_to<std::string_view>;
};
} // namespace snitch

namespace snitch::impl {
template<typename T>
concept exception_with_what = requires(const T& e) {
{ e.what() } -> convertible_to<std::string_view>;
};
{ e.what() } -> convertible_to<std::string_view>;
};

template<typename T, typename M>
[[nodiscard]] constexpr auto match(T&& value, M&& matcher) noexcept {
10 changes: 5 additions & 5 deletions include/snitch/snitch_registry.hpp
Original file line number Diff line number Diff line change
@@ -108,11 +108,11 @@ struct registered_reporter {
};

template<typename T>
concept reporter_type =
requires(registry& reg) { T{reg}; } &&
requires(T& rep, registry& reg, std::string_view k, std::string_view v) {
{ rep.configure(reg, k, v) } -> convertible_to<bool>;
} && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); };
concept reporter_type = requires(registry& reg) {
T{reg};
} && requires(T& rep, registry& reg, std::string_view k, std::string_view v) {
{ rep.configure(reg, k, v) } -> convertible_to<bool>;
} && requires(T& rep, const registry& reg, const event::data& e) { rep.report(reg, e); };

class registry {
// Contains all registered test cases.
6 changes: 3 additions & 3 deletions src/snitch_main.cpp
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@

#if SNITCH_DEFINE_MAIN
namespace snitch {
int main(int argc, char* argv[]) {
if constexpr(snitch::is_enabled) {
int main(int argc, char* argv[]) {
if constexpr (snitch::is_enabled) {
std::optional<snitch::cli::input> args = snitch::cli::parse_arguments(argc, argv);
if (!args) {
return 1;
@@ -15,7 +15,7 @@ int main(int argc, char* argv[]) {
return 0;
}
}
}
} // namespace snitch

SNITCH_EXPORT int main(int argc, char* argv[]) {
return snitch::main(argc, argv);
66 changes: 33 additions & 33 deletions src/snitch_registry.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "snitch/snitch_registry.hpp"

# include "snitch/snitch_time.hpp"
#include "snitch/snitch_time.hpp"

# include <algorithm> // for std::sort
# include <optional> // for std::optional
#include <algorithm> // for std::sort
#include <optional> // for std::optional

// Testing framework implementation.
// ---------------------------------
@@ -399,14 +399,14 @@ void register_assertion(bool success, impl::test_state& state) {
++section.allowed_assertion_failure_count;
}

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
if (state.held_info.has_value()) {
for (auto& section : state.held_info.value().sections.current_section) {
++section.assertion_count;
++section.allowed_assertion_failure_count;
}
}
# endif
#endif

impl::set_state(state.test, impl::test_case_state::allowed_fail);
} else {
@@ -418,14 +418,14 @@ void register_assertion(bool success, impl::test_state& state) {
++section.assertion_failure_count;
}

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
if (state.held_info.has_value()) {
for (auto& section : state.held_info.value().sections.current_section) {
++section.assertion_count;
++section.assertion_failure_count;
}
}
# endif
#endif

impl::set_state(state.test, impl::test_case_state::failed);
}
@@ -436,13 +436,13 @@ void register_assertion(bool success, impl::test_state& state) {
++section.assertion_count;
}

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
if (state.held_info.has_value()) {
for (auto& section : state.held_info.value().sections.current_section) {
++section.assertion_count;
}
}
# endif
#endif
}
}

@@ -455,7 +455,7 @@ void report_assertion_impl(

register_assertion(success, state);

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
const bool use_held_info = (state.unhandled_exception || std::uncaught_exceptions() > 0) &&
state.held_info.has_value();

@@ -472,13 +472,13 @@ void report_assertion_impl(
state.in_check
? assertion_location{last_location.file, last_location.line, location_type::exact}
: last_location;
# else
#else
const auto captures_buffer = impl::make_capture_buffer(state.info.captures);
const auto& current_section = state.info.sections.current_section;
const auto& last_location = state.info.locations.back();
const auto location =
assertion_location{last_location.file, last_location.line, location_type::exact};
# endif
#endif

if (success) {
if (r.verbose >= registry::verbosity::full) {
@@ -558,7 +558,7 @@ void registry::report_section_ended(const section& sec) noexcept {

const bool skipped = state.test.state == impl::test_case_state::skipped;

# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
const auto duration = get_duration_in_seconds(sec.start_time, get_current_time());
state.reg.report_callback(
state.reg, event::section_ended{
@@ -569,7 +569,7 @@ void registry::report_section_ended(const section& sec) noexcept {
.assertion_failure_count = sec.assertion_failure_count,
.allowed_assertion_failure_count = sec.allowed_assertion_failure_count,
.duration = duration});
# else
#else
state.reg.report_callback(
state.reg, event::section_ended{
.id = sec.id,
@@ -578,7 +578,7 @@ void registry::report_section_ended(const section& sec) noexcept {
.assertion_count = sec.assertion_count,
.assertion_failure_count = sec.assertion_failure_count,
.allowed_assertion_failure_count = sec.allowed_assertion_failure_count});
# endif
#endif
}

impl::test_state registry::run(impl::test_case& test) noexcept {
@@ -610,13 +610,13 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
impl::test_state* previous_run = impl::try_get_current_test();
impl::set_current_test(&state);

# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
const auto time_start = get_current_time();
# endif
#endif

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
try {
# endif
#endif

do {
// Reset section state.
@@ -640,7 +640,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
} while (!state.info.sections.levels.empty() &&
state.test.state != impl::test_case_state::skipped);

# if SNITCH_WITH_EXCEPTIONS
#if SNITCH_WITH_EXCEPTIONS
state.in_check = true;
report_assertion(true, "no exception caught");
state.in_check = false;
@@ -660,7 +660,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
}

state.unhandled_exception = false;
# endif
#endif

if (state.should_fail) {
state.should_fail = false;
@@ -671,12 +671,12 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
state.should_fail = true;
}

# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
state.duration = get_duration_in_seconds(time_start, get_current_time());
# endif
#endif

if (verbose >= registry::verbosity::high) {
# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
report_callback(
*this, event::test_case_ended{
.id = test.id,
@@ -686,7 +686,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
.allowed_assertion_failure_count = state.allowed_failures,
.state = impl::convert_to_public_state(state.test.state),
.duration = state.duration});
# else
#else
report_callback(
*this, event::test_case_ended{
.id = test.id,
@@ -695,7 +695,7 @@ impl::test_state registry::run(impl::test_case& test) noexcept {
.assertion_failure_count = state.failures,
.allowed_assertion_failure_count = state.allowed_failures,
.state = impl::convert_to_public_state(state.test.state)});
# endif
#endif
}

impl::set_current_test(previous_run);
@@ -722,9 +722,9 @@ bool registry::run_selected_tests(
std::size_t assertion_failure_count = 0;
std::size_t allowed_assertion_failure_count = 0;

# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
const auto time_start = get_current_time();
# endif
#endif

for (impl::test_case& t : this->test_cases()) {
if (!predicate(t.id)) {
@@ -763,12 +763,12 @@ bool registry::run_selected_tests(
}
}

# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
const float duration = get_duration_in_seconds(time_start, get_current_time());
# endif
#endif

if (verbose >= registry::verbosity::normal) {
# if SNITCH_WITH_TIMINGS
#if SNITCH_WITH_TIMINGS
report_callback(
*this, event::test_run_ended{
.name = run_name,
@@ -783,7 +783,7 @@ bool registry::run_selected_tests(
.duration = duration,
.success = success,
});
# else
#else
report_callback(
*this, event::test_run_ended{
.name = run_name,
@@ -796,7 +796,7 @@ bool registry::run_selected_tests(
.assertion_failure_count = assertion_failure_count,
.allowed_assertion_failure_count = allowed_assertion_failure_count,
.success = success});
# endif
#endif
}

return success;
2 changes: 1 addition & 1 deletion src/snitch_reporter_catch2_xml.cpp
Original file line number Diff line number Diff line change
@@ -243,7 +243,7 @@ void reporter::report(const registry& r, const snitch::event::data& event) noexc
e.allowed_assertion_failure_count)},
{"failures", make_string(e.assertion_failure_count)},
{"expectedFailures", make_string(e.allowed_assertion_failure_count)},
{"skipped", e.skipped?"true":"false"}
{"skipped", e.skipped ? "true" : "false"}
# if SNITCH_WITH_TIMINGS
,
{"durationInSeconds", make_string(e.duration)}
6 changes: 3 additions & 3 deletions tests/runtime_tests/check.cpp
Original file line number Diff line number Diff line change
@@ -1688,11 +1688,11 @@ TEST_CASE("require throws matches", "[test macros]") {
}

namespace {
#if SNITCH_ENABLE
# if SNITCH_ENABLE
[[nodiscard]]
#else
# else
[[maybe_unused]]
#endif
# endif
int nodiscard_function() {
return 1;
}
2 changes: 1 addition & 1 deletion tests/runtime_tests/function_ref.cpp
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ bool function_called = false;
#if !SNITCH_ENABLE
[[maybe_unused]]
#endif
int return_value = 0u;
int return_value = 0u;

struct test_object {
test_object() noexcept {
3 changes: 2 additions & 1 deletion tests/runtime_tests/string_utility.cpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ struct frob {
#if !SNITCH_ENABLE
[[maybe_unused]]
#endif
void foo() {}
void foo() {
}

using function_ptr_type = void (*)();
using member_function_ptr_type = void (frob::*)();
Loading
Oops, something went wrong.