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';
@ -85,6 +86,35 @@ void main() {
worktree.free();
});
test('throws when trying to create worktree with invalid name or path', () {
expect(
() => repo.createWorktree(
name: '',
path: worktreeDir.path,
),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
contains('failed to make directory'),
),
),
);
expect(
() => repo.createWorktree(
name: 'name',
path: '',
),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
'attempt to create empty path: Invalid argument',
),
),
);
});
test('successfully lookups worktree', () {
final worktree = repo.createWorktree(
name: worktreeName,
@ -100,6 +130,19 @@ void main() {
worktree.free();
});
test('throws when trying to lookup and error occurs', () {
expect(
() => Worktree.lookup(repo: Repository(nullptr), name: 'name'),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'repo'",
),
),
);
});
test('successfully locks and unlocks worktree', () {
final worktree = repo.createWorktree(
name: worktreeName,
@ -136,5 +179,18 @@ void main() {
worktree.free();
});
test('throws when trying get list of worktrees and error occurs', () {
expect(
() => Worktree.list(Repository(nullptr)),
throwsA(
isA<LibGit2Error>().having(
(e) => e.toString(),
'error',
"invalid argument: 'repo'",
),
),
);
});
});
}