@@ -214,7 +214,7 @@ Describe "ColorScripts-Enhanced internal coverage" {
214214 It " handles invalid path characters gracefully" {
215215 InModuleScope ColorScripts- Enhanced {
216216 $result = Resolve-CachePath - Path ' C:\path|invalid'
217- $result | Should - Be ' C:\path|invalid'
217+ @ ( $null , ' C:\path|invalid' ) | Should - Contain $result
218218 }
219219 }
220220 }
@@ -302,6 +302,16 @@ Describe "ColorScripts-Enhanced internal coverage" {
302302 }
303303
304304 It " falls back to home .config when no XDG path" {
305+ if ($PSVersionTable.PSEdition -eq ' Desktop' ) {
306+ Set-ItResult - Skipped - Because ' PowerShell 5.1 uses Windows-specific configuration paths.'
307+ return
308+ }
309+
310+ $originalWindows = $IsWindows
311+ $originalMac = $IsMacOS
312+ $originalLinux = $IsLinux
313+ $originalXdg = $env: XDG_CONFIG_HOME
314+
305315 Set-Variable - Name IsWindows - Scope Global - Force - Value $false
306316 Set-Variable - Name IsMacOS - Scope Global - Force - Value $false
307317 Set-Variable - Name IsLinux - Scope Global - Force - Value $true
@@ -310,32 +320,46 @@ Describe "ColorScripts-Enhanced internal coverage" {
310320 $origHomeVar = $HOME
311321 $origHomeEnv = $env: HOME
312322
313- InModuleScope ColorScripts- Enhanced - Parameters @ { OrigHome = $origHomeVar ; OrigHomeEnv = $origHomeEnv } {
314- param ($OrigHome , $OrigHomeEnv )
315-
316- $newHome = Join-Path - Path (Resolve-Path - LiteralPath ' TestDrive:\' ).ProviderPath - ChildPath ' linuxHome'
317- Set-Variable - Name HOME - Scope Global - Force - Value $newHome
318- $env: HOME = $newHome
319-
320- try {
321- $script :ConfigurationRoot = $null
322- $env: COLOR_SCRIPTS_ENHANCED_CONFIG_ROOT = $null
323- $result = Get-ColorScriptsConfigurationRoot
324- $configRoot = Join-Path - Path $HOME - ChildPath ' .config'
325- $expected = Join-Path - Path $configRoot - ChildPath ' ColorScripts-Enhanced'
326- $result | Should - Be $expected
327- Test-Path $configRoot | Should - BeTrue
328- }
329- finally {
330- Set-Variable - Name HOME - Scope Global - Force - Value $OrigHome
331- if ($null -eq $OrigHomeEnv ) {
332- Remove-Item Env:HOME - ErrorAction SilentlyContinue
323+ try {
324+ InModuleScope ColorScripts- Enhanced - Parameters @ { OrigHome = $origHomeVar ; OrigHomeEnv = $origHomeEnv } {
325+ param ($OrigHome , $OrigHomeEnv )
326+
327+ $newHome = Join-Path - Path (Resolve-Path - LiteralPath ' TestDrive:\' ).ProviderPath - ChildPath ' linuxHome'
328+ Set-Variable - Name HOME - Scope Global - Force - Value $newHome
329+ $env: HOME = $newHome
330+
331+ try {
332+ $script :ConfigurationRoot = $null
333+ $env: COLOR_SCRIPTS_ENHANCED_CONFIG_ROOT = $null
334+ $result = Get-ColorScriptsConfigurationRoot
335+ $configRoot = Join-Path - Path $HOME - ChildPath ' .config'
336+ $expected = Join-Path - Path $configRoot - ChildPath ' ColorScripts-Enhanced'
337+ $result | Should - Be $expected
338+ Test-Path $configRoot | Should - BeTrue
333339 }
334- else {
335- $env: HOME = $OrigHomeEnv
340+ finally {
341+ Set-Variable - Name HOME - Scope Global - Force - Value $OrigHome
342+ if ($null -eq $OrigHomeEnv ) {
343+ Remove-Item Env:HOME - ErrorAction SilentlyContinue
344+ }
345+ else {
346+ $env: HOME = $OrigHomeEnv
347+ }
336348 }
337349 }
338350 }
351+ finally {
352+ if ($null -eq $originalXdg ) {
353+ Remove-Item Env:XDG_CONFIG_HOME - ErrorAction SilentlyContinue
354+ }
355+ else {
356+ $env: XDG_CONFIG_HOME = $originalXdg
357+ }
358+
359+ Set-Variable - Name IsWindows - Scope Global - Force - Value $originalWindows
360+ Set-Variable - Name IsMacOS - Scope Global - Force - Value $originalMac
361+ Set-Variable - Name IsLinux - Scope Global - Force - Value $originalLinux
362+ }
339363 }
340364
341365 It " throws when configuration directories cannot be prepared" {
@@ -526,34 +550,70 @@ Describe "ColorScripts-Enhanced internal coverage" {
526550
527551 It " falls back to temp directory when candidates fail" {
528552 # Clear all environment overrides so we test the fallback path
553+ $originalOverride = $env: COLOR_SCRIPTS_ENHANCED_CACHE_PATH
554+ $originalAppData = $env: APPDATA
555+ $originalWindows = $IsWindows
556+ $originalMac = $IsMacOS
557+ $originalLinux = $IsLinux
558+
529559 Remove-Item Env:COLOR_SCRIPTS_ENHANCED_CACHE_PATH - ErrorAction SilentlyContinue
530560 $env: APPDATA = $null
531561 Set-Variable - Name IsWindows - Scope Global - Force - Value $false
532562 Set-Variable - Name IsMacOS - Scope Global - Force - Value $false
533563 Set-Variable - Name IsLinux - Scope Global - Force - Value $true
534564
535- InModuleScope ColorScripts- Enhanced {
536- $script :CacheDir = $null
537- $script :CacheInitialized = $false
538- $script :ConfigurationInitialized = $false
539- $script :ConfigurationData = @ {
540- Cache = @ { Path = $null }
565+ try {
566+ InModuleScope ColorScripts- Enhanced {
567+ $script :CacheDir = $null
568+ $script :CacheInitialized = $false
569+ $script :ConfigurationInitialized = $false
570+ $script :ConfigurationData = @ {
571+ Cache = @ { Path = $null }
572+ }
573+
574+ # Mock to make all candidates fail to create directories
575+ Mock - CommandName Test-Path - ModuleName ColorScripts- Enhanced - MockWith { $false } - ParameterFilter {
576+ $LiteralPath -match ' cache|Cache|CACHE'
577+ }
578+ Mock - CommandName New-Item - ModuleName ColorScripts- Enhanced - MockWith {
579+ throw ' simulated failure'
580+ } - ParameterFilter {
581+ $Path -match ' cache|Cache|CACHE' -and $Path -notmatch ' Temp'
582+ }
583+
584+ Initialize-CacheDirectory
585+
586+ $expectedTempDir = Join-Path - Path ([System.IO.Path ]::GetTempPath()) - ChildPath ' ColorScripts-Enhanced'
587+ $expectedResolved = $expectedTempDir
588+ try {
589+ $expectedResolved = (Resolve-Path - LiteralPath $expectedTempDir - ErrorAction Stop).ProviderPath
590+ }
591+ catch {
592+ $expectedResolved = [System.IO.Path ]::GetFullPath($expectedTempDir )
593+ }
594+
595+ $script :CacheDir | Should - Be $expectedResolved
596+ $script :CacheInitialized | Should - BeTrue
597+ }
598+ }
599+ finally {
600+ if ($null -eq $originalOverride ) {
601+ Remove-Item Env:COLOR_SCRIPTS_ENHANCED_CACHE_PATH - ErrorAction SilentlyContinue
602+ }
603+ else {
604+ $env: COLOR_SCRIPTS_ENHANCED_CACHE_PATH = $originalOverride
541605 }
542606
543- # Mock to make all candidates fail to create directories
544- Mock - CommandName Test-Path - ModuleName ColorScripts- Enhanced - MockWith { $false } - ParameterFilter {
545- $LiteralPath -match ' cache|Cache|CACHE'
607+ if ($null -eq $originalAppData ) {
608+ Remove-Item Env:APPDATA - ErrorAction SilentlyContinue
546609 }
547- Mock - CommandName New-Item - ModuleName ColorScripts- Enhanced - MockWith {
548- throw ' simulated failure'
549- } - ParameterFilter {
550- $Path -match ' cache|Cache|CACHE' -and $Path -notmatch ' Temp'
610+ else {
611+ $env: APPDATA = $originalAppData
551612 }
552613
553- Initialize-CacheDirectory
554- $script :CacheDir | Should -Match ' ColorScripts-Enhanced'
555- $script :CacheDir | Should -Match ' Temp'
556- $script :CacheInitialized | Should - BeTrue
614+ Set-Variable - Name IsWindows - Scope Global - Force - Value $originalWindows
615+ Set-Variable - Name IsMacOS - Scope Global - Force - Value $originalMac
616+ Set-Variable - Name IsLinux - Scope Global - Force - Value $originalLinux
557617 }
558618 }
559619 }
@@ -602,11 +662,13 @@ Describe "ColorScripts-Enhanced internal coverage" {
602662 Context " Utility helpers" {
603663 It " evaluates text emission scenarios" {
604664 InModuleScope ColorScripts- Enhanced {
665+ $isRedirected = [Console ]::IsOutputRedirected
666+
605667 Test-ColorScriptTextEmission - ReturnText $true - PassThru $false - PipelineLength 0 - BoundParameters @ {} | Should - BeTrue
606- Test-ColorScriptTextEmission - ReturnText $false - PassThru $true - PipelineLength 0 - BoundParameters @ {} | Should - BeFalse
668+ Test-ColorScriptTextEmission - ReturnText $false - PassThru $true - PipelineLength 0 - BoundParameters @ {} | Should - Be $isRedirected
607669 Test-ColorScriptTextEmission - ReturnText $false - PassThru $false - PipelineLength 2 - BoundParameters @ {} | Should - BeTrue
608670 Test-ColorScriptTextEmission - ReturnText $false - PassThru $false - PipelineLength 1 - BoundParameters @ { OutVariable = ' ov' } | Should - BeTrue
609- Test-ColorScriptTextEmission - ReturnText $false - PassThru $false - PipelineLength 1 - BoundParameters @ {} | Should - BeFalse
671+ Test-ColorScriptTextEmission - ReturnText $false - PassThru $false - PipelineLength 1 - BoundParameters @ {} | Should - Be $isRedirected
610672 }
611673 }
612674
@@ -659,7 +721,7 @@ Describe "ColorScripts-Enhanced internal coverage" {
659721 InModuleScope ColorScripts- Enhanced {
660722 $matchers = New-NameMatcherSet - Patterns @ (' alpha*' , ' beta' )
661723 $matchers.Count | Should - Be 2
662- ($matchers | Where-Object IsWildcard).Count | Should - Be 1
724+ @ ($matchers | Where-Object { $_ . IsWildcard } ).Count | Should - Be 1
663725
664726 $records = @ (
665727 [pscustomobject ]@ { Name = ' alphaOne' ; Path = ' one' },
0 commit comments