Skip to content
Merged
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
9 changes: 9 additions & 0 deletions libc/test/UnitTest/LibcTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ CString libc_make_test_file_path_func(const char *file_name);
SuiteClass##_##TestName SuiteClass##_##TestName##_Instance; \
void SuiteClass##_##TestName::Run()

// Helper to trick the compiler into ignoring lack of braces on the else
// branch. We cannot introduce braces at this point, since it would prevent
// using `<< ...` after the test macro for additional failure output.
#define LIBC_TEST_DISABLE_DANGLING_ELSE \
switch (0) \
case 0: \
default: // NOLINT

// If RET_OR_EMPTY is the 'return' keyword we perform an early return which
// corresponds to an assert. If it is empty the execution continues, this
// corresponds to an expect.
Expand All @@ -411,6 +419,7 @@ CString libc_make_test_file_path_func(const char *file_name);
// returning a boolean. This expression is responsible for logging the
// diagnostic in case of failure.
#define LIBC_TEST_SCAFFOLDING_(TEST, RET_OR_EMPTY) \
LIBC_TEST_DISABLE_DANGLING_ELSE \
if (TEST) \
; \
else \
Expand Down
Loading