Skip to content

Commit 68f4e03

Browse files
committed
appveyor: Run tests for PowerShell 5 and 6
- Add commit flag to skip PSScriptAnalyzer - Add commit flag to skip manifest validation - Skips manifest validation if no JSON has changed - Skips test and linting if no PowerShell script has changed
1 parent 2a2c205 commit 68f4e03

11 files changed

Lines changed: 140 additions & 35 deletions

appveyor.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,36 @@ branches:
44
except:
55
- gh-pages
66

7-
init:
8-
- ps: (get-psprovider 'FileSystem').Home = $(pwd)
9-
- ps: Install-PackageProvider Nuget -Force
10-
- ps: Install-Module -Name Pester -Repository PSGallery -Force
11-
- ps: Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force
12-
137
build: off
8+
deploy: off
9+
clone_depth: 50
10+
11+
image:
12+
- Visual Studio 2017
13+
14+
environment:
15+
matrix:
16+
- PowerShell: 5
17+
- PowerShell: 6
18+
19+
cache:
20+
- '%USERPROFILE%\Documents\WindowsPowerShell\Modules -> appveyor.yml'
21+
22+
matrix:
23+
fast_finish: true
1424

15-
test_script:
16-
- ps: $result = invoke-pester -path test/ -outputfile TestResults.xml -outputformat NUnitXML -passthru; $env:failedcount = $result.failedcount
17-
- ps: (new-object net.webclient).uploadfile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (resolve-path ./TestResults.xml))
18-
- ps: if($env:failedcount -gt 0) { exit $env:failedcount }
25+
for:
26+
- matrix:
27+
only:
28+
- PowerShell: 5
29+
install:
30+
- ps: .\test\bin\init.ps1
31+
test_script:
32+
- ps: .\test\bin\test.ps1
33+
- matrix:
34+
only:
35+
- PowerShell: 6
36+
install:
37+
- pwsh: .\test\bin\init.ps1
38+
test_script:
39+
- pwsh: .\test\bin\test.ps1

test/Scoop-Alias.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
reset_aliases
44

5-
describe "add_alias" {
5+
describe "add_alias" -Tag 'Scoop' {
66
mock shimdir { "TestDrive:\shim" }
77
mock set_config { }
88
mock get_config { @{} }

test/Scoop-Config.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
. "$psscriptroot\..\lib\core.ps1"
22
. "$psscriptroot\..\lib\config.ps1"
33

4-
describe "hashtable" {
4+
describe "hashtable" -Tag 'Scoop' {
55
$json = '{ "one": 1, "two": [ { "a": "a" }, "b", 2 ], "three": { "four": 4 }, "five": true, "six": false, "seven": "\/Date(1529917395805)\/" }'
66

77
it "converts pscustomobject to hashtable" {

test/Scoop-Core.Tests.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName
77
$isUnix = is_unix
88

9-
describe "is_directory" {
9+
describe "is_directory" -Tag 'Scoop' {
1010
beforeall {
1111
$working_dir = setup_working "is_directory"
1212
}
@@ -23,7 +23,7 @@ describe "is_directory" {
2323
}
2424
}
2525

26-
describe "movedir" {
26+
describe "movedir" -Tag 'Scoop' {
2727
$extract_dir = "subdir"
2828
$extract_to = $null
2929

@@ -61,7 +61,7 @@ describe "movedir" {
6161
}
6262
}
6363

64-
describe "unzip_old" {
64+
describe "unzip_old" -Tag 'Scoop' {
6565
beforeall {
6666
$working_dir = setup_working "unzip_old"
6767
}
@@ -117,7 +117,7 @@ describe "unzip_old" {
117117
}
118118
}
119119

120-
describe "shim" {
120+
describe "shim" -Tag 'Scoop' {
121121
beforeall {
122122
$working_dir = setup_working "shim"
123123
$shimdir = shimdir
@@ -153,7 +153,7 @@ describe "shim" {
153153
}
154154
}
155155

156-
describe "rm_shim" {
156+
describe "rm_shim" -Tag 'Scoop' {
157157
beforeall {
158158
$working_dir = setup_working "shim"
159159
$shimdir = shimdir
@@ -172,7 +172,7 @@ describe "rm_shim" {
172172
}
173173
}
174174

175-
Describe "get_app_name_from_ps1_shim" {
175+
Describe "get_app_name_from_ps1_shim" -Tag 'Scoop' {
176176
BeforeAll {
177177
$working_dir = setup_working "shim"
178178
$shimdir = shimdir
@@ -211,7 +211,7 @@ Describe "get_app_name_from_ps1_shim" {
211211
}
212212
}
213213

214-
describe "ensure_robocopy_in_path" {
214+
describe "ensure_robocopy_in_path" -Tag 'Scoop' {
215215
$shimdir = shimdir $false
216216
mock versiondir { $repo_dir }
217217

@@ -245,7 +245,7 @@ describe "ensure_robocopy_in_path" {
245245
}
246246
}
247247

248-
describe 'sanitary_path' {
248+
describe 'sanitary_path' -Tag 'Scoop' {
249249
it 'removes invalid path characters from a string' {
250250
$path = 'test?.json'
251251
$valid_path = sanitary_path $path
@@ -254,7 +254,7 @@ describe 'sanitary_path' {
254254
}
255255
}
256256

257-
describe 'app' {
257+
describe 'app' -Tag 'Scoop' {
258258
it 'parses the bucket name from an app query' {
259259
$query = "C:\test.json"
260260
$app, $bucket, $version = parse_app $query

test/Scoop-GetOpts.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
. "$psscriptroot\Scoop-TestLib.ps1"
22
. "$psscriptroot\..\lib\getopt.ps1"
33

4-
describe "getopt" {
4+
describe "getopt" -Tag 'Scoop' {
55
it 'handle short option with required argument missing' {
66
$null, $null, $err = getopt '-x' 'x:' ''
77
$err | should be 'Option -x requires an argument.'

test/Scoop-Install.Tests.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$isUnix = is_unix
88

9-
describe "ensure_architecture" {
9+
describe "ensure_architecture" -Tag 'Scoop' {
1010
it "should keep correct architectures" {
1111
ensure_architecture "32bit" | Should be "32bit"
1212
ensure_architecture "32" | Should be "32bit"
@@ -37,13 +37,13 @@ describe "ensure_architecture" {
3737
}
3838
}
3939

40-
describe "appname_from_url" {
40+
describe "appname_from_url" -Tag 'Scoop' {
4141
it "should extract the correct name" {
4242
appname_from_url "https://example.org/directory/foobar.json" | Should be "foobar"
4343
}
4444
}
4545

46-
describe "url_filename" {
46+
describe "url_filename" -Tag 'Scoop' {
4747
it "should extract the real filename from an url" {
4848
url_filename "http://example.org/foo.txt" | Should be "foo.txt"
4949
url_filename "http://example.org/foo.txt?var=123" | Should be "foo.txt"
@@ -54,7 +54,7 @@ describe "url_filename" {
5454
}
5555
}
5656

57-
describe "url_remote_filename" {
57+
describe "url_remote_filename" -Tag 'Scoop' {
5858
it "should extract the real filename from an url" {
5959
url_remote_filename "http://example.org/foo.txt" | Should be "foo.txt"
6060
url_remote_filename "http://example.org/foo.txt?var=123" | Should be "foo.txt"
@@ -65,7 +65,7 @@ describe "url_remote_filename" {
6565
}
6666
}
6767

68-
describe "is_in_dir" {
68+
describe "is_in_dir" -Tag 'Scoop' {
6969
it "should work correctly" -skip:$isUnix {
7070
is_in_dir "C:\test" "C:\foo" | Should be $false
7171
is_in_dir "C:\test" "C:\test\foo\baz.zip" | Should be $true
@@ -75,7 +75,7 @@ describe "is_in_dir" {
7575
}
7676
}
7777

78-
describe "env add and remove path" {
78+
describe "env add and remove path" -Tag 'Scoop' {
7979
# test data
8080
$manifest = @{
8181
"env_add_path" = @("foo", "bar")
@@ -101,7 +101,7 @@ describe "env add and remove path" {
101101
}
102102
}
103103

104-
describe "shim_def" {
104+
describe "shim_def" -Tag 'Scoop' {
105105
it "should use strings correctly" {
106106
$target, $name, $shimArgs = shim_def "command.exe"
107107
$target | Should be "command.exe"
@@ -122,7 +122,7 @@ describe "shim_def" {
122122
}
123123
}
124124

125-
describe 'persist_def' {
125+
describe 'persist_def' -Tag 'Scoop' {
126126
it 'parses string correctly' {
127127
$source, $target = persist_def "test"
128128
$source | Should be "test"
@@ -153,7 +153,7 @@ describe 'persist_def' {
153153
}
154154
}
155155

156-
describe 'compute_hash' {
156+
describe 'compute_hash' -Tag 'Scoop' {
157157
beforeall {
158158
$working_dir = setup_working "manifest"
159159
}

test/Scoop-Linting.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).directory.parent.FullName
22

3-
Describe "PSScriptAnalyzer" {
3+
Describe -Tag 'Linter' "PSScriptAnalyzer" {
44
$scoop_modules = Get-ChildItem $repo_dir -Recurse -Include *.psd1, *.psm1, *.ps1
55
$scoop_modules = $scoop_modules | Where-Object { $_.DirectoryName -notlike '*\supporting*' -and $_.DirectoryName -notlike '*\test*' }
66
$scoop_modules = $scoop_modules | Select-Object -ExpandProperty Directory -Unique

test/Scoop-Manifest.Tests.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
. "$psscriptroot\..\lib\core.ps1"
33
. "$psscriptroot\..\lib\manifest.ps1"
44

5-
describe "manifest-validation" {
5+
describe -Tag 'Manifests' "manifest-validation" {
66
beforeall {
77
$working_dir = setup_working "manifest"
88
$schema = "$psscriptroot/../schema.json"
@@ -48,14 +48,23 @@ describe "manifest-validation" {
4848
if ($null -eq $bucketdir) {
4949
$bucketdir = "$psscriptroot\..\bucket\"
5050
}
51+
$changed_manifests = @()
52+
if($env:CI -eq $true) {
53+
$commit = if($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
54+
$changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit)
55+
}
5156
$manifest_files = Get-ChildItem $bucketdir *.json
5257
$validator = new-object Scoop.Validator($schema, $true)
5358
}
5459

5560
$quota_exceeded = $false
5661

5762
$manifest_files | ForEach-Object {
58-
it "$_" {
63+
$skip_manifest = ($changed_manifests -inotcontains $_.FullName)
64+
if($env:CI -ne $true -or $changed_manifests -contains 'schema.json') {
65+
$skip_manifest = $false
66+
}
67+
it "$_" -skip:$skip_manifest {
5968
$file = $_ # exception handling may overwrite $_
6069

6170
if(!($quota_exceeded)) {

test/Scoop-Versions.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
. "$psscriptroot\Scoop-TestLib.ps1"
22
. "$psscriptroot\..\lib\versions.ps1"
33

4-
describe "versions" {
4+
describe "versions" -Tag 'Scoop' {
55
it 'compares versions with integer-string mismatch' {
66
$a = '1.8.9'
77
$b = '1.8.5-1'

test/bin/init.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Write-Host "PowerShell: $($PSVersionTable.PSVersion)"
2+
3+
Write-Host "Install dependencies ..."
4+
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name Pester -SkipPublisherCheck
5+
Install-Module -Repository PSGallery -Scope CurrentUser -Name PSScriptAnalyzer,BuildHelpers
6+
7+
if($env:CI -eq $true) {
8+
Write-Host "Load 'BuildHelpers' environment variables ..."
9+
Set-BuildEnvironment -Force
10+
}
11+
12+
$buildVariables = ( Get-ChildItem -Path 'Env:' ).Where( { $_.Name -match "^(?:BH|CI(?:_|$)|APPVEYOR)" } )
13+
$buildVariables += ( Get-Variable -Name 'CI_*' -Scope 'Script' )
14+
$details = $buildVariables |
15+
Where-Object -FilterScript { $_.Name -notmatch 'EMAIL' } |
16+
Sort-Object -Property 'Name' |
17+
Format-Table -AutoSize -Property 'Name', 'Value' |
18+
Out-String
19+
Write-Host "CI variables:"
20+
Write-Host $details -ForegroundColor DarkGray

0 commit comments

Comments
 (0)