aboutsummaryrefslogtreecommitdiffstats
path: root/t/unit-tests/test-lib.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-08-19 11:07:36 -0700
committerJunio C Hamano <gitster@pobox.com>2024-08-19 11:07:36 -0700
commit4dbca805e07de19412807da9dde45bd61f510710 (patch)
treeaeebd2cda1c4573e866de1a72cf6456ed7c46dbd /t/unit-tests/test-lib.h
parentb9849e4f7631d80f146d159bf7b60263b3205632 (diff)
parent9ddec6b79af6786bc628e66a75f47040fea1857b (diff)
downloadgit-4dbca805e07de19412807da9dde45bd61f510710.tar.gz
Merge branch 'rs/unit-tests-test-run'
Unit-test framework has learned a simple control structure to allow embedding test statements in-line instead of having to create a new function to contain them. * rs/unit-tests-test-run: t-strvec: use if_test t-reftable-basics: use if_test t-ctype: use if_test unit-tests: add if_test unit-tests: show location of checks outside of tests t0080: use here-doc test body
Diffstat (limited to 't/unit-tests/test-lib.h')
-rw-r--r--t/unit-tests/test-lib.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/t/unit-tests/test-lib.h b/t/unit-tests/test-lib.h
index c59f646fd9..e4b234697f 100644
--- a/t/unit-tests/test-lib.h
+++ b/t/unit-tests/test-lib.h
@@ -15,6 +15,23 @@
TEST_LOCATION(), __VA_ARGS__)
/*
+ * Run a test unless test_skip_all() has been called. Acts like a
+ * conditional; the test body is expected as a statement or block after
+ * the closing parenthesis. The description for each test should be
+ * unique. E.g.:
+ *
+ * if_test ("something else %d %d", arg1, arg2) {
+ * prepare();
+ * test_something_else(arg1, arg2);
+ * cleanup();
+ * }
+ */
+#define if_test(...) \
+ if (test__run_begin() ? \
+ (test__run_end(0, TEST_LOCATION(), __VA_ARGS__), 0) : \
+ (test__run_describe(TEST_LOCATION(), __VA_ARGS__), 1))
+
+/*
* Print a test plan, should be called before any tests. If the number
* of tests is not known in advance test_done() will automatically
* print a plan at the end of the test program.
@@ -154,6 +171,9 @@ union test__tmp {
extern union test__tmp test__tmp[2];
+__attribute__((format (printf, 2, 3)))
+void test__run_describe(const char *, const char *, ...);
+
int test__run_begin(void);
__attribute__((format (printf, 3, 4)))
int test__run_end(int, const char *, const char *, ...);