Skip to content
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased
- Add-AssertionOperator can be called multiple times for identical parameters without errors. [GH-893]
- Syntax for the Should operator updated in Pester tests itself, an about_* documentation, examples
due to the prefered syntax change introduced in Pester v4 [GH-903]
- Support for PowerShell Core on Windows, Linux and macOS added [GH-639]

## 4.0.8 (September 15, 2017)
Expand Down
10 changes: 5 additions & 5 deletions Examples/Calculator/Add-Numbers.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ $here = Split-Path -Parent $MyInvocation.MyCommand.Path
Describe -Tags "Example" "Add-Numbers" {

It "adds positive numbers" {
Add-Numbers 2 3 | Should Be 5
Add-Numbers 2 3 | Should -Be 5
}

It "adds negative numbers" {
Add-Numbers (-2) (-2) | Should Be (-4)
Add-Numbers (-2) (-2) | Should -Be (-4)
}

It "adds one negative number to positive number" {
Add-Numbers (-2) 2 | Should Be 0
Add-Numbers (-2) 2 | Should -Be 0
}

It "concatenates strings if given strings" {
Add-Numbers two three | Should Be "twothree"
Add-Numbers two three | Should -Be "twothree"
}

It "should not be 0" {
Add-Numbers 2 3 | Should Not Be 0
Add-Numbers 2 3 | Should -Not -Be 0
}
}

8 changes: 4 additions & 4 deletions Examples/Gherkin/VariableScope.Steps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Then 'the variable ([\w:]+) should be "([^"]+)"' {
"Two" { $Two }
"Script:Two" { $Script:Two }
}
$Result | Should Be $Value
$Result | Should -Be $Value
}

Then "the variable ([\w:]+) should not exist" {
Expand All @@ -39,13 +39,13 @@ Then "the variable ([\w:]+) should not exist" {
switch($Name)
{
"One" {
Test-Path Variable:One | Should Be $False
Test-Path Variable:One | Should -Be $False
}
"Two" {
Test-Path Variable:Two | Should Be $False
Test-Path Variable:Two | Should -Be $False
}
"Script:Two" {
Test-Path Variable:Script:Two | Should Be $False
Test-Path Variable:Script:Two | Should -Be $False
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/Validator/Validator.Steps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ When 'MyValidator is called with (?<word>\w+)' {
Then 'MyValidator should return (?<expected>\w+)' {
param($expected)
$expected = $expected -eq "true"
$Validation | Should Be $expected
$Validation | Should -Be $expected
}
4 changes: 2 additions & 2 deletions Examples/Validator/Validator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Describe "MyValidator" {

It "passes things that start with the letter S" {
$result = MyValidator "summer"
$result | Should Be $true
$result | Should -Be $true
}

It "does not pass a param that does not start with S" {
$result = MyValidator "bummer"
$result | Should Be $false
$result | Should -Be $false
}
}

4 changes: 2 additions & 2 deletions Functions/Assertions/Be.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ InModuleScope Pester {
It 'Does not overflow on IEnumerable' {
# see https://github.com/pester/Pester/issues/785
$doc = [xml]'<?xml version="1.0" encoding="UTF-8" standalone="no" ?><root></root>'
$doc | Should be $doc
$doc | Should -be $doc
}

# The test excluded on macOS due to issue https://github.com/PowerShell/PowerShell/issues/4268
Expand All @@ -98,7 +98,7 @@ InModuleScope Pester {
$a2 = @($a1,2)
$a1[0] = $a2

{ $a1 | Should be $a2 } | Should throw 'recursion depth limit'
{ $a1 | Should -be $a2 } | Should -throw 'recursion depth limit'
}
}

Expand Down
4 changes: 2 additions & 2 deletions Functions/Assertions/BeLike.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ InModuleScope Pester {
}

It "returns false for things that do not match" {
{ "foobar" | Should BeLike "oob" } | Should Throw
{ "foobar" | Should -BeLike "oob" } | Should -Throw
}

It "passes for strings with different case" {
"foobar" | Should BeLike "FOOBAR"
"foobar" | Should -BeLike "FOOBAR"
}
}
}
4 changes: 2 additions & 2 deletions Functions/Assertions/PesterThrow.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ InModuleScope Pester {
$e = $_
}

$e | Should Not Be $null
$e.Exception | Should BeOfType ArgumentException
$e | Should -Not -Be $null
$e.Exception | Should -BeOfType ArgumentException
}
}

Expand Down
80 changes: 40 additions & 40 deletions Functions/Coverage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,38 @@ InModuleScope Pester {
Enter-CoverageAnalysis -CodeCoverage "$(Join-Path -Path $root -ChildPath TestScript.ps1)", "$(Join-Path -Path $root -ChildPath TestScript.ps1)" -PesterState $testState

It 'Has the proper number of breakpoints defined' {
$testState.CommandCoverage.Count | Should Be 7
$testState.CommandCoverage.Count | Should -Be 7
}

$null = & "$(Join-Path -Path $root -ChildPath TestScript.ps1)"
$coverageReport = Get-CoverageReport -PesterState $testState

It 'Reports the proper number of executed commands' {
$coverageReport.NumberOfCommandsExecuted | Should Be 6
$coverageReport.NumberOfCommandsExecuted | Should -Be 6
}

It 'Reports the proper number of analyzed commands' {
$coverageReport.NumberOfCommandsAnalyzed | Should Be 7
$coverageReport.NumberOfCommandsAnalyzed | Should -Be 7
}

It 'Reports the proper number of analyzed files' {
$coverageReport.NumberOfFilesAnalyzed | Should Be 1
$coverageReport.NumberOfFilesAnalyzed | Should -Be 1
}

It 'Reports the proper number of missed commands' {
$coverageReport.MissedCommands.Count | Should Be 1
$coverageReport.MissedCommands.Count | Should -Be 1
}

It 'Reports the correct missed command' {
$coverageReport.MissedCommands[0].Command | Should Be "'I am function two. I never get called.'"
$coverageReport.MissedCommands[0].Command | Should -Be "'I am function two. I never get called.'"
}

It 'Reports the proper number of hit commands' {
$coverageReport.HitCommands.Count | Should Be 6
$coverageReport.HitCommands.Count | Should -Be 6
}

It 'Reports the correct hit command' {
$coverageReport.HitCommands[0].Command | Should Be "'I am the nested function.'"
$coverageReport.HitCommands[0].Command | Should -Be "'I am the nested function.'"
}

It 'JaCoCo report must be correct'{
Expand All @@ -80,7 +80,7 @@ InModuleScope Pester {
$jaCoCoReportXml = $jaCoCoReportXml -replace 'start="[0-9]*"','start=""'
$jaCoCoReportXml = $jaCoCoReportXml -replace 'dump="[0-9]*"','dump=""'
$jaCoCoReportXml = $jaCoCoReportXml -replace "$([System.Environment]::NewLine)",''
$jaCoCoReportXml | should be '<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd"><report name="Pester (date)"><sessioninfo id="this" start="" dump="" /><counter type="INSTRUCTION" missed="1" covered="6" /><counter type="LINE" missed="1" covered="6" /><counter type="METHOD" missed="1" covered="3" /><counter type="CLASS" missed="0" covered="1" /></report>'
$jaCoCoReportXml | should -be '<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd"><report name="Pester (date)"><sessioninfo id="this" start="" dump="" /><counter type="INSTRUCTION" missed="1" covered="6" /><counter type="LINE" missed="1" covered="6" /><counter type="METHOD" missed="1" covered="3" /><counter type="CLASS" missed="0" covered="1" /></report>'
}
Exit-CoverageAnalysis -PesterState $testState
}
Expand All @@ -91,30 +91,30 @@ InModuleScope Pester {
Enter-CoverageAnalysis -CodeCoverage @{Path = "$(Join-Path -Path $root -ChildPath TestScript.ps1)"; Function = 'FunctionTwo'} -PesterState $testState

It 'Has the proper number of breakpoints defined' {
$testState.CommandCoverage.Count | Should Be 1
$testState.CommandCoverage.Count | Should -Be 1
}

$null = & "$(Join-Path -Path $root -ChildPath TestScript.ps1)"
$coverageReport = Get-CoverageReport -PesterState $testState

It 'Reports the proper number of executed commands' {
$coverageReport.NumberOfCommandsExecuted | Should Be 0
$coverageReport.NumberOfCommandsExecuted | Should -Be 0
}

It 'Reports the proper number of analyzed commands' {
$coverageReport.NumberOfCommandsAnalyzed | Should Be 1
$coverageReport.NumberOfCommandsAnalyzed | Should -Be 1
}

It 'Reports the proper number of missed commands' {
$coverageReport.MissedCommands.Count | Should Be 1
$coverageReport.MissedCommands.Count | Should -Be 1
}

It 'Reports the correct missed command' {
$coverageReport.MissedCommands[0].Command | Should Be "'I am function two. I never get called.'"
$coverageReport.MissedCommands[0].Command | Should -Be "'I am function two. I never get called.'"
}

It 'Reports the proper number of hit commands' {
$coverageReport.HitCommands.Count | Should Be 0
$coverageReport.HitCommands.Count | Should -Be 0
}

Exit-CoverageAnalysis -PesterState $testState
Expand All @@ -126,30 +126,30 @@ InModuleScope Pester {
Enter-CoverageAnalysis -CodeCoverage @{Path = "$(Join-Path -Path $root -ChildPath TestScript.ps1)"; Function = 'FunctionOne'} -PesterState $testState

It 'Has the proper number of breakpoints defined' {
$testState.CommandCoverage.Count | Should Be 5
$testState.CommandCoverage.Count | Should -Be 5
}

$null = & "$(Join-Path -Path $root -ChildPath TestScript.ps1)"
$coverageReport = Get-CoverageReport -PesterState $testState

It 'Reports the proper number of executed commands' {
$coverageReport.NumberOfCommandsExecuted | Should Be 5
$coverageReport.NumberOfCommandsExecuted | Should -Be 5
}

It 'Reports the proper number of analyzed commands' {
$coverageReport.NumberOfCommandsAnalyzed | Should Be 5
$coverageReport.NumberOfCommandsAnalyzed | Should -Be 5
}

It 'Reports the proper number of missed commands' {
$coverageReport.MissedCommands.Count | Should Be 0
$coverageReport.MissedCommands.Count | Should -Be 0
}

It 'Reports the proper number of hit commands' {
$coverageReport.HitCommands.Count | Should Be 5
$coverageReport.HitCommands.Count | Should -Be 5
}

It 'Reports the correct hit command' {
$coverageReport.HitCommands[0].Command | Should Be "'I am the nested function.'"
$coverageReport.HitCommands[0].Command | Should -Be "'I am the nested function.'"
}

Exit-CoverageAnalysis -PesterState $testState
Expand All @@ -161,30 +161,30 @@ InModuleScope Pester {
Enter-CoverageAnalysis -CodeCoverage @{Path = "$(Join-Path -Path $root -ChildPath TestScript.ps1)"; StartLine = 11; EndLine = 12 } -PesterState $testState

It 'Has the proper number of breakpoints defined' {
$testState.CommandCoverage.Count | Should Be 2
$testState.CommandCoverage.Count | Should -Be 2
}

$null = & "$(Join-Path -Path $root -ChildPath TestScript.ps1)"
$coverageReport = Get-CoverageReport -PesterState $testState

It 'Reports the proper number of executed commands' {
$coverageReport.NumberOfCommandsExecuted | Should Be 2
$coverageReport.NumberOfCommandsExecuted | Should -Be 2
}

It 'Reports the proper number of analyzed commands' {
$coverageReport.NumberOfCommandsAnalyzed | Should Be 2
$coverageReport.NumberOfCommandsAnalyzed | Should -Be 2
}

It 'Reports the proper number of missed commands' {
$coverageReport.MissedCommands.Count | Should Be 0
$coverageReport.MissedCommands.Count | Should -Be 0
}

It 'Reports the proper number of hit commands' {
$coverageReport.HitCommands.Count | Should Be 2
$coverageReport.HitCommands.Count | Should -Be 2
}

It 'Reports the correct hit command' {
$coverageReport.HitCommands[0].Command | Should Be "'I am functionOne'"
$coverageReport.HitCommands[0].Command | Should -Be "'I am functionOne'"
}

Exit-CoverageAnalysis -PesterState $testState
Expand All @@ -196,38 +196,38 @@ InModuleScope Pester {
Enter-CoverageAnalysis -CodeCoverage @{Path = "$(Join-Path -Path $root -ChildPath *.ps1)"; Function = '*' } -PesterState $testState

It 'Has the proper number of breakpoints defined' {
$testState.CommandCoverage.Count | Should Be 6
$testState.CommandCoverage.Count | Should -Be 6
}

$null = & "$(Join-Path -Path $root -ChildPath TestScript.ps1)"
$coverageReport = Get-CoverageReport -PesterState $testState

It 'Reports the proper number of executed commands' {
$coverageReport.NumberOfCommandsExecuted | Should Be 5
$coverageReport.NumberOfCommandsExecuted | Should -Be 5
}

It 'Reports the proper number of analyzed commands' {
$coverageReport.NumberOfCommandsAnalyzed | Should Be 6
$coverageReport.NumberOfCommandsAnalyzed | Should -Be 6
}

It 'Reports the proper number of analyzed files' {
$coverageReport.NumberOfFilesAnalyzed | Should Be 1
$coverageReport.NumberOfFilesAnalyzed | Should -Be 1
}

It 'Reports the proper number of missed commands' {
$coverageReport.MissedCommands.Count | Should Be 1
$coverageReport.MissedCommands.Count | Should -Be 1
}

It 'Reports the correct missed command' {
$coverageReport.MissedCommands[0].Command | Should Be "'I am function two. I never get called.'"
$coverageReport.MissedCommands[0].Command | Should -Be "'I am function two. I never get called.'"
}

It 'Reports the proper number of hit commands' {
$coverageReport.HitCommands.Count | Should Be 5
$coverageReport.HitCommands.Count | Should -Be 5
}

It 'Reports the correct hit command' {
$coverageReport.HitCommands[0].Command | Should Be "'I am the nested function.'"
$coverageReport.HitCommands[0].Command | Should -Be "'I am the nested function.'"
}

Exit-CoverageAnalysis -PesterState $testState
Expand Down Expand Up @@ -266,14 +266,14 @@ InModuleScope Pester {


It 'Identifies the correct parent path' {
$commonPath | Should Be $expectedCommonPath
$commonPath | Should -Be $expectedCommonPath
}

$expectedRelativePath = Normalize-Path 'UniqueSubfolder1/File.ps1'
$relativePath = Get-RelativePath -Path $paths[0] -RelativeTo $commonPath

It 'Strips the common path correctly' {
$relativePath | Should Be $expectedRelativePath
$relativePath | Should -Be $expectedRelativePath
}
}

Expand Down Expand Up @@ -322,7 +322,7 @@ InModuleScope Pester {
It 'Has the proper number of breakpoints defined' {
if($runsInPowerShell4) { $expected = 7 } else { $expected = 8 }

$testState.CommandCoverage.Count | Should Be $expected
$testState.CommandCoverage.Count | Should -Be $expected
}

$null = . "$root\TestScriptWithConfiguration.ps1"
Expand All @@ -331,7 +331,7 @@ InModuleScope Pester {
It 'Reports the proper number of missed commands before running the configuration' {
if($runsInPowerShell4) { $expected = 4 } else { $expected = 5 }

$coverageReport.MissedCommands.Count | Should Be $expected
$coverageReport.MissedCommands.Count | Should -Be $expected
}

MyTestConfig -OutputPath $root
Expand All @@ -340,7 +340,7 @@ InModuleScope Pester {
It 'Reports the proper number of missed commands after running the configuration' {
if($runsInPowerShell4) { $expected = 2 } else { $expected = 3 }

$coverageReport.MissedCommands.Count | Should Be $expected
$coverageReport.MissedCommands.Count | Should -Be $expected
}

Exit-CoverageAnalysis -PesterState $testState
Expand Down
Loading