From 0728478f246a36afb3891ee11b7eddbc31257d29 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 10 Nov 2023 23:18:07 -0500 Subject: [PATCH] Assertion facility. --- CMakeLists.txt | 1 + assertion.h | 30 ++++++++++++++++++++++++++++++ assertion.test/0.cc | 4 ++++ assertion.test/CMakeLists.txt | 1 + 4 files changed, 36 insertions(+) create mode 100644 assertion.h create mode 100644 assertion.test/0.cc create mode 100644 assertion.test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index afd6717..039b94d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ add_subdirectory( word_wrap.test ) add_subdirectory( string_algorithms.test ) add_subdirectory( tuplize_args.test ) add_subdirectory( Thread.test ) +add_subdirectory( assertion.test ) # Sample applications add_executable( example example.cc ) diff --git a/assertion.h b/assertion.h new file mode 100644 index 0000000..17f4b07 --- /dev/null +++ b/assertion.h @@ -0,0 +1,30 @@ +static_assert( __cplusplus > 2020'99 ); + +#pragma once + +#include + +#include + +namespace Alepha::Hydrogen ::detail:: assertion_m +{ + inline namespace exports + { + class ProgrammerExpectationViolation : public virtual Violation {}; + + inline void + assertion( const bool b ) + { + if( not b ) + { + throw build_exception< ProgrammerExpectationViolation >( + "Expectation violated." ); + } + } + } +} + +namespace Alepha::Hydrogen::inline exports::inline assertion_m +{ + using namespace detail::assertion_m::exports; +} diff --git a/assertion.test/0.cc b/assertion.test/0.cc new file mode 100644 index 0000000..8603305 --- /dev/null +++ b/assertion.test/0.cc @@ -0,0 +1,4 @@ +static_assert( __cplusplus > 2020'99 ); + +#include "../assertion.h" + diff --git a/assertion.test/CMakeLists.txt b/assertion.test/CMakeLists.txt new file mode 100644 index 0000000..b099603 --- /dev/null +++ b/assertion.test/CMakeLists.txt @@ -0,0 +1 @@ +unit_test( 0 )