From b5fb3a6a30d8c8bc2195ef3e6798997d8d7c521a Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:13:42 -0400 Subject: [PATCH 01/14] :bug: Avoid error on missing module folder - This is an expected case for Modules to be missing in the user folder so just check the path and avoid searching it if it doesn't exist yet --- PSKoans/Public/Get-PSKoan.ps1 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/PSKoans/Public/Get-PSKoan.ps1 b/PSKoans/Public/Get-PSKoan.ps1 index 6158b695f..c10fcc065 100644 --- a/PSKoans/Public/Get-PSKoan.ps1 +++ b/PSKoans/Public/Get-PSKoan.ps1 @@ -45,15 +45,19 @@ function Get-PSKoan { 'Module' { Join-Path -Path $script:ModuleRoot -ChildPath 'Koans' } } - if ($pscmdlet.ParameterSetName -eq 'ListModules') { - $moduleList = Join-Path -Path $ParentPath -ChildPath 'Modules' | - Get-ChildItem -Directory | - Select-Object -ExpandProperty Name + if ($PSCmdlet.ParameterSetName -eq 'ListModules') { + $modulesPath = Join-Path -Path $ParentPath -ChildPath 'Modules' - return $moduleList + if (Test-Path $modulesPath) { + $modulesPath | + Get-ChildItem -Directory | + Select-Object -ExpandProperty Name + } + + return } - $KoanDirectories = switch ($pscmdlet.ParameterSetName) { + $KoanDirectories = switch ($PSCmdlet.ParameterSetName) { 'IncludeModule' { $Module = $IncludeModule Get-ChildItem $ParentPath -Exclude Modules -Directory @@ -61,9 +65,11 @@ function Get-PSKoan { { $Module } { $ModuleRegex = ConvertFrom-WildcardPattern -Pattern $Module - Join-Path -Path $ParentPath -ChildPath 'Modules' | - Get-ChildItem -Directory | + $modulesPath = Join-Path -Path $ParentPath -ChildPath 'Modules' + if (Test-Path $modulesPath) { + Get-ChildItem $modulesPath -Directory | Where-Object { $_.Name -match $ModuleRegex } + } } } From 2792b03b0ccff59949bbc63293b490c63e6c8ea4 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:21:35 -0400 Subject: [PATCH 02/14] :bug: Explicitly import required modules - Check script required modules & import them prior to invoking Pester --- PSKoans/Private/Invoke-Koan.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PSKoans/Private/Invoke-Koan.ps1 b/PSKoans/Private/Invoke-Koan.ps1 index 5befa832c..59445f4ee 100644 --- a/PSKoans/Private/Invoke-Koan.ps1 +++ b/PSKoans/Private/Invoke-Koan.ps1 @@ -27,16 +27,26 @@ ) end { try { + $Requirements = (Get-Command $ParameterSplat.Script).ScriptBlock.Ast.ScriptRequirements + $Script = { - param( $Params ) + param( $Params, $RequiredModules ) . ([scriptblock]::Create('using module PSKoans')) + foreach ($module in $RequiredModules) { + Import-Module $module + } + Invoke-Pester @Params } $Thread = [powershell]::Create() $Thread.AddScript($Script) > $null - $Thread.AddArgument($ParameterSplat) > $null + $Thread.AddParameter('Params', $ParameterSplat) > $null + + if ($Requirements.RequiredModules) { + $Thread.AddParameter('RequiredModules', $Requirements.RequiredModules) + } $Status = $Thread.BeginInvoke() From 1fba555ba31c1a4f0e4435836febbe8cf3249a7d Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:30:42 -0400 Subject: [PATCH 03/14] :bug: Fix Show-Karma parameter sets - Sets prevented use of -(Include)Module with -Contemplate :( --- PSKoans/Public/Show-Karma.ps1 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index 65dbc5ba5..b36f234a8 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -5,9 +5,13 @@ function Show-Karma { [Alias('Invoke-PSKoans', 'Test-Koans', 'Get-Enlightenment', 'Meditate', 'Clear-Path', 'Measure-Karma')] param( [Parameter(ParameterSetName = 'ListKoans')] + [Parameter(ParameterSetName = 'ListKoans-ModuleOnly')] + [Parameter(ParameterSetName = 'ListKoans-IncludeModule')] [Parameter(ParameterSetName = 'ModuleOnly')] [Parameter(ParameterSetName = 'IncludeModule')] [Parameter(ParameterSetName = 'OpenFile')] + [Parameter(ParameterSetName = 'OpenFile-ModuleOnly')] + [Parameter(ParameterSetName = 'OpenFile-IncludeModule')] [Parameter(ParameterSetName = 'Default')] [Alias('Koan', 'File')] [SupportsWildcards()] @@ -15,22 +19,30 @@ function Show-Karma { $Topic, [Parameter(Mandatory, ParameterSetName = 'ModuleOnly')] - [Parameter(ParameterSetName = 'ListKoans')] + [Parameter(Mandatory, ParameterSetName = 'ListKoans-ModuleOnly')] + [Parameter(Mandatory, ParameterSetName = 'OpenFile-ModuleOnly')] [SupportsWildcards()] [string[]] $Module, [Parameter(Mandatory, ParameterSetName = 'IncludeModule')] + [Parameter(Mandatory, ParameterSetName = 'ListKoans-IncludeModule')] + [Parameter(Mandatory, ParameterSetName = 'OpenFile-IncludeModule')] + [Alias('Meditate')] [SupportsWildcards()] [string[]] $IncludeModule, [Parameter(Mandatory, ParameterSetName = 'ListKoans')] + [Parameter(Mandatory, ParameterSetName = 'ListKoans-ModuleOnly')] + [Parameter(Mandatory, ParameterSetName = 'ListKoans-IncludeModule')] [Alias('ListKoans', 'ListTopics')] [switch] $List, [Parameter(Mandatory, ParameterSetName = 'OpenFile')] + [Parameter(Mandatory, ParameterSetName = 'OpenFile-ModuleOnly')] + [Parameter(Mandatory, ParameterSetName = 'OpenFile-IncludeModule')] [Alias('Meditate')] [switch] $Contemplate, @@ -61,7 +73,7 @@ function Show-Karma { } switch ($PSCmdlet.ParameterSetName) { - 'ListKoans' { + { $_ -match '^ListKoans' } { Get-PSKoan @GetParams } 'OpenFolder' { @@ -140,8 +152,7 @@ function Show-Karma { try { Get-Karma @GetParams | Format-Custom @FormatParams | - Out-String | - Write-Host + Out-Host } catch { $PSCmdlet.ThrowTerminatingError($_) @@ -149,3 +160,4 @@ function Show-Karma { } } } +} From 12f2775d6eb21ae000317515b4652831dc2710c5 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:39:25 -0400 Subject: [PATCH 04/14] :bug: Fix errors --- PSKoans/Public/Show-Karma.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index b36f234a8..670411679 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -98,7 +98,7 @@ function Show-Karma { $KoanLocation | Invoke-Item } } - 'OpenFile' { + {$_ -match '^OpenFile'} { # If there is no cached data, we need to call Get-Karma to populate it if (-not $script:CurrentTopic -or ($Topic -and $script:CurrentTopic.Name -notlike $Topic)) { try { @@ -160,4 +160,3 @@ function Show-Karma { } } } -} From b5e1f1db2993678affa0d695e3e3617e0229ee6d Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:49:30 -0400 Subject: [PATCH 05/14] :bug: remove misplaced alias --- PSKoans/Public/Show-Karma.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index 670411679..1d34edd01 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -28,7 +28,6 @@ function Show-Karma { [Parameter(Mandatory, ParameterSetName = 'IncludeModule')] [Parameter(Mandatory, ParameterSetName = 'ListKoans-IncludeModule')] [Parameter(Mandatory, ParameterSetName = 'OpenFile-IncludeModule')] - [Alias('Meditate')] [SupportsWildcards()] [string[]] $IncludeModule, From f6bc1dd3495ac115a7659468560dcb7212ede959 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Mon, 22 Jun 2020 10:59:42 -0400 Subject: [PATCH 06/14] :bug: Make sure module params are added to get --- PSKoans/Public/Show-Karma.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index 1d34edd01..03b3486c0 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -66,8 +66,8 @@ function Show-Karma { $GetParams = @{ } switch ($PSCmdlet.ParameterSetName) { - 'IncludeModule' { $GetParams['IncludeModule'] = $IncludeModule } - 'ModuleOnly' { $GetParams['Module'] = $Module } + { $_ -match 'IncludeModule$' } { $GetParams['IncludeModule'] = $IncludeModule } + { $_ -match 'ModuleOnly$' } { $GetParams['Module'] = $Module } { $PSBoundParameters.ContainsKey('Topic') } { $GetParams['Topic'] = $Topic } } From 72c595b687861141fdffe1ab16b1dc55d54f85fa Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 00:40:44 -0400 Subject: [PATCH 07/14] :bug: Improve handling for modules Added handling to Get-Karma to ensure Update-PSKoan copies module files when module params are specified. --- PSKoans/Public/Get-Karma.ps1 | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/PSKoans/Public/Get-Karma.ps1 b/PSKoans/Public/Get-Karma.ps1 index db9d72d95..9d5b09a6e 100644 --- a/PSKoans/Public/Get-Karma.ps1 +++ b/PSKoans/Public/Get-Karma.ps1 @@ -37,7 +37,7 @@ 'ListKoans' { Get-PSKoan @GetParams } - "Default" { + default { Write-Verbose 'Sorting koans...' try { $SortedKoanList = Get-PSKoan @GetParams @@ -46,6 +46,17 @@ $PSCmdlet.ThrowTerminatingError($_) } + foreach ($item in $IncludeModule) { + if ($SortedKoanList.Where{ $_.Module -notlike $item }.Count -eq 0) { + $warningString = @( + "Koans for a module name matching '$item' were not found in your user directory." + "Please run Update-PSKoan -Module $item to ensure those modules are present." + ) -join ' ' + + Write-Warning $warningString + } + } + Write-Verbose "Koan files retrieved: $($SortedKoanList.Count)" Write-Verbose 'Counting koans...' [int]$TotalKoans = $SortedKoanList | Measure-Koan @@ -68,9 +79,24 @@ $PSCmdlet.ThrowTerminatingError( (New-PSKoanErrorRecord @ErrorDetails) ) } + if ($Module) { + # No koans were found because modules aren't copied by default. + Update-PSKoan -Module $Module -Confirm:$false + Get-Karma @PSBoundParameters + + return + } + # Something's wrong; possibly a koan folder from older versions, or a folder exists but has no files + $Modules = if ($IncludeModule) { + @{ IncludeModule = $IncludeModule } + } + else { + @{ } + } + Write-Warning 'No koans found in your koan directory. Initiating full reset...' - Update-PSKoan -Confirm:$false + Update-PSKoan -Confirm:$false @Modules Get-Karma @PSBoundParameters # Re-call ourselves with the same parameters return # Skip the rest of the function From 36df69124a62bc9d9d0d14efc49a082abe254da5 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 00:51:08 -0400 Subject: [PATCH 08/14] :bug: Fix Invoke-Koan functionality - Fix edge case where PSKoans is not on PSModulePath. - Copy PSModulePath and PSKoans path into new runspace. - Propagate errors from runspace to current session in case of errors. --- PSKoans/Private/Invoke-Koan.ps1 | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/PSKoans/Private/Invoke-Koan.ps1 b/PSKoans/Private/Invoke-Koan.ps1 index 59445f4ee..a45ad17a5 100644 --- a/PSKoans/Private/Invoke-Koan.ps1 +++ b/PSKoans/Private/Invoke-Koan.ps1 @@ -27,12 +27,23 @@ ) end { try { - $Requirements = (Get-Command $ParameterSplat.Script).ScriptBlock.Ast.ScriptRequirements + $Requirements = [System.Management.Automation.Language.Parser]::ParseFile( + $ParameterSplat.Script, + [ref]$null, + [ref]$null + ).Ast.ScriptRequirements $Script = { - param( $Params, $RequiredModules ) + param( $Params, $RequiredModules, $PSKoansPath, $PSModulePath ) - . ([scriptblock]::Create('using module PSKoans')) + [System.Collections.Generic.HashSet[string]] $ModulePaths = @( + $PSModulePath -split [System.IO.Path]::PathSeparator + $env:PSModulePath -split [System.IO.Path]::PathSeparator + ) + + $env:PSModulePath = $ModulePaths -join [System.IO.Path]::PathSeparator + + Import-Module $PSKoansPath foreach ($module in $RequiredModules) { Import-Module $module } @@ -40,22 +51,33 @@ Invoke-Pester @Params } - $Thread = [powershell]::Create() - $Thread.AddScript($Script) > $null - $Thread.AddParameter('Params', $ParameterSplat) > $null + $Runspace = [powershell]::Create() + $Runspace.AddScript($Script) > $null + $Runspace.AddParameter('Params', $ParameterSplat) > $null + $Runspace.AddParameter('PSKoansPath', $MyInvocation.MyCommand.Module.ModuleBase) > $null + $Runspace.AddParameter('PSModulePath', $env:PSModulePath) > $null if ($Requirements.RequiredModules) { - $Thread.AddParameter('RequiredModules', $Requirements.RequiredModules) + $Runspace.AddParameter('RequiredModules', $Requirements.RequiredModules) } - $Status = $Thread.BeginInvoke() + $Status = $Runspace.BeginInvoke() do { Start-Sleep -Milliseconds 1 } until ($Status.IsCompleted) - $Thread.EndInvoke($Status) + $Result = $Runspace.EndInvoke($Status) + + if ($Runspace.HadErrors) { + # These will be errors outside the test itself; better propagate them upwards. + foreach ($errorItem in $Runspace.Streams.Error) { + $PSCmdlet.WriteError($errorItem) + } + } + + $Result } finally { - $Thread.Dispose() + $Runspace.Dispose() } } } From 42f12ca10ea250b594941424fe22684630321b76 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 00:51:22 -0400 Subject: [PATCH 09/14] :art: Indentation fix --- PSKoans/Public/Get-PSKoan.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSKoans/Public/Get-PSKoan.ps1 b/PSKoans/Public/Get-PSKoan.ps1 index c10fcc065..49645d3d3 100644 --- a/PSKoans/Public/Get-PSKoan.ps1 +++ b/PSKoans/Public/Get-PSKoan.ps1 @@ -68,7 +68,7 @@ function Get-PSKoan { $modulesPath = Join-Path -Path $ParentPath -ChildPath 'Modules' if (Test-Path $modulesPath) { Get-ChildItem $modulesPath -Directory | - Where-Object { $_.Name -match $ModuleRegex } + Where-Object { $_.Name -match $ModuleRegex } } } } From 078061942780be43f7c6bf2644215988afa7523b Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 02:09:23 -0400 Subject: [PATCH 10/14] :bug: Fix Unix issue - Apparently Import-Module fails to recognise Unix fully qualified path --- PSKoans/Private/Invoke-Koan.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSKoans/Private/Invoke-Koan.ps1 b/PSKoans/Private/Invoke-Koan.ps1 index a45ad17a5..61c1a3f4a 100644 --- a/PSKoans/Private/Invoke-Koan.ps1 +++ b/PSKoans/Private/Invoke-Koan.ps1 @@ -43,7 +43,7 @@ $env:PSModulePath = $ModulePaths -join [System.IO.Path]::PathSeparator - Import-Module $PSKoansPath + Get-Module $PSKoansPath -ListAvailable | Import-Module foreach ($module in $RequiredModules) { Import-Module $module } From 943de3e4f5e9501ad7a3b87f24336b3935fd030d Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 20:57:05 -0400 Subject: [PATCH 11/14] :sparkles: Add debugging script --- .vscode/launch.json | 32 ++++++++++---------------------- Start-DebugSession.ps1 | 11 +++++++++++ 2 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 Start-DebugSession.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json index ee6013c73..ae10584f8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,37 +5,19 @@ "version": "0.2.0", "configurations": [ { - "name": "PowerShell Launch Current File", + "name": "PowerShell Launch Script", "type": "PowerShell", "request": "launch", - "script": "${file}", - "args": [], - "cwd": "${file}" - }, - { - "name": "PowerShell Launch Current File in Temporary Console", - "type": "PowerShell", - "request": "launch", - "script": "${file}", - "args": [], - "cwd": "${file}", - "createTemporaryIntegratedConsole": true + "script": "./Start-DebugSession.ps1", + "cwd": "${workspaceFolder}" }, { - "name": "PowerShell Launch Current File w/Args Prompt", + "name": "PowerShell: Launch Current File", "type": "PowerShell", "request": "launch", "script": "${file}", - "args": [ - "${command:SpecifyScriptArgs}" - ], "cwd": "${file}" }, - { - "name": "PowerShell Attach to Host Process", - "type": "PowerShell", - "request": "attach" - }, { "name": "PowerShell Interactive Session", "type": "PowerShell", @@ -47,6 +29,12 @@ "type": "PowerShell", "request": "attach", "processId": "current" + }, + { + "name": "PowerShell Attach to Host Process", + "type": "PowerShell", + "request": "attach", + "runspaceId": 1 } ] } diff --git a/Start-DebugSession.ps1 b/Start-DebugSession.ps1 new file mode 100644 index 000000000..0b5c8f408 --- /dev/null +++ b/Start-DebugSession.ps1 @@ -0,0 +1,11 @@ +$env:PSModulePath = $( + @( + $env:PSModulePath -split [System.IO.Path]::PathSeparator + $PSScriptRoot + ) | Select-Object -Unique +) -join [System.IO.Path]::PathSeparator + +Import-Module $PSScriptRoot/PSKoans + +### Enter code to test below +Invoke-Pester -Path $PSScriptRoot/Tests/Functions/Public/Show-Karma.Tests.ps1 From d237454bac5c53184f22d16f2143897d94014142 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sat, 4 Jul 2020 22:29:15 -0400 Subject: [PATCH 12/14] :white_check_mark: Update Show-Karma tests --- Tests/Functions/Public/Show-Karma.Tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/Functions/Public/Show-Karma.Tests.ps1 b/Tests/Functions/Public/Show-Karma.Tests.ps1 index a758309d6..15259688a 100644 --- a/Tests/Functions/Public/Show-Karma.Tests.ps1 +++ b/Tests/Functions/Public/Show-Karma.Tests.ps1 @@ -25,7 +25,7 @@ Describe 'Show-Karma' { Context 'Default Behaviour' { BeforeAll { - Mock Write-Host { } + Mock Out-Host { } Mock Get-Karma -ModuleName 'PSKoans' { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -50,7 +50,7 @@ Describe 'Show-Karma' { } It 'should write the formatted output to host' { - Assert-MockCalled Write-Host + Assert-MockCalled Out-Host } It 'should call Get-Karma to examine the koans' { @@ -60,7 +60,7 @@ Describe 'Show-Karma' { Context 'With All Koans Completed' { BeforeAll { - Mock Write-Host { } + Mock Out-Host { } Mock Get-Karma -ModuleName 'PSKoans' { [PSCustomObject]@{ PSTypeName = 'PSKoans.CompleteResult' @@ -80,7 +80,7 @@ Describe 'Show-Karma' { Context 'With -ClearScreen Switch' { BeforeAll { Mock Clear-Host { } - Mock Write-Host { } + Mock Out-Host { } Mock Get-Karma -ModuleName 'PSKoans' { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -109,7 +109,7 @@ Describe 'Show-Karma' { } It 'should display the rendered output' { - Assert-MockCalled Write-Host + Assert-MockCalled Out-Host } It 'should Invoke-Pester on each of the koans' { @@ -119,7 +119,7 @@ Describe 'Show-Karma' { Context 'With Nonexistent Koans Folder / No Koans Found' { BeforeAll { - Mock Write-Host { } + Mock Out-Host { } Mock Get-PSKoan -ModuleName 'PSKoans' { } Mock Update-PSKoan -ModuleName 'PSKoans' { throw 'Prevent recursion' } Mock Write-Warning @@ -174,7 +174,7 @@ Describe 'Show-Karma' { Context 'With -Topic Parameter' { BeforeAll { - Mock Write-Host { } + Mock Out-Host { } Mock Get-Karma -MockWith { [PSCustomObject]@{ PSTypeName = 'PSKoans.Result' @@ -204,7 +204,7 @@ Describe 'Show-Karma' { Context 'With All Koans in a Single Topic Completed' { BeforeAll { Mock Format-Custom { $InputObject.Complete } - Mock Write-Host { } + Mock Out-Host { } Mock Get-Karma -ModuleName 'PSKoans' { [PSCustomObject]@{ PSTypeName = 'PSKoans.CompleteResult' From bf2cefefd54c04e7494ad82b5291f032952f0cdb Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:45:18 -0400 Subject: [PATCH 13/14] :bug: Fix null path with -Module and -Contemplate --- PSKoans/Public/Show-Karma.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PSKoans/Public/Show-Karma.ps1 b/PSKoans/Public/Show-Karma.ps1 index 03b3486c0..d0007f589 100644 --- a/PSKoans/Public/Show-Karma.ps1 +++ b/PSKoans/Public/Show-Karma.ps1 @@ -97,7 +97,7 @@ function Show-Karma { $KoanLocation | Invoke-Item } } - {$_ -match '^OpenFile'} { + { $_ -match '^OpenFile' } { # If there is no cached data, we need to call Get-Karma to populate it if (-not $script:CurrentTopic -or ($Topic -and $script:CurrentTopic.Name -notlike $Topic)) { try { @@ -110,7 +110,12 @@ function Show-Karma { } $Editor = Get-PSKoanSetting -Name Editor - $FilePath = (Get-PSKoan -Topic $script:CurrentTopic.Name -Scope User).Path + $KoanParams = @{ + Topic = $script:CurrentTopic.Name + IncludeModule = @( $Module; $IncludeModule ) + Scope = 'User' + } + $FilePath = (Get-PSKoan @KoanParams).Path $LineNumber = $script:CurrentTopic.CurrentLine $Arguments = switch ($Editor) { From 13af974007ff04483030fe5eaadcb66ba18e5806 Mon Sep 17 00:00:00 2001 From: Joel Sallow <32407840+vexx32@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:58:50 -0400 Subject: [PATCH 14/14] :construction: Add format generation to debug script --- Start-DebugSession.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Start-DebugSession.ps1 b/Start-DebugSession.ps1 index 0b5c8f408..f28582f67 100644 --- a/Start-DebugSession.ps1 +++ b/Start-DebugSession.ps1 @@ -5,7 +5,7 @@ $env:PSModulePath = $( ) | Select-Object -Unique ) -join [System.IO.Path]::PathSeparator +& $PSScriptRoot/PSKoans.ezformat.ps1 Import-Module $PSScriptRoot/PSKoans ### Enter code to test below -Invoke-Pester -Path $PSScriptRoot/Tests/Functions/Public/Show-Karma.Tests.ps1