Add test helper macros. (#465)
- Refactor the existing SNMALLOC_ASSERT and SNMALLOC_CHECK. These now use the FatalErrorBuilder to format the output if a format string is provided. - Extend the FatalErrorBuilder to print decimal integers for signed values. - Rename FatalErrorBuilder to MessageBuilder. - Rewrite the macros used in the jemalloc tests to use FatalErrorBuilder and move them into a header. - Refactor some of the tests to use the new macros.
This commit is contained in:
39
src/test/helpers.h
Normal file
39
src/test/helpers.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#ifdef _MSC_VER
|
||||
# define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||
#endif
|
||||
|
||||
namespace snmalloc
|
||||
{
|
||||
/**
|
||||
* The name of the function under test. This is set in the START_TEST macro
|
||||
* and used for error reporting in EXPECT.
|
||||
*/
|
||||
const char* current_test = "";
|
||||
|
||||
/**
|
||||
* Log that the test started.
|
||||
*/
|
||||
#define START_TEST(msg, ...) \
|
||||
do \
|
||||
{ \
|
||||
current_test = __PRETTY_FUNCTION__; \
|
||||
MessageBuilder<1024> mb{"Starting test: " msg "\n", ##__VA_ARGS__}; \
|
||||
fputs(mb.get_message(), stderr); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* An assertion that fires even in debug builds. Uses the value set by
|
||||
* START_TEST.
|
||||
*/
|
||||
#define EXPECT(x, msg, ...) \
|
||||
SNMALLOC_CHECK_MSG(x, " in test {} " msg "\n", current_test, ##__VA_ARGS__)
|
||||
|
||||
#define INFO(msg, ...) \
|
||||
do \
|
||||
{ \
|
||||
MessageBuilder<1024> mb{msg "\n", ##__VA_ARGS__}; \
|
||||
fputs(mb.get_message(), stderr); \
|
||||
} while (0)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user