diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h index b4e3819ea958d..fbeafd0bacb75 100644 --- a/libc/test/UnitTest/LibcTest.h +++ b/libc/test/UnitTest/LibcTest.h @@ -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. @@ -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 \