test: add more tests for throws and their messages

This commit is contained in:
Aleksey Kulikov 2021-10-19 17:16:39 +03:00
parent d6eae1e9ed
commit 127849519d
80 changed files with 2741 additions and 1501 deletions

View file

@ -1,3 +1,4 @@
import 'dart:ffi';
import 'dart:io';
import 'package:test/test.dart';
import 'package:libgit2dart/libgit2dart.dart';
@ -25,6 +26,25 @@ void main() {
});
group('RevWalk', () {
test('successfully initializes', () {
final walker = RevWalk(repo);
expect(walker, isA<RevWalk>());
walker.free();
});
test('throws when trying to initialize and error occurs', () {
expect(
() => RevWalk(Repository(nullptr)),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'repo'",
),
),
);
});
test('returns list of commits with default sorting', () {
final walker = RevWalk(repo);
final start = Oid.fromSHA(repo: repo, sha: log.first);
@ -88,11 +108,9 @@ void main() {
test('successfully hides commit and its ancestors', () {
final walker = RevWalk(repo);
final start = Oid.fromSHA(repo: repo, sha: log.first);
final oidToHide = Oid.fromSHA(repo: repo, sha: log[2]);
walker.push(start);
walker.hide(oidToHide);
walker.push(repo[log.first]);
walker.hide(repo[log[2]]);
final commits = walker.walk();
expect(commits.length, 2);
@ -103,6 +121,23 @@ void main() {
walker.free();
});
test('throws when trying to hide commit oid and error occurs', () {
final walker = RevWalk(repo);
expect(
() => walker.hide(repo['0' * 40]),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"odb: cannot read object: null OID cannot exist",
),
),
);
walker.free();
});
test('successfully resets walker', () {
final walker = RevWalk(repo);
final start = Oid.fromSHA(repo: repo, sha: log.first);
@ -134,5 +169,23 @@ void main() {
}
walker.free();
});
test('throws when trying to add new root for traversal and error occurs',
() {
final walker = RevWalk(repo);
expect(
() => walker.push(repo['0' * 40]),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"odb: cannot read object: null OID cannot exist",
),
),
);
walker.free();
});
});
}