-
-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from dahlbyk/rkeithhill/fix-pester-tests
Fix tests on WinPS, PS Core Windows and Linux
- Loading branch information
Showing
7 changed files
with
318 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
. $PSScriptRoot\Shared.ps1 | ||
|
||
function GetMacOSAdjustedTempPath($Path) { | ||
if (($PSVersionTable.PSVersion.Major -ge 6) -and $IsMacOS) { | ||
# Mac OS's temp folder has a symlink in its path - /var is linked to /private/var | ||
return "/private${Path}" | ||
} | ||
|
||
$Path | ||
} | ||
|
||
Describe 'Get-GitDiretory Tests' { | ||
Context "Test normal repository" { | ||
BeforeAll { | ||
|
@@ -15,7 +24,7 @@ Describe 'Get-GitDiretory Tests' { | |
Get-GitDirectory | Should BeNullOrEmpty | ||
} | ||
It 'Returns $null for not a filesystem path' { | ||
Set-Location Cert:\CurrentUser | ||
Set-Location Alias:\ | ||
Get-GitDirectory | Should BeNullOrEmpty | ||
} | ||
It 'Returns correct path when in the root of repo' { | ||
|
@@ -38,18 +47,23 @@ Describe 'Get-GitDiretory Tests' { | |
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName()) | ||
$worktreePath = Join-Path $temp ([IO.Path]::GetRandomFileName()) | ||
|
||
git init $repoPath | ||
&$gitbin init $repoPath | ||
Set-Location $repoPath | ||
'foo' > .\README.md | ||
git add .\README.md | ||
|
||
# Git rid of Git warnings about configuring user for the commit we do below | ||
&$gitbin config user.email "[email protected]" | ||
&$gitbin config user.name "Pester User" | ||
|
||
'foo' > ./README.md | ||
&$gitbin add ./README.md | ||
# Quoting is a hack due to our use of the global:git function and how it converts args for invoke-expression | ||
git commit -m "`"initial commit.`"" | ||
&$gitbin commit -m "`"initial commit.`"" | ||
|
||
if (Test-Path $worktreePath) { | ||
Remove-Item $worktreePath -Recurse -Force | ||
} | ||
New-Item $worktreePath -ItemType Directory > $null | ||
git worktree add -b test-worktree $worktreePath master 2>$null | ||
&$gitbin worktree add -b test-worktree $worktreePath master 2>$null | ||
} | ||
AfterEach { | ||
Set-Location $origPath | ||
|
@@ -64,7 +78,8 @@ Describe 'Get-GitDiretory Tests' { | |
It 'Returns the correct dir when under a worktree' { | ||
Set-Location $worktreePath | ||
$worktreeBaseName = Split-Path $worktreePath -Leaf | ||
Get-GitDirectory | Should BeExactly (MakeGitPath $repoPath\.git\worktrees\$worktreeBaseName) | ||
$path = GetMacOSAdjustedTempPath $repoPath | ||
Get-GitDirectory | Should BeExactly (MakeGitPath $path\.git\worktrees\$worktreeBaseName) | ||
} | ||
} | ||
|
||
|
@@ -78,7 +93,7 @@ Describe 'Get-GitDiretory Tests' { | |
if (Test-Path $bareRepoPath) { | ||
Remove-Item $bareRepoPath -Recurse -Force | ||
} | ||
git init --bare $bareRepoPath | ||
&$gitbin init --bare $bareRepoPath | ||
} | ||
AfterAll { | ||
Set-Location $origPath | ||
|
@@ -93,7 +108,8 @@ Describe 'Get-GitDiretory Tests' { | |
} | ||
It 'Returns correct path when under a child folder of the root of bare repo' { | ||
Set-Location $bareRepoPath\hooks -ErrorVariable Stop | ||
MakeNativePath (Get-GitDirectory) | Should BeExactly $bareRepoPath | ||
$path = GetMacOSAdjustedTempPath $bareRepoPath | ||
Get-GitDirectory | Should BeExactly (MakeNativePath $path) | ||
} | ||
} | ||
|
||
|
@@ -102,7 +118,7 @@ Describe 'Get-GitDiretory Tests' { | |
Remove-Item Env:\GIT_DIR -ErrorAction SilentlyContinue | ||
} | ||
It 'Returns the value in GIT_DIR env var' { | ||
$env:GIT_DIR = 'C:\xyzzy\posh-git\.git' | ||
$env:GIT_DIR = MakeNativePath '/xyzzy/posh-git/.git' | ||
Get-GitDirectory | Should BeExactly $env:GIT_DIR | ||
} | ||
} | ||
|
Oops, something went wrong.