Skip to content

Commit 8e5281c

Browse files
pks-tethomson
authored andcommitted
tests: add allocation failure test for buffers
Test that `git_buf` correctly fails if no more bytes can be allocated. This is mostly for demonstration purposes.
1 parent 90cc077 commit 8e5281c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/util/str/oom.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "clar_libgit2.h"
2+
#include "clar_libgit2_alloc.h"
23

34
/* Override default allocators with ones that will fail predictably. */
45

@@ -56,3 +57,15 @@ void test_str_oom__grow_by(void)
5657
cl_assert(git_str_grow_by(&buf, 101) == -1);
5758
cl_assert(git_str_oom(&buf));
5859
}
60+
61+
void test_str_oom__allocation_failure(void)
62+
{
63+
git_str buf = GIT_STR_INIT;
64+
65+
cl_alloc_limit(10);
66+
67+
cl_git_pass(git_str_puts(&buf, "foobar"));
68+
cl_git_fail(git_str_puts(&buf, "foobar"));
69+
70+
cl_alloc_reset();
71+
}

0 commit comments

Comments
 (0)