Skip to content

implement SNITCH_DISABLE feature #192

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

Merged
merged 21 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
7 changes: 5 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ 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: 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"}
Expand All @@ -105,6 +106,7 @@ jobs:
- { 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: 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"}
build-type:
- Release
- Debug
Expand Down Expand Up @@ -161,19 +163,20 @@ jobs:
- name: Test (with doctest)
# A bug in Node.js/V8 prevents these tests from running in Debug config for WebAssembly.
# https://bugs.chromium.org/p/v8/issues/detail?id=13961
if: ${{!(matrix.platform.compiler == 'em++' && matrix.build-type == 'Debug')}}
if: ${{!(matrix.platform.compiler == 'em++' && matrix.build-type == 'Debug') && !contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}}
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake --build . --config ${{matrix.build-type}} --target snitch_runtime_tests_run

- name: Test (with snitch)
if: ${{!contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}}
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake --build . --config ${{matrix.build-type}} --target snitch_runtime_tests_self_run

- name: Approval tests (with doctest)
# Approval tests only run on "default" library configuration, which happens to be the published one
if: matrix.platform.publish
if: ${{matrix.platform.publish && !contains(matrix.platform.flags, '-DSNITCH_ENABLE=OFF')}}
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake --build . --config ${{matrix.build-type}} --target snitch_approval_tests_run
Expand Down
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SNITCH_MAX_PATH_LENGTH 1024 CACHE STRING "Maximum length of a file
set(SNITCH_MAX_REPORTER_SIZE_BYTES 128 CACHE STRING "Maximum size (in bytes) of a reporter object.")

# Feature toggles.
set(SNITCH_ENABLE ON CACHE BOOL "Enable snitch at build time")
set(SNITCH_DEFINE_MAIN ON CACHE BOOL "Define main() in snitch -- disable to provide your own main() function.")
set(SNITCH_WITH_EXCEPTIONS ON CACHE BOOL "Use exceptions in snitch implementation -- will be forced OFF if exceptions are not available.")
set(SNITCH_WITH_MULTITHREADING ON CACHE BOOL "Make the testing framework thread-safe -- disable if multithreading is not needed.")
Expand Down Expand Up @@ -115,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 @@ -211,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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The goal of _snitch_ is to be a simple, cheap, non-invasive, and user-friendly t
- Additional API not in _Catch2_, or different from _Catch2_:
- Matchers use a different API (see [Matchers](#matchers) below).
- Additional macros for testing [`constexpr`](#run-time-and-compile-time) and [`consteval`](#compile-time) expressions.
- Can be disabled at build time, to allow mixing code and tests in the same file with minimal overheads.

If you need features that are not in the list above, please use _Catch2_ or _doctest_.

Expand Down
3 changes: 3 additions & 0 deletions include/snitch/snitch_config.hpp.config
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
#if !defined(SNITCH_SHARED_LIBRARY)
#cmakedefine01 SNITCH_SHARED_LIBRARY
#endif
#if !defined(SNITCH_ENABLE)
#cmakedefine01 SNITCH_ENABLE
#endif
// clang-format on

#if defined(_MSC_VER)
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
Loading