Skip to content

Commit 7dcb7c0

Browse files
authored
fix(tests): Fix tests in Linux and macOS (#5179)
1 parent 9fda542 commit 7dcb7c0

9 files changed

+106
-194
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- **auto-pr:** Add `CommitMessageFormat` option ([#5171](https://github.com/ScoopInstaller/Scoop/issues/5171))
1616
- **checkver:** Support XML default namespace ([#5191](https://github.com/ScoopInstaller/Scoop/issues/5191))
1717

18+
### Tests
19+
20+
- **unix:** Fix tests in Linux and macOS ([#5179](https://github.com/ScoopInstaller/Scoop/issues/5179))
21+
1822
## [v0.3.0](https://github.com/ScoopInstaller/Scoop/compare/v0.2.4...v0.3.0) - 2022-10-10
1923

2024
### Features

test/Scoop-Alias.Tests.ps1

+27-40
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,41 @@
33
. "$PSScriptRoot\..\lib\help.ps1"
44
. "$PSScriptRoot\..\libexec\scoop-alias.ps1" | Out-Null
55

6-
Describe 'add_alias' -Tag 'Scoop' {
7-
Mock shimdir { "$env:TEMP\shims" }
8-
Mock set_config { }
9-
Mock get_config { @{} }
10-
11-
$shimdir = shimdir
12-
ensure $shimdir
13-
14-
Context "alias doesn't exist" {
15-
It 'creates a new alias' {
16-
$alias_file = "$shimdir\scoop-rm.ps1"
17-
$alias_file | Should -Not -Exist
18-
19-
add_alias 'rm' '"hello, world!"'
20-
& $alias_file | Should -Be 'hello, world!'
21-
}
6+
Describe 'Manipulate Alias' -Tag 'Scoop' {
7+
BeforeAll {
8+
Mock shimdir { "$TestDrive\shims" }
9+
Mock set_config { }
10+
Mock get_config { @{} }
11+
12+
$shimdir = shimdir
13+
ensure $shimdir
2214
}
2315

24-
Context 'alias exists' {
25-
It 'does not change existing alias' {
26-
$alias_file = "$shimdir\scoop-rm.ps1"
27-
New-Item $alias_file -Type File -Force
28-
$alias_file | Should -Exist
16+
It 'Creates a new alias if alias doesn''t exist' {
17+
$alias_file = "$shimdir\scoop-rm.ps1"
18+
$alias_file | Should -Not -Exist
2919

30-
add_alias 'rm' 'test'
31-
$alias_file | Should -FileContentMatch ''
32-
}
20+
add_alias 'rm' '"hello, world!"'
21+
& $alias_file | Should -Be 'hello, world!'
3322
}
34-
}
3523

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

41-
$shimdir = shimdir
42-
ensure $shimdir
29+
add_alias 'rm' 'test'
30+
& $alias_file | Should -Not -Be 'test'
31+
}
4332

44-
Context 'alias exists' {
45-
It 'removes an existing alias' {
46-
$alias_file = "$shimdir\scoop-rm.ps1"
47-
add_alias 'rm' '"hello, world!"'
33+
It 'Removes an existing alias' {
34+
$alias_file = "$shimdir\scoop-rm.ps1"
35+
add_alias 'rm' '"hello, world!"'
4836

49-
$alias_file | Should -Exist
50-
Mock get_config { @(@{'rm' = 'scoop-rm' }) }
37+
$alias_file | Should -Exist
38+
Mock get_config { @(@{'rm' = 'scoop-rm' }) }
5139

52-
rm_alias 'rm'
53-
$alias_file | Should -Not -Exist
54-
}
40+
rm_alias 'rm'
41+
$alias_file | Should -Not -Exist
5542
}
5643
}

test/Scoop-Config.Tests.ps1

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

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

13-
BeforeEach {
14-
$scoopConfig = $null
10+
AfterAll {
11+
Remove-Item -Path $configFile -Force
1512
}
1613

1714
It 'load_cfg should return null if config file does not exist' {

test/Scoop-Core.Tests.ps1

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
. "$PSScriptRoot\Scoop-TestLib.ps1"
22
. "$PSScriptRoot\..\lib\core.ps1"
33
. "$PSScriptRoot\..\lib\install.ps1"
4-
. "$PSScriptRoot\..\lib\unix.ps1"
54

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

97
Describe 'Get-AppFilePath' -Tag 'Scoop' {
108
BeforeAll {
@@ -128,23 +126,23 @@ Describe 'is_directory' -Tag 'Scoop' {
128126
}
129127
}
130128

131-
Describe 'movedir' -Tag 'Scoop' {
129+
Describe 'movedir' -Tag 'Scoop', 'Windows' {
132130
$extract_dir = 'subdir'
133131
$extract_to = $null
134132

135133
BeforeAll {
136134
$working_dir = setup_working 'movedir'
137135
}
138136

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

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

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

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

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

@@ -166,14 +164,14 @@ Describe 'movedir' -Tag 'Scoop' {
166164
}
167165
}
168166

169-
Describe 'shim' -Tag 'Scoop' {
167+
Describe 'shim' -Tag 'Scoop', 'Windows' {
170168
BeforeAll {
171169
$working_dir = setup_working 'shim'
172170
$shimdir = shimdir
173171
$(ensure_in_path $shimdir) | Out-Null
174172
}
175173

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

189187
Context 'user with quote' {
190-
It 'shims a file with quote in path' -Skip:$isUnix {
188+
It 'shims a file with quote in path' {
191189
{ Get-Command 'shim-test' -ea stop } | Should -Throw
192190
{ shim-test } | Should -Throw
193191

@@ -202,14 +200,14 @@ Describe 'shim' -Tag 'Scoop' {
202200
}
203201
}
204202

205-
Describe 'rm_shim' -Tag 'Scoop' {
203+
Describe 'rm_shim' -Tag 'Scoop', 'Windows' {
206204
BeforeAll {
207205
$working_dir = setup_working 'shim'
208206
$shimdir = shimdir
209207
$(ensure_in_path $shimdir) | Out-Null
210208
}
211209

212-
It 'removes shim from path' -Skip:$isUnix {
210+
It 'removes shim from path' {
213211
shim "$working_dir\shim-test.ps1" $false 'shim-test'
214212

215213
rm_shim 'shim-test' $shimdir
@@ -221,19 +219,19 @@ Describe 'rm_shim' -Tag 'Scoop' {
221219
}
222220
}
223221

224-
Describe 'get_app_name_from_shim' -Tag 'Scoop' {
222+
Describe 'get_app_name_from_shim' -Tag 'Scoop', 'Windows' {
225223
BeforeAll {
226224
$working_dir = setup_working 'shim'
227225
$shimdir = shimdir
228226
$(ensure_in_path $shimdir) | Out-Null
229227
Mock appsdir { $working_dir }
230228
}
231229

232-
It 'returns empty string if file does not exist' -Skip:$isUnix {
230+
It 'returns empty string if file does not exist' {
233231
get_app_name_from_shim 'non-existent-file' | Should -Be ''
234232
}
235233

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

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

266-
Describe 'ensure_robocopy_in_path' -Tag 'Scoop' {
264+
Describe 'ensure_robocopy_in_path' -Tag 'Scoop', 'Windows' {
267265
$shimdir = shimdir $false
268266
Mock versiondir { $repo_dir }
269267

270268
Context 'robocopy is not in path' {
271-
It 'shims robocopy when not on path' -Skip:$isUnix {
269+
It 'shims robocopy when not on path' {
272270
Mock Test-CommandAvailable { $false }
273271
Test-CommandAvailable robocopy | Should -Be $false
274272

@@ -283,7 +281,7 @@ Describe 'ensure_robocopy_in_path' -Tag 'Scoop' {
283281
}
284282

285283
Context 'robocopy is in path' {
286-
It 'does not shim robocopy when it is in path' -Skip:$isUnix {
284+
It 'does not shim robocopy when it is in path' {
287285
Mock Test-CommandAvailable { $true }
288286
Test-CommandAvailable robocopy | Should -Be $true
289287

0 commit comments

Comments
 (0)