Skip to content

Commit

Permalink
(chocolateyGH-501) Fix Propagation of VerbosePreference (chocolatey#512)
Browse files Browse the repository at this point in the history
The VerbosePreference parameter was not being set
correctly for new choco.exe processes as well as
when exporting environment variables.
  • Loading branch information
MalwareMechanic authored Aug 27, 2022
1 parent 9b5c0a0 commit f3634ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Boxstarter.Chocolatey/Chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ function Export-BoxstarterVars {

function Export-ToEnvironment($varToExport, $scope) {
$val = Invoke-Expression "`$$($scope):$varToExport"
if ($val -is [string] -or $val -is [boolean]) {
if ($val -is [string] -or $val -is [boolean] -or $val -is [system.management.automation.actionpreference]) {
Set-Item -Path "Env:\BEX.$varToExport" -Value $val.ToString() -Force
}
elseif ($null -eq $val) {
Expand Down
2 changes: 1 addition & 1 deletion Boxstarter.Chocolatey/invoke-chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Invoke-Chocolatey($chocoArgs) {
UseNewEnvironment = $false
Wait = $false
WorkingDirectory = $targetWdir
Verbose = $VerbosePreference
Verbose = ($global:VerbosePreference -eq "Continue")
}

$p = Start-Process @pargs
Expand Down
17 changes: 17 additions & 0 deletions tests/Chocolatey/Chocolatey.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,23 @@ Describe "Call-Chocolatey" {
}
}

context "when not verbose" {
$script:passedArgs = ""
Mock Invoke-LocalChocolatey { $script:passedArgs = $chocoArgs }
$global:VerbosePreference="SilentlyContinue"
choco Install pkg
$global:VerbosePreference | Should Be "SilentlyContinue"

it "passes expected params" {
$passedArgs.count | Should Be 5
$passedArgs[0] | Should Be "Install"
$passedArgs[1] | Should Be "pkg"
$passedArgs[2] | Should Be "-Source"
# $passedArgs[3] -> feeds, may differ from system to system
$passedArgs[4] | Should Be "-y"
}
}

context "when verbose" {
$script:passedArgs = ""
Mock Invoke-LocalChocolatey { $script:passedArgs = $chocoArgs }
Expand Down

0 comments on commit f3634ce

Please sign in to comment.