src/cx/test.h

changeset 985
68754c7de906
parent 959
0e1bf3c199bf
--- a/src/cx/test.h	Thu Nov 07 20:22:56 2024 +0100
+++ b/src/cx/test.h	Thu Nov 07 22:46:58 2024 +0100
@@ -96,6 +96,7 @@
 typedef struct CxTestSuite CxTestSuite;
 
 /** Pointer to a test function. */
+cx_attr_nonnull
 typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func);
 
 /** Type for the internal list of test cases. */
@@ -137,6 +138,10 @@
  * @param name optional name of the suite
  * @return a new test suite
  */
+cx_attr_nonnull
+cx_attr_nodiscard
+cx_attr_cstr_arg(1)
+cx_attr_malloc
 static inline CxTestSuite* cx_test_suite_new(const char *name) {
     CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite));
     if (suite != NULL) {
@@ -154,6 +159,7 @@
  * @param suite the test suite to destroy
  */
 static inline void cx_test_suite_free(CxTestSuite* suite) {
+    if (suite == NULL) return;
     CxTestSet *l = suite->tests;
     while (l != NULL) {
         CxTestSet *e = l;
@@ -170,6 +176,7 @@
  * @param test the test function to register
  * @return zero on success or non-zero on failure
  */
+cx_attr_nonnull
 static inline int cx_test_register(CxTestSuite* suite, CxTest test) {
     CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet));
     if (t) {
@@ -196,6 +203,7 @@
  * @param out_target the target buffer or file to write the output to
  * @param out_writer the write function writing to \p out_target
  */
+cx_attr_nonnull
 static inline void cx_test_run(CxTestSuite *suite,
                                void *out_target, cx_write_func out_writer) {
     if (suite->name == NULL) {

mercurial