Skip to content

Commit c0dce0e

Browse files
KevinMarquetter15ch13
authored andcommitted
Use Pester 4.0 syntax to multiple files (#2714)
1 parent b37349a commit c0dce0e

6 files changed

Lines changed: 58 additions & 58 deletions

test/Scoop-Alias.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ describe "add_alias" -Tag 'Scoop' {
1313
context "alias doesn't exist" {
1414
it "creates a new alias" {
1515
$alias_file = "$shimdir\scoop-rm.ps1"
16-
$alias_file | should not exist
16+
$alias_file | should -not -exist
1717

1818
add_alias "rm" '"hello, world!"'
19-
Invoke-Expression $alias_file | should be "hello, world!"
19+
Invoke-Expression $alias_file | should -be "hello, world!"
2020
}
2121
}
2222

2323
context "alias exists" {
2424
it "does not change existing alias" {
2525
$alias_file = "$shimdir\scoop-rm.ps1"
2626
new-item $alias_file -type file
27-
$alias_file | should exist
27+
$alias_file | should -exist
2828

2929
add_alias "rm" "test"
30-
$alias_file | should FileContentMatch ""
30+
$alias_file | should -FileContentMatch ""
3131
}
3232
}
3333
}
@@ -45,11 +45,11 @@ describe "rm_alias" {
4545
$alias_file = "$shimdir\scoop-rm.ps1"
4646
add_alias "rm" '"hello, world!"'
4747

48-
$alias_file | should exist
48+
$alias_file | should -exist
4949
mock get_config { @(@{"rm" = "scoop-rm"}) }
5050

5151
rm_alias "rm"
52-
$alias_file | should not exist
52+
$alias_file | should -not -exist
5353
}
5454
}
5555
}

test/Scoop-Config.Tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ describe "hashtable" -Tag 'Scoop' {
88
$obj = convertfrom-json $json
99
$ht = hashtable $obj
1010

11-
$ht.one | should beexactly 1
12-
$ht.two[0].a | should be "a"
13-
$ht.two[1] | should be "b"
14-
$ht.two[2] | should beexactly 2
15-
$ht.three.four | should beexactly 4
16-
$ht.five | should beexactly $true
17-
$ht.six | should beexactly $false
18-
[System.DateTime]::Equals($ht.seven, $(New-Object System.DateTime (2018, 06, 25, 09, 03, 15, 805))) | should be $true
11+
$ht.one | should -beexactly 1
12+
$ht.two[0].a | should -be "a"
13+
$ht.two[1] | should -be "b"
14+
$ht.two[2] | should -beexactly 2
15+
$ht.three.four | should -beexactly 4
16+
$ht.five | should -beexactly $true
17+
$ht.six | should -beexactly $false
18+
[System.DateTime]::Equals($ht.seven, $(New-Object System.DateTime (2018, 06, 25, 09, 03, 15, 805))) | should -betrue
1919
}
2020
}

test/Scoop-GetOpts.Tests.ps1

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,68 @@
44
describe "getopt" -Tag 'Scoop' {
55
it 'handle short option with required argument missing' {
66
$null, $null, $err = getopt '-x' 'x:' ''
7-
$err | should be 'Option -x requires an argument.'
7+
$err | should -be 'Option -x requires an argument.'
88

99
$null, $null, $err = getopt '-xy' 'x:y' ''
10-
$err | should be 'Option -x requires an argument.'
10+
$err | should -be 'Option -x requires an argument.'
1111
}
1212

1313
it 'handle long option with required argument missing' {
1414
$null, $null, $err = getopt '--arb' '' 'arb='
15-
$err | should be 'Option --arb requires an argument.'
15+
$err | should -be 'Option --arb requires an argument.'
1616
}
1717

1818
it 'handle unrecognized short option' {
1919
$null, $null, $err = getopt '-az' 'a' ''
20-
$err | should be 'Option -z not recognized.'
20+
$err | should -be 'Option -z not recognized.'
2121
}
2222

2323
it 'handle unrecognized long option' {
2424
$null, $null, $err = getopt '--non-exist' '' ''
25-
$err | should be 'Option --non-exist not recognized.'
25+
$err | should -be 'Option --non-exist not recognized.'
2626

2727
$null, $null, $err = getopt '--global','--another' 'abc:de:' 'global','one'
28-
$err | should be 'Option --another not recognized.'
28+
$err | should -be 'Option --another not recognized.'
2929
}
3030

3131
it 'remaining args returned' {
3232
$opt, $rem, $err = getopt '-g','rem' 'g' ''
33-
$err | should be $null
34-
$opt.g | should be $true
35-
$rem | should not be $null
36-
$rem.length | should be 1
37-
$rem[0] | should be 'rem'
33+
$err | should -benullorempty
34+
$opt.g | should -betrue
35+
$rem | should -not -benullorempty
36+
$rem.length | should -be 1
37+
$rem[0] | should -be 'rem'
3838
}
3939

4040
it 'get a long flag and a short option with argument' {
4141
$a = "--global -a 32bit test" -split ' '
4242
$opt, $rem, $err = getopt $a 'ga:' 'global','arch='
4343

44-
$err | should be $null
45-
$opt.global | should be $true
46-
$opt.a | should be '32bit'
44+
$err | should -benullorempty
45+
$opt.global | should -betrue
46+
$opt.a | should -be '32bit'
4747
}
4848

4949
it 'handles regex characters' {
5050
$a = "-?"
51-
{ $opt, $rem, $err = getopt $a 'ga:' 'global' 'arch=' } | should not throw
52-
{ $null, $null, $null = getopt $a '?:' 'help' | should not throw }
51+
{ $opt, $rem, $err = getopt $a 'ga:' 'global' 'arch=' } | should -not -throw
52+
{ $null, $null, $null = getopt $a '?:' 'help' | should -not -throw }
5353
}
5454

5555
it 'handles short option without required argument' {
5656
$null, $null, $err = getopt '-x' 'x' ''
57-
$err | should be $null
57+
$err | should -benullorempty
5858
}
5959

6060
it 'handles long option without required argument' {
6161
$opt, $null, $err = getopt '--long-arg' '' 'long-arg'
62-
$err | should be $null
63-
$opt."long-arg" | should be $true
62+
$err | should -benullorempty
63+
$opt."long-arg" | should -betrue
6464
}
6565

6666
it 'handles long option with required argument' {
6767
$opt, $null, $err = getopt '--long-arg', 'test' '' 'long-arg='
68-
$err | should be $null
69-
$opt."long-arg" | should be "test"
68+
$err | should -benullorempty
69+
$opt."long-arg" | should -be "test"
7070
}
7171
}

test/Scoop-Linting.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Describe -Tag 'Linter' "PSScriptAnalyzer" {
77

88
Context "Checking ScriptAnalyzer" {
99
It "Invoke-ScriptAnalyzer Cmdlet should exist" {
10-
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw
10+
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | should -not -throw
1111
}
1212
It "PSScriptAnalyzerSettings.ps1 should exist" {
13-
Test-Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | Should Be $true
13+
Test-Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | should -betrue
1414
}
1515
It "There should be files to test" {
16-
$scoop_modules.Count | Should Not Be 0
16+
$scoop_modules.Count | should -not -be 0
1717
}
1818
}
1919

@@ -23,7 +23,7 @@ Describe -Tag 'Linter' "PSScriptAnalyzer" {
2323
foreach($directory in $scoop_modules) {
2424
$analysis = Invoke-ScriptAnalyzer -Path $directory.FullName -Settings $linting_settings.FullName
2525
It "Should pass: $directory" {
26-
$analysis.Count | Should Be 0
26+
$analysis.Count | should -be 0
2727
}
2828
if($analysis) {
2929
foreach($result in $analysis) {

test/Scoop-Manifest.Tests.ps1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@ describe -Tag 'Manifests' "manifest-validation" {
1212
}
1313

1414
it "Scoop.Validator is available" {
15-
([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | should be 'Scoop.Validator'
15+
([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | should -be 'Scoop.Validator'
1616
}
1717

1818
context "parse_json function" {
1919
it "fails with invalid json" {
20-
{ parse_json "$working_dir\broken_wget.json" } | should throw
20+
{ parse_json "$working_dir\broken_wget.json" } | should -throw
2121
}
2222
}
2323

2424
context "schema validation" {
2525
it "fails with broken schema" {
2626
$validator = new-object Scoop.Validator("$working_dir/broken_schema.json", $true)
27-
$validator.Validate("$working_dir/wget.json") | should be $false
28-
$validator.Errors.Count | should be 1
29-
$validator.Errors | select-object -First 1 | should match "broken_schema.*(line 6).*(position 4)"
27+
$validator.Validate("$working_dir/wget.json") | should -BeFalse
28+
$validator.Errors.Count | should -be 1
29+
$validator.Errors | select-object -First 1 | should -match "broken_schema.*(line 6).*(position 4)"
3030
}
3131
it "fails with broken manifest" {
3232
$validator = new-object Scoop.Validator($schema, $true)
33-
$validator.Validate("$working_dir/broken_wget.json") | should be $false
34-
$validator.Errors.Count | should be 1
35-
$validator.Errors | select-object -First 1 | should match "broken_wget.*(line 5).*(position 4)"
33+
$validator.Validate("$working_dir/broken_wget.json") | should -BeFalse
34+
$validator.Errors.Count | should -be 1
35+
$validator.Errors | select-object -First 1 | should -match "broken_wget.*(line 5).*(position 4)"
3636
}
3737
it "fails with invalid manifest" {
3838
$validator = new-object Scoop.Validator($schema, $true)
39-
$validator.Validate("$working_dir/invalid_wget.json") | should be $false
40-
$validator.Errors.Count | should be 16
41-
$validator.Errors | select-object -First 1 | should match "invalid_wget.*randomproperty.*properties\.$"
42-
$validator.Errors | select-object -Last 1 | should match "invalid_wget.*version\.$"
39+
$validator.Validate("$working_dir/invalid_wget.json") | should -BeFalse
40+
$validator.Errors.Count | should -be 16
41+
$validator.Errors | select-object -First 1 | should -match "invalid_wget.*randomproperty.*properties\.$"
42+
$validator.Errors | select-object -Last 1 | should -match "invalid_wget.*version\.$"
4343
}
4444
}
4545

@@ -74,7 +74,7 @@ describe -Tag 'Manifests' "manifest-validation" {
7474
if ($validator.Errors.Count -gt 0) {
7575
write-host -f yellow $validator.ErrorsAsString
7676
}
77-
$validator.Errors.Count | should be 0
77+
$validator.Errors.Count | should -be 0
7878
} catch {
7979
if($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {
8080
$quota_exceeded = $true
@@ -91,7 +91,7 @@ describe -Tag 'Manifests' "manifest-validation" {
9191
if(!$url) {
9292
$url = $url64
9393
}
94-
$url | should not benullorempty
94+
$url | should -not -benullorempty
9595
}
9696
}
9797
}

test/Scoop-Versions.Tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ describe "versions" -Tag 'Scoop' {
77
$b = '1.8.5-1'
88
$res = compare_versions $a $b
99

10-
$res | should be 1
10+
$res | should -be 1
1111
}
1212

1313
it 'handles plain string version comparison to int version' {
1414
$a = 'latest'
1515
$b = '20150405'
1616
$res = compare_versions $a $b
1717

18-
$res | should be 1
18+
$res | should -be 1
1919
}
2020

2121
it 'handles dashed version components' {
@@ -24,14 +24,14 @@ describe "versions" -Tag 'Scoop' {
2424

2525
$res = compare_versions $a $b
2626

27-
$res | should be -1
27+
$res | should -be -1
2828
}
2929

3030
it 'handles comparsion against en empty string' {
31-
compare_versions '7.0.4-9' '' | should be 1
31+
compare_versions '7.0.4-9' '' | should -be 1
3232
}
3333

3434
it 'handles equal versions' {
35-
compare_versions '12.0' '12.0' | should be 0
35+
compare_versions '12.0' '12.0' | should -be 0
3636
}
3737
}

0 commit comments

Comments
 (0)