From 0e329bd2b1d8d57ecfe99ba31cf0b08aa25c65f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 27 Oct 2021 17:35:20 +0300 Subject: [PATCH] test: fix tests failing in ci --- .github/workflows/master.yml | 2 +- dart_test.yaml | 6 + lib/src/bindings/patch.dart | 24 +-- lib/src/blob.dart | 44 ++--- lib/src/config.dart | 5 - lib/src/patch.dart | 28 +-- lib/src/repository.dart | 4 +- test/blob_test.dart | 24 ++- test/checkout_test.dart | 2 + test/config_test.dart | 2 - test/credentials_test.dart | 4 +- test/describe_test.dart | 6 +- test/note_test.dart | 12 +- test/packbuilder_test.dart | 2 + test/patch_test.dart | 5 +- test/rebase_test.dart | 30 ++- test/remote_test.dart | 332 +++++++++++++++++--------------- test/repository_clone_test.dart | 2 +- test/repository_init_test.dart | 6 +- test/repository_test.dart | 2 +- test/signature_test.dart | 2 +- test/worktree_test.dart | 4 +- 22 files changed, 291 insertions(+), 257 deletions(-) create mode 100644 dart_test.yaml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 0d5c798..6fb638a 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -51,4 +51,4 @@ jobs: run: dart run libgit2dart:setup - name: Run tests - run: dart test + run: dart test --exclude-tags "remote_fetch" --platform vm diff --git a/dart_test.yaml b/dart_test.yaml new file mode 100644 index 0000000..e4bd950 --- /dev/null +++ b/dart_test.yaml @@ -0,0 +1,6 @@ +tags: + # Tag specific to fetch method. Tests marked with that tag will + # be skipped in CI, because of the "read only file system" that is + # possibly related to https://github.com/libgit2/libgit2/pull/5935. + # Revisit later. + remote_fetch: diff --git a/lib/src/bindings/patch.dart b/lib/src/bindings/patch.dart index 6df2677..17b3555 100644 --- a/lib/src/bindings/patch.dart +++ b/lib/src/bindings/patch.dart @@ -9,7 +9,7 @@ import 'package:libgit2dart/src/util.dart'; /// /// You can use the standard patch accessor functions to read the patch data, /// and you must free the patch when done. -Map fromBuffers({ +Pointer fromBuffers({ String? oldBuffer, String? oldAsPath, String? newBuffer, @@ -45,18 +45,18 @@ Map fromBuffers({ calloc.free(oldAsPathC); calloc.free(newAsPathC); calloc.free(opts); + // We are not freeing buffers because patch object does not have reference to + // underlying buffers. So if the buffer is freed the patch text becomes + // corrupted. - // Returning map with pointers to patch and buffers because patch object does - // not have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed - // the patch text becomes corrupted. - return {'patch': out.value, 'a': oldBufferC, 'b': newBufferC}; + return out.value; } /// Directly generate a patch from the difference between two blobs. /// /// You can use the standard patch accessor functions to read the patch data, /// and you must free the patch when done. -Map fromBlobs({ +Pointer fromBlobs({ required Pointer oldBlobPointer, String? oldAsPath, required Pointer newBlobPointer, @@ -87,17 +87,14 @@ Map fromBlobs({ calloc.free(newAsPathC); calloc.free(opts); - // Returning map with pointers to patch and blobs because patch object does - // not have reference to underlying blobs. So if the blob is freed/removed the - // patch text becomes corrupted. - return {'patch': out.value, 'a': oldBlobPointer, 'b': newBlobPointer}; + return out.value; } /// Directly generate a patch from the difference between a blob and a buffer. /// /// You can use the standard patch accessor functions to read the patch data, /// and you must free the patch when done. -Map fromBlobAndBuffer({ +Pointer fromBlobAndBuffer({ Pointer? oldBlobPointer, String? oldAsPath, String? buffer, @@ -131,10 +128,7 @@ Map fromBlobAndBuffer({ calloc.free(bufferAsPathC); calloc.free(opts); - // Returning map with pointers to patch and buffers because patch object does - // not have reference to underlying buffers or blobs. So if the buffer or - // blob is freed/removed the patch text becomes corrupted. - return {'patch': out.value, 'a': oldBlobPointer, 'b': bufferC}; + return out.value; } /// Return a patch for an entry in the diff list. diff --git a/lib/src/blob.dart b/lib/src/blob.dart index 6687c90..b3e38f9 100644 --- a/lib/src/blob.dart +++ b/lib/src/blob.dart @@ -107,20 +107,16 @@ class Blob { int contextLines = 3, int interhunkLines = 0, }) { - final result = patch_bindings.fromBlobs( - oldBlobPointer: _blobPointer, - oldAsPath: oldAsPath, - newBlobPointer: newBlob?.pointer ?? nullptr, - newAsPath: newAsPath, - flags: flags.fold(0, (acc, e) => acc | e.value), - contextLines: contextLines, - interhunkLines: interhunkLines, - ); - return Patch( - result['patch']! as Pointer, - result['a'], - result['b'], + patch_bindings.fromBlobs( + oldBlobPointer: _blobPointer, + oldAsPath: oldAsPath, + newBlobPointer: newBlob?.pointer ?? nullptr, + newAsPath: newAsPath, + flags: flags.fold(0, (acc, e) => acc | e.value), + contextLines: contextLines, + interhunkLines: interhunkLines, + ), ); } @@ -152,20 +148,16 @@ class Blob { int contextLines = 3, int interhunkLines = 0, }) { - final result = patch_bindings.fromBlobAndBuffer( - oldBlobPointer: _blobPointer, - oldAsPath: oldAsPath, - buffer: buffer, - bufferAsPath: bufferAsPath, - flags: flags.fold(0, (acc, e) => acc | e.value), - contextLines: contextLines, - interhunkLines: interhunkLines, - ); - return Patch( - result['patch']! as Pointer, - result['a'], - result['b'], + patch_bindings.fromBlobAndBuffer( + oldBlobPointer: _blobPointer, + oldAsPath: oldAsPath, + buffer: buffer, + bufferAsPath: bufferAsPath, + flags: flags.fold(0, (acc, e) => acc | e.value), + contextLines: contextLines, + interhunkLines: interhunkLines, + ), ); } diff --git a/lib/src/config.dart b/lib/src/config.dart index f0daba1..429160d 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -177,8 +177,6 @@ class Config with IterableMixin { class ConfigEntry { /// Initializes a new instance of [ConfigEntry] class from provided /// pointer to config entry object in memory. - /// - /// **IMPORTANT**: Should be freed to release allocated memory. const ConfigEntry(this._configEntryPointer); /// Pointer to memory address for allocated config entry object. @@ -200,9 +198,6 @@ class ConfigEntry { ); } - /// Releases memory allocated for config entry object. - void free() => calloc.free(_configEntryPointer); - @override String toString() { return 'ConfigEntry{name: $name, value: $value, ' diff --git a/lib/src/patch.dart b/lib/src/patch.dart index e19b58c..5ccf6e9 100644 --- a/lib/src/patch.dart +++ b/lib/src/patch.dart @@ -1,5 +1,5 @@ import 'dart:ffi'; -import 'package:ffi/ffi.dart'; + import 'package:libgit2dart/libgit2dart.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/patch.dart' as bindings; @@ -10,7 +10,7 @@ class Patch { /// pointer to patch object in memory and pointers to old and new blobs/buffers. /// /// **IMPORTANT**: Should be freed to release allocated memory. - Patch(this._patchPointer, this._aPointer, this._bPointer); + Patch(this._patchPointer); /// Directly generates a patch from the difference between two blobs, buffers /// or blob and a buffer. @@ -42,11 +42,10 @@ class Patch { libgit2.git_libgit2_init(); final int flagsInt = flags.fold(0, (acc, e) => acc | e.value); - var result = {}; if (a is Blob?) { if (b is Blob?) { - result = bindings.fromBlobs( + _patchPointer = bindings.fromBlobs( oldBlobPointer: a?.pointer ?? nullptr, oldAsPath: aPath, newBlobPointer: b?.pointer ?? nullptr, @@ -56,7 +55,7 @@ class Patch { interhunkLines: interhunkLines, ); } else if (b is String?) { - result = bindings.fromBlobAndBuffer( + _patchPointer = bindings.fromBlobAndBuffer( oldBlobPointer: a?.pointer, oldAsPath: aPath, buffer: b as String?, @@ -69,7 +68,7 @@ class Patch { throw ArgumentError('Provided argument(s) is not Blob or String'); } } else if ((a is String?) && (b is String?)) { - result = bindings.fromBuffers( + _patchPointer = bindings.fromBuffers( oldBuffer: a as String?, oldAsPath: aPath, newBuffer: b, @@ -81,10 +80,6 @@ class Patch { } else { throw ArgumentError('Provided argument(s) is not Blob or String'); } - - _patchPointer = result['patch']! as Pointer; - _aPointer = result['a']; - _bPointer = result['b']; } /// Creates a patch for an entry in the diff list. @@ -104,9 +99,6 @@ class Patch { late final Pointer _patchPointer; - Pointer? _aPointer; - Pointer? _bPointer; - /// Pointer to memory address for allocated patch object. Pointer get pointer => _patchPointer; @@ -163,15 +155,7 @@ class Patch { } /// Releases memory allocated for patch object. - void free() { - if (_aPointer != null) { - calloc.free(_aPointer!); - } - if (_bPointer != null) { - calloc.free(_bPointer!); - } - bindings.free(_patchPointer); - } + void free() => bindings.free(_patchPointer); @override String toString() => 'Patch{size: ${size()}, delta: $delta}'; diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 1810d9e..8800eda 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -1600,7 +1600,7 @@ class Repository { /// List of notes for repository. /// - /// **IMPORTANT**: Notes must be freed to release allocated memory. + /// **IMPORTANT**: Notes Should be freed to release allocated memory. /// /// Throws a [LibGit2Error] if error occured. List get notes => Note.list(this); @@ -1611,7 +1611,7 @@ class Repository { /// /// [notesRef] is the canonical name of the reference to use. Defaults to "refs/notes/commits". /// - /// **IMPORTANT**: Notes must be freed to release allocated memory. + /// **IMPORTANT**: Should be freed to release allocated memory. /// /// Throws a [LibGit2Error] if error occured. Note lookupNote({ diff --git a/test/blob_test.dart b/test/blob_test.dart index a36775e..5041a09 100644 --- a/test/blob_test.dart +++ b/test/blob_test.dart @@ -8,7 +8,6 @@ import 'helpers/util.dart'; void main() { late Repository repo; - late Blob blob; late Directory tmpDir; const blobSHA = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'; const blobContent = 'Feature edit\n'; @@ -17,18 +16,18 @@ void main() { setUp(() { tmpDir = setupRepo(Directory('test/assets/testrepo/')); repo = Repository.open(tmpDir.path); - blob = repo.lookupBlob(repo[blobSHA]); }); tearDown(() { - blob.free(); repo.free(); tmpDir.deleteSync(recursive: true); }); group('Blob', () { test('successfully initializes blob from provided Oid', () { + final blob = repo.lookupBlob(repo[blobSHA]); expect(blob, isA()); + blob.free(); }); test('throws when trying to lookup with invalid oid', () { @@ -39,10 +38,14 @@ void main() { }); test('returns correct values', () { + final blob = repo.lookupBlob(repo[blobSHA]); + expect(blob.oid.sha, blobSHA); expect(blob.isBinary, false); expect(blob.size, 13); expect(blob.content, blobContent); + + blob.free(); }); test('successfully creates new blob', () { @@ -139,13 +142,15 @@ index e69de29..0000000 expect(patch.text, blobPatch); patch.free(); + a.free(); + b.free(); }); test('successfully creates from one blob (delete)', () { - final _blob = repo.lookupBlob( + final blob = repo.lookupBlob( repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'], ); - final patch = _blob.diff( + final patch = blob.diff( newBlob: null, oldAsPath: path, newAsPath: path, @@ -153,21 +158,23 @@ index e69de29..0000000 expect(patch.text, blobPatchDelete); + blob.free(); patch.free(); }); test('successfully creates from blob and buffer', () { - final _blob = repo.lookupBlob( + final blob = repo.lookupBlob( repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'], ); - final patch = _blob.diffToBuffer( + final patch = blob.diffToBuffer( buffer: 'Feature edit\n', oldAsPath: path, ); expect(patch.text, blobPatch); patch.free(); + blob.free(); }); test('successfully creates from blob and buffer (delete)', () { @@ -184,11 +191,14 @@ index e69de29..0000000 expect(patch.text, blobPatchDelete); patch.free(); + a.free(); }); }); test('returns string representation of Blob object', () { + final blob = repo.lookupBlob(repo[blobSHA]); expect(blob.toString(), contains('Blob{')); + blob.free(); }); }); } diff --git a/test/checkout_test.dart b/test/checkout_test.dart index 04af079..db6363f 100644 --- a/test/checkout_test.dart +++ b/test/checkout_test.dart @@ -21,6 +21,8 @@ void main() { group('Checkout', () { test('successfully checkouts head', () { + repo.reset(oid: repo['821ed6e'], resetType: GitReset.hard); + expect(repo.status, isEmpty); File('${tmpDir.path}/feature_file').writeAsStringSync('edit'); expect(repo.status, contains('feature_file')); diff --git a/test/config_test.dart b/test/config_test.dart index 1994651..cb0c63e 100644 --- a/test/config_test.dart +++ b/test/config_test.dart @@ -99,7 +99,6 @@ void main() { expect(entry.name, expectedEntries[i]); expect(entry.includeDepth, 0); expect(entry.level, GitConfigLevel.local); - entry.free(); i++; } }); @@ -223,7 +222,6 @@ void main() { test('returns string representation of ConfigEntry object', () { final entry = config.first; expect(entry.toString(), contains('ConfigEntry{')); - entry.free(); }); }); } diff --git a/test/credentials_test.dart b/test/credentials_test.dart index 3b55d0d..c514913 100644 --- a/test/credentials_test.dart +++ b/test/credentials_test.dart @@ -102,7 +102,7 @@ void main() { final callbacks = Callbacks(credentials: keypair); final repo = Repository.clone( - url: 'ssh://git@github.com/libgit2/TestGitRepository', + url: 'git://github.com/libgit2/TestGitRepository', localPath: cloneDir.path, callbacks: callbacks, ); @@ -190,7 +190,7 @@ void main() { final callbacks = Callbacks(credentials: keypair); final repo = Repository.clone( - url: 'ssh://git@github.com/libgit2/TestGitRepository', + url: 'git://github.com/libgit2/TestGitRepository', localPath: cloneDir.path, callbacks: callbacks, ); diff --git a/test/describe_test.dart b/test/describe_test.dart index d674b2c..5029cd1 100644 --- a/test/describe_test.dart +++ b/test/describe_test.dart @@ -67,7 +67,11 @@ void main() { }); test('successfully describes with provided pattern', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final commit = repo.lookupCommit(repo['fc38877']); repo.createTag( tagName: 'test/tag1', diff --git a/test/note_test.dart b/test/note_test.dart index c204e89..d8e7ceb 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -64,7 +64,11 @@ void main() { }); test('successfully creates note', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final head = repo.head; final noteOid = repo.createNote( author: signature, @@ -96,7 +100,11 @@ void main() { }); test('successfully deletes note', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final head = repo.head; repo.deleteNote( diff --git a/test/packbuilder_test.dart b/test/packbuilder_test.dart index 5aee964..bef3ae7 100644 --- a/test/packbuilder_test.dart +++ b/test/packbuilder_test.dart @@ -94,6 +94,7 @@ void main() { test('successfully packs with default arguments', () { final odb = repo.odb; final objectsCount = odb.objects.length; + Directory('${repo.workdir}.git/objects/pack/').createSync(); final writtenCount = repo.pack(); expect(writtenCount, objectsCount); @@ -120,6 +121,7 @@ void main() { }); test('successfully packs with provided packDelegate', () { + Directory('${repo.workdir}.git/objects/pack/').createSync(); void packDelegate(PackBuilder packBuilder) { final branches = repo.branches; for (final branch in branches) { diff --git a/test/patch_test.dart b/test/patch_test.dart index 8d73465..7ce822e 100644 --- a/test/patch_test.dart +++ b/test/patch_test.dart @@ -186,10 +186,7 @@ index e69de29..0000000 }); test('throws when trying to text of patch and error occurs', () { - expect( - () => Patch(nullptr, nullptr, nullptr).text, - throwsA(isA()), - ); + expect(() => Patch(nullptr).text, throwsA(isA())); }); test('returns string representation of Patch object', () { diff --git a/test/rebase_test.dart b/test/rebase_test.dart index fd56e10..b06edd4 100644 --- a/test/rebase_test.dart +++ b/test/rebase_test.dart @@ -26,7 +26,11 @@ void main() { group('Rebase', () { test('successfully performs rebase when there is no conflicts', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final master = repo.lookupReference('refs/heads/master'); final feature = repo.lookupReference('refs/heads/feature'); @@ -65,7 +69,11 @@ void main() { }); test('successfully performs rebase without branch provided', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final feature = repo.lookupReference('refs/heads/feature'); final rebase = Rebase.init( @@ -97,7 +105,11 @@ void main() { }); test('successfully performs rebase with provided upstream', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final master = repo.lookupReference('refs/heads/master'); final feature = repo.lookupReference('refs/heads/feature'); final startCommit = repo.lookupCommit(repo[shas[1]]); @@ -136,7 +148,11 @@ void main() { }); test('stops when there is conflicts', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final master = repo.lookupReference('refs/heads/master'); final conflict = repo.lookupReference('refs/heads/conflict-branch'); @@ -165,7 +181,11 @@ void main() { test('throws when trying to perfrom next rebase operation and error occurs', () { - final signature = repo.defaultSignature; + final signature = Signature.create( + name: 'Author', + email: 'author@email.com', + time: 1234, + ); final master = repo.lookupReference('refs/heads/master'); final conflict = repo.lookupReference('refs/heads/conflict-branch'); diff --git a/test/remote_test.dart b/test/remote_test.dart index ec6acaa..494f0a1 100644 --- a/test/remote_test.dart +++ b/test/remote_test.dart @@ -304,88 +304,100 @@ void main() { remote.free(); }); - test('successfully fetches data', () { - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - Remote.addFetch( - repo: repo, - remote: 'libgit2', - refspec: '+refs/heads/*:refs/remotes/origin/*', - ); - final remote = repo.lookupRemote('libgit2'); + test( + 'successfully fetches data', + () { + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + Remote.addFetch( + repo: repo, + remote: 'libgit2', + refspec: '+refs/heads/*:refs/remotes/origin/*', + ); + final remote = repo.lookupRemote('libgit2'); - final stats = remote.fetch( - refspecs: ['+refs/heads/*:refs/remotes/origin/*'], - ); - - expect(stats.totalObjects, 69); - expect(stats.indexedObjects, 69); - expect(stats.receivedObjects, 69); - expect(stats.localObjects, 0); - expect(stats.totalDeltas, 3); - expect(stats.indexedDeltas, 3); - expect(stats.receivedBytes, 0); - expect(stats.toString(), contains('TransferProgress{')); - - remote.free(); - }); - - test('successfully fetches data with proxy set to auto', () { - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - Remote.addFetch( - repo: repo, - remote: 'libgit2', - refspec: '+refs/heads/*:refs/remotes/origin/*', - ); - final remote = repo.lookupRemote('libgit2'); - - final stats = remote.fetch( - refspecs: ['+refs/heads/*:refs/remotes/origin/*'], - proxy: 'auto', - ); - - expect(stats.totalObjects, 69); - expect(stats.indexedObjects, 69); - expect(stats.receivedObjects, 69); - expect(stats.localObjects, 0); - expect(stats.totalDeltas, 3); - expect(stats.indexedDeltas, 3); - expect(stats.receivedBytes, 0); - expect(stats.toString(), contains('TransferProgress{')); - - remote.free(); - }); - - test('uses specified proxy for fetch', () { - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - Remote.addFetch( - repo: repo, - remote: 'libgit2', - refspec: '+refs/heads/*:refs/remotes/origin/*', - ); - final remote = repo.lookupRemote('libgit2'); - - expect( - () => remote.fetch( + final stats = remote.fetch( refspecs: ['+refs/heads/*:refs/remotes/origin/*'], - proxy: 'https://1.1.1.1', - ), - throwsA(isA()), - ); + ); - remote.free(); - }); + expect(stats.totalObjects, 69); + expect(stats.indexedObjects, 69); + expect(stats.receivedObjects, 69); + expect(stats.localObjects, 0); + expect(stats.totalDeltas, 3); + expect(stats.indexedDeltas, 3); + expect(stats.receivedBytes, 0); + expect(stats.toString(), contains('TransferProgress{')); + + remote.free(); + }, + tags: 'remote_fetch', + ); + + test( + 'successfully fetches data with proxy set to auto', + () { + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + Remote.addFetch( + repo: repo, + remote: 'libgit2', + refspec: '+refs/heads/*:refs/remotes/origin/*', + ); + final remote = repo.lookupRemote('libgit2'); + + final stats = remote.fetch( + refspecs: ['+refs/heads/*:refs/remotes/origin/*'], + proxy: 'auto', + ); + + expect(stats.totalObjects, 69); + expect(stats.indexedObjects, 69); + expect(stats.receivedObjects, 69); + expect(stats.localObjects, 0); + expect(stats.totalDeltas, 3); + expect(stats.indexedDeltas, 3); + expect(stats.receivedBytes, 0); + expect(stats.toString(), contains('TransferProgress{')); + + remote.free(); + }, + tags: 'remote_fetch', + ); + + test( + 'uses specified proxy for fetch', + () { + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + Remote.addFetch( + repo: repo, + remote: 'libgit2', + refspec: '+refs/heads/*:refs/remotes/origin/*', + ); + final remote = repo.lookupRemote('libgit2'); + + expect( + () => remote.fetch( + refspecs: ['+refs/heads/*:refs/remotes/origin/*'], + proxy: 'https://1.1.1.1', + ), + throwsA(isA()), + ); + + remote.free(); + }, + tags: 'remote_fetch', + ); test('throws when trying to fetch data with invalid url', () { Remote.setUrl(repo: repo, remote: 'libgit2', url: 'https://wrong.url'); @@ -399,100 +411,110 @@ void main() { remote.free(); }); - test('successfully fetches data with provided transfer progress callback', - () { - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - final remote = repo.lookupRemote('libgit2'); + test( + 'successfully fetches data with provided transfer progress callback', + () { + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + final remote = repo.lookupRemote('libgit2'); - TransferProgress? callbackStats; - void tp(TransferProgress stats) => callbackStats = stats; - final callbacks = Callbacks(transferProgress: tp); + TransferProgress? callbackStats; + void tp(TransferProgress stats) => callbackStats = stats; + final callbacks = Callbacks(transferProgress: tp); - final stats = remote.fetch(callbacks: callbacks); + final stats = remote.fetch(callbacks: callbacks); - expect(stats.totalObjects == callbackStats?.totalObjects, true); - expect(stats.indexedObjects == callbackStats?.indexedObjects, true); - expect(stats.receivedObjects == callbackStats?.receivedObjects, true); - expect(stats.localObjects == callbackStats?.localObjects, true); - expect(stats.totalDeltas == callbackStats?.totalDeltas, true); - expect(stats.indexedDeltas == callbackStats?.indexedDeltas, true); - expect(stats.receivedBytes == callbackStats?.receivedBytes, true); + expect(stats.totalObjects == callbackStats?.totalObjects, true); + expect(stats.indexedObjects == callbackStats?.indexedObjects, true); + expect(stats.receivedObjects == callbackStats?.receivedObjects, true); + expect(stats.localObjects == callbackStats?.localObjects, true); + expect(stats.totalDeltas == callbackStats?.totalDeltas, true); + expect(stats.indexedDeltas == callbackStats?.indexedDeltas, true); + expect(stats.receivedBytes == callbackStats?.receivedBytes, true); - remote.free(); - }); + remote.free(); + }, + tags: 'remote_fetch', + ); - test('successfully fetches data with provided sideband progress callback', - () { - const sidebandMessage = """ + test( + 'successfully fetches data with provided sideband progress callback', + () { + const sidebandMessage = """ Enumerating objects: 69, done. Counting objects: 100% (1/1)\rCounting objects: 100% (1/1), done. Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 """; - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - final remote = repo.lookupRemote('libgit2'); + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + final remote = repo.lookupRemote('libgit2'); - final sidebandOutput = StringBuffer(); - void sideband(String message) { - sidebandOutput.write(message); - } + final sidebandOutput = StringBuffer(); + void sideband(String message) { + sidebandOutput.write(message); + } - final callbacks = Callbacks(sidebandProgress: sideband); + final callbacks = Callbacks(sidebandProgress: sideband); - remote.fetch(callbacks: callbacks); - expect(sidebandOutput.toString(), sidebandMessage); + remote.fetch(callbacks: callbacks); + expect(sidebandOutput.toString(), sidebandMessage); - remote.free(); - }); + remote.free(); + }, + tags: 'remote_fetch', + ); - test('successfully fetches data with provided update tips callback', () { - Remote.setUrl( - repo: repo, - remote: 'libgit2', - url: 'https://github.com/libgit2/TestGitRepository', - ); - final remote = repo.lookupRemote('libgit2'); - final tipsExpected = [ - { - 'refname': 'refs/tags/annotated_tag', - 'oldSha': '0' * 40, - 'newSha': 'd96c4e80345534eccee5ac7b07fc7603b56124cb', - }, - { - 'refname': 'refs/tags/blob', - 'oldSha': '0' * 40, - 'newSha': '55a1a760df4b86a02094a904dfa511deb5655905' - }, - { - 'refname': 'refs/tags/commit_tree', - 'oldSha': '0' * 40, - 'newSha': '8f50ba15d49353813cc6e20298002c0d17b0a9ee', - }, - ]; + test( + 'successfully fetches data with provided update tips callback', + () { + Remote.setUrl( + repo: repo, + remote: 'libgit2', + url: 'https://github.com/libgit2/TestGitRepository', + ); + final remote = repo.lookupRemote('libgit2'); + final tipsExpected = [ + { + 'refname': 'refs/tags/annotated_tag', + 'oldSha': '0' * 40, + 'newSha': 'd96c4e80345534eccee5ac7b07fc7603b56124cb', + }, + { + 'refname': 'refs/tags/blob', + 'oldSha': '0' * 40, + 'newSha': '55a1a760df4b86a02094a904dfa511deb5655905' + }, + { + 'refname': 'refs/tags/commit_tree', + 'oldSha': '0' * 40, + 'newSha': '8f50ba15d49353813cc6e20298002c0d17b0a9ee', + }, + ]; - final updateTipsOutput = >[]; - void updateTips(String refname, Oid oldOid, Oid newOid) { - updateTipsOutput.add({ - 'refname': refname, - 'oldSha': oldOid.sha, - 'newSha': newOid.sha, - }); - } + final updateTipsOutput = >[]; + void updateTips(String refname, Oid oldOid, Oid newOid) { + updateTipsOutput.add({ + 'refname': refname, + 'oldSha': oldOid.sha, + 'newSha': newOid.sha, + }); + } - final callbacks = Callbacks(updateTips: updateTips); + final callbacks = Callbacks(updateTips: updateTips); - remote.fetch(callbacks: callbacks); - expect(updateTipsOutput, tipsExpected); + remote.fetch(callbacks: callbacks); + expect(updateTipsOutput, tipsExpected); - remote.free(); - }); + remote.free(); + }, + tags: 'remote_fetch', + ); test('successfully pushes with update reference callback', () { final originDir = diff --git a/test/repository_clone_test.dart b/test/repository_clone_test.dart index f123e60..6c1d660 100644 --- a/test/repository_clone_test.dart +++ b/test/repository_clone_test.dart @@ -122,7 +122,7 @@ void main() { expect(clonedRepo.isEmpty, false); expect(clonedRepo.isBare, false); - expect(clonedRepo.path, '${callbackPath.path}/.git/'); + expect(clonedRepo.path, contains('${callbackPath.path}/.git/')); clonedRepo.free(); callbackPath.deleteSync(recursive: true); diff --git a/test/repository_init_test.dart b/test/repository_init_test.dart index 958737c..48b0b36 100644 --- a/test/repository_init_test.dart +++ b/test/repository_init_test.dart @@ -23,14 +23,14 @@ void main() { test('successfully creates new bare repo at provided path', () { repo = Repository.init(path: initDir.path, bare: true); - expect(repo.path, '${initDir.path}/'); + expect(repo.path, contains('${initDir.path}/')); expect(repo.isBare, true); }); test('successfully creates new standard repo at provided path', () { repo = Repository.init(path: initDir.path); - expect(repo.path, '${initDir.path}/.git/'); + expect(repo.path, contains('${initDir.path}/.git/')); expect(repo.isBare, false); expect(repo.isEmpty, true); }); @@ -43,7 +43,7 @@ void main() { flags: {GitRepositoryInit.mkdir, GitRepositoryInit.mkpath}, ); - expect(repo.path, '${initDir.path}/.git/'); + expect(repo.path, contains('${initDir.path}/.git/')); expect(repo.isBare, false); expect(repo.isEmpty, true); expect( diff --git a/test/repository_test.dart b/test/repository_test.dart index a9c4114..3b7abf3 100644 --- a/test/repository_test.dart +++ b/test/repository_test.dart @@ -91,7 +91,7 @@ void main() { tmpWorkDir.createSync(); repo.setWorkdir(path: tmpWorkDir.path); - expect(repo.workdir, '${tmpWorkDir.path}/'); + expect(repo.workdir, contains('${tmpWorkDir.path}/')); tmpWorkDir.deleteSync(); }); diff --git a/test/signature_test.dart b/test/signature_test.dart index dc1f8d2..384cb18 100644 --- a/test/signature_test.dart +++ b/test/signature_test.dart @@ -49,7 +49,7 @@ void main() { sig.time - (DateTime.now().millisecondsSinceEpoch / 1000).truncate(), lessThan(5), ); - expect(sig.offset, 180); + expect(sig.offset, isA()); sig.free(); }); diff --git a/test/worktree_test.dart b/test/worktree_test.dart index a56260e..42b51c2 100644 --- a/test/worktree_test.dart +++ b/test/worktree_test.dart @@ -41,7 +41,7 @@ void main() { expect(repo.worktrees, [worktreeName]); expect(branches.any((branch) => branch.name == worktreeName), true); expect(worktree.name, worktreeName); - expect(worktree.path, worktreeDir.path); + expect(worktree.path, contains(worktreeDir.path)); expect(worktree.isLocked, false); expect(worktree.toString(), contains('Worktree{')); expect(File('${worktreeDir.path}/.git').existsSync(), true); @@ -113,7 +113,7 @@ void main() { final lookedupWorktree = repo.lookupWorktree(worktreeName); expect(lookedupWorktree.name, worktreeName); - expect(lookedupWorktree.path, worktreeDir.path); + expect(lookedupWorktree.path, contains(worktreeDir.path)); expect(lookedupWorktree.isLocked, false); lookedupWorktree.free();