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';
|
||||
|
@ -34,6 +35,19 @@ void main() {
|
|||
expect(repo.status.isEmpty, true);
|
||||
});
|
||||
|
||||
test('throws when trying to save and error occurs', () {
|
||||
expect(
|
||||
() => Repository(nullptr).createStash(stasher: stasher),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"invalid argument: 'repo'",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully saves changes to stash including ignored', () {
|
||||
final swpPath = File('${tmpDir.path}/some.swp');
|
||||
swpPath.writeAsStringSync('ignored');
|
||||
|
@ -78,6 +92,19 @@ void main() {
|
|||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
test('successfully applies changes from stash with paths provided', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
expect(repo.status.isEmpty, true);
|
||||
|
||||
repo.applyStash(paths: ['file']);
|
||||
expect(repo.status, contains('file'));
|
||||
});
|
||||
|
||||
test('successfully applies changes from stash including index changes', () {
|
||||
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
|
||||
final index = repo.index;
|
||||
|
@ -95,6 +122,26 @@ void main() {
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to apply with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.applyStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully drops stash', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
@ -103,10 +150,30 @@ void main() {
|
|||
|
||||
repo.createStash(stasher: stasher);
|
||||
final stash = repo.stashes.first;
|
||||
repo.dropStash(stash.index);
|
||||
repo.dropStash(index: stash.index);
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('throws when trying to drop with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.dropStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully pops from stash', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
@ -119,6 +186,18 @@ void main() {
|
|||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('successfully pops from stash with provided path', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
repo.popStash(paths: ['file']);
|
||||
expect(repo.status, contains('file'));
|
||||
expect(() => repo.applyStash(), throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
|
||||
test('successfully pops from stash including index changes', () {
|
||||
File('${tmpDir.path}/stash.this').writeAsStringSync('stash');
|
||||
final index = repo.index;
|
||||
|
@ -136,6 +215,26 @@ void main() {
|
|||
index.free();
|
||||
});
|
||||
|
||||
test('throws when trying to pop with wrong index', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
mode: FileMode.append,
|
||||
);
|
||||
|
||||
repo.createStash(stasher: stasher);
|
||||
|
||||
expect(
|
||||
() => repo.popStash(index: 10),
|
||||
throwsA(
|
||||
isA<LibGit2Error>().having(
|
||||
(e) => e.toString(),
|
||||
'error',
|
||||
"no stashed state at position 10",
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns list of stashes', () {
|
||||
File('${tmpDir.path}/file').writeAsStringSync(
|
||||
'edit',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue