Skip to content

Update examples-module to use Pester 5 #3214

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

Merged
merged 1 commit into from
Mar 1, 2021
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
67 changes: 35 additions & 32 deletions examples/Tests/PathProcessing.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,102 +8,105 @@
# test task runner defined in .vscode\tasks.json.

# This (empty) file is required by some of the tests.
$null = New-Item -Path "$PSScriptRoot\foo[1].txt" -Force

Import-Module $PSScriptRoot\..\SampleModule.psd1
BeforeAll {
$null = New-Item -Path "$PSScriptRoot\foo[1].txt" -Force

$WorkspaceRoot = Convert-Path $PSScriptRoot/..
Set-Location $WorkspaceRoot
Import-Module $PSScriptRoot\..\SampleModule.psd1

$WorkspaceRoot = Convert-Path $PSScriptRoot/..
Set-Location $WorkspaceRoot
}

Describe 'Verify Path Processing for Non-existing Paths Allowed Impl' {
It 'Processes non-wildcard absolute path to non-existing file via -Path param' {
New-File -Path $WorkspaceRoot\ReadmeNew.md | Should Be "$WorkspaceRoot\READMENew.md"
New-File -Path $WorkspaceRoot\ReadmeNew.md | Should -Be "$WorkspaceRoot\READMENew.md"
}
It 'Processes multiple absolute paths via -Path param' {
New-File -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\XYZZY.ps1 |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
}
It 'Processes relative path via -Path param' {
New-File -Path ..\Examples\READMENew.md | Should Be "$WorkspaceRoot\READMENew.md"
New-File -Path ..\Examples\READMENew.md | Should -Be "$WorkspaceRoot\READMENew.md"
}
It 'Processes multiple relative path via -Path param' {
New-File -Path ..\Examples\README.md, XYZZY.ps1 |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\XYZZY.ps1")
}

It 'Should accept pipeline input to Path' {
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | New-File | Should Be "$PSScriptRoot\foo[1].txt"
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | New-File | Should -Be "$PSScriptRoot\foo[1].txt"
}
}

Describe 'Verify Path Processing for NO Wildcards Allowed Impl' {
It 'Processes non-wildcard absolute path via -Path param' {
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md | Should Be "$WorkspaceRoot\README.md"
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md | Should -Be "$WorkspaceRoot\README.md"
}
It 'Processes multiple absolute paths via -Path param' {
Import-FileNoWildcard -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\PathProcessingWildcards.ps1 |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
}
It 'Processes relative path via -Path param' {
Import-FileNoWildcard -Path ..\examples\README.md | Should Be "$WorkspaceRoot\README.md"
Import-FileNoWildcard -Path ..\examples\README.md | Should -Be "$WorkspaceRoot\README.md"
}
It 'Processes multiple relative path via -Path param' {
Import-FileNoWildcard -Path ..\examples\README.md, .vscode\launch.json |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
}

It 'Should accept pipeline input to Path' {
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileNoWildcard | Should Be "$PSScriptRoot\foo[1].txt"
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileNoWildcard | Should -Be "$PSScriptRoot\foo[1].txt"
}
}

Describe 'Verify Path Processing for Wildcards Allowed Impl' {
It 'Processes non-wildcard absolute path via -Path param' {
Import-FileWildcard -Path $WorkspaceRoot\Readme.md | Should Be "$WorkspaceRoot\README.md"
Import-FileWildcard -Path $WorkspaceRoot\Readme.md | Should -Be "$WorkspaceRoot\README.md"
}
It 'Processes multiple absolute paths via -Path param' {
Import-FileWildcard -Path $WorkspaceRoot\Readme.md, $WorkspaceRoot\PathProcessingWildcards.ps1 |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\PathProcessingWildcards.ps1")
}
It 'Processes wildcard absolute path via -Path param' {
$files = Import-FileWildcard -Path $WorkspaceRoot\*.psd1
$files.Count | Should Be 2
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
$files.Count | Should -Be 2
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
}
It 'Processes wildcard relative path via -Path param' {
$files = Import-FileWildcard -Path *.psd1
$files.Count | Should Be 2
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
$files.Count | Should -Be 2
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
}
It 'Processes relative path via -Path param' {
Import-FileWildcard -Path ..\examples\README.md | Should Be "$WorkspaceRoot\README.md"
Import-FileWildcard -Path ..\examples\README.md | Should -Be "$WorkspaceRoot\README.md"
}
It 'Processes multiple relative path via -Path param' {
Import-FileWildcard -Path ..\examples\README.md, .vscode\launch.json |
Should Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
Should -Be @("$WorkspaceRoot\README.md", "$WorkspaceRoot\.vscode\launch.json")
}

It 'DefaultParameterSet should be Path' {
It 'DefaultParameterSet should -be Path' {
$files = Import-FileWildcard *.psd1
$files.Count | Should Be 2
$files[0] | Should Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should Be "$WorkspaceRoot\SampleModule.psd1"
$files.Count | Should -Be 2
$files[0] | Should -Be "$WorkspaceRoot\PSScriptAnalyzerSettings.psd1"
$files[1] | Should -Be "$WorkspaceRoot\SampleModule.psd1"
}

It 'Should process absolute literal paths via -LiteralPath param'{
Import-FileWildcard -LiteralPath "$PSScriptRoot\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt"
Import-FileWildcard -LiteralPath "$PSScriptRoot\foo[1].txt" | Should -Be "$PSScriptRoot\foo[1].txt"
}
It 'Should process relative literal paths via -LiteralPath param'{
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt" | Should Be "$PSScriptRoot\foo[1].txt"
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt" | Should -Be "$PSScriptRoot\foo[1].txt"
}
It 'Should process multiple literal paths via -LiteralPath param'{
Import-FileWildcard -LiteralPath "..\examples\Tests\foo[1].txt", "$WorkspaceRoot\README.md" |
Should Be @("$PSScriptRoot\foo[1].txt", "$WorkspaceRoot\README.md")
Should -Be @("$PSScriptRoot\foo[1].txt", "$WorkspaceRoot\README.md")
}

It 'Should accept pipeline input to LiteralPath' {
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileWildcard | Should Be "$PSScriptRoot\foo[1].txt"
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileWildcard | Should -Be "$PSScriptRoot\foo[1].txt"
}
}
9 changes: 5 additions & 4 deletions examples/Tests/SampleModule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
$ModuleManifestName = 'SampleModule.psd1'
Import-Module $PSScriptRoot\..\$ModuleManifestName

BeforeAll {
$ModuleManifestName = 'SampleModule.psd1'
Import-Module $PSScriptRoot\..\$ModuleManifestName
}
Describe 'Module Manifest Tests' {
It 'Passes Test-ModuleManifest' {
Test-ModuleManifest -Path $PSScriptRoot\..\$ModuleManifestName
$? | Should Be $true
$? | Should -Be $true
}
}