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
Show file tree
Hide file tree
Changes from 5 commits
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
6 changes: 1 addition & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,20 @@ jobs:
matrix:
platform:
- { name: Ubuntu GCC, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu GCC disabled, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='--coverage' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: Ubuntu GCC disabled, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-disabled", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: Ubuntu GCC noexcept, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu GCC notime, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-notime", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_WITH_TIMINGS=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu GCC nounity, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-static-nounity", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_UNITY_BUILD=0 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu GCC header-only, os: ubuntu-latest, publish: true, compiler: g++, arch: "64", build: "header-only", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DSNITCH_HEADER_ONLY=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu GCC shared, os: ubuntu-latest, publish: false, compiler: g++, arch: "64", build: "ubuntu64-libstdc++-shared", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=g++ -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu Clang, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu Clang noexcept, os: ubuntu-latest, publish: false, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++ -fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Ubuntu Clang disabled, os: ubuntu-latest, publish: true, compiler: clang++, arch: "64", build: "ubuntu64-libc++-static", cmakepp: "", flags: "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS='-stdlib=libc++' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: Windows 32, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Windows 32 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "32", build: "win32-vs2019-static", cmakepp: "", flags: "-A Win32 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: Windows 64, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Windows 64 noexcept, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-static-noexcept", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Windows 64 shared, os: windows-latest, publish: false, compiler: vs2019, arch: "64", build: "win64-vs2019-shared", cmakepp: "", flags: "-A x64 -DBUILD_SHARED_LIBS=1 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: Windows 64 disable, os: windows-latest, publish: true, compiler: vs2019, arch: "64", build: "win64-vs2019-static", cmakepp: "", flags: "-A x64 --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: MacOS, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: MacOS noexcept, os: macos-latest, publish: false, compiler: clang++, arch: "64", build: "osx-libc++-static-noexcept", cmakepp: "", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' --warn-uninitialized -Wdev -Wno-deprecated -Werror=dev"}
- { name: MacOS disable, os: macos-latest, publish: true, compiler: clang++, arch: "64", build: "osx-libc++-static", cmakepp: "", flags: "--warn-uninitialized -Wdev -Wno-deprecated -Werror=dev -DSNITCH_ENABLE=OFF"}
- { name: WebAssembly, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node"}
- { name: WebAssembly noexcept, os: ubuntu-latest, publish: false, compiler: em++, arch: "32", build: "wasm32-noexcept", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-fno-exceptions' -DCMAKE_CROSSCOMPILING_EMULATOR=node"}
- { name: WebAssembly disable, os: ubuntu-latest, publish: true, compiler: em++, arch: "32", build: "wasm32", cmakepp: "emcmake", flags: "-DCMAKE_CXX_FLAGS='-s DISABLE_EXCEPTION_CATCHING=0' -DCMAKE_CROSSCOMPILING_EMULATOR=node -DSNITCH_ENABLE=OFF"}
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ set(SNITCH_SOURCES_INDIVIDUAL
${PROJECT_SOURCE_DIR}/src/snitch_test_data.cpp
${PROJECT_SOURCE_DIR}/src/snitch_time.cpp)

if (SNITCH_UNITY_BUILD)
set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch.cpp)
if (SNITCH_ENABLE)
if (SNITCH_UNITY_BUILD)
set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch.cpp)
else()
set(SNITCH_SOURCES ${SNITCH_SOURCES_INDIVIDUAL})
endif()
else()
set(SNITCH_SOURCES ${SNITCH_SOURCES_INDIVIDUAL})
set(SNITCH_SOURCES ${PROJECT_SOURCE_DIR}/src/snitch_main.cpp)
endif()

function(configure_snitch_exports TARGET)
Expand Down Expand Up @@ -212,7 +216,7 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/snitch COMPONENT Development)

# Setup tests
if (SNITCH_DO_TEST)
if (SNITCH_DO_TEST AND SNITCH_ENABLE)
enable_testing()

# We need to use a different snitch configuration for tests, so we can't reuse
Expand Down
2 changes: 1 addition & 1 deletion include/snitch/snitch_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}; \
}
Expand Down
30 changes: 16 additions & 14 deletions include/snitch/snitch_macros_test_case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) \
Expand Down
12 changes: 5 additions & 7 deletions include/snitch/snitch_matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
157 changes: 6 additions & 151 deletions include/snitch/snitch_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ constexpr std::size_t max_registered_reporters = SNITCH_MAX_REGISTERED_REPORTERS
// Maximum size of a reporter instance, in bytes.
constexpr std::size_t max_reporter_size_bytes = SNITCH_MAX_REPORTER_SIZE_BYTES;
// Is snitch disabled?
constexpr bool is_disabled = !SNITCH_ENABLE;
constexpr bool is_enabled = SNITCH_ENABLE;
} // namespace snitch

namespace snitch::impl {
Expand Down Expand Up @@ -108,13 +108,12 @@ 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); };

#if SNITCH_ENABLE
class registry {
// Contains all registered test cases.
small_vector<impl::test_case, max_test_cases> test_list;
Expand Down Expand Up @@ -333,150 +332,6 @@ class registry {
SNITCH_EXPORT small_vector_span<const registered_reporter> reporters() const noexcept;
};

#else // SNITCH_ENABLE

class registry {
SNITCH_EXPORT void report_default(const registry&, const event::data&) noexcept {}

public:
enum class verbosity { quiet, normal, high, full } verbose = verbosity::normal;
bool with_color = SNITCH_DEFAULT_WITH_COLOR == 1;

using print_function = snitch::print_function;
using initialize_report_function = snitch::initialize_report_function;
using configure_report_function = snitch::configure_report_function;
using report_function = snitch::report_function;
using finish_report_function = snitch::finish_report_function;

print_function print_callback = nullptr;
report_function report_callback = nullptr;
finish_report_function finish_callback = nullptr;

// Internal API; do not use.
template<typename T>
void append_or_print(small_string<max_message_length>&, T&&) const noexcept {}

template<typename... Args>
void print(Args&&...) const noexcept {}

template<convertible_to<std::string_view> T>
void print(const T&) const noexcept {}

// Requires: number of reporters + 1 <= max_registered_reporters.
SNITCH_EXPORT std::string_view add_reporter(
std::string_view name,
const std::optional<initialize_report_function>& initialize,
const std::optional<configure_report_function>& configure,
const report_function& report,
const std::optional<finish_report_function>& finish);

// Requires: number of reporters + 1 <= max_registered_reporters.
template<reporter_type T>
std::string_view add_reporter(std::string_view) {
return {};
}

// Internal API; do not use.
// Requires: number of tests + 1 <= max_test_cases, well-formed test ID.
SNITCH_EXPORT const char*
add_impl(const test_id& id, const source_location& location, impl::test_ptr func);

// Internal API; do not use.
// Requires: number of tests + 1 <= max_test_cases, well-formed test ID.
SNITCH_EXPORT const char*
add(const impl::name_and_tags& id, const source_location& location, impl::test_ptr func);

// Internal API; do not use.
// Requires: number of tests + added tests <= max_test_cases, well-formed test ID.
template<typename... Args, typename F>
const char* add_with_types(const impl::name_and_tags&, const source_location&, const F&) {
static_assert(sizeof...(Args) > 0, "empty type list in TEMPLATE_TEST_CASE");
return {};
}

// Internal API; do not use.
// Requires: number of tests + added tests <= max_test_cases, well-formed test ID.
template<typename T, typename F>
const char* add_with_type_list(const impl::name_and_tags&, const source_location&, const F&) {
return {};
}

// Internal API; do not use.
// Requires: number of tests + 1 <= max_test_cases, well-formed test ID.
SNITCH_EXPORT const char* add_fixture(
const impl::fixture_name_and_tags& id,
const source_location& location,
impl::test_ptr func);

// Internal API; do not use.
// Requires: number of tests + added tests <= max_test_cases, well-formed test ID.
template<typename... Args, typename F>
const char*
add_fixture_with_types(const impl::fixture_name_and_tags&, const source_location&, const F&) {
return {};
}

// Internal API; do not use.
// Requires: number of tests + added tests <= max_test_cases, well-formed test ID.
template<typename T, typename F>
const char* add_fixture_with_type_list(
const impl::fixture_name_and_tags&, const source_location&, const F&) {
return {};
}

// Internal API; do not use.
SNITCH_EXPORT static void report_assertion(bool, std::string_view) noexcept;

// Internal API; do not use.
SNITCH_EXPORT static void report_assertion(bool, std::string_view, std::string_view) noexcept;

// Internal API; do not use.
SNITCH_EXPORT static void report_assertion(bool, const impl::expression&) noexcept;

// Internal API; do not use.
SNITCH_EXPORT static void report_skipped(std::string_view) noexcept;

// Internal API; do not use.
SNITCH_EXPORT static void report_section_started(const section&) noexcept;

// Internal API; do not use.
SNITCH_EXPORT static void report_section_ended(const section&) noexcept;

// Internal API; do not use.
SNITCH_EXPORT impl::test_state run(impl::test_case& test) noexcept;

// Internal API; do not use.
SNITCH_EXPORT bool run_tests(std::string_view) noexcept;

// Internal API; do not use.
SNITCH_EXPORT bool run_selected_tests(
std::string_view,
const filter_info&,
const function_ref<bool(const test_id&) noexcept>&) noexcept;

/* ---- */

SNITCH_EXPORT bool run_tests(const cli::input&) noexcept;

SNITCH_EXPORT void configure(const cli::input&);

SNITCH_EXPORT void list_all_tests() const noexcept;

SNITCH_EXPORT void list_all_tags() const;

SNITCH_EXPORT void list_tests_with_tag(std::string_view) const noexcept;

SNITCH_EXPORT void list_all_reporters() const noexcept;

SNITCH_EXPORT small_vector_span<impl::test_case> test_cases() noexcept;
SNITCH_EXPORT small_vector_span<const impl::test_case> test_cases() const noexcept;

SNITCH_EXPORT small_vector_span<registered_reporter> reporters() noexcept;
SNITCH_EXPORT small_vector_span<const registered_reporter> reporters() const noexcept;
};

#endif // SNITCH_ENABLE

SNITCH_EXPORT extern constinit registry tests;
} // namespace snitch

Expand Down
Loading