vexx32 / PSKoans

A simple, fun, and interactive way to learn the PowerShell language through Pester unit testing.
GNU General Public License v3.0
1.73k stars 176 forks source link

AboutCmdletVerbs: Use Join-Path for hardcoded / #427

Closed Maamue closed 3 years ago

Maamue commented 3 years ago

PR Summary

Change hardcoded forward slash / in filepath variable into os-dependent path separator with Join-Path

Context

$FilePath was declared "$env:TMP/YOUR_PATH.txt". This leads to an issue on Windows platforms on the last pester test requesting an error message. While Powershell itself treats both / and \ without any contempt, the error message expects backslashes for the path. Without Join-Path and its os dependant path separator, the test for the error message can't be fulfilled. The path it checks against is given as (shorthand)

AppData\Local\Temp/YOUR_PATH.txt

due to the koan hardcoding the forward slash into the variable. With Join-Path building the path, it gets resolved correctly as

AppData\Local\Temp\YOUR_PATH.txt

Changes

"$env:TMP/YOUR_PATH.txt" --> Join-Path -Path "$env:TMP" -ChildPath "YOUR_PATH.txt"

Checklist

indented-automation commented 3 years ago

@vexx32 should be using $TestDrive instead of $env:TMP?

Maamue commented 3 years ago

should be using $TestDrive instead of $env:TMP?

Changed to $TestDrive. I can change it back if necessary, but I agree that $TestDrive is to be preferred. We do not want to leave files behind on the filesystem.

vexx32 commented 3 years ago

Thanks for taking care of this! 💖