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

Temp: drive is not available in PowerShell 5.1 #433

Closed peetrike closed 3 years ago

peetrike commented 3 years ago

Describe "Koan Bug, Issue, or Help Request"

Show-Karma -Topic AboutpsProviders

with PowerShell 5.1 it gets following error:

Invoke-Koan : Cannot find drive. A drive with the name 'TEMP' does not exist.
At C:\Program Files\WindowsPowerShell\Modules\PSKoans\0.67.1\Public\Get-Karma.ps1:111 char:32
+                 $PesterTests = Invoke-Koan @{
+                                ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TEMP:String) [Invoke-Koan], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Invoke-Koan

Context "The Problematic Assertions"

https://github.com/vexx32/PSKoans/blob/c1ad5c98d63d0dbe02a50d4dd56d6a7fd5923810/PSKoans/Koans/Cmdlets%201/AboutPSProviders.Koans.ps1#L137 uses PSDrive TEMP: that is not defined in PowerShell 5.1.

Instead, it could use New-TemporaryFile cmdlet. That should work both in PowerShell 5.1 and 7.x

peetrike commented 3 years ago

Alternatively, the TEMP: PSDrive should be created, when not existing...

vexx32 commented 3 years ago

Ah, good catch. I think given the intention of the topic, checking for and creating the TEMP: drive if need be would be preferable.