Repository navigation
AboutCmdletVerbs.Koans.ps1 - Forward slash in $Filename results in wrong string comparison at the end #453
Copy link
Copy link
Closed
Labels
Category-KoansInvoking the Great DoubtInvoking the Great DoubtIssue-Bug 🐛Something's wrong!Something's wrong!status: stale
Description
Describe "Koan Bug, Issue, or Help Request"
minor typo...
AboutCmdletVerbs.Koans.ps1
Line 25: $FilePath = "$env:TMP/YOUR_PATH.txt"
This works to find the path all the way until the last assertion
Context "The Problematic Assertions"
$Message = "Cannot find path '$FilePath' because it does not exist."
{ Remove-Item -Path $FilePath -ErrorAction Stop } | Should -Throw -ExpectedMessage $Message
Context "Your Attempts"
The answers you seek...
Expected an exception, with message 'Cannot find path
'C:\Users\David\AppData\Local\Temp**/**YOUR_PATH.txt' because it does not exist.' to be
thrown, but the message was 'Cannot find path
'C:\Users\David\AppData\Local\Temp**\**YOUR_PATH.txt' because it does not exist.'. from
C:\Users\David\PSKoans\Introduction\AboutCmdletVerbs.Koans.ps1:286 char:15
+ { Remove-Item -Path $FilePath -ErrorAction Stop } | Shoul ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Context "Additional Information"
My local Environment:
PowerShell Module Paths
C:\Users\David\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PowerShell Version Table
Name Value
---- -----
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PowerShell Host
Name : ConsoleHost
Version : 5.1.19041.1023
InstanceId : 3d2266c5-f8cb-40e4-8275-45dd17603f04
UI : System.Management.Automation.Internal.Host.InternalHostUserInterfa
ce
CurrentCulture : en-GB
CurrentUICulture : en-GB
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Installed NET Frameworks
PSChildName Version Release
----------- ------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.04084 528372
Full 4.8.04084 528372
Client 4.0.0.0
Relevant Modules (installed)
❯ Get-Module Pester
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 4.10.1 Pester {Add-AssertionOperator, ...
❯ Get-Module Pester -ListAvailable
Directory: C:\Users\David\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 5.2.2 Pester {Invoke-Pester, Describe...
Script 5.2.1 Pester {Invoke-Pester, Describe...
Script 5.1.1 Pester {Invoke-Pester, Describe...
Script 4.10.1 Pester {Describe, Context, It, ...
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 3.4.0 Pester {Describe, Context, It, ...Changing Line 25 to $FilePath = "$env:TMP\YOUR_PATH.txt" works for me.
Is this intentional to highlight? I did not think so as it isn't described...
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Category-KoansInvoking the Great DoubtInvoking the Great DoubtIssue-Bug 🐛Something's wrong!Something's wrong!status: stale
Activity
vexx32 commentedon Aug 8, 2021
Hmm. That'll be tricky, it'll break for folks on non-Windows OSes if we change that to be
\for everyone. I suppose we should change this to use[IO.Path]::DirectorySeparatorCharto find the right char to use in this instance.paulhey commentedon Oct 28, 2023
An easy solution would be to change:
to:
This seems to work correctly on PS7 and PS5.1 on Windows. On PS7 on Linux, I had to also define
$env:TMPbefore runningShow-Karmaby using:as it doesn't seem to be defined by default in my installation and I was getting errors like
Access to the path '/YOUR_PATH.txt' is denied..github-actions commentedon Sep 20, 2026
This issue has had no activity for 60 days. It will be closed in 30 days unless there is new activity or a maintainer removes the stale label.
HeyItsGilbert commentedon Sep 21, 2026
Fixed:
AboutCmdletVerbs.Koans.ps1now builds$FilePathwithJoin-Path -Path $TestDrive -ChildPath "YOUR_PATH.txt"inside aBeforeAllblock instead of"$env:TMP/YOUR_PATH.txt". This uses Pester's$TestDriveand the platform-correct separator viaJoin-Path, so the forward-slash vs backslash mismatch in the -ExpectedMessage comparison no longer occurs. Closing.