diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index c4bdf32..0d5c798 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -7,6 +7,9 @@ on: branches: [master] workflow_dispatch: +env: + PUB_ENVIRONMENT: bot.github + jobs: analyze: runs-on: ubuntu-latest diff --git a/lib/src/config.dart b/lib/src/config.dart index eff0621..f0daba1 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -141,7 +141,6 @@ class Config with IterableMixin { /// highest level (usually the local one). /// /// The [regexp] is applied case-sensitively on the value. - /// Empty [regexp] sets [value] for all values of a multivar [variable]. void setMultivar({ required String variable, required String regexp, @@ -159,7 +158,6 @@ class Config with IterableMixin { /// file with the highest level (usually the local one). /// /// The [regexp] is applied case-sensitively on the value. - /// Empty [regexp] deletes all values of a multivar [variable]. void deleteMultivar({required String variable, required String regexp}) { bindings.deleteMultivar( configPointer: _configPointer, diff --git a/lib/src/error.dart b/lib/src/error.dart index 08c14e9..83cac80 100644 --- a/lib/src/error.dart +++ b/lib/src/error.dart @@ -1,3 +1,5 @@ +// coverage:ignore-file + import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; diff --git a/test/blame_test.dart b/test/blame_test.dart index 4c270f7..2293af1 100644 --- a/test/blame_test.dart +++ b/test/blame_test.dart @@ -85,16 +85,7 @@ void main() { }); test('throws when provided file path is invalid', () { - expect( - () => repo.blame(path: 'invalid'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the path 'invalid' does not exist in the given tree", - ), - ), - ); + expect(() => repo.blame(path: 'invalid'), throwsA(isA())); }); test( @@ -134,32 +125,14 @@ void main() { test('throws when provided index for hunk is invalid', () { final blame = repo.blame(path: 'feature_file'); - expect( - () => blame[10], - throwsA( - isA().having( - (e) => e.message, - 'error', - '10 is out of bounds', - ), - ), - ); + expect(() => blame[10], throwsA(isA())); blame.free(); }); test('throws when provided line number for hunk is invalid', () { final blame = repo.blame(path: 'feature_file'); - expect( - () => blame.forLine(10), - throwsA( - isA().having( - (e) => e.message, - 'error', - '10 is out of bounds', - ), - ), - ); + expect(() => blame.forLine(10), throwsA(isA())); blame.free(); }); diff --git a/test/blob_test.dart b/test/blob_test.dart index 6456275..a36775e 100644 --- a/test/blob_test.dart +++ b/test/blob_test.dart @@ -34,13 +34,7 @@ void main() { test('throws when trying to lookup with invalid oid', () { expect( () => repo.lookupBlob(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'odb: cannot read object: null OID cannot exist', - ), - ), + throwsA(isA()), ); }); @@ -67,13 +61,7 @@ void main() { final nullRepo = Repository(nullptr); expect( () => Blob.create(repo: nullRepo, content: ''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -93,13 +81,7 @@ void main() { test('throws when creating new blob from invalid path', () { expect( () => repo.createBlobFromWorkdir('invalid/path.txt'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "could not find '${repo.workdir}invalid/path.txt' to stat: No such file or directory", - ), - ), + throwsA(isA()), ); }); @@ -118,13 +100,7 @@ void main() { test('throws when trying to create from invalid path', () { expect( () => repo.createBlobFromDisk('invalid.file'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to resolve path 'invalid.file': No such file or directory", - ), - ), + throwsA(isA()), ); }); diff --git a/test/branch_test.dart b/test/branch_test.dart index 7dbfd87..0d318f7 100644 --- a/test/branch_test.dart +++ b/test/branch_test.dart @@ -51,16 +51,7 @@ void main() { test('throws when trying to return list and error occurs', () { final nullRepo = Repository(nullptr); - expect( - () => Branch.list(repo: nullRepo), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), - ); + expect(() => Branch.list(repo: nullRepo), throwsA(isA())); }); test('returns a branch with provided name', () { @@ -72,24 +63,12 @@ void main() { test('throws when provided name not found', () { expect( () => repo.lookupBranch(name: 'invalid'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot locate local branch 'invalid'", - ), - ), + throwsA(isA()), ); expect( () => repo.lookupBranch(name: 'origin/invalid', type: GitBranch.remote), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot locate remote-tracking branch 'origin/invalid'", - ), - ), + throwsA(isA()), ); }); @@ -108,13 +87,7 @@ void main() { final nullBranch = Branch(nullptr); expect( () => nullBranch.isHead, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'branch'", - ), - ), + throwsA(isA()), ); }); @@ -133,13 +106,7 @@ void main() { final nullBranch = Branch(nullptr); expect( () => nullBranch.isCheckedOut, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'branch'", - ), - ), + throwsA(isA()), ); }); @@ -151,16 +118,7 @@ void main() { test('throws when getting name and error occurs', () { final nullBranch = Branch(nullptr); - expect( - () => nullBranch.name, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'ref'", - ), - ), - ); + expect(() => nullBranch.name, throwsA(isA())); }); group('create()', () { @@ -185,14 +143,7 @@ void main() { expect( () => repo.createBranch(name: 'feature', target: commit), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to write reference 'refs/heads/feature': " - "a reference with that name already exists.", - ), - ), + throwsA(isA()), ); commit.free(); @@ -225,26 +176,14 @@ void main() { expect( () => repo.lookupBranch(name: 'feature'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot locate local branch 'feature'", - ), - ), + throwsA(isA()), ); }); test('throws when trying to delete current HEAD', () { expect( () => repo.deleteBranch('master'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot delete branch 'refs/heads/master' as it is the current HEAD of the repository.", - ), - ), + throwsA(isA()), ); }); }); @@ -258,13 +197,7 @@ void main() { expect(branches.length, 2); expect( () => repo.lookupBranch(name: 'feature'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot locate local branch 'feature'", - ), - ), + throwsA(isA()), ); expect(branch.target, featureCommit); @@ -277,14 +210,7 @@ void main() { test('throws when name already exists', () { expect( () => repo.renameBranch(oldName: 'feature', newName: 'master'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to write reference 'refs/heads/master': " - "a reference with that name already exists.", - ), - ), + throwsA(isA()), ); }); @@ -304,13 +230,7 @@ void main() { test('throws when name is invalid', () { expect( () => repo.renameBranch(oldName: 'feature', newName: 'inv@{id'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the given reference name 'refs/heads/inv@{id' is not valid", - ), - ), + throwsA(isA()), ); }); }); diff --git a/test/checkout_test.dart b/test/checkout_test.dart index 97db666..04af079 100644 --- a/test/checkout_test.dart +++ b/test/checkout_test.dart @@ -40,13 +40,7 @@ void main() { refName: 'HEAD', directory: 'not/there', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to make directory 'not/there': No such file or directory", - ), - ), + throwsA(isA()), ); }); @@ -69,13 +63,7 @@ void main() { 'directory', () { expect( () => repo.checkout(directory: 'not/there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to make directory 'not/there': No such file or directory", - ), - ), + throwsA(isA()), ); }); @@ -117,13 +105,7 @@ void main() { refName: 'refs/heads/feature', directory: 'not/there', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to make directory 'not/there': No such file or directory", - ), - ), + throwsA(isA()), ); }); diff --git a/test/commit_test.dart b/test/commit_test.dart index fa9e2ed..9ecae5f 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -53,13 +53,7 @@ void main() { test('throws when trying to lookup with invalid oid', () { expect( () => repo.lookupCommit(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); @@ -72,13 +66,7 @@ void main() { test('throws when trying to lookup annotated commit with invalid oid', () { expect( () => AnnotatedCommit.lookup(repo: repo, oid: repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); @@ -108,13 +96,7 @@ void main() { revertCommit: nullCommit, ourCommit: nullCommit, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'revert_commit'", - ), - ), + throwsA(isA()), ); }); @@ -212,13 +194,7 @@ void main() { tree: tree, parents: [parent], ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'git_tree_owner(tree) == repo'", - ), - ), + throwsA(isA()), ); parent.free(); @@ -309,13 +285,7 @@ void main() { message: 'amended commit\n', updateRef: 'HEAD', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "commit to amend is not the tip of the given branch", - ), - ), + throwsA(isA()), ); commit.free(); diff --git a/test/config_test.dart b/test/config_test.dart index d1a533f..1994651 100644 --- a/test/config_test.dart +++ b/test/config_test.dart @@ -54,16 +54,7 @@ void main() { }); test('throws when trying to open non existing file', () { - expect( - () => Config.open('not.there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Exception: File not found", - ), - ), - ); + expect(() => Config.open('not.there'), throwsA(isA())); }); test('successfully opens system file or throws is there is none', () { @@ -121,13 +112,7 @@ void main() { test("throws when variable isn't found", () { expect( () => config['not.there'], - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "config value 'not.there' was not found", - ), - ), + throwsA(isA()), ); }); }); @@ -151,13 +136,7 @@ void main() { test('throws when trying to set invalid value', () { expect( () => config['remote.origin.url'] = 0.1, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "0.1 must be either bool, int or String"', - ), - ), + throwsA(isA()), ); }); }); @@ -214,19 +193,6 @@ void main() { expect(multivarValues, isNot(contains('default-proxy'))); expect(multivarValues, contains('updated')); }); - - test('sets value for all multivar values when regexp is empty', () { - config.setMultivar( - variable: 'core.gitproxy', - regexp: '', - value: 'updated', - ); - final multivarValues = config.multivar(variable: 'core.gitproxy'); - expect(multivarValues, isNot(contains('default-proxy'))); - expect(multivarValues, isNot(contains('proxy-command for kernel.org'))); - expect(multivarValues, contains('updated')); - expect(multivarValues.length, 2); - }); }); group('deleteMultivar()', () { @@ -252,21 +218,6 @@ void main() { [], ); }); - - test('successfully deletes all values of a multivar when regexp is empty', - () { - expect( - config.multivar(variable: 'core.gitproxy'), - [ - 'proxy-command for kernel.org', - 'default-proxy', - ], - ); - - config.deleteMultivar(variable: 'core.gitproxy', regexp: ''); - - expect(config.multivar(variable: 'core.gitproxy'), []); - }); }); test('returns string representation of ConfigEntry object', () { diff --git a/test/credentials_test.dart b/test/credentials_test.dart index 70b4938..3b55d0d 100644 --- a/test/credentials_test.dart +++ b/test/credentials_test.dart @@ -88,13 +88,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Incorrect credentials.", - ), - ), + throwsA(isA()), ); }); @@ -124,13 +118,7 @@ void main() { url: 'ssh://git@github.com/libgit2/TestGitRepository', localPath: cloneDir.path, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "authentication required but no callback set", - ), - ), + throwsA(isA()), ); }); @@ -149,14 +137,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Failed to authenticate SSH session: Unable to open public key ' - 'file', - ), - ), + throwsA(isA()), ); }); @@ -175,13 +156,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Incorrect credentials.", - ), - ), + throwsA(isA()), ); }); @@ -199,13 +174,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Invalid credential type GitCredential.userPassPlainText", - ), - ), + throwsA(isA()), ); }); @@ -247,13 +216,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Incorrect credentials.", - ), - ), + throwsA(isA()), ); }); @@ -266,13 +229,7 @@ void main() { localPath: cloneDir.path, callbacks: callbacks, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Incorrect credentials.", - ), - ), + throwsA(isA()), ); }); }); diff --git a/test/describe_test.dart b/test/describe_test.dart index 7b210f3..d674b2c 100644 --- a/test/describe_test.dart +++ b/test/describe_test.dart @@ -27,16 +27,7 @@ void main() { test('throws when trying to describe and error occurs', () { final nullRepo = Repository(nullptr); - expect( - () => nullRepo.describe(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), - ); + expect(() => nullRepo.describe(), throwsA(isA())); }); test('successfully describes commit', () { @@ -50,17 +41,7 @@ void main() { test('throws when trying to describe and no reference found', () { final commit = repo.lookupCommit(repo['f17d0d48']); - expect( - () => repo.describe(commit: commit), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot describe - no tags can describe " - "'f17d0d48eae3aa08cecf29128a35e310c97b3521'.", - ), - ), - ); + expect(() => repo.describe(commit: commit), throwsA(isA())); commit.free(); }); @@ -93,7 +74,7 @@ void main() { target: repo['f17d0d48'], targetType: GitObject.commit, tagger: signature, - message: '', + message: 'message', ); expect( diff --git a/test/diff_test.dart b/test/diff_test.dart index dbea2cf..6f88381 100644 --- a/test/diff_test.dart +++ b/test/diff_test.dart @@ -148,16 +148,7 @@ index e69de29..c217c63 100644 () { final nullRepo = Repository(nullptr); final nullTree = Tree(nullptr); - expect( - () => nullRepo.diff(a: nullTree), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), - ); + expect(() => nullRepo.diff(a: nullTree), throwsA(isA())); }); test('successfully returns diff between tree and index', () { @@ -204,28 +195,13 @@ index e69de29..c217c63 100644 final nullTree = Tree(nullptr); expect( () => nullRepo.diff(a: nullTree, b: nullTree), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); test('throws when trying to diff between null and tree', () { final tree = repo.lookupTree(repo['b85d53c']); - expect( - () => repo.diff(b: tree), - throwsA( - isA().having( - (e) => e.message, - 'error', - "Must not be null", - ), - ), - ); + expect(() => repo.diff(b: tree), throwsA(isA())); tree.free(); }); @@ -293,16 +269,7 @@ index e69de29..c217c63 100644 test('throws when trying to apply diff and error occurs', () { final nullDiff = Diff(nullptr); - expect( - () => repo.apply(diff: nullDiff), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'diff'", - ), - ), - ); + expect(() => repo.apply(diff: nullDiff), throwsA(isA())); }); test('successfully creates patch from entry index in diff', () { @@ -345,30 +312,12 @@ index e69de29..c217c63 100644 test('throws when trying to find similar entries and error occurs', () { final nullDiff = Diff(nullptr); - expect( - () => nullDiff.findSimilar(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'diff'", - ), - ), - ); + expect(() => nullDiff.findSimilar(), throwsA(isA())); }); test('throws when trying to get patch Oid and error occurs', () { final nullDiff = Diff(nullptr); - expect( - () => nullDiff.patchOid, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'diff'", - ), - ), - ); + expect(() => nullDiff.patchOid, throwsA(isA())); }); test('returns deltas', () { @@ -409,16 +358,7 @@ index e69de29..c217c63 100644 final index = repo.index; final diff = index.diffToWorkdir(); - expect( - () => diff.deltas[-1], - throwsA( - isA().having( - (e) => e.message, - 'error', - "Invalid value", - ), - ), - ); + expect(() => diff.deltas[-1], throwsA(isA())); diff.free(); index.free(); @@ -456,29 +396,14 @@ index e69de29..c217c63 100644 test('throws when trying to get stats and error occurs', () { final nullDiff = Diff(nullptr); - expect( - () => nullDiff.stats, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'diff'", - ), - ), - ); + expect(() => nullDiff.stats, throwsA(isA())); }); test('throws when trying to print stats and error occurs', () { final nullStats = DiffStats(nullptr); expect( () => nullStats.print(format: {GitDiffStats.full}, width: 80), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'stats'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/index_test.dart b/test/index_test.dart index f620462..9c7777d 100644 --- a/test/index_test.dart +++ b/test/index_test.dart @@ -78,16 +78,7 @@ void main() { }); test('throws when trying to clear the contents and error occurs', () { - expect( - () => Index(nullptr).clear(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'index'", - ), - ), - ); + expect(() => Index(nullptr).clear(), throwsA(isA())); }); group('add()', () { @@ -106,29 +97,13 @@ void main() { }); test('throws if file not found at provided path', () { - expect( - () => index.add('not_there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "could not find '${repo.workdir}not_there' to stat: No such file " - "or directory", - ), - ), - ); + expect(() => index.add('not_there'), throwsA(isA())); }); test('throws if provided IndexEntry is invalid', () { expect( () => index.add(IndexEntry(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'source_entry && source_entry->path'", - ), - ), + throwsA(isA()), ); }); @@ -136,17 +111,7 @@ void main() { final bare = Repository.open('test/assets/empty_bare.git'); final bareIndex = bare.index; - expect( - () => bareIndex.add('config'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot create blob from file. This operation is not allowed " - "against bare repositories.", - ), - ), - ); + expect(() => bareIndex.add('config'), throwsA(isA())); bareIndex.free(); bare.free(); @@ -180,17 +145,7 @@ void main() { final bare = Repository.open('test/assets/empty_bare.git'); final bareIndex = bare.index; - expect( - () => bareIndex.addAll([]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot index add all. This operation is not allowed against " - "bare repositories.", - ), - ), - ); + expect(() => bareIndex.addAll([]), throwsA(isA())); bareIndex.free(); bare.free(); @@ -218,16 +173,7 @@ void main() { }); test('throws when trying to remove entry with invalid path', () { - expect( - () => index.remove('invalid'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "index does not contain invalid at stage 0", - ), - ), - ); + expect(() => index.remove('invalid'), throwsA(isA())); }); test('removes all entries with matching pathspec', () { @@ -262,13 +208,7 @@ void main() { test('throws when trying to write tree to invalid repository', () { expect( () => index.writeTree(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -280,16 +220,7 @@ void main() { final index = repo.index; repo.merge(conflictBranch.target); - expect( - () => index.writeTree(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot create a tree from a not fully merged index.", - ), - ), - ); + expect(() => index.writeTree(), throwsA(isA())); conflictBranch.free(); index.free(); @@ -418,13 +349,7 @@ void main() { expect( () => ConflictEntry(index.pointer, 'invalid.path', null, null, null) .remove(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "index does not contain invalid.path", - ), - ), + throwsA(isA()), ); }); diff --git a/test/mailmap_test.dart b/test/mailmap_test.dart index 44bd05e..b384de9 100644 --- a/test/mailmap_test.dart +++ b/test/mailmap_test.dart @@ -178,13 +178,7 @@ Santa Claus test('throws when initializing from repository and error occurs', () { expect( () => Mailmap.fromRepository(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -230,13 +224,7 @@ Santa Claus () => mailmap.addEntry( replaceEmail: ' ', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "replaceEmail can\'t be empty"', - ), - ), + throwsA(isA()), ); mailmap.free(); diff --git a/test/merge_test.dart b/test/merge_test.dart index 6ba681f..8ede70a 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -173,13 +173,7 @@ Another feature edit ours: IndexEntry(nullptr), theirs: IndexEntry(nullptr), ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'ours'", - ), - ), + throwsA(isA()), ); }); }); @@ -255,13 +249,7 @@ Another feature edit ourCommit: Commit(nullptr), theirCommit: Commit(nullptr), ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'commit'", - ), - ), + throwsA(isA()), ); }); }); @@ -277,13 +265,7 @@ Another feature edit test('throws when trying to find merge base for invalid oid', () { expect( () => repo.mergeBase(a: repo['0' * 40], b: repo['5aecfa0']), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); @@ -364,13 +346,7 @@ Another feature edit ourTree: Tree(nullptr), theirTree: Tree(nullptr), ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); }); @@ -387,13 +363,7 @@ Another feature edit repo.removeMessage(); expect( () => repo.message, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "could not access message file: No such file or directory", - ), - ), + throwsA(isA()), ); index.free(); @@ -402,13 +372,7 @@ Another feature edit test('throws when error occurs', () { expect( () => repo.cherryPick(Commit(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'commit'", - ), - ), + throwsA(isA()), ); }); }); diff --git a/test/note_test.dart b/test/note_test.dart index 7a5af7e..c204e89 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -48,16 +48,7 @@ void main() { test('throws when trying to get list of notes and error occurs', () { Directory('${repo.workdir}.git/refs/notes').deleteSync(recursive: true); - expect( - () => repo.notes, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'refs/notes/commits' not found", - ), - ), - ); + expect(() => repo.notes, throwsA(isA())); }); test('successfully lookups note', () { @@ -100,13 +91,7 @@ void main() { annotatedOid: repo['0' * 40], note: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -122,13 +107,7 @@ void main() { expect( () => repo.lookupNote(annotatedOid: head.target), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "note could not be found", - ), - ), + throwsA(isA()), ); head.free(); @@ -142,13 +121,7 @@ void main() { committer: Signature(nullptr), annotatedOid: repo['0' * 40], ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/odb_test.dart b/test/odb_test.dart index 778e729..63bf698 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -33,13 +33,7 @@ void main() { Directory('${repo.workdir}.git/objects/').deleteSync(recursive: true); expect( () => repo.odb, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - contains("failed to load object database"), - ), - ), + throwsA(isA()), ); }); @@ -77,13 +71,7 @@ void main() { expect( () => odb.read(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); odb.free(); @@ -104,13 +92,7 @@ void main() { expect( () => odb.objects, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "object not found - failed to refresh packfiles", - ), - ), + throwsA(isA()), ); odb.free(); @@ -132,13 +114,7 @@ void main() { final odb = repo.odb; expect( () => odb.write(type: GitObject.any, data: 'testing'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "GitObject.any is invalid type"', - ), - ), + throwsA(isA()), ); odb.free(); @@ -150,13 +126,7 @@ void main() { expect( () => odb.write(type: GitObject.blob, data: ''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot write object - unsupported in the loaded odb backends", - ), - ), + throwsA(isA()), ); odb.free(); diff --git a/test/oid_test.dart b/test/oid_test.dart index c9b793a..ebbb9a1 100644 --- a/test/oid_test.dart +++ b/test/oid_test.dart @@ -41,26 +41,14 @@ void main() { test('throws when sha hex string is too short', () { expect( () => Oid.fromSHA(repo: repo, sha: 'sha'), - throwsA( - isA().having( - (e) => e.toString(), - 'value', - 'Invalid argument: "sha is not a valid sha hex string"', - ), - ), + throwsA(isA()), ); }); test('throws when sha hex string is invalid', () { expect( () => Oid.fromSHA(repo: repo, sha: '0000000'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "object not found - no match for id prefix (0000000)", - ), - ), + throwsA(isA()), ); }); }); diff --git a/test/packbuilder_test.dart b/test/packbuilder_test.dart index b3637cf..5aee964 100644 --- a/test/packbuilder_test.dart +++ b/test/packbuilder_test.dart @@ -33,13 +33,7 @@ void main() { test('throws when trying to initialize and error occurs', () { expect( () => PackBuilder(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -62,13 +56,7 @@ void main() { expect( () => packbuilder.add(Oid(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'oid'", - ), - ), + throwsA(isA()), ); packbuilder.free(); @@ -89,13 +77,7 @@ void main() { expect( () => packbuilder.addRecursively(Oid(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'id'", - ), - ), + throwsA(isA()), ); packbuilder.free(); @@ -160,13 +142,7 @@ void main() { expect( () => packbuilder.write('invalid/path'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - contains('failed to create temporary file'), - ), - ), + throwsA(isA()), ); packbuilder.free(); diff --git a/test/patch_test.dart b/test/patch_test.dart index e9a69ce..8d73465 100644 --- a/test/patch_test.dart +++ b/test/patch_test.dart @@ -162,13 +162,7 @@ index e69de29..0000000 aPath: 'file', bPath: 'file', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Invalid argument(s): Provided argument(s) is not Blob or String", - ), - ), + throwsA(isA()), ); expect( @@ -178,13 +172,7 @@ index e69de29..0000000 aPath: 'file', bPath: 'file', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "Invalid argument(s): Provided argument(s) is not Blob or String", - ), - ), + throwsA(isA()), ); commit.free(); @@ -193,26 +181,14 @@ index e69de29..0000000 test('throws when trying to create from diff and error occurs', () { expect( () => Patch.fromDiff(diff: Diff(nullptr), index: 0), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'diff'", - ), - ), + throwsA(isA()), ); }); test('throws when trying to text of patch and error occurs', () { expect( () => Patch(nullptr, nullptr, nullptr).text, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'patch'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/rebase_test.dart b/test/rebase_test.dart index 79a1367..fd56e10 100644 --- a/test/rebase_test.dart +++ b/test/rebase_test.dart @@ -31,16 +31,7 @@ void main() { final feature = repo.lookupReference('refs/heads/feature'); repo.checkout(refName: feature.name); - expect( - () => repo.index['.gitignore'], - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: ".gitignore was not found"', - ), - ), - ); + expect(() => repo.index['.gitignore'], throwsA(isA())); final rebase = Rebase.init( repo: repo, @@ -112,16 +103,7 @@ void main() { final startCommit = repo.lookupCommit(repo[shas[1]]); repo.checkout(refName: feature.name); - expect( - () => repo.index['conflict_file'], - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "conflict_file was not found"', - ), - ), - ); + expect(() => repo.index['conflict_file'], throwsA(isA())); final rebase = Rebase.init( repo: repo, @@ -150,16 +132,7 @@ void main() { test( 'throws when trying to initialize rebase without upstream and onto ' 'provided', () { - expect( - () => Rebase.init(repo: repo), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'upstream || onto'", - ), - ), - ); + expect(() => Rebase.init(repo: repo), throwsA(isA())); }); test('stops when there is conflicts', () { @@ -181,13 +154,7 @@ void main() { expect(repo.state, GitRepositoryState.rebaseMerge); expect( () => rebase.commit(committer: signature), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'unstaged changes exist in workdir', - ), - ), + throwsA(isA()), ); rebase.free(); @@ -212,17 +179,7 @@ void main() { expect(rebase.operationsCount, 1); rebase.next(); // repo now have conflicts - expect( - () => rebase.next(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "object not found - failed to find pack entry " - "(790b86f5fb50db485586370f27c5f90bada97d83)", - ), - ), - ); + expect(() => rebase.next(), throwsA(isA())); rebase.free(); conflict.free(); diff --git a/test/reference_test.dart b/test/reference_test.dart index 81206e4..c9729c5 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -39,13 +39,7 @@ void main() { test('throws when trying to get a list of references and error occurs', () { expect( () => Repository(nullptr).references, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -74,13 +68,7 @@ void main() { test('throws when trying to resolve invalid reference', () { expect( () => Reference(nullptr).target, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid reference", - ), - ), + throwsA(isA()), ); }); @@ -183,13 +171,7 @@ void main() { name: 'refs/tags/invalid', target: '78b', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the given reference name '78b' is not valid", - ), - ), + throwsA(isA()), ); expect( @@ -197,14 +179,7 @@ void main() { name: 'refs/tags/invalid', target: 0, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "0 must be either Oid or String reference ' - 'name"', - ), - ), + throwsA(isA()), ); }); @@ -214,13 +189,7 @@ void main() { name: 'refs/tags/invalid~', target: repo[lastCommit], ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the given reference name 'refs/tags/invalid~' is not valid", - ), - ), + throwsA(isA()), ); }); @@ -253,14 +222,7 @@ void main() { name: 'refs/tags/test', target: repo[lastCommit], ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to write reference 'refs/tags/test': a reference with that " - "name already exists.", - ), - ), + throwsA(isA()), ); ref.free(); @@ -310,14 +272,7 @@ void main() { name: 'refs/tags/exists', target: 'refs/heads/master', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to write reference 'refs/tags/exists': a reference with that " - "name already exists.", - ), - ), + throwsA(isA()), ); ref.free(); @@ -329,13 +284,7 @@ void main() { name: 'refs/tags/invalid~', target: 'refs/heads/master', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the given reference name 'refs/tags/invalid~' is not valid", - ), - ), + throwsA(isA()), ); }); @@ -377,13 +326,7 @@ void main() { test('throws when error occured', () { expect( () => repo.lookupReference('refs/heads/not/there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'refs/heads/not/there' not found", - ), - ), + throwsA(isA()), ); }); }); @@ -437,37 +380,15 @@ void main() { final ref = repo.lookupReference('HEAD'); expect( () => ref.setTarget(target: 'refs/heads/invalid~'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "the given reference name 'refs/heads/invalid~' is not valid", - ), - ), + throwsA(isA()), ); expect( () => ref.setTarget(target: Oid(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'id'", - ), - ), + throwsA(isA()), ); - expect( - () => ref.setTarget(target: 0), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "0 must be either Oid or String reference ' - 'name"', - ), - ), - ); + expect(() => ref.setTarget(target: 0), throwsA(isA())); ref.free(); }); @@ -592,16 +513,7 @@ void main() { }); test('throws when trying to peel and error occurs', () { - expect( - () => Reference(nullptr).peel(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'ref'", - ), - ), - ); + expect(() => Reference(nullptr).peel(), throwsA(isA())); }); test('successfully compresses references', () { @@ -619,13 +531,7 @@ void main() { test('throws when trying to compress and error occurs', () { expect( () => Reference.compress(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/remote_prune_test.dart b/test/remote_prune_test.dart index 007e87f..55ebf98 100644 --- a/test/remote_prune_test.dart +++ b/test/remote_prune_test.dart @@ -96,17 +96,10 @@ void main() { } }); - test('throws when trying to prune remote refs and error occurs', () { - expect( - () => remote.prune(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "this remote has never connected", - ), - ), - ); + test( + 'throws when trying to prune remote refs and remote has never ' + 'connected', () { + expect(() => remote.prune(), throwsA(isA())); }); }); } diff --git a/test/remote_test.dart b/test/remote_test.dart index 5c1c6e9..ec6acaa 100644 --- a/test/remote_test.dart +++ b/test/remote_test.dart @@ -77,13 +77,7 @@ void main() { url: '', fetch: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "'' is not a valid remote name.", - ), - ), + throwsA(isA()), ); }); @@ -100,13 +94,7 @@ void main() { test('throws when trying to delete non existing remote', () { expect( () => repo.deleteRemote('not/there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "remote 'not/there' does not exist", - ), - ), + throwsA(isA()), ); }); @@ -142,13 +130,7 @@ void main() { test('throws when renaming with invalid names', () { expect( () => repo.renameRemote(oldName: '', newName: ''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "'' is not a valid remote name.", - ), - ), + throwsA(isA()), ); }); @@ -225,24 +207,12 @@ void main() { expect( () => refspec.transform('invalid/name'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "ref 'invalid/name' doesn't match the source", - ), - ), + throwsA(isA()), ); expect( () => refspec.rTransform('invalid/name'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "ref 'invalid/name' doesn't match the destination", - ), - ), + throwsA(isA()), ); remote.free(); @@ -274,13 +244,7 @@ void main() { remote: '', refspec: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "'' is not a valid remote name.", - ), - ), + throwsA(isA()), ); }); @@ -304,13 +268,7 @@ void main() { remote: '', refspec: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "'' is not a valid remote name.", - ), - ), + throwsA(isA()), ); }); @@ -341,16 +299,7 @@ void main() { Remote.setUrl(repo: repo, remote: 'libgit2', url: 'invalid'); final remote = repo.lookupRemote('libgit2'); - expect( - () => remote.ls(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "unsupported URL protocol", - ), - ), - ); + expect(() => remote.ls(), throwsA(isA())); remote.free(); }); @@ -432,13 +381,7 @@ void main() { refspecs: ['+refs/heads/*:refs/remotes/origin/*'], proxy: 'https://1.1.1.1', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "proxy returned unexpected status: 400", - ), - ), + throwsA(isA()), ); remote.free(); @@ -450,14 +393,7 @@ void main() { expect( () => remote.fetch(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to resolve address for wrong.url: Name or service " - "not known", - ), - ), + throwsA(isA()), ); remote.free(); @@ -600,14 +536,7 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 expect( () => remote.push(refspecs: ['refs/heads/master']), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to resolve address for wrong.url: Name or service " - "not known", - ), - ), + throwsA(isA()), ); remote.free(); diff --git a/test/repository_empty_test.dart b/test/repository_empty_test.dart index 4fa1ff8..ecd133c 100644 --- a/test/repository_empty_test.dart +++ b/test/repository_empty_test.dart @@ -83,16 +83,7 @@ void main() { }); test('throws when checking if it is empty and error occurs', () { - expect( - () => Repository(nullptr).isEmpty, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), - ); + expect(() => Repository(nullptr).isEmpty, throwsA(isA())); }); test('checks if head is detached', () { diff --git a/test/repository_test.dart b/test/repository_test.dart index b738d7b..a9c4114 100644 --- a/test/repository_test.dart +++ b/test/repository_test.dart @@ -99,53 +99,20 @@ void main() { test('throws when trying to set working directory to invalid', () { expect( () => repo.setWorkdir(path: 'invalid/path'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to resolve path 'invalid/path': No such file or directory", - ), - ), + throwsA(isA()), ); }); test('throws when trying to get head and error occurs', () { File('${repo.workdir}.git/HEAD').deleteSync(); - expect( - () => repo.head, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'HEAD' not found", - ), - ), - ); - expect( - () => repo.isHeadDetached, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'HEAD' not found", - ), - ), - ); + expect(() => repo.head, throwsA(isA())); + expect(() => repo.isHeadDetached, throwsA(isA())); }); test('throws when trying to check if branch is unborn and error occurs', () { File('${repo.workdir}.git/HEAD').deleteSync(); - expect( - () => repo.isBranchUnborn, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'HEAD' not found", - ), - ), - ); + expect(() => repo.isBranchUnborn, throwsA(isA())); }); group('setHead', () { @@ -177,39 +144,17 @@ void main() { }); test('throws when target is invalid', () { - expect( - () => repo.setHead(0), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'Invalid argument: "0 must be either Oid or String reference ' - 'name"', - ), - ), - ); + expect(() => repo.setHead(0), throwsA(isA())); }); test('throws when error occurs', () { expect( () => Repository(nullptr).setHead('refs/heads/feature'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); expect( () => Repository(nullptr).setHead(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); }); @@ -300,17 +245,7 @@ void main() { test('throws when trying to get status of bare repository', () { final bare = Repository.open('test/assets/empty_bare.git'); - expect( - () => bare.status, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "cannot status. This operation is not allowed against bare " - "repositories.", - ), - ), - ); + expect(() => bare.status, throwsA(isA())); bare.free(); }); @@ -330,13 +265,7 @@ void main() { test('throws when trying to clean up state and error occurs', () { expect( () => Repository(nullptr).stateCleanup(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -353,16 +282,7 @@ void main() { }); test('throws when checking status of a single file for invalid path', () { - expect( - () => repo.statusFile('not-there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "attempt to get status of nonexistent file 'not-there'", - ), - ), - ); + expect(() => repo.statusFile('not-there'), throwsA(isA())); }); test('returns default signature', () { @@ -418,13 +338,7 @@ void main() { final nullRepo = Repository(nullptr); expect( () => nullRepo.descendantOf(commit: commit1, ancestor: commit2), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/revparse_test.dart b/test/revparse_test.dart index c148be8..5972a6e 100644 --- a/test/revparse_test.dart +++ b/test/revparse_test.dart @@ -40,24 +40,9 @@ void main() { test('.single() throws when spec string not found or invalid', () { expect( () => repo.revParseSingle('invalid'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "revspec 'invalid' not found", - ), - ), - ); - expect( - () => repo.revParseSingle(''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to parse revision specifier - Invalid pattern ''", - ), - ), + throwsA(isA()), ); + expect(() => repo.revParseSingle(''), throwsA(isA())); }); test('.ext() returns commit and reference', () { @@ -98,24 +83,9 @@ void main() { test('.ext() throws when spec string not found or invalid', () { expect( () => repo.revParseExt('invalid'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "revspec 'invalid' not found", - ), - ), - ); - expect( - () => repo.revParseExt(''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to parse revision specifier - Invalid pattern ''", - ), - ), + throwsA(isA()), ); + expect(() => repo.revParseExt(''), throwsA(isA())); }); test( @@ -156,23 +126,11 @@ void main() { test('throws on invalid range spec', () { expect( () => repo.revParse('invalid..5aecfa'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "revspec 'invalid' not found", - ), - ), + throwsA(isA()), ); expect( () => repo.revParse('master.......5aecfa'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to parse revision specifier - Invalid pattern '....5aecfa'", - ), - ), + throwsA(isA()), ); }); }); diff --git a/test/revwalk_test.dart b/test/revwalk_test.dart index 4731606..3fcbe61 100644 --- a/test/revwalk_test.dart +++ b/test/revwalk_test.dart @@ -37,13 +37,7 @@ void main() { test('throws when trying to initialize and error occurs', () { expect( () => RevWalk(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -128,13 +122,7 @@ void main() { expect( () => walker.hide(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); walker.free(); @@ -178,13 +166,7 @@ void main() { expect( () => walker.push(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); walker.free(); diff --git a/test/signature_test.dart b/test/signature_test.dart index 861445c..dc1f8d2 100644 --- a/test/signature_test.dart +++ b/test/signature_test.dart @@ -27,14 +27,7 @@ void main() { test('throws when trying to create with empty name and email', () { expect( () => Signature.create(name: '', email: '', time: 0), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to parse signature - Signature cannot have an empty name " - "or email", - ), - ), + throwsA(isA()), ); }); @@ -43,14 +36,7 @@ void main() { 'default time', () { expect( () => Signature.create(name: '', email: ''), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to parse signature - Signature cannot have an empty name " - "or email", - ), - ), + throwsA(isA()), ); }); diff --git a/test/stash_test.dart b/test/stash_test.dart index 97bf646..c30220d 100644 --- a/test/stash_test.dart +++ b/test/stash_test.dart @@ -40,13 +40,7 @@ void main() { test('throws when trying to save and error occurs', () { expect( () => Repository(nullptr).createStash(stasher: stasher), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -131,16 +125,7 @@ void main() { repo.createStash(stasher: stasher); - expect( - () => repo.applyStash(index: 10), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "no stashed state at position 10", - ), - ), - ); + expect(() => repo.applyStash(index: 10), throwsA(isA())); }); test('successfully drops stash', () { @@ -163,16 +148,7 @@ void main() { repo.createStash(stasher: stasher); - expect( - () => repo.dropStash(index: 10), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "no stashed state at position 10", - ), - ), - ); + expect(() => repo.dropStash(index: 10), throwsA(isA())); }); test('successfully pops from stash', () { @@ -224,16 +200,7 @@ void main() { repo.createStash(stasher: stasher); - expect( - () => repo.popStash(index: 10), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "no stashed state at position 10", - ), - ), - ); + expect(() => repo.popStash(index: 10), throwsA(isA())); }); test('returns list of stashes', () { diff --git a/test/submodule_test.dart b/test/submodule_test.dart index 10ebebe..8eb6391 100644 --- a/test/submodule_test.dart +++ b/test/submodule_test.dart @@ -49,13 +49,7 @@ void main() { test('throws when trying to lookup and submodule not found', () { expect( () => repo.lookupSubmodule('not/there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "no submodule named 'not/there'", - ), - ), + throwsA(isA()), ); }); @@ -81,13 +75,7 @@ void main() { test('throws when trying to update not initialized submodule', () { expect( () => repo.updateSubmodule(submodule: testSubmodule), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "submodule is not initialized", - ), - ), + throwsA(isA()), ); }); @@ -113,18 +101,7 @@ void main() { test('throws when trying to open repository for not initialized submodule', () { final submodule = repo.lookupSubmodule(testSubmodule); - - expect( - () => submodule.open(), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - contains("failed to resolve path"), - ), - ), - ); - + expect(() => submodule.open(), throwsA(isA())); submodule.free(); }); @@ -149,14 +126,7 @@ void main() { url: 'https://wrong.url/', path: 'test', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'failed to resolve address for wrong.url: Name or service ' - 'not known', - ), - ), + throwsA(isA()), ); }); @@ -166,13 +136,7 @@ void main() { url: 'https://wrong.url/', path: 'test', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); diff --git a/test/tag_test.dart b/test/tag_test.dart index 1cf688c..fa56a32 100644 --- a/test/tag_test.dart +++ b/test/tag_test.dart @@ -33,27 +33,12 @@ void main() { test('throws when trying to lookup tag for invalid oid', () { expect( () => repo.lookupTag(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); test('throws when trying to get target of a tag and error occurs', () { - expect( - () => Tag(nullptr).target, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 't'", - ), - ), - ); + expect(() => Tag(nullptr).target, throwsA(isA())); }); test('returns correct values', () { @@ -217,13 +202,7 @@ void main() { tagger: Signature(nullptr), message: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: '!create_tag_annotation || (tagger && message)'", - ), - ), + throwsA(isA()), ); }); @@ -236,13 +215,7 @@ void main() { tagger: Signature(nullptr), message: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); @@ -251,16 +224,7 @@ void main() { }); test('throws when trying to get list of tags and error occurs', () { - expect( - () => Repository(nullptr).tags, - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), - ); + expect(() => Repository(nullptr).tags, throwsA(isA())); }); test('successfully deletes tag', () { @@ -271,16 +235,7 @@ void main() { }); test('throws when trying to delete non existing tag', () { - expect( - () => repo.deleteTag('not.there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "reference 'refs/tags/not.there' not found", - ), - ), - ); + expect(() => repo.deleteTag('not.there'), throwsA(isA())); }); }); } diff --git a/test/tree_test.dart b/test/tree_test.dart index 0d39739..0a34802 100644 --- a/test/tree_test.dart +++ b/test/tree_test.dart @@ -34,13 +34,7 @@ void main() { test('throws when looking up tree for invalid oid', () { expect( () => repo.lookupTree(repo['0' * 40]), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "odb: cannot read object: null OID cannot exist", - ), - ), + throwsA(isA()), ); }); @@ -101,7 +95,6 @@ void main() { expect(entry.oid, fileOid); builder.free(); - entry.free(); newTree.free(); }); }); diff --git a/test/treebuilder_test.dart b/test/treebuilder_test.dart index 75ff970..e53db6a 100644 --- a/test/treebuilder_test.dart +++ b/test/treebuilder_test.dart @@ -45,13 +45,7 @@ void main() { test('throws when trying to initialize and error occurs', () { expect( () => TreeBuilder(repo: Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -91,13 +85,7 @@ void main() { oid: repo['0' * 40], filemode: GitFilemode.blob, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to insert entry: invalid name for a tree entry - ", - ), - ), + throwsA(isA()), ); expect( () => builder.add( @@ -105,13 +93,7 @@ void main() { oid: repo['0' * 40], filemode: GitFilemode.blob, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to insert entry: invalid null OID - some.file", - ), - ), + throwsA(isA()), ); builder.free(); @@ -131,18 +113,7 @@ void main() { test('throws when trying to remove entry that is not in the tree', () { final builder = TreeBuilder(repo: repo); - - expect( - () => builder.remove('not.there'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "failed to remove entry: file isn't in the tree - not.there", - ), - ), - ); - + expect(() => builder.remove('not.there'), throwsA(isA())); builder.free(); }); }); diff --git a/test/worktree_test.dart b/test/worktree_test.dart index 6799c02..a56260e 100644 --- a/test/worktree_test.dart +++ b/test/worktree_test.dart @@ -94,26 +94,14 @@ void main() { name: '', path: worktreeDir.path, ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - contains('failed to make directory'), - ), - ), + throwsA(isA()), ); expect( () => repo.createWorktree( name: 'name', path: '', ), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - 'attempt to create empty path: Invalid argument', - ), - ), + throwsA(isA()), ); }); @@ -135,13 +123,7 @@ void main() { test('throws when trying to lookup and error occurs', () { expect( () => Worktree.lookup(repo: Repository(nullptr), name: 'name'), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); @@ -185,13 +167,7 @@ void main() { test('throws when trying get list of worktrees and error occurs', () { expect( () => Worktree.list(Repository(nullptr)), - throwsA( - isA().having( - (e) => e.toString(), - 'error', - "invalid argument: 'repo'", - ), - ), + throwsA(isA()), ); }); });