summaryrefslogtreecommitdiff
path: root/tests/util
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-02-27 09:20:58 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-02-27 09:20:58 -0500
commitd9b041e6d7de9e2fc8fcdbb6e28acba45af4d888 (patch)
tree6db5e99e79b945b4097b71bef49346f50c9c33c2 /tests/util
parente32db9f2b85685801fb249e35bf62a32ef09dc98 (diff)
downloadlibgit2-d9b041e6d7de9e2fc8fcdbb6e28acba45af4d888.tar.gz
assert: add `ASSERT_WITH_CLEANUP`
Now that we safely assert and return, we may need to be in a place where we need to unlock mutexes or cleanup resources. Provide `ASSERT_WITH_CLEANUP` that permits for this behavior by taking a block.
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/assert.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/util/assert.c b/tests/util/assert.c
index 26c429787..3babc475a 100644
--- a/tests/util/assert.c
+++ b/tests/util/assert.c
@@ -36,6 +36,21 @@ static const char *bad_returns_string(void)
return hello_world;
}
+static int has_cleanup(void)
+{
+ int error = 42;
+
+ GIT_ASSERT_WITH_CLEANUP(1 + 1 == 3, {
+ error = 99;
+ goto foobar;
+ });
+
+ return 0;
+
+foobar:
+ return error;
+}
+
void test_assert__argument(void)
{
cl_git_fail(dummy_fn(NULL));
@@ -92,3 +107,11 @@ void test_assert__internal(void)
cl_assert_equal_i(GIT_ERROR_INTERNAL, git_error_last()->klass);
cl_assert_equal_s("unrecoverable internal error: '1 + 1 == 3'", git_error_last()->message);
}
+
+void test_assert__with_cleanup(void)
+{
+ cl_git_fail_with(99, has_cleanup());
+ cl_assert(git_error_last());
+ cl_assert_equal_i(GIT_ERROR_INTERNAL, git_error_last()->klass);
+ cl_assert_equal_s("unrecoverable internal error: '1 + 1 == 3'", git_error_last()->message);
+}