8000 Throw terminating error in New-TemporaryFile and make it not rely on the presence of the 'TEMP' environment variable by bergmeister · Pull Request #6182 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Throw terminating error in New-TemporaryFile and make it not rely on the presence of the 'TEMP' environment variable #6182

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension < 8000 label class="SelectMenu-item" role="menuitem"> .ps1  (1)

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ public class NewTemporaryFileCommand : Cmdlet
protected override void EndProcessing()
{
string filePath = null;
string tempPath = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath = Path.GetTempPath();
if (ShouldProcess(tempPath))
{
try
{
filePath = Path.GetTempFileName();
}
catch (Exception e)
catch (IOException ioException)
{
WriteError(
ThrowTerminatingError(
new ErrorRecord(
e,
ioException,
"NewTemporaryFileWriteError",
ErrorCategory.WriteError,
tempPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
A FileInfo object for the temporary file is returned.
#>

Describe "NewTemporaryFile" -Tags "CI" {
Describe "New-TemporaryFile" -Tags "CI" {

It "creates a new temporary file" {
$tempFile = New-TemporaryFile

Test-Path $tempFile | Should be $true
$tempFile | Should Exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a black box testing point of view, it seems that we should check that the $tempFile path starts with the path returned from GetTempPath()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could... Would you be ok with this one:

$tempFile | Should BeLikeExactly "$([System.IO.Path]::GetTempPath())*"

$tempFile | Should BeOfType System.IO.FileInfo
$tempFile | Should BeLikeExactly "$([System.IO.Path]::GetTempPath())*"

if(Test-Path $tempFile)
{
if (Test-Path $tempFile) {
Remove-Item $tempFile -ErrorAction SilentlyContinue -Force
}
}
Expand Down
0