Handle allocation failures when instantiating documents

This commit is contained in:
Max Brunsfeld 2016-01-18 10:44:49 -08:00
parent 9d0835edbf
commit 1543a6c7b0
12 changed files with 255 additions and 31 deletions

View file

@ -2,6 +2,7 @@
#include "helpers/spy_input.h"
#include "helpers/test_languages.h"
#include "helpers/log_debugger.h"
#include "helpers/record_alloc.h"
START_TEST
@ -14,11 +15,14 @@ describe("Parser", [&]() {
before_each([&]() {
chunk_size = 3;
input = nullptr;
doc = ts_document_make();
});
after_each([&]() {
ts_document_free(doc);
if (doc)
ts_document_free(doc);
if (input)
delete input;
});
@ -421,6 +425,32 @@ describe("Parser", [&]() {
AssertThat(ts_node_end_byte(root), Equals(strlen("'\u03A9\u03A9\u03A9 \u2014 \u0394\u0394';")));
});
});
describe("handling allocation failures", [&]() {
before_each([&]() {
record_alloc::start();
});
after_each([&]() {
record_alloc::stop();
});
it("handles failures when allocating documents", [&]() {
TSDocument *document = ts_document_make();
ts_document_free(document);
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
size_t allocation_count = record_alloc::allocation_count();
AssertThat(allocation_count, IsGreaterThan<size_t>(1));
for (size_t i = 0; i < allocation_count; i++) {
record_alloc::start();
record_alloc::fail_at_allocation_index(i);
AssertThat(ts_document_make(), Equals<TSDocument *>(nullptr));
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
}
});
});
});
END_TEST