refactor!: use Finalizer to automatically free allocated memory for objects (#48)

BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
Aleksey Kulikov 2022-04-28 11:04:48 +03:00 committed by GitHub
parent 94c40f9a94
commit a3213a88a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 2278 additions and 2595 deletions

View file

@ -29,8 +29,6 @@ void main() {
expect(annotated.oid, tip);
expect(annotated.refName, '');
annotated.free();
});
test('throws when trying to lookup annotated commit with invalid oid', () {
@ -41,33 +39,27 @@ void main() {
});
test('creates annotated commit from provided reference', () {
final reference = Reference.lookup(repo: repo, name: 'refs/heads/master');
const refName = 'refs/heads/master';
final reference = Reference.lookup(repo: repo, name: refName);
final annotated = AnnotatedCommit.fromReference(
repo: repo,
reference: reference,
);
expect(annotated.oid, reference.target);
expect(annotated.refName, 'refs/heads/master');
annotated.free();
reference.free();
expect(annotated.refName, refName);
});
test(
'throws when trying to create annotated commit from provided '
'reference and error occurs', () {
final reference = Reference.lookup(repo: repo, name: 'refs/heads/master');
expect(
() => AnnotatedCommit.fromReference(
repo: Repository(nullptr),
reference: reference,
reference: Reference.lookup(repo: repo, name: 'refs/heads/master'),
),
throwsA(isA<LibGit2Error>()),
);
reference.free();
});
test('creates annotated commit from provided revspec', () {
@ -75,8 +67,6 @@ void main() {
expect(annotated.oid.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
expect(annotated.refName, '');
annotated.free();
});
test('throws when trying to create annotated commit from invalid revspec',
@ -98,8 +88,6 @@ void main() {
expect(annotated.oid, oid);
expect(annotated.refName, 'master');
annotated.free();
});
test(
@ -115,5 +103,10 @@ void main() {
throwsA(isA<LibGit2Error>()),
);
});
test('manually releases allocated memory', () {
final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip);
expect(() => annotated.free(), returnsNormally);
});
});
}