mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 03:46:17 +01:00
gtestutils: Document difference between g_assert() and g_assert_*()
g_assert() must not be used in tests. g_assert_*() must not be used in production code. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/glib/issues/976
This commit is contained in:
parent
ad3947c42e
commit
51ce8d204c
@ -87,14 +87,18 @@
|
||||
* creates a test suite called "misc" with a single test case named
|
||||
* "assertions", which consists of running the test_assertions function.
|
||||
*
|
||||
* In addition to the traditional g_assert(), the test framework provides
|
||||
* In addition to the traditional g_assert_true(), the test framework provides
|
||||
* an extended set of assertions for comparisons: g_assert_cmpfloat(),
|
||||
* g_assert_cmpfloat_with_epsilon(), g_assert_cmpint(), g_assert_cmpuint(),
|
||||
* g_assert_cmphex(), g_assert_cmpstr(), and g_assert_cmpmem(). The
|
||||
* advantage of these variants over plain g_assert() is that the assertion
|
||||
* advantage of these variants over plain g_assert_true() is that the assertion
|
||||
* messages can be more elaborate, and include the values of the compared
|
||||
* entities.
|
||||
*
|
||||
* Note that g_assert() should not be used in unit tests, since it is a no-op
|
||||
* when compiling with `G_DISABLE_ASSERT`. Use g_assert() in production code,
|
||||
* and g_assert_true() in unit tests.
|
||||
*
|
||||
* A full example of creating a test suite with two tests using fixtures:
|
||||
* |[<!-- language="C" -->
|
||||
* #include <glib.h>
|
||||
@ -473,7 +477,10 @@
|
||||
*
|
||||
* The macro can be turned off in final releases of code by defining
|
||||
* `G_DISABLE_ASSERT` when compiling the application, so code must
|
||||
* not depend on any side effects from @expr.
|
||||
* not depend on any side effects from @expr. Similarly, it must not be used
|
||||
* in unit tests, otherwise the unit tests will be ineffective if compiled with
|
||||
* `G_DISABLE_ASSERT`. Use g_assert_true() and related macros in unit tests
|
||||
* instead.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -484,7 +491,8 @@
|
||||
* application is terminated.
|
||||
*
|
||||
* The macro can be turned off in final releases of code by defining
|
||||
* `G_DISABLE_ASSERT` when compiling the application.
|
||||
* `G_DISABLE_ASSERT` when compiling the application. Hence, it should not be
|
||||
* used in unit tests, where assertions should always be effective.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -497,6 +505,10 @@
|
||||
* an error message is logged and the application is either
|
||||
* terminated or the testcase marked as failed.
|
||||
*
|
||||
* Note that unlike g_assert(), this macro is unaffected by whether
|
||||
* `G_DISABLE_ASSERT` is defined. Hence it should only be used in tests and,
|
||||
* conversely, g_assert() should not be used in tests.
|
||||
*
|
||||
* See g_test_set_nonfatal_assertions().
|
||||
*
|
||||
* Since: 2.38
|
||||
@ -512,6 +524,10 @@
|
||||
* an error message is logged and the application is either
|
||||
* terminated or the testcase marked as failed.
|
||||
*
|
||||
* Note that unlike g_assert(), this macro is unaffected by whether
|
||||
* `G_DISABLE_ASSERT` is defined. Hence it should only be used in tests and,
|
||||
* conversely, g_assert() should not be used in tests.
|
||||
*
|
||||
* See g_test_set_nonfatal_assertions().
|
||||
*
|
||||
* Since: 2.38
|
||||
@ -527,6 +543,10 @@
|
||||
* an error message is logged and the application is either
|
||||
* terminated or the testcase marked as failed.
|
||||
*
|
||||
* Note that unlike g_assert(), this macro is unaffected by whether
|
||||
* `G_DISABLE_ASSERT` is defined. Hence it should only be used in tests and,
|
||||
* conversely, g_assert() should not be used in tests.
|
||||
*
|
||||
* See g_test_set_nonfatal_assertions().
|
||||
*
|
||||
* Since: 2.38
|
||||
@ -542,6 +562,10 @@
|
||||
* an error message is logged and the application is either
|
||||
* terminated or the testcase marked as failed.
|
||||
*
|
||||
* Note that unlike g_assert(), this macro is unaffected by whether
|
||||
* `G_DISABLE_ASSERT` is defined. Hence it should only be used in tests and,
|
||||
* conversely, g_assert() should not be used in tests.
|
||||
*
|
||||
* See g_test_set_nonfatal_assertions().
|
||||
*
|
||||
* Since: 2.40
|
||||
|
Loading…
Reference in New Issue
Block a user