Additional messages can be logged during a test case (safely even in concurrent threads).
The INFO()
macro allows heterogeneous sequences of expressions to be captured by listing them with commas.
INFO("The number is ", i);
This message will be relevant to all asserts after it in the current scope or in scopes nested in the current one and will be printed later only if an assert fails.
The expression is NOT evaluated right away - instead it gets lazily evaluated only when needed.
Some notes:
The lazy evaluation means that in the common case when no asserts fail the code runs super fast. This makes it suitable even in loops - perhaps to log the iteration.
There is also the CAPTURE()
macro which is a convenience wrapper of INFO()
:
CAPTURE(some_variable)
This will handle the stringification of the variable name for you (actually it works with any expression, not just variables).
This would log something like:
some_variable := 42
There are a few other macros for logging information:
MESSAGE(message)
FAIL_CHECK(message)
FAIL(message)
FAIL()
is like a REQUIRE
assert - fails the test case and exits it. FAIL_CHECK()
acts like a CHECK
assert - fails the test case but continues with the execution. MESSAGE()
just prints a message.
FAIL("This is not supposed to happen! some var: ", var);
Also there is no lazy stringification here - strings are always constructed and printed.
There are also a few more intended for use by third party libraries such as mocking frameworks:
ADD_MESSAGE_AT(file, line, message)
ADD_FAIL_CHECK_AT(file, line, message)
ADD_FAIL_AT(file, line, message)
They can be useful when integrating asserts from a different framework with doctest.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。