Skip to content

Commit 466ef5c

Browse files
authored
Merge pull request #46 from vexx32/dev
Fix tests & speed isssues
2 parents 05b5db2 + 195cadc commit 466ef5c

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

Build/Psake.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ STATUS: Testing with PowerShell $PSVersion
5454
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
5555

5656
# Import the module
57-
Import-Module "$ProjectRoot\PSKoans\PSKoans.psd1"
57+
Import-Module "$ProjectRoot/PSKoans/PSKoans.psd1"
5858

5959
# Gather test results. Store them in a variable and file
6060
$PesterParams = @{
61-
Path = "$ProjectRoot\Tests"
61+
Path = "$ProjectRoot/Tests"
6262
PassThru = $true
6363
OutputFormat = 'NUnitXml'
64-
OutputFile = "$ProjectRoot\$TestFile"
64+
OutputFile = "$ProjectRoot/$TestFile"
6565
}
6666
$TestResults = Invoke-Pester @PesterParams
6767

@@ -75,7 +75,7 @@ STATUS: Testing with PowerShell $PSVersion
7575
)
7676
}
7777

78-
Remove-Item -Path "$ProjectRoot\$TestFile" -Force -ErrorAction SilentlyContinue
78+
Remove-Item -Path "$ProjectRoot/$TestFile" -Force -ErrorAction SilentlyContinue
7979

8080
# Failed tests?
8181
# Need to tell psake or it will proceed to the deployment. Danger!

PSKoans/Koans/Cmdlets 1/AboutDiscovery.Koans.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,18 @@ Describe 'Get-Command' {
166166
When looking for related commands, use of the -Verb and -Noun search options
167167
is often easier than figuring out how many wildcards you need in a -Name search.
168168
#>
169-
BeforeAll {
170-
# Try calling Get-Command in a PowerShell console to see the typical output!
171-
$Commands = Get-Command
172-
}
173169

174170
It 'lists available commands' {
175-
$Commands.Count | Should -Be __
176-
$Commands[7].Name | Should -Be '__'
171+
# Try calling Get-Command in a PowerShell console to see the typical output!
172+
$CommandCount = Get-Command | Measure-Object | Select-Object -ExpandProperty Count
173+
$CommandCount | Should -Be __
174+
Get-Command | Select-Object -First 1 -ExpandProperty Name | Should -Be '__'
177175
}
178176

179177
It 'indicates the type of command' {
180-
$CommandTypes = $Commands | Select-Object -ExpandProperty CommandType | Sort-Object -Unique
178+
$CommandType = Get-Command | Select-Object -Skip 3 -First 1 -ExpandProperty CommandType
181179

182-
@('__', '__', 'Cmdlet') | Should -Be $CommandTypes
180+
'__' | Should -Be $CommandType
183181
}
184182

185183
It 'can filter the output by keywords' {

PSKoans/PSKoans.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
#
22
# Module manifest for module 'PSKoans'
33
#
44
# Generated by: Joel Sallow
@@ -12,7 +12,7 @@
1212
RootModule = 'PSKoans.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.39.0'
15+
ModuleVersion = '0.39.5'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Desktop', 'Core')

PSKoans/PSKoans.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Get-ChildItem "$PSScriptRoot\Public", "$PSScriptRoot\Private" | ForEach-Object {
1+
Get-ChildItem "$PSScriptRoot/Public", "$PSScriptRoot/Private" | ForEach-Object {
22
. $_.FullName
33
}
4+
. "$PSScriptRoot/ExportedTypes.ps1"
45

56
$env:PSKoans_Folder = $Home | Join-Path -ChildPath 'PSKoans'
67
$script:ModuleFolder = $PSScriptRoot

PSKoans/Public/Get-Enlightenment.ps1

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,28 @@ function Get-Enlightenment {
6161

6262
Write-MeditationPrompt -Greeting
6363

64+
$KoanScripts = $null
65+
6466
$SortedKoanList = Get-ChildItem "$env:PSKoans_Folder" -Recurse -Filter '*.Koans.ps1' |
6567
Get-Command {$_.FullName} |
6668
Where-Object {$_.ScriptBlock.Attributes.TypeID -match 'KoanAttribute'} |
6769
Sort-Object {
68-
$_.ScriptBlock.Attributes.Where( {
69-
$_.TypeID -match 'KoanAttribute'
70-
}).Position
71-
} | Select-Object -ExpandProperty Path
70+
$_.ScriptBlock.Attributes.Where( {
71+
$_.TypeID -match 'KoanAttribute'
72+
}).Position
73+
}
7274

73-
$PesterParams = @{
74-
Script = $SortedKoanList
75-
PassThru = $true
76-
Show = 'None'
77-
}
78-
$PesterTestCount = Invoke-Pester @PesterParams |
79-
Select-Object -ExpandProperty TotalCount
75+
$TotalKoans = $SortedKoanList.ScriptBlock.Ast.FindAll(
76+
{
77+
param($Item)
78+
$Item -is [System.Management.Automation.Language.CommandAst] -and
79+
$Item.GetCommandName() -eq 'It'
80+
}, $true
81+
).Count
8082

8183
$KoansPassed = 0
8284

83-
foreach ($KoanFile in $SortedKoanList) {
85+
foreach ($KoanFile in $SortedKoanList.Path) {
8486
$PesterParams = @{
8587
Script = $KoanFile
8688
PassThru = $true
@@ -105,7 +107,7 @@ function Get-Enlightenment {
105107
ItName = $NextKoanFailed.Name
106108
Meditation = $NextKoanFailed.StackTrace
107109
KoansPassed = $KoansPassed
108-
TotalKoans = $PesterTestCount
110+
TotalKoans = $TotalKoans
109111
}
110112
Write-MeditationPrompt @Meditation
111113
}

Tests/Get-Enlightenment.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ InModuleScope 'PSKoans' {
1111
}
1212

1313
It 'should not produce output' {
14-
Get-Enlightenment | Should -BeNullOrEmpty
14+
Get-Enlightenment | Should -Be $null
1515
}
1616

1717
It 'should clear the screen' {
@@ -22,12 +22,12 @@ InModuleScope 'PSKoans' {
2222
Assert-MockCalled Write-MeditationPrompt -Times 2
2323
}
2424

25-
It 'should Invoke-Pester globally, and on each of the koans' {
25+
It 'should Invoke-Pester on each of the koans' {
2626
$ValidKoans = Get-ChildItem "$env:PSKoans_Folder" -Recurse -Filter '*.Koans.ps1' |
2727
Get-Command {$_.FullName} |
2828
Where-Object {$_.ScriptBlock.Attributes.TypeID -match 'KoanAttribute'}
2929

30-
Assert-MockCalled Invoke-Pester -Times ($ValidKoans.Count + 1)
30+
Assert-MockCalled Invoke-Pester -Times ($ValidKoans.Count)
3131
}
3232
}
3333

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
secure: G4KH7AVKvqA+2gNNtmnF1YxP9r2MWe55HbTy9no7fmACcNj6tXy0l4VKMOR8s0lx
1010

1111
install:
12-
- pwsh: >-
12+
- ps: >-
1313
Install-Module -Name Psake, PSDeploy, BuildHelpers -Force -Scope CurrentUser
1414
1515
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser
@@ -23,4 +23,4 @@ build: false
2323

2424
#Kick off the CI/CD pipeline
2525
test_script:
26-
- pwsh: . .\build\build.ps1
26+
- ps: . .\build\build.ps1

0 commit comments

Comments
 (0)