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

add Pester 4.0 syntax to multiple files #2714

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
add Pester 4.0 syntax to multiple files
  • Loading branch information
KevinMarquette committed Oct 28, 2018
commit 4936059b3e9bd3ce7ac6706d12365a1add304670
12 changes: 6 additions & 6 deletions test/Scoop-Alias.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ describe "add_alias" -Tag 'Scoop' {
context "alias doesn't exist" {
it "creates a new alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
$alias_file | should not exist
$alias_file | should -not -exist

add_alias "rm" '"hello, world!"'
Invoke-Expression $alias_file | should be "hello, world!"
Invoke-Expression $alias_file | should -be "hello, world!"
}
}

context "alias exists" {
it "does not change existing alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
new-item $alias_file -type file
$alias_file | should exist
$alias_file | should -exist

add_alias "rm" "test"
$alias_file | should FileContentMatch ""
$alias_file | should -FileContentMatch ""
}
}
}
Expand All @@ -45,11 +45,11 @@ describe "rm_alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias "rm" '"hello, world!"'

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

rm_alias "rm"
$alias_file | should not exist
$alias_file | should -not -exist
}
}
}
16 changes: 8 additions & 8 deletions test/Scoop-Config.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ describe "hashtable" -Tag 'Scoop' {
$obj = convertfrom-json $json
$ht = hashtable $obj

$ht.one | should beexactly 1
$ht.two[0].a | should be "a"
$ht.two[1] | should be "b"
$ht.two[2] | should beexactly 2
$ht.three.four | should beexactly 4
$ht.five | should beexactly $true
$ht.six | should beexactly $false
[System.DateTime]::Equals($ht.seven, $(New-Object System.DateTime (2018, 06, 25, 09, 03, 15, 805))) | should be $true
$ht.one | should -beexactly 1
$ht.two[0].a | should -be "a"
$ht.two[1] | should -be "b"
$ht.two[2] | should -beexactly 2
$ht.three.four | should -beexactly 4
$ht.five | should -beexactly $true
$ht.six | should -beexactly $false
[System.DateTime]::Equals($ht.seven, $(New-Object System.DateTime (2018, 06, 25, 09, 03, 15, 805))) | should -betrue
}
}
42 changes: 21 additions & 21 deletions test/Scoop-GetOpts.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,68 @@
describe "getopt" -Tag 'Scoop' {
it 'handle short option with required argument missing' {
$null, $null, $err = getopt '-x' 'x:' ''
$err | should be 'Option -x requires an argument.'
$err | should -be 'Option -x requires an argument.'

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

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

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

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

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

it 'remaining args returned' {
$opt, $rem, $err = getopt '-g','rem' 'g' ''
$err | should be $null
$opt.g | should be $true
$rem | should not be $null
$rem.length | should be 1
$rem[0] | should be 'rem'
$err | should -benullorempty
$opt.g | should -betrue
$rem | should -not -benullorempty
$rem.length | should -be 1
$rem[0] | should -be 'rem'
}

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

$err | should be $null
$opt.global | should be $true
$opt.a | should be '32bit'
$err | should -benullorempty
$opt.global | should -betrue
$opt.a | should -be '32bit'
}

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

it 'handles short option without required argument' {
$null, $null, $err = getopt '-x' 'x' ''
$err | should be $null
$err | should -benullorempty
}

it 'handles long option without required argument' {
$opt, $null, $err = getopt '--long-arg' '' 'long-arg'
$err | should be $null
$opt."long-arg" | should be $true
$err | should -benullorempty
$opt."long-arg" | should -betrue
}

it 'handles long option with required argument' {
$opt, $null, $err = getopt '--long-arg', 'test' '' 'long-arg='
$err | should be $null
$opt."long-arg" | should be "test"
$err | should -benullorempty
$opt."long-arg" | should -be "test"
}
}
8 changes: 4 additions & 4 deletions test/Scoop-Linting.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Describe -Tag 'Linter' "PSScriptAnalyzer" {

Context "Checking ScriptAnalyzer" {
It "Invoke-ScriptAnalyzer Cmdlet should exist" {
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | should -not -throw
}
It "PSScriptAnalyzerSettings.ps1 should exist" {
Test-Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | Should Be $true
Test-Path "$repo_dir\PSScriptAnalyzerSettings.psd1" | should -betrue
}
It "There should be files to test" {
$scoop_modules.Count | Should Not Be 0
$scoop_modules.Count | should -not -be 0
}
}

Expand All @@ -23,7 +23,7 @@ Describe -Tag 'Linter' "PSScriptAnalyzer" {
foreach($directory in $scoop_modules) {
$analysis = Invoke-ScriptAnalyzer -Path $directory.FullName -Settings $linting_settings.FullName
It "Should pass: $directory" {
$analysis.Count | Should Be 0
$analysis.Count | should -be 0
}
if($analysis) {
foreach($result in $analysis) {
Expand Down
28 changes: 14 additions & 14 deletions test/Scoop-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ describe -Tag 'Manifests' "manifest-validation" {
}

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

context "parse_json function" {
it "fails with invalid json" {
{ parse_json "$working_dir\broken_wget.json" } | should throw
{ parse_json "$working_dir\broken_wget.json" } | should -throw
}
}

context "schema validation" {
it "fails with broken schema" {
$validator = new-object Scoop.Validator("$working_dir/broken_schema.json", $true)
$validator.Validate("$working_dir/wget.json") | should be $false
$validator.Errors.Count | should be 1
$validator.Errors | select-object -First 1 | should match "broken_schema.*(line 6).*(position 4)"
$validator.Validate("$working_dir/wget.json") | should -BeFalse
$validator.Errors.Count | should -be 1
$validator.Errors | select-object -First 1 | should -match "broken_schema.*(line 6).*(position 4)"
}
it "fails with broken manifest" {
$validator = new-object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/broken_wget.json") | should be $false
$validator.Errors.Count | should be 1
$validator.Errors | select-object -First 1 | should match "broken_wget.*(line 5).*(position 4)"
$validator.Validate("$working_dir/broken_wget.json") | should -BeFalse
$validator.Errors.Count | should -be 1
$validator.Errors | select-object -First 1 | should -match "broken_wget.*(line 5).*(position 4)"
}
it "fails with invalid manifest" {
$validator = new-object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/invalid_wget.json") | should be $false
$validator.Errors.Count | should be 16
$validator.Errors | select-object -First 1 | should match "invalid_wget.*randomproperty.*properties\.$"
$validator.Errors | select-object -Last 1 | should match "invalid_wget.*version\.$"
$validator.Validate("$working_dir/invalid_wget.json") | should -BeFalse
$validator.Errors.Count | should -be 16
$validator.Errors | select-object -First 1 | should -match "invalid_wget.*randomproperty.*properties\.$"
$validator.Errors | select-object -Last 1 | should -match "invalid_wget.*version\.$"
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ describe -Tag 'Manifests' "manifest-validation" {
if ($validator.Errors.Count -gt 0) {
write-host -f yellow $validator.ErrorsAsString
}
$validator.Errors.Count | should be 0
$validator.Errors.Count | should -be 0
} catch {
if($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {
$quota_exceeded = $true
Expand All @@ -91,7 +91,7 @@ describe -Tag 'Manifests' "manifest-validation" {
if(!$url) {
$url = $url64
}
$url | should not benullorempty
$url | should -not -benullorempty
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/Scoop-Versions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ describe "versions" -Tag 'Scoop' {
$b = '1.8.5-1'
$res = compare_versions $a $b

$res | should be 1
$res | should -be 1
}

it 'handles plain string version comparison to int version' {
$a = 'latest'
$b = '20150405'
$res = compare_versions $a $b

$res | should be 1
$res | should -be 1
}

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

$res = compare_versions $a $b

$res | should be -1
$res | should -be -1
}

it 'handles comparsion against en empty string' {
compare_versions '7.0.4-9' '' | should be 1
compare_versions '7.0.4-9' '' | should -be 1
}

it 'handles equal versions' {
compare_versions '12.0' '12.0' | should be 0
compare_versions '12.0' '12.0' | should -be 0
}
}