Skip to content

Commit ce875f3

Browse files
tomlarsevexx32
authored andcommitted
🔧 Fix divide by zero on some systems (#192)
* $TotalKoans in stead of $PesterTests.Totalcount so it is consistent in both conditions. * Added tests for divide by zero error * minor changes * oops
1 parent b160923 commit ce875f3

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

PSKoans/Public/Measure-Karma.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
@{
172172
Complete = $true
173173
KoansPassed = $KoansPassed
174-
TotalKoans = $PesterTests.TotalCount
174+
TotalKoans = $TotalKoans
175175
}
176176
}
177177

Tests/Functions/Public/Measure-Karma.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ Describe 'Measure-Karma' {
129129
Measure-Karma -Topic $Topic
130130
Assert-MockCalled Invoke-Koan -Times @($Topic).Count
131131
}
132+
133+
It 'should not divide by zero if all Koans are completed' {
134+
$KoansCompletedTestLocation = 'TestDrive:{0}PSKoansCompletedTest' -f [System.IO.Path]::DirectorySeparatorChar
135+
$TestFile = Join-Path -Path $KoansCompletedTestLocation -ChildPath 'SingleTopicTest.Koans.Ps1'
136+
137+
New-Item $KoansCompletedTestLocation -ItemType Directory
138+
New-Item $TestFile -ItemType File
139+
140+
@'
141+
using module PSKoans
142+
[Koan(Position = 1)]
143+
param()
144+
145+
Describe 'Koans Test' {
146+
It 'is easy to solve' {
147+
$true | should -be $true
148+
}
149+
}
150+
'@ | Set-Content $TestFile
151+
152+
Set-PSKoanLocation $KoansCompletedTestLocation
153+
154+
{Measure-Karma -Topic SingleTopicTest} | Should -Not -Throw
155+
156+
Set-PSKoanLocation $TestLocation
157+
}
132158
}
133159

134160
Context 'With -Reset Switch' {

0 commit comments

Comments
 (0)