Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): Fix tests in Linux and macOS #5179

Merged
merged 9 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function Expand-ZipArchive {
$OriDestinationPath = $DestinationPath
$DestinationPath = "$DestinationPath\_tmp"
}
Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
Microsoft.PowerShell.Archive\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
if ($ExtractDir) {
movedir "$DestinationPath\$ExtractDir" $OriDestinationPath | Out-Null
Remove-Item $DestinationPath -Recurse -Force
Expand Down
67 changes: 27 additions & 40 deletions test/Scoop-Alias.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,41 @@
. "$PSScriptRoot\..\lib\help.ps1"
. "$PSScriptRoot\..\libexec\scoop-alias.ps1" | Out-Null

Describe 'add_alias' -Tag 'Scoop' {
Mock shimdir { "$env:TEMP\shims" }
Mock set_config { }
Mock get_config { @{} }

$shimdir = shimdir
ensure $shimdir

Context "alias doesn't exist" {
It 'creates a new alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
$alias_file | Should -Not -Exist

add_alias 'rm' '"hello, world!"'
& $alias_file | Should -Be 'hello, world!'
}
Describe 'Manipulate Alias' -Tag 'Scoop' {
BeforeAll {
Mock shimdir { "$TestDrive\shims" }
Mock set_config { }
Mock get_config { @{} }

$shimdir = shimdir
ensure $shimdir
}

Context 'alias exists' {
It 'does not change existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
New-Item $alias_file -Type File -Force
$alias_file | Should -Exist
It 'Creates a new alias if alias doesn''t exist' {
$alias_file = "$shimdir\scoop-rm.ps1"
$alias_file | Should -Not -Exist

add_alias 'rm' 'test'
$alias_file | Should -FileContentMatch ''
}
add_alias 'rm' '"hello, world!"'
& $alias_file | Should -Be 'hello, world!'
}
}

Describe 'rm_alias' -Tag 'Scoop' {
Mock shimdir { "$env:TEMP\shims" }
Mock set_config { }
Mock get_config { @{} }
It 'Does not change existing alias if alias exists' {
$alias_file = "$shimdir\scoop-rm.ps1"
New-Item $alias_file -Type File -Force
$alias_file | Should -Exist

$shimdir = shimdir
ensure $shimdir
add_alias 'rm' 'test'
& $alias_file | Should -Not -Be 'test'
}

Context 'alias exists' {
It 'removes an existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias 'rm' '"hello, world!"'
It 'Removes an existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias 'rm' '"hello, world!"'

$alias_file | Should -Exist
Mock get_config { @(@{'rm' = 'scoop-rm' }) }
$alias_file | Should -Exist
Mock get_config { @(@{'rm' = 'scoop-rm' }) }

rm_alias 'rm'
$alias_file | Should -Not -Exist
}
rm_alias 'rm'
$alias_file | Should -Not -Exist
}
}
9 changes: 3 additions & 6 deletions test/Scoop-Config.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

Describe 'config' -Tag 'Scoop' {
BeforeAll {
$configFile = "$env:TEMP\ScoopTestFixtures\config.json"
if (Test-Path $configFile) {
Remove-Item -Path $configFile -Force
}
$configFile = [IO.Path]::GetTempFileName()
$unicode = [Regex]::Unescape('\u4f60\u597d\u3053\u3093\u306b\u3061\u306f') # 你好こんにちは
}

BeforeEach {
$scoopConfig = $null
AfterAll {
Remove-Item -Path $configFile -Force
}

It 'load_cfg should return null if config file does not exist' {
Expand Down
34 changes: 16 additions & 18 deletions test/Scoop-Core.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
. "$PSScriptRoot\..\lib\unix.ps1"

$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName
$isUnix = is_unix

Describe 'Get-AppFilePath' -Tag 'Scoop' {
BeforeAll {
Expand Down Expand Up @@ -128,23 +126,23 @@ Describe 'is_directory' -Tag 'Scoop' {
}
}

Describe 'movedir' -Tag 'Scoop' {
Describe 'movedir' -Tag 'Scoop', 'Windows' {
$extract_dir = 'subdir'
$extract_to = $null

BeforeAll {
$working_dir = setup_working 'movedir'
}

It 'moves directories with no spaces in path' -Skip:$isUnix {
It 'moves directories with no spaces in path' {
$dir = "$working_dir\user"
movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to"

"$dir\test.txt" | Should -FileContentMatch 'this is the one'
"$dir\_tmp\$extract_dir" | Should -Not -Exist
}

It 'moves directories with spaces in path' -Skip:$isUnix {
It 'moves directories with spaces in path' {
$dir = "$working_dir\user with space"
movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to"

Expand All @@ -157,7 +155,7 @@ Describe 'movedir' -Tag 'Scoop' {
"$dir\_tmp" | Should -Not -Exist
}

It 'moves directories with quotes in path' -Skip:$isUnix {
It 'moves directories with quotes in path' {
$dir = "$working_dir\user with 'quote"
movedir "$dir\_tmp\$extract_dir" "$dir\$extract_to"

Expand All @@ -166,14 +164,14 @@ Describe 'movedir' -Tag 'Scoop' {
}
}

Describe 'shim' -Tag 'Scoop' {
Describe 'shim' -Tag 'Scoop', 'Windows' {
BeforeAll {
$working_dir = setup_working 'shim'
$shimdir = shimdir
$(ensure_in_path $shimdir) | Out-Null
}

It "links a file onto the user's path" -Skip:$isUnix {
It "links a file onto the user's path" {
{ Get-Command 'shim-test' -ea stop } | Should -Throw
{ Get-Command 'shim-test.ps1' -ea stop } | Should -Throw
{ Get-Command 'shim-test.cmd' -ea stop } | Should -Throw
Expand All @@ -187,7 +185,7 @@ Describe 'shim' -Tag 'Scoop' {
}

Context 'user with quote' {
It 'shims a file with quote in path' -Skip:$isUnix {
It 'shims a file with quote in path' {
{ Get-Command 'shim-test' -ea stop } | Should -Throw
{ shim-test } | Should -Throw

Expand All @@ -202,14 +200,14 @@ Describe 'shim' -Tag 'Scoop' {
}
}

Describe 'rm_shim' -Tag 'Scoop' {
Describe 'rm_shim' -Tag 'Scoop', 'Windows' {
BeforeAll {
$working_dir = setup_working 'shim'
$shimdir = shimdir
$(ensure_in_path $shimdir) | Out-Null
}

It 'removes shim from path' -Skip:$isUnix {
It 'removes shim from path' {
shim "$working_dir\shim-test.ps1" $false 'shim-test'

rm_shim 'shim-test' $shimdir
Expand All @@ -221,19 +219,19 @@ Describe 'rm_shim' -Tag 'Scoop' {
}
}

Describe 'get_app_name_from_shim' -Tag 'Scoop' {
Describe 'get_app_name_from_shim' -Tag 'Scoop', 'Windows' {
BeforeAll {
$working_dir = setup_working 'shim'
$shimdir = shimdir
$(ensure_in_path $shimdir) | Out-Null
Mock appsdir { $working_dir }
}

It 'returns empty string if file does not exist' -Skip:$isUnix {
It 'returns empty string if file does not exist' {
get_app_name_from_shim 'non-existent-file' | Should -Be ''
}

It 'returns app name if file exists and is a shim to an app' -Skip:$isUnix {
It 'returns app name if file exists and is a shim to an app' {
ensure "$working_dir/mockapp/current/"
Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp1.ps1"
shim "$working_dir/mockapp/current/mockapp1.ps1" $false 'shim-test1'
Expand All @@ -246,7 +244,7 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' {
get_app_name_from_shim "$shim_path2" | Should -Be 'mockapp'
}

It 'returns empty string if file exists and is not a shim' -Skip:$isUnix {
It 'returns empty string if file exists and is not a shim' {
Write-Output 'lorem ipsum' | Out-File -Encoding ascii "$working_dir/mock-shim.ps1"
get_app_name_from_shim "$working_dir/mock-shim.ps1" | Should -Be ''
}
Expand All @@ -263,12 +261,12 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' {
}
}

Describe 'ensure_robocopy_in_path' -Tag 'Scoop' {
Describe 'ensure_robocopy_in_path' -Tag 'Scoop', 'Windows' {
$shimdir = shimdir $false
Mock versiondir { $repo_dir }

Context 'robocopy is not in path' {
It 'shims robocopy when not on path' -Skip:$isUnix {
It 'shims robocopy when not on path' {
Mock Test-CommandAvailable { $false }
Test-CommandAvailable robocopy | Should -Be $false

Expand All @@ -283,7 +281,7 @@ Describe 'ensure_robocopy_in_path' -Tag 'Scoop' {
}

Context 'robocopy is in path' {
It 'does not shim robocopy when it is in path' -Skip:$isUnix {
It 'does not shim robocopy when it is in path' {
Mock Test-CommandAvailable { $true }
Test-CommandAvailable robocopy | Should -Be $true

Expand Down
Loading