-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#3318) Add -WhatIf unit tests for helper commands
Update-SessionEnvironment, Set-EnvironmentVariable, and (Un)Install-ChocolateyPath implement ShouldProcess, so we can use -WhatIf to verify their behaviour with unit tests.
- Loading branch information
Showing
5 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function Get-WhatIfResult { | ||
<# | ||
.SYNOPSIS | ||
Runs a $Command in a new powershell.exe process, and then returns *only* | ||
the output lines that are prefixed with 'What if:' which are written as | ||
console output. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# The script to execute in the new process. | ||
[Parameter(Mandatory)] | ||
[scriptblock] | ||
$Command, | ||
|
||
# Any setup scripts that are required for running. All output from this | ||
# script block will be suppressed, if possible. | ||
[Parameter()] | ||
[scriptblock] | ||
$Preamble | ||
) | ||
|
||
$commandString = @' | ||
. {{ {0} }} *>&1 > $null | ||
& {{ {1} }} | ||
'@ -f $Preamble, $Command | ||
|
||
powershell -NoProfile -NonInteractive -Command $commandString | | ||
Where-Object { $_ -like "What if:*" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
tests/pester-tests/powershell-commands/Set-EnvironmentVariable.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters