aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorkatherine <ageha@airen-no-jikken.icu>2019-06-15 18:51:10 -0700
committerkatherine <ageha@airen-no-jikken.icu>2019-06-15 18:51:10 -0700
commit8b1b6b7f1b8ab79e5fd3d4d16e7de7ec681130b7 (patch)
treef70f7a1b6e49a23b3699ad617dee2436d9134e92 /doc
parentcae280b3246a51cd485cb01c8ec73a205ceac7e8 (diff)
downloadsimple-test-8b1b6b7f1b8ab79e5fd3d4d16e7de7ec681130b7.tar.gz
replace USE/REGISTER_TEARDOWN with TEARDOWNHEADmaster
simpler and more flexible
Diffstat (limited to 'doc')
-rw-r--r--doc/example.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/doc/example.c b/doc/example.c
index 0229d2a..c048465 100644
--- a/doc/example.c
+++ b/doc/example.c
@@ -10,14 +10,15 @@
/* global variables, functions, and includes must come before BEGIN_TEST */
char *global_s;
-/* a teardown function is called by TESTs which include USE_TEARDOWN. the call
- * occurs either after an ASSERT fails or after the TEST is finished.
+/* a teardown function must be of type `void function(void)` and can be called
+ * by TESTs which include them using the TEARDOWN macro. the call occurs either
+ * after an ASSERT fails or after the TEST is finished.
+ *
+ * the macro may be called multiple times, but only the most recently set
+ * teardown function will be called.
*
- * defining one is optional, but, if used, REGISTER_TEARDOWN must appear
- * between BEGIN_TEST and the first TEST statement.
- *
* here i'm using it to free memory that's alloced inside tests below */
-void teardown(void)
+void teardown_fun(void)
{
free(global_s);
}
@@ -25,9 +26,6 @@ void teardown(void)
/* must appear before an (optional) REGISTER_TEARDOWN and all TESTs */
BEGIN_TEST
-/* if used, must appear before first TEST and after BEGIN_TEST */
-REGISTER_TEARDOWN(teardown);
-
/* run a test. provided description must be a string literal */
TEST("basic assertion")
{
@@ -86,9 +84,9 @@ TEST("string comparison")
char *s = "test";
global_s = strdup("test");
- /* USE_TEARDOWN; tells this test to call the previously defined teardown
- * function on exiting (successfully or otherwise) */
- USE_TEARDOWN;
+ /* this tells this test to call the previously defined teardown function on
+ * exiting (successfully or otherwise) */
+ TEARDOWN(teardown_fun);
/* strings are compared by content, so this assertion succeeds */
ASSERT_EQ(s, global_s);
@@ -98,7 +96,7 @@ TEST("pointer comparison")
{
char *s = "test";
global_s = strdup("test");
- USE_TEARDOWN;
+ TEARDOWN(teardown_fun);
/* you can cast parameters in order to use a different type of comparison.
* here i'm casting the 'char *' to 'void *' so assertion performs a