From a71bb14b86458d9b51a56f05bfa24444bf46c3b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Fri, 29 Oct 2021 10:59:30 +0300 Subject: [PATCH] test: fix tests failing on windows --- .github/workflows/master.yml | 6 +++++- test/odb_test.dart | 7 ++----- test/repository_clone_test.dart | 2 +- test/repository_empty_test.dart | 25 ++++++------------------- test/repository_init_test.dart | 8 ++++---- test/repository_test.dart | 2 +- test/submodule_test.dart | 6 +++++- test/worktree_test.dart | 4 ++-- 8 files changed, 26 insertions(+), 34 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 62a44d4..089da16 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -39,6 +39,11 @@ jobs: runs-on: ${{ matrix.platform }} steps: + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 with: @@ -52,4 +57,3 @@ jobs: - name: Run tests run: dart test --exclude-tags "remote_fetch" --platform vm - if: matrix.platform != 'windows-latest' diff --git a/test/odb_test.dart b/test/odb_test.dart index 63bf698..2dc8105 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -1,3 +1,4 @@ +import 'dart:ffi'; import 'dart:io'; import 'package:libgit2dart/libgit2dart.dart'; @@ -30,11 +31,7 @@ void main() { }); test('throws when trying to get odb and error occurs', () { - Directory('${repo.workdir}.git/objects/').deleteSync(recursive: true); - expect( - () => repo.odb, - throwsA(isA()), - ); + expect(() => Repository((nullptr)).odb, throwsA(isA())); }); test('successfully creates new odb with no backends', () { diff --git a/test/repository_clone_test.dart b/test/repository_clone_test.dart index 6c1d660..4cc4005 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, contains('${callbackPath.path}/.git/')); + expect(clonedRepo.path, contains('/callbackRepo/.git/')); clonedRepo.free(); callbackPath.deleteSync(recursive: true); diff --git a/test/repository_empty_test.dart b/test/repository_empty_test.dart index ecd133c..6d63297 100644 --- a/test/repository_empty_test.dart +++ b/test/repository_empty_test.dart @@ -1,5 +1,4 @@ import 'dart:ffi'; -import 'dart:io'; import 'package:libgit2dart/libgit2dart.dart'; import 'package:test/test.dart'; @@ -10,7 +9,7 @@ void main() { group('Repository.open', () { test("throws when repository isn't found at provided path", () { expect( - () => Repository.open(''), + () => Repository.open('/not/there'), throwsA(isA()), ); }); @@ -33,17 +32,11 @@ void main() { }); test('returns path to the repository', () { - expect( - repo.path, - '${Directory.current.path}/test/assets/empty_bare.git/', - ); + expect(repo.path, contains('/test/assets/empty_bare.git/')); }); test('returns path to root directory for the repository', () { - expect( - repo.commonDir, - '${Directory.current.path}/test/assets/empty_bare.git/', - ); + expect(repo.commonDir, contains('/test/assets/empty_bare.git/')); }); test('returns empty string as path of the working directory', () { @@ -65,16 +58,13 @@ void main() { }); test('returns path to the repository', () { - expect( - repo.path, - '${Directory.current.path}/test/assets/empty_standard/.gitdir/', - ); + expect(repo.path, contains('/test/assets/empty_standard/.gitdir/')); }); test("returns path to parent repo's .git folder for the repository", () { expect( repo.commonDir, - '${Directory.current.path}/test/assets/empty_standard/.gitdir/', + contains('/test/assets/empty_standard/.gitdir/'), ); }); @@ -113,10 +103,7 @@ void main() { }); test('returns path to working directory', () { - expect( - repo.workdir, - '${Directory.current.path}/test/assets/empty_standard/', - ); + expect(repo.workdir, contains('/test/assets/empty_standard/')); }); }); }); diff --git a/test/repository_init_test.dart b/test/repository_init_test.dart index 48b0b36..ffc4f82 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, contains('${initDir.path}/')); + expect(repo.path, contains('init_repo/')); expect(repo.isBare, true); }); test('successfully creates new standard repo at provided path', () { repo = Repository.init(path: initDir.path); - expect(repo.path, contains('${initDir.path}/.git/')); + expect(repo.path, contains('init_repo/.git/')); expect(repo.isBare, false); expect(repo.isEmpty, true); }); @@ -43,11 +43,11 @@ void main() { flags: {GitRepositoryInit.mkdir, GitRepositoryInit.mkpath}, ); - expect(repo.path, contains('${initDir.path}/.git/')); + expect(repo.path, contains('init_repo/.git/')); expect(repo.isBare, false); expect(repo.isEmpty, true); expect( - File('${initDir.path}/.git/description').readAsStringSync(), + File('${repo.workdir}.git/description').readAsStringSync(), 'test repo', ); expect(repo.lookupRemote('origin').url, 'test.url'); diff --git a/test/repository_test.dart b/test/repository_test.dart index 3b7abf3..f9a4cbd 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, contains('${tmpWorkDir.path}/')); + expect(repo.workdir, contains('/tmp_work_dir/')); tmpWorkDir.deleteSync(); }); diff --git a/test/submodule_test.dart b/test/submodule_test.dart index 8eb6391..ab9ea40 100644 --- a/test/submodule_test.dart +++ b/test/submodule_test.dart @@ -20,7 +20,11 @@ void main() { tearDown(() { repo.free(); - tmpDir.deleteSync(recursive: true); + try { + tmpDir.deleteSync(recursive: true); + } catch (e) { + return; + } }); group('Submodule', () { diff --git a/test/worktree_test.dart b/test/worktree_test.dart index 42b51c2..17c1a29 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, contains(worktreeDir.path)); + expect(worktree.path, contains('/worktree')); 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, contains(worktreeDir.path)); + expect(lookedupWorktree.path, contains('/worktree')); expect(lookedupWorktree.isLocked, false); lookedupWorktree.free();