Skip to content
Draft
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
4 changes: 2 additions & 2 deletions tst/Format2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ InPesterModuleScope {
} -ArgumentList (Get-Module Pester).Path, $TestDrive
$result = $job | Wait-Job -Timeout 10 | Receive-Job
$job | Remove-Job -Force
$result | Should -Not -BeNullOrEmpty
$result | Verify-NotNull
}

# Regression test for https://github.com/pester/Pester/issues/2828
Expand Down Expand Up @@ -354,7 +354,7 @@ InPesterModuleScope {
$result = Format-String2 -Value $value
# The result should not contain any of the original control characters
# (C0 0x00-0x1F, DEL 0x7F, or C1 0x80-0x9F).
$result | Should -Not -Match '[\x00-\x1F\x7F-\x9F]'
$result | Should-NotMatchString '[\x00-\x1F\x7F-\x9F]'
}
}
}
25 changes: 13 additions & 12 deletions tst/Help.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@ Describe "Testing module help" -Tag 'Help' -ForEach @{ exportedFunctions = $expo
}

It 'Help is found' {
$help.Name | Should -Be $_.Name
$help.Category | Should -Be $_.CommandType
$help.ModuleName | Should -Be $moduleName
$help.Name | Should-BeString $_.Name
$help.Category | Should-Be $_.CommandType
$help.ModuleName | Should-BeString $moduleName
}

It 'Synopsis is defined' {
$help.Synopsis | Should -Not -BeNullOrEmpty
$help.Synopsis | Should-NotBeEmptyString
# Syntax is used as synopsis when none is defined in help.
$help.Synopsis | Should -Not -Match "^\s*$($_.Name)((\s+\[+?-\w+)|$)"
$help.Synopsis | Should-NotMatchString "^\s*$($_.Name)((\s+\[+?-\w+)|$)"
}

It 'Description is defined' {
# Property is missing if undefined
$help.description | Should -Not -BeNullOrEmpty
$help.description | Should-NotBeNull
$help.description.Count | Should-BeGreaterThan 0
}

It 'Has link sections' {
$help.psobject.properties.name -match 'relatedLinks' | Should -Not -BeNullOrEmpty -Because 'all exported functions should at least have link to online version as first Uri'
$help.psobject.properties.name -match 'relatedLinks' | Should-NotBeNull -Because 'all exported functions should at least have link to online version as first Uri'

$functionName = $_.Name
$alias = Get-Alias -Name Should* | Where-Object { $_.Definition -eq $functionName }
$helpName = if ($alias) { $alias.Name } else { $help.Name }

$firstUri = $help.relatedLinks.navigationLink | Where-Object uri | Select-Object -First 1 -ExpandProperty uri
$firstUri | Should -Be "https://pester.dev/docs/commands/$helpName" -Because 'first uri-link should be to online version of this help topic'
$firstUri | Should-BeString "https://pester.dev/docs/commands/$helpName" -Because 'first uri-link should be to online version of this help topic'
}

It 'Has at least one example' {
$help.Examples | Should -Not -BeNullOrEmpty
$help.Examples.example | Where-Object { -not $_.Code.Trim() } | Foreach-Object { $_.title.Trim("- ") } | Should -Be @() -Because 'no examples should be empty'
$help.Examples | Should-NotBeNull
$help.Examples.example | Where-Object { -not $_.Code.Trim() } | Foreach-Object { $_.title.Trim("- ") } | Should-BeCollection @() -Because 'no examples should be empty'
}

It 'All static parameters have description' {
Expand All @@ -53,7 +54,7 @@ Describe "Testing module help" -Tag 'Help' -ForEach @{ exportedFunctions = $expo
Where-Object { $_.psobject.properties.name -notcontains 'description' } |
ForEach-Object name)

$parametersMissingHelp | Should -Be @()
$parametersMissingHelp | Should-BeCollection @()
}
else {
Set-ItResult -Skipped -Because 'no static parameters to test'
Expand All @@ -74,7 +75,7 @@ Describe "Testing module help" -Tag 'Help' -ForEach @{ exportedFunctions = $expo
$null -eq $attr -or $attr.HelpMessage -eq $null
} | ForEach-Object Name)

$parametersMissingHelp | Should -Be @() -Because "it it's required for Should's online docs"
$parametersMissingHelp | Should-BeCollection @() -Because "it it's required for Should's online docs"
}
}
}
62 changes: 31 additions & 31 deletions tst/Pester.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Describe -Tags 'VersionChecks' "Pester manifest and changelog" {
}

It "has a valid name in the manifest" {
$script:manifest.Name | Should -Be Pester
$script:manifest.Name | Should-BeString 'Pester'
}

It "has a valid guid in the manifest" {
$script:manifest.Guid | Should -Be 'a699dea5-2c73-4616-a270-1f7abb777e71'
$script:manifest.Guid | Should-BeString 'a699dea5-2c73-4616-a270-1f7abb777e71'
}

if ((Get-Command -Name git -ErrorAction SilentlyContinue) -and (Get-Item ".git" -ErrorAction Ignore)) {
Expand All @@ -39,12 +39,12 @@ Describe -Tags 'VersionChecks' "Pester manifest and changelog" {
$script:tagVersionShort, $script:tagPrerelease = $script:tagVersion -split "-", 2
}

$script:tagVersion | Should -Not -BeNullOrEmpty
$script:tagVersionShort -as [Version] | Should -Not -BeNullOrEmpty
$script:tagVersion | Should-NotBeNull
$script:tagVersionShort -as [Version] | Should-NotBeNull
}

It "has valid release notes in the manifest" {
$script:manifest.PrivateData.PSData.ReleaseNotes | Should -Be "https://github.com/pester/Pester/releases/tag/$script:tagVersion"
$script:manifest.PrivateData.PSData.ReleaseNotes | Should-BeString "https://github.com/pester/Pester/releases/tag/$script:tagVersion"
}

It "tag and changelog versions are the same" {
Expand All @@ -57,25 +57,25 @@ Describe -Tags 'VersionChecks' "Pester manifest and changelog" {
}
}

$script:changelogVersion | Should -Be $script:tagVersion
$script:changelogVersionShort | Should -Be $script:tagVersionShort
$script:changelogVersion | Should-Be $script:tagVersion
$script:changelogVersionShort | Should-Be $script:tagVersionShort
}

It "tag and changelog versions are the same" {
$script:changelogVersion | Should -Be $script:tagVersion
$script:changelogVersion | Should-Be $script:tagVersion
}

It "all short versions are the same" {
$script:changelogVersionShort -as [Version] | Should -Be ( $script:manifest.Version -as [Version] )
$script:manifest.Version -as [Version] | Should -Be ( $script:tagVersionShort -as [Version] )
$script:changelogVersionShort -as [Version] | Should-Be ( $script:manifest.Version -as [Version] )
$script:manifest.Version -as [Version] | Should-Be ( $script:tagVersionShort -as [Version] )
}
}
}

It "has valid pre-release suffix in manifest (empty for stable version)" {
# might be empty or null, as well as the tagPrerelase. we need empty string to eq $null but not to eq any other value
$prereleaseFromManifest = $script:manifest.PrivateData.PSData.Prerelease | where { $_ }
$prereleaseFromManifest | Should -Be $script:tagPrerelease
$prereleaseFromManifest | Should-Be $script:tagPrerelease
}
}

Expand All @@ -86,12 +86,12 @@ if ($PSVersionTable.PSVersion.Major -ge 3) {
}
Context 'A Context' {
It 'Performs a successful test' {
$true | Should -Be $true
$true | Should-BeTrue
}
}

It 'Did not add anything to the $error variable' {
$error.Count | Should -Be 0
$error.Count | Should-Be 0
}
}

Expand Down Expand Up @@ -127,7 +127,7 @@ if ($PSVersionTable.PSVersion.Major -ge 3) {
}

It 'The SafeCommands table contains all commands that are called from the module' {
$missingSafeCommands | Should -Be $null
$missingSafeCommands | Should-BeNull
}
}
}
Expand All @@ -139,7 +139,7 @@ Describe 'Public API' {
? { $_.CommandType -ne 'Alias' } | # Get-Command outputs aliases in PowerShell 2
? { -not $_.CmdletBinding } |
% { $_.Name }
$r | Should -beNullOrEmpty
$r | Should-BeCollection @()
}
}

Expand Down Expand Up @@ -237,34 +237,34 @@ InPesterModuleScope {

It 'Resolves non-wildcarded file paths regardless of whether the file ends with Tests.ps1' {
$result = @(Find-File 'TestDrive:\SomeOtherFile.ps1' -Extension ".Tests.ps1")
$result.Count | Should -Be 1
$result[0].UnresolvedPath | Should -Be 'TestDrive:\SomeOtherFile.ps1'
$result.Count | Should-Be 1
$result[0].UnresolvedPath | Should-BeString 'TestDrive:\SomeOtherFile.ps1'
}

It 'Finds only *.Tests.ps1 files when the path contains wildcards' {
$result = @(Find-File 'TestDrive:\*.ps1' -Extension ".Tests.ps1")
$result.Count | Should -Be 2
$result.Count | Should-Be 2

$paths = $result | Select-Object -ExpandProperty FullName
$testDrive = (Get-PSDrive TestDrive).Root
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should-BeTrue
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should-BeTrue
}

It 'Finds only *.Tests.ps1 files when the path refers to a directory and does not contain wildcards' {
$result = @(Find-File 'TestDrive:\' -Extension ".Tests.ps1")

$result.Count | Should -Be 2
$result.Count | Should-Be 2

$paths = $result | Select-Object -ExpandProperty FullName
$testDrive = (Get-PSDrive TestDrive).Root
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should-BeTrue
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should-BeTrue
}

It 'Deduplicates filepaths when the provided paths overlaps' {
$result = @(Find-File 'TestDrive:\*.ps1','TestDrive:\*.ps1' -Extension '.Tests.ps1')
$result.Count | Should -Be 2
$result.Count | Should-Be 2
}

Context 'Hidden folders and VCS metadata' {
Expand Down Expand Up @@ -306,21 +306,21 @@ InPesterModuleScope {

It 'discovers test files inside dot-prefixed (hidden) folders' {
$names = @(Find-File -Path 'TestDrive:\' -Extension '.Tests.ps1' | Select-Object -ExpandProperty Name)
$names | Should -Contain 'InHidden.Tests.ps1'
$names | Should-ContainCollection 'InHidden.Tests.ps1'
}

It 'discovers test files in nested hidden folders' {
$names = @(Find-File -Path 'TestDrive:\' -Extension '.Tests.ps1' | Select-Object -ExpandProperty Name)
$names | Should -Contain 'NestedHidden.Tests.ps1'
$names | Should-ContainCollection 'NestedHidden.Tests.ps1'
}

It 'does not descend into .git directories' {
# Both files live under .git at different depths; neither should
# appear in the result, proving the walker stops at .git without
# opening its contents.
$names = @(Find-File -Path 'TestDrive:\' -Extension '.Tests.ps1' | Select-Object -ExpandProperty Name)
$names | Should -Not -Contain 'HeadLevel.Tests.ps1'
$names | Should -Not -Contain 'DeepInGit.Tests.ps1'
$names | Should-NotContainCollection 'HeadLevel.Tests.ps1'
$names | Should-NotContainCollection 'DeepInGit.Tests.ps1'
}

It 'returns the same set as Get-ChildItem -Recurse -Force minus VCS folders' {
Expand All @@ -331,7 +331,7 @@ InPesterModuleScope {
Select-Object -ExpandProperty FullName |
Sort-Object
)
$found | Should -Be $expected
$found | Should-BeCollection $expected
}
}

Expand Down Expand Up @@ -476,7 +476,7 @@ InModuleScope -ModuleName Pester {
@{ Filter = "*Unit*"; Collection = "Low", "Medium", "High" }
) {
Contain-AnyStringLike -Filter $Filter -Collection $Collection |
Should -BeFalse
Should-BeFalse
}

It 'Given a filter <filter> that matches one or more items in collection <collection> it returns $true' -TestCases @(
Expand All @@ -488,7 +488,7 @@ InModuleScope -ModuleName Pester {
@{ Filter = "l*"; Collection = "Low", "Medium", "High" }
) {
Contain-AnyStringLike -Filter $Filter -Collection $Collection |
Should -BeTrue
Should-BeTrue
}
}
}
26 changes: 13 additions & 13 deletions tst/PesterConfiguration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ Describe "PesterConfiguration.Format.ps1xml" {
$options = @($section.GetProperties() | Where-Object { $_.PropertyType.IsSubclassOf([Pester.Option]) })
}
It 'Has a single view defined of type ListControl' {
$formatData | Should -Not -BeNullOrEmpty
$formatData.FormatViewDefinition.Count | Should -Be 1
$formatData.FormatViewDefinition[0].Name | Should -BeExactly $section.FullName
$formatData.FormatViewDefinition[0].Control | Should -BeOfType ([System.Management.Automation.ListControl])
$formatData | Should-NotBeNull
$formatData.FormatViewDefinition.Count | Should-Be 1
$formatData.FormatViewDefinition[0].Name | Should-BeString $section.FullName -CaseSensitive
$formatData.FormatViewDefinition[0].Control | Should-HaveType ([System.Management.Automation.ListControl])
}

It 'View includes all options' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Entries.Items.DisplayEntry | Where-Object ValueType -eq 'Property')
$propertiesInView.Count | Should -Be $options.Count
$propertiesInView.Count | Should-Be $options.Count
$missingOptions = $options.Name | Where-Object { $propertiesInView.Value -notcontains $_ }
$missingOptions | Should -Be @()
$missingOptions | Should-BeCollection @()
}
}

Expand All @@ -32,22 +32,22 @@ Describe "PesterConfiguration.Format.ps1xml" {
$options = [Pester.Option[bool]].GetProperties() | Where-Object Name -notin 'IsModified'
}
It 'Has a single view defined of type TableControl' {
$formatData | Should -Not -BeNullOrEmpty
$formatData.FormatViewDefinition.Count | Should -Be 1
$formatData.FormatViewDefinition[0].Name | Should -BeExactly 'Pester.Option'
$formatData.FormatViewDefinition[0].Control | Should -BeOfType ([System.Management.Automation.TableControl])
$formatData | Should-NotBeNull
$formatData.FormatViewDefinition.Count | Should-Be 1
$formatData.FormatViewDefinition[0].Name | Should-BeString 'Pester.Option' -CaseSensitive
$formatData.FormatViewDefinition[0].Control | Should-HaveType ([System.Management.Automation.TableControl])
}

It 'View includes all options' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Rows.Columns.DisplayEntry | Where-Object ValueType -EQ 'Property')
$propertiesInView.Count | Should -Be $options.Count
$propertiesInView.Count | Should-Be $options.Count
$missingOptions = $options.Name | Where-Object { $propertiesInView.Value -notcontains $_ }
$missingOptions | Should -Be @()
$missingOptions | Should-BeCollection @()
}

It 'View does not include IsModified' {
$propertiesInView = @($formatData.FormatViewDefinition[0].Control.Rows.Columns.DisplayEntry | Where-Object ValueType -EQ 'Property')
$propertiesInView.Value | Should -Not -Contain 'IsModified'
$propertiesInView.Value | Should-NotContainCollection 'IsModified'
}
}
}
6 changes: 3 additions & 3 deletions tst/functions/Context.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Describe 'Testing Context' {

}
}
} | Should -Throw 'Test fixture name has multiple lines and no test fixture is provided. (Have you provided a name for the test group?)'
} | Should-Throw -ExceptionMessage 'Test fixture name has multiple lines and no test fixture is provided. (Have you provided a name for the test group?)'
}

It "Has a name that looks like a script block" {
Expand All @@ -17,11 +17,11 @@ Describe 'Testing Context' {

}
}
} | Should -Throw 'No test fixture is provided. (Have you put the open curly brace on the next line?)'
} | Should-Throw -ExceptionMessage 'No test fixture is provided. (Have you put the open curly brace on the next line?)'
}

It 'Throws when provided unbound scriptblock' {
# Unbound scriptblocks would execute in Pester's internal module state
{ Context 'c' -Fixture ([scriptblock]::Create('')) } | Should -Throw -ExpectedMessage 'Unbound scriptblock*'
{ Context 'c' -Fixture ([scriptblock]::Create('')) } | Should-Throw -ExceptionMessage 'Unbound scriptblock*'
}
}
Loading
Loading