pentest-distro-builder/filesystem/root/.vscode/extensions/ms-vscode.powershell-1.8.4/examples/Tests/PathProcessing.Tests.ps1

110 lines
5.3 KiB
PowerShell
Raw Normal View History

2018-10-17 14:11:16 -06:00
# These Pester tests are for the for parameter-* and ex-path* snippets.
# Take a look at the .vscode\tasks.json file to see how you can create
# and configure a test task runner that will run all the Pester tests
# in your workspace folder.
# To run these Pester tests, press Ctrl+Shift+T or press Ctrl+Shift+P,
# type "test" and select "Tasks: Run Test Task". This will invoke the
# 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
$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"
}
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")
}
It 'Processes relative path via -Path param' {
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")
}
It 'Should accept pipeline input to Path' {
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"
}
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")
}
It 'Processes relative path via -Path param' {
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")
}
It 'Should accept pipeline input to Path' {
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"
}
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")
}
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"
}
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"
}
It 'Processes relative path via -Path param' {
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")
}
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"
}
It 'Should process absolute literal paths via -LiteralPath param'{
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"
}
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")
}
It 'Should accept pipeline input to LiteralPath' {
Get-ChildItem -LiteralPath "$WorkspaceRoot\Tests\foo[1].txt" | Import-FileWildcard | Should Be "$PSScriptRoot\foo[1].txt"
}
}