summaryrefslogtreecommitdiffstats
path: root/tests/util/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/util/errors.c')
-rw-r--r--tests/util/errors.c84
1 files changed, 40 insertions, 44 deletions
diff --git a/tests/util/errors.c b/tests/util/errors.c
index 78654a7..f9b85a6 100644
--- a/tests/util/errors.c
+++ b/tests/util/errors.c
@@ -5,7 +5,10 @@ void test_errors__public_api(void)
char *str_in_error;
git_error_clear();
- cl_assert(git_error_last() == NULL);
+
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
git_error_set_oom();
@@ -23,7 +26,9 @@ void test_errors__public_api(void)
cl_assert(str_in_error != NULL);
git_error_clear();
- cl_assert(git_error_last() == NULL);
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
}
#include "common.h"
@@ -35,7 +40,9 @@ void test_errors__new_school(void)
char *str_in_error;
git_error_clear();
- cl_assert(git_error_last() == NULL);
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
git_error_set_oom(); /* internal fn */
@@ -53,7 +60,9 @@ void test_errors__new_school(void)
cl_assert(str_in_error != NULL);
git_error_clear();
- cl_assert(git_error_last() == NULL);
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
do {
struct stat st;
@@ -88,52 +97,32 @@ void test_errors__new_school(void)
void test_errors__restore(void)
{
- git_error_state err_state = {0};
+ git_error *last_error;
git_error_clear();
- cl_assert(git_error_last() == NULL);
-
- cl_assert_equal_i(0, git_error_state_capture(&err_state, 0));
-
- memset(&err_state, 0x0, sizeof(git_error_state));
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp("no error", git_error_last()->message) == 0);
git_error_set(42, "Foo: %s", "bar");
- cl_assert_equal_i(-1, git_error_state_capture(&err_state, -1));
-
- cl_assert(git_error_last() == NULL);
-
- git_error_set(99, "Bar: %s", "foo");
-
- git_error_state_restore(&err_state);
-
- cl_assert_equal_i(42, git_error_last()->klass);
- cl_assert_equal_s("Foo: bar", git_error_last()->message);
-}
-
-void test_errors__free_state(void)
-{
- git_error_state err_state = {0};
+ cl_assert(git_error_save(&last_error) == 0);
git_error_clear();
-
- git_error_set(42, "Foo: %s", "bar");
- cl_assert_equal_i(-1, git_error_state_capture(&err_state, -1));
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp("no error", git_error_last()->message) == 0);
git_error_set(99, "Bar: %s", "foo");
- git_error_state_free(&err_state);
-
- cl_assert_equal_i(99, git_error_last()->klass);
- cl_assert_equal_s("Bar: foo", git_error_last()->message);
+ git_error_restore(last_error);
- git_error_state_restore(&err_state);
-
- cl_assert(git_error_last() == NULL);
+ cl_assert(git_error_last()->klass == 42);
+ cl_assert(strcmp("Foo: bar", git_error_last()->message) == 0);
}
void test_errors__restore_oom(void)
{
- git_error_state err_state = {0};
+ git_error *last_error;
const git_error *oom_error = NULL;
git_error_clear();
@@ -141,15 +130,18 @@ void test_errors__restore_oom(void)
git_error_set_oom(); /* internal fn */
oom_error = git_error_last();
cl_assert(oom_error);
+ cl_assert(oom_error->klass == GIT_ERROR_NOMEMORY);
- cl_assert_equal_i(-1, git_error_state_capture(&err_state, -1));
-
- cl_assert(git_error_last() == NULL);
- cl_assert_equal_i(GIT_ERROR_NOMEMORY, err_state.error_msg.klass);
- cl_assert_equal_s("Out of memory", err_state.error_msg.message);
+ cl_assert(git_error_save(&last_error) == 0);
+ cl_assert(last_error->klass == GIT_ERROR_NOMEMORY);
+ cl_assert(strcmp("Out of memory", last_error->message) == 0);
- git_error_state_restore(&err_state);
+ git_error_clear();
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp("no error", git_error_last()->message) == 0);
+ git_error_restore(last_error);
cl_assert(git_error_last()->klass == GIT_ERROR_NOMEMORY);
cl_assert_(git_error_last() == oom_error, "static oom error not restored");
@@ -204,11 +196,15 @@ void test_errors__integer_overflow_sets_oom(void)
git_error_clear();
cl_assert(!GIT_ADD_SIZET_OVERFLOW(&out, SIZE_MAX-1, 1));
- cl_assert_equal_p(NULL, git_error_last());
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
git_error_clear();
cl_assert(!GIT_ADD_SIZET_OVERFLOW(&out, 42, 69));
- cl_assert_equal_p(NULL, git_error_last());
+ cl_assert(git_error_last() != NULL);
+ cl_assert(git_error_last()->klass == GIT_ERROR_NONE);
+ cl_assert(strcmp(git_error_last()->message, "no error") == 0);
git_error_clear();
cl_assert(GIT_ADD_SIZET_OVERFLOW(&out, SIZE_MAX, SIZE_MAX));