Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ PSKoans.psproj
PSKoans/*/PSKoans-help.xml

Output/**
Tests/out/**
tests/out/**
testResults.xml
2 changes: 1 addition & 1 deletion psakeFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Properties {

# Test configuration -- the module must be imported from the staged output before
# Pester runs since the test suite expects `PSKoans` to already be loaded/resolvable
$PSBPreference.Test.RootDir = Join-Path $PSScriptRoot 'Tests'
$PSBPreference.Test.RootDir = Join-Path $PSScriptRoot 'tests'
$PSBPreference.Test.ImportModule = $true
$PSBPreference.Test.OutputFile = 'out/testResults.xml'
$PSBPreference.Test.OutputFormat = 'JUnitXml'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
#Requires -Module @{ ModuleName = 'Pester'; ModuleVersion = '5.0.0' }
BeforeDiscovery {
if ($null -eq $env:BHProjectName) {
# Run the build in a child process -- build.ps1 calls `exit` on completion, which
# would otherwise terminate the host process running this test file.
& pwsh -NoProfile -File '.\build.ps1' -Task Build
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build PSKoans before running tests.'
}
Set-BuildEnvironment -Force
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
$env:PSModulePath = $outputModDir + [IO.Path]::PathSeparator + $env:PSModulePath
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}
Describe 'ConvertFrom-WildcardPattern' {
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' }
) {
InModuleScope 'PSKoans' -Parameters @{ Pattern = $Pattern } {
param($Pattern)
ConvertFrom-WildcardPattern $Pattern
} | Should -Be $Expected
}
}
#Requires -Module @{ ModuleName = 'Pester'; ModuleVersion = '5.0.0' }

BeforeDiscovery {
if ($null -eq $env:BHProjectName) {
# Run the build in a child process -- build.ps1 calls `exit` on completion, which
# would otherwise terminate the host process running this test file.
& pwsh -NoProfile -File '.\build.ps1' -Task Build
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build PSKoans before running tests.'
}
Set-BuildEnvironment -Force
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
$env:PSModulePath = $outputModDir + [IO.Path]::PathSeparator + $env:PSModulePath

# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}

Describe 'ConvertFrom-WildcardPattern' {

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' }
) {
InModuleScope 'PSKoans' -Parameters @{ Pattern = $Pattern } {
param($Pattern)

ConvertFrom-WildcardPattern $Pattern
} | Should -Be $Expected
}
}
Original file line number Diff line number Diff line change
@@ -1,112 +1,112 @@
#Requires -Module @{ ModuleName = 'Pester'; ModuleVersion = '5.0.0' }
BeforeDiscovery {
if ($null -eq $env:BHProjectName) {
# Run the build in a child process -- build.ps1 calls `exit` on completion, which
# would otherwise terminate the host process running this test file.
& pwsh -NoProfile -File '.\build.ps1' -Task Build
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build PSKoans before running tests.'
}
Set-BuildEnvironment -Force
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
$env:PSModulePath = $outputModDir + [IO.Path]::PathSeparator + $env:PSModulePath
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}
Describe 'Measure-Koan' -Skip {
BeforeAll {
Set-Content -Path 'TestDrive:\TestCases.Koans.ps1' -Value @'
Describe 'Test cases param' {
It 'first <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)
$TestCase | Should -BeOfType int
}
}
'@
Set-Content -Path 'TestDrive:\JustIt.Koans.ps1' -Value @'
Describe 'Just it' {
It 'first' {
$true | Should -BeTrue
}
It 'second' {
$true | Should -BeTrue
}
}
'@
Set-Content -Path TestDrive:\Mixed.Koans.ps1 -Value @'
Describe 'Mixed' {
It 'first' {
$true | Should -BeTrue
}
It 'second <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
) {
param($TestCase)
$TestCase | Should -BeOfType int
}
}
'@
Set-Content -Path TestDrive:\MutlipleTestCases.Koans.ps1 -Value @'
Describe 'Test cases param' {
It 'first <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)
$TestCase | Should -BeOfType int
}
It 'second <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)
$TestCase | Should -BeOfType int
}
}
'@
}
It 'correctly counts the number of tests in <Path>, including -TestCases' -TestCases @(
@{ Path = 'TestDrive:\TestCases.Koans.ps1'; ExpectedValue = 3 }
@{ Path = 'TestDrive:\JustIt.Koans.ps1'; ExpectedValue = 2 }
@{ Path = 'TestDrive:\Mixed.Koans.ps1'; ExpectedValue = 3 }
@{ Path = 'TestDrive:\MutlipleTestCases.Koans.ps1'; ExpectedValue = 6 }
) {
$koanInfo = [PSCustomObject]@{
Path = $Path
PSTypeName = 'PSKoans.KoanInfo'
}
InModuleScope 'PSKoans' -Parameters @{ Koan = $koanInfo } {
param($Koan)
Measure-Koan $Koan
} | Should -Be $ExpectedValue
}
}
#Requires -Module @{ ModuleName = 'Pester'; ModuleVersion = '5.0.0' }

BeforeDiscovery {
if ($null -eq $env:BHProjectName) {
# Run the build in a child process -- build.ps1 calls `exit` on completion, which
# would otherwise terminate the host process running this test file.
& pwsh -NoProfile -File '.\build.ps1' -Task Build
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build PSKoans before running tests.'
}
Set-BuildEnvironment -Force
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"
$env:PSModulePath = $outputModDir + [IO.Path]::PathSeparator + $env:PSModulePath

# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}

Describe 'Measure-Koan' -Skip {

BeforeAll {
Set-Content -Path 'TestDrive:\TestCases.Koans.ps1' -Value @'
Describe 'Test cases param' {
It 'first <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)

$TestCase | Should -BeOfType int
}
}
'@

Set-Content -Path 'TestDrive:\JustIt.Koans.ps1' -Value @'
Describe 'Just it' {
It 'first' {
$true | Should -BeTrue
}

It 'second' {
$true | Should -BeTrue
}
}
'@

Set-Content -Path TestDrive:\Mixed.Koans.ps1 -Value @'
Describe 'Mixed' {
It 'first' {
$true | Should -BeTrue
}

It 'second <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
) {
param($TestCase)

$TestCase | Should -BeOfType int
}
}
'@

Set-Content -Path TestDrive:\MutlipleTestCases.Koans.ps1 -Value @'
Describe 'Test cases param' {
It 'first <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)

$TestCase | Should -BeOfType int
}

It 'second <TestCase>' -TestCases @(
@{ TestCase = 1 }
@{ TestCase = 2 }
@{ TestCase = 3 }
) {
param($TestCase)

$TestCase | Should -BeOfType int
}
}
'@
}

It 'correctly counts the number of tests in <Path>, including -TestCases' -TestCases @(
@{ Path = 'TestDrive:\TestCases.Koans.ps1'; ExpectedValue = 3 }
@{ Path = 'TestDrive:\JustIt.Koans.ps1'; ExpectedValue = 2 }
@{ Path = 'TestDrive:\Mixed.Koans.ps1'; ExpectedValue = 3 }
@{ Path = 'TestDrive:\MutlipleTestCases.Koans.ps1'; ExpectedValue = 6 }
) {
$koanInfo = [PSCustomObject]@{
Path = $Path
PSTypeName = 'PSKoans.KoanInfo'
}

InModuleScope 'PSKoans' -Parameters @{ Koan = $koanInfo } {
param($Koan)
Measure-Koan $Koan
} | Should -Be $ExpectedValue
}
}
Loading
Loading