Skip to content

Commit

Permalink
Adds OR_RETURN test macros. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
phkaeser authored Jun 23, 2024
1 parent 60e6011 commit 179fc58
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,20 @@ const char *bs_test_resolve_path(const char *fname_ptr);
/* == Verification macros ================================================== */

/**
* Reports the test as failed, at current position .
* Reports the test as failed, at current position.
*
* @param _test
*/
#define BS_TEST_FAIL(_test, ...) { \
bs_test_fail_at((_test), __FILE__, __LINE__, __VA_ARGS__); \
}

/** Verifies that _expr is true, and returns (stops tests) if not. */
#define BS_TEST_VERIFY_TRUE_OR_RETURN(_test, _expr) { \
BS_TEST_VERIFY_TRUE(_test, _expr); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that _expr is true.
*
Expand All @@ -226,6 +232,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
} \
}

/** Verifies that _expr is false, and reutrns (stop tests) if not. */
#define BS_TEST_VERIFY_FALSE_OR_RETURN(_test, _expr) { \
BS_TEST_VERIFY_FALSE(_test, _expr); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that _expr is false.
*
Expand All @@ -239,6 +251,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
} \
}

/** Verifies that _a == _b, and reutrns (stop tests) if not. */
#define BS_TEST_VERIFY_EQ_OR_RETURN(_test, _a, _b) { \
BS_TEST_VERIFY_EQ(_test, _a, _b); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that _a == _b
*
Expand All @@ -253,6 +271,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
} \
}

/** Verifies that _a != _b, and reutrns (stop tests) if not. */
#define BS_TEST_VERIFY_NEQ_OR_RETURN(_test, _a, _b) { \
BS_TEST_VERIFY_NEQ(_test, _a, _b); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that _a != _b
*
Expand All @@ -267,6 +291,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
} \
}

/** Verifies that the strings _a == _b. Returns (stop test) if not. */
#define BS_TEST_VERIFY_STREQ_OR_RETURN(_test, _a, _b) { \
BS_TEST_VERIFY_STREQ(_test, _a, _b); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that the strings _a == _b.
*
Expand All @@ -279,6 +309,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
(_test), __FILE__, __LINE__, _a, #_a, _b, #_b); \
}

/** Verifies that the string _a matches _regex.. Returns (stop test) if not. */
#define BS_TEST_VERIFY_STRMATCH_OR_RETURN(_test, _a, _regex) { \
BS_TEST_VERIFY_STRMATCH(_test, _a, _regex); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that the string _a matches the regular expression _regex.
*
Expand All @@ -291,6 +327,12 @@ const char *bs_test_resolve_path(const char *fname_ptr);
(_test), __FILE__, __LINE__, _a, #_a, _regex); \
}

/** Verifies that the memory buffers _a == _b. Returns (stop tests) if not. */
#define BS_TEST_VERIFY_MEMEQ_OR_RETURN(_test, _a, _b, _size) { \
BS_TEST_VERIFY_MEMEQ(_test, _a, _b, _size); \
if (bs_test_failed(test_ptr)) return; \
}

/**
* Verifies that the memory buffers _a == _b.
*
Expand Down

0 comments on commit 179fc58

Please sign in to comment.