-
-
Notifications
You must be signed in to change notification settings - Fork 185
WIP: Adds Bugfixing kata #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
7a96a39
e2b5787
530d4fb
0ab501a
0f64dab
a24164e
77bb15b
87c40bd
d377986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| using module PSKoans | ||
| [Koan(Position = 152)] | ||
| param() | ||
|
|
||
| <# | ||
| Kata: Bug fixing | ||
|
|
||
| The bug fixing challenges below are based on some real world examples. | ||
| #> | ||
| Describe 'Debugging' { | ||
| Context 'The sticky one' { | ||
| BeforeAll { | ||
| function Debug-Me { | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter()] | ||
| [string] | ||
| $ObjectData | ||
| ) | ||
|
|
||
| $ObjectData = [PSCustomObject]@{ | ||
| Name = $ObjectData | ||
| } | ||
|
|
||
| if ($ObjectData.Name -eq 'Value') { | ||
| $true | ||
| } else { | ||
| $ObjectData | ||
| } | ||
| } | ||
| } | ||
|
|
||
| It 'should return true' { | ||
| Debug-Me | Should -BeExactly $true | ||
| } | ||
| } | ||
|
|
||
| Context 'What about the iterator' { | ||
| BeforeAll { | ||
| function Debug-Me { | ||
| [CmdletBinding(DefaultParameterSetName = 'Default')] | ||
| param ( | ||
| [Parameter()] | ||
| [string] | ||
| $InputObject, | ||
|
|
||
| [Parameter(ParameterSetName = 'Switch')] | ||
| [switch] | ||
| $Switch | ||
| ) | ||
|
|
||
| switch ($InputObject) { | ||
| default { | ||
| 'A value' | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| It 'is supposed to return a value' { | ||
| { Debug-Me -InputObject 'Hello world' } | Should -Not -Throw | ||
| } | ||
| } | ||
|
|
||
| Context 'Pay attention to your surroudings' { | ||
| BeforeAll { | ||
| function Debug-Me { | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(ValueFromPipeline)] | ||
| [string] | ||
| $InputObject | ||
| ) | ||
|
|
||
| Write-Verbose 'Starting Debug-Me' | ||
|
|
||
| process | ||
| { | ||
| Write-Verbose "Working on $InputObject" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| It 'should not be returning anything' { | ||
| Debug-Me -InputObject 'a value' | Should -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'But the blog said this would work' { | ||
| BeforeAll { | ||
| function Debug-Me { | ||
| $process = Get—Process -Id $PID | ||
| if ($process -and $process.Name -eq 'powershell') { | ||
| Write-Host 'you must be using PowerShell' | ||
| } | ||
| } | ||
|
Comment on lines
+91
to
+98
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't throw, will it? Might need to swap your
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will throw (as-is) until the bug is fixed :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me tweak it just a little, to make it less obvious.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even the new example here doesn't look like it'll throw? Pester's |
||
| } | ||
|
|
||
| It 'should not be broken' { | ||
| { Debug-Me } | Should -Not -Throw | ||
| } | ||
| } | ||
|
|
||
| Context 'Something is leaking' { | ||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.