Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update sanity tests - Update private function tests - Update public function tests :white_check_mark: Skip Measure-Koan tests These tests are currently unstable and prone to corrupting Pester's internal state. Without a better option at the moment, we'll need to skip these tests for the time being. The function has been manually verified and seems to be more accurate than the original version.
- Loading branch information
Showing
23 changed files
with
1,423 additions
and
1,345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,64 @@ | ||
#region Header | ||
if (-not (Get-Module PSKoans)) { | ||
$moduleBase = Join-Path -Path $psscriptroot.Substring(0, $psscriptroot.IndexOf('\Tests')) -ChildPath 'PSKoans' | ||
#Requires -Modules PSKoans | ||
|
||
Import-Module $moduleBase -Force | ||
} | ||
#endregion | ||
|
||
if ($PSVersionTable.PSEdition -eq 'Desktop' -or $PSVersionTable.Platform -eq 'Win32NT') { | ||
InModuleScope PSKoans { | ||
Describe Assert-UnblockedFile { | ||
BeforeAll { | ||
$defaultParams = @{ | ||
FileInfo = [System.IO.FileInfo](Join-Path -Path $TestDrive -ChildPath 'AboutSomething.Koans.ps1') | ||
PassThru = $true | ||
} | ||
} | ||
#region Discovery | ||
$SkipTests = $PSVersionTable.PSEdition -ne 'Desktop' -or $PSVersionTable.Platform -ne 'Win32NT' | ||
#endregion Discovery | ||
|
||
BeforeEach { | ||
Set-Content -Path $defaultParams.FileInfo.FullName -Value @' | ||
using module PSKoans | ||
Describe 'Assert-UnblockedFile' -Skip:$SkipTests { | ||
|
||
[Koan(Position = 1)] | ||
param ( ) | ||
BeforeAll { | ||
$defaultParams = @{ | ||
FileInfo = [System.IO.FileInfo](Join-Path -Path $TestDrive -ChildPath 'AboutSomething.Koans.ps1') | ||
PassThru = $true | ||
} | ||
} | ||
|
||
Describe 'About something' { | ||
It 'Has examples' { | ||
$true | Should -BeTrue | ||
} | ||
} | ||
'@ | ||
} | ||
BeforeEach { | ||
Set-Content -Path $defaultParams.FileInfo.FullName -Value @' | ||
using module PSKoans | ||
[Koan(Position = 1)] | ||
param() | ||
Describe 'About something' { | ||
AfterEach { | ||
Remove-Item -Path $defaultParams.FileInfo.FullName | ||
It 'Has examples' { | ||
$true | Should -BeTrue | ||
} | ||
} | ||
'@ | ||
} | ||
|
||
Context 'File is blocked' { | ||
BeforeEach { | ||
Set-Content -Path $defaultParams.FileInfo.FullName -Stream Zone.Identifier -Value @' | ||
[ZoneTransfer] | ||
ZoneId=3 | ||
ReferrerUrl=C:\Downloads\File.zip | ||
AfterEach { | ||
Remove-Item -Path $defaultParams.FileInfo.FullName | ||
} | ||
|
||
Context 'File With External Zone Identifier' { | ||
|
||
BeforeEach { | ||
Set-Content -Path $defaultParams.FileInfo.FullName -Stream Zone.Identifier -Value @' | ||
[ZoneTransfer] | ||
ZoneId=3 | ||
ReferrerUrl=C:\Downloads\File.zip | ||
'@ | ||
} | ||
} | ||
|
||
It 'should throw a terminating error if the file is blocked' { | ||
{ Assert-UnblockedFile @defaultParams } | Should -Throw -ErrorId 'PSKoans.KoanFileIsBlocked' | ||
It 'should throw a terminating error if the file is blocked' { | ||
{ | ||
InModuleScope 'PSKoans' -Parameters @{ Params = $defaultParams } { | ||
param($Params) | ||
Assert-UnblockedFile @Params | ||
} | ||
} | ||
} | Should -Throw -ErrorId 'PSKoans.KoanFileIsBlocked' | ||
} | ||
} | ||
|
||
Context 'File is not blocked' { | ||
It 'returns the original object with -PassThru if the file is not blocked' { | ||
Assert-UnblockedFile @defaultParams | Should -BeOfType [System.IO.FileInfo] | ||
} | ||
} | ||
Context 'File Without Zone Identifier' { | ||
|
||
It 'returns the original object with -PassThru if the file is not blocked' { | ||
InModuleScope 'PSKoans' -Parameters @{ Params = $defaultParams } { | ||
param($Params) | ||
Assert-UnblockedFile @Params | ||
} | Should -BeOfType [System.IO.FileInfo] | ||
} | ||
} | ||
} |
39 changes: 18 additions & 21 deletions
39
Tests/Functions/Private/ConvertFrom-WildcardPattern.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
#Requires -Modules PSKoans | ||
|
||
InModuleScope 'PSKoans' { | ||
Describe 'ConvertFrom-WildcardPattern' { | ||
Describe 'ConvertFrom-WildcardPattern' { | ||
|
||
It 'adds start and end of string anchors to an explicit value' { | ||
ConvertFrom-WildcardPattern 'AboutArrays' | Should -Be '^AboutArrays$' | ||
} | ||
|
||
It 'joins multiple expressions with or' { | ||
ConvertFrom-WildcardPattern 'AboutArrays', 'AboutComparison' | Should -Be '^AboutArrays$|^AboutComparison$' | ||
} | ||
It 'adds start and end of string anchors to an explicit value' { | ||
InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays' } | Should -Be '^AboutArrays$' | ||
} | ||
|
||
It 'joins multiple expressions with |' { | ||
InModuleScope 'PSKoans' { ConvertFrom-WildcardPattern 'AboutArrays', 'AboutComparison' } | | ||
Should -Be '^AboutArrays$|^AboutComparison$' | ||
} | ||
|
||
It 'Replaces wildcard characters with regex equivalent' -TestCases @( | ||
@{ Pattern = 'About*son'; Expected = '^About.*son$' } | ||
@{ Pattern = 'AboutArrays*'; Expected = '^AboutArrays' } | ||
@{ Pattern = '*Arrays'; Expected = 'Arrays$' } | ||
@{ Pattern = '*Array*'; Expected = 'Array' } | ||
) { | ||
param ( | ||
$Pattern, | ||
$Expected | ||
) | ||
It 'replaces wildcard characters with regex equivalent' -TestCases @( | ||
@{ Pattern = 'About*son'; Expected = '^About.*son$' } | ||
@{ Pattern = 'AboutArrays*'; Expected = '^AboutArrays' } | ||
@{ Pattern = '*Arrays'; Expected = 'Arrays$' } | ||
@{ Pattern = '*Array*'; Expected = 'Array' } | ||
) { | ||
InModuleScope 'PSKoans' -Parameters @{ Pattern = $Pattern } { | ||
param($Pattern) | ||
|
||
ConvertFrom-WildcardPattern $Pattern | Should -Be $Expected | ||
} | ||
ConvertFrom-WildcardPattern $Pattern | ||
} | Should -Be $Expected | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,66 @@ | ||
#region Header | ||
if (-not (Get-Module PSKoans)) { | ||
$moduleBase = Join-Path -Path $psscriptroot.Substring(0, $psscriptroot.IndexOf('\Tests')) -ChildPath 'PSKoans' | ||
#Requires -Modules PSKoans | ||
|
||
Import-Module $moduleBase -Force | ||
} | ||
#endregion | ||
|
||
InModuleScope PSKoans { | ||
Describe Get-KoanAst { | ||
BeforeAll { | ||
$path = Join-Path $TestDrive 'AboutSomething.Koans.ps1' | ||
|
||
Set-Content -Path $path -Value @' | ||
using module PSKoans | ||
[Koan(Position = 1)] | ||
param() | ||
<# | ||
About Something | ||
#> | ||
Describe 'Something' { | ||
It 'Has some examples' { | ||
$true | Should -BeTrue | ||
} | ||
Describe 'Get-KoanAst' { | ||
|
||
BeforeAll { | ||
$path = Join-Path $TestDrive 'AboutSomething.Koans.ps1' | ||
|
||
Set-Content -Path $path -Value @' | ||
using module PSKoans | ||
[Koan(Position = 1)] | ||
param() | ||
<# | ||
About Something | ||
#> | ||
Describe 'Something' { | ||
It 'Has some examples' { | ||
$true | Should -BeTrue | ||
} | ||
} | ||
'@ | ||
} | ||
|
||
It 'excludes the "using module PSKoans" statement from the AST' { | ||
$ast = InModuleScope 'PSKoans' -Parameters @{ Path = $path } { | ||
param($Path) | ||
Get-KoanAst -Path $Path | ||
} | ||
|
||
It 'Excludes the "using module PSKoans" statement from the AST' { | ||
$ast = Get-KoanAst -Path $path | ||
$ast.UsingStatements | Should -BeNullOrEmpty | ||
} | ||
|
||
$ast.UsingStatements | Should -BeNullOrEmpty | ||
} | ||
It 'maintains consistency of position data when reading and modifying the source' { | ||
$tokens = $errors = $null | ||
$originalAst = [System.Management.Automation.Language.Parser]::ParseFile( | ||
$path, | ||
[Ref]$tokens, | ||
[Ref]$errors | ||
) | ||
|
||
It 'When reading and modifying the source, position data is consistent' { | ||
$tokens = $errors = @() | ||
$originalAst = [System.Management.Automation.Language.Parser]::ParseFile( | ||
$path, | ||
[Ref]$tokens, | ||
[Ref]$errors | ||
) | ||
$originalItBlock = $originalAst.Find( { | ||
$originalItBlock = $originalAst.Find( | ||
{ | ||
$args[0] -is [System.Management.Automation.Language.CommandAst] -and | ||
$args[0].GetCommandName() -eq 'It' | ||
}, $true) | ||
}, | ||
$true | ||
) | ||
|
||
$modifiedAst = Get-KoanAst -Path $path | ||
$modifiedItBlock = $modifiedAst.Find( { | ||
$modifiedAst = InModuleScope 'PSKoans' -Parameters @{ Path = $path } { | ||
param($Path) | ||
Get-KoanAst -Path $Path | ||
} | ||
|
||
$modifiedItBlock = $modifiedAst.Find( | ||
{ | ||
$args[0] -is [System.Management.Automation.Language.CommandAst] -and | ||
$args[0].GetCommandName() -eq 'It' | ||
}, $true) | ||
}, | ||
$true | ||
) | ||
|
||
$modifiedItBlock.Extent.StartOffset | Should -Be $originalItBlock.Extent.StartOffset | ||
$modifiedItBlock.Extent.EndOffset | Should -Be $originalItBlock.Extent.EndOffset | ||
} | ||
$modifiedItBlock.Extent.StartOffset | | ||
Should -Be $originalItBlock.Extent.StartOffset -Because 'the start offsets should match' | ||
$modifiedItBlock.Extent.EndOffset | | ||
Should -Be $originalItBlock.Extent.EndOffset -Because 'the end offsets should match' | ||
} | ||
} |
Oops, something went wrong.