Skip to content
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

AboutCmdletVerbs.Koans.ps1 - Forward slash in $Filename results in wrong string comparison at the end #453

Open
DEberhardt opened this issue Aug 8, 2021 · 2 comments
Labels
Category-Koans Invoking the Great Doubt Issue-Bug 🐛 Something's wrong!

Comments

@DEberhardt
Copy link
Contributor

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...

@DEberhardt DEberhardt added Category-Koans Invoking the Great Doubt Issue-Discussion Let's talk about it! labels Aug 8, 2021
@vexx32
Copy link
Owner

vexx32 commented 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]::DirectorySeparatorChar to find the right char to use in this instance.

@vexx32 vexx32 added Issue-Bug 🐛 Something's wrong! and removed Issue-Discussion Let's talk about it! labels Aug 8, 2021
@paulhey
Copy link

paulhey commented Oct 28, 2023

An easy solution would be to change:

$FilePath = "$env:TMP/YOUR_PATH.txt"

to:

$FilePath = (Join-Path -Path $env:TMP -ChildPath 'YOUR_PATH.txt')

This seems to work correctly on PS7 and PS5.1 on Windows. On PS7 on Linux, I had to also define $env:TMP before running Show-Karma by using:

[Environment]::SetEnvironmentVariable('TMP','/tmp')

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category-Koans Invoking the Great Doubt Issue-Bug 🐛 Something's wrong!
Projects
None yet
Development

No branches or pull requests

3 participants