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

Add ANTITHESIS_MAX_NAME_LEN macro #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
22 changes: 18 additions & 4 deletions antithesis_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ namespace antithesis::internal::assertions {

namespace antithesis::internal {
namespace { // Anonymous namespace which is translation-unit-specific; certain symbols aren't exposed in the symbol table as a result
enum msg_name_e { msg_name };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestions for better name here are welcome.


template <std::size_t N>
struct fixed_string {
std::array<char, N> contents;
Expand All @@ -776,11 +778,20 @@ namespace { // Anonymous namespace which is translation-unit-specific; certain s

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"

constexpr fixed_string( const char (&arr)[N] )
{
for(unsigned int i=0; i<N; i++) contents[i] = arr[i];
}

constexpr fixed_string( const char (&arr)[N], msg_name_e )
{
#ifdef ANTITHESIS_MAX_NAME_LEN
static_assert(N <= ANTITHESIS_MAX_NAME_LEN + 1);
#endif
for(unsigned int i=0; i<N; i++) contents[i] = arr[i];
}

static constexpr fixed_string<N> from_c_str( const char* s ) {
fixed_string<N> it;
for(unsigned int i=0; i<N && s[i]; i++)
Expand All @@ -795,6 +806,9 @@ namespace { // Anonymous namespace which is translation-unit-specific; certain s
template <std::size_t N>
fixed_string( const char (&arr)[N] ) -> fixed_string<N>;

template <std::size_t N>
fixed_string( const char (&arr)[N], msg_name_e ) -> fixed_string<N>;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
static constexpr size_t string_length( const char * s ) {
Expand Down Expand Up @@ -935,7 +949,7 @@ namespace { // Anonymous namespace which is translation-unit-specific; certain s
#define ANTITHESIS_ASSERT_RAW(type, cond, message, ...) ( \
antithesis::internal::CatalogEntry< \
type, \
antithesis::internal::fixed_string(message), \
antithesis::internal::fixed_string(message, antithesis::internal::msg_name), \
FIXED_STRING_FROM_C_STR(std::source_location::current().file_name()), \
FIXED_STRING_FROM_C_STR(std::source_location::current().function_name()), \
std::source_location::current().line(), \
Expand All @@ -955,7 +969,7 @@ do { \
antithesis::internal::NumericGuidanceCatalogEntry< \
decltype(left), \
guidepost_type, \
antithesis::internal::fixed_string(message), \
antithesis::internal::fixed_string(message, antithesis::internal::msg_name), \
FIXED_STRING_FROM_C_STR(std::source_location::current().file_name()), \
FIXED_STRING_FROM_C_STR(std::source_location::current().function_name()), \
std::source_location::current().line(), \
Expand Down Expand Up @@ -995,7 +1009,7 @@ do { \
antithesis::internal::BooleanGuidanceCatalogEntry< \
decltype(json_pairs), \
antithesis::internal::assertions::GUIDEPOST_NONE, \
antithesis::internal::fixed_string(message), \
antithesis::internal::fixed_string(message, antithesis::internal::msg_name), \
FIXED_STRING_FROM_C_STR(std::source_location::current().file_name()), \
FIXED_STRING_FROM_C_STR(std::source_location::current().function_name()), \
std::source_location::current().line(), \
Expand All @@ -1018,7 +1032,7 @@ do { \
antithesis::internal::BooleanGuidanceCatalogEntry< \
decltype(json_pairs), \
antithesis::internal::assertions::GUIDEPOST_ALL, \
antithesis::internal::fixed_string(message), \
antithesis::internal::fixed_string(message, antithesis::internal::msg_name), \
FIXED_STRING_FROM_C_STR(std::source_location::current().file_name()), \
FIXED_STRING_FROM_C_STR(std::source_location::current().function_name()), \
std::source_location::current().line(), \
Expand Down