mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
test: add more tests for throws and their messages
This commit is contained in:
parent
d6eae1e9ed
commit
127849519d
80 changed files with 2741 additions and 1501 deletions
|
@ -1,3 +1,4 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
|
@ -41,12 +42,44 @@ void main() {
|
|||
});
|
||||
|
||||
group('Commit', () {
|
||||
test('successfully returns when 40 char sha hex is provided', () {
|
||||
test('successfully lookups for provided oid', () {
|
||||
final commit = repo.lookupCommit(mergeCommit);
|
||||
expect(commit, isA<Commit>());
|
||||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup with invalid oid', () {
|
||||
expect(
|
||||
() => repo.lookupCommit(repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully lookups annotated commit for provided oid', () {
|
||||
final annotated = AnnotatedCommit.lookup(repo: repo, oid: mergeCommit);
|
||||
expect(annotated, isA<AnnotatedCommit>());
|
||||
annotated.free();
|
||||
});
|
||||
|
||||
test('throws when trying to lookup annotated commit with invalid oid', () {
|
||||
expect(
|
||||
() => AnnotatedCommit.lookup(repo: repo, oid: repo['0' * 40]),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"odb: cannot read object: null OID cannot exist",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully reverts commit', () {
|
||||
final to = repo.lookupCommit(
|
||||
repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'],
|
||||
|
@ -66,6 +99,23 @@ void main() {
|
|||
from.free();
|
||||
});
|
||||
|
||||
test('throws when trying to revert commit and error occurs', () {
|
||||
final nullCommit = Commit(nullptr);
|
||||
expect(
|
||||
() => repo.revertCommit(
|
||||
revertCommit: nullCommit,
|
||||
ourCommit: nullCommit,
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'revert_commit'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates commit', () {
|
||||
final parent = repo.lookupCommit(mergeCommit);
|
||||
final oid = repo.createCommit(
|
||||
|
@ -148,6 +198,30 @@ void main() {
|
|||
commit.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create commit and error occurs', () {
|
||||
final parent = repo.lookupCommit(mergeCommit);
|
||||
final nullRepo = Repository(nullptr);
|
||||
|
||||
expect(
|
||||
() => nullRepo.createCommit(
|
||||
message: message,
|
||||
author: author,
|
||||
commiter: commiter,
|
||||
tree: tree,
|
||||
parents: [parent],
|
||||
),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'git_tree_owner(tree) == repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
parent.free();
|
||||
});
|
||||
|
||||
test('returns string representation of Commit object', () {
|
||||
final commit = repo.lookupCommit(mergeCommit);
|
||||
expect(commit.toString(), contains('Commit{'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue