troubleshooting chocolatey/boxstarter#405
function choco {
<#
.SYNOPSIS
Intercepts Chocolatey call to check for reboots
#>
param(
[string]$command,
[string[]]$packageNames=@('')
)
Write-BoxstarterMessage "'choco' wrapper: command: '$command' packageNames: $($packageNames | % { "$($_); " })" -Verbose
Write-BoxstarterMessage "'choco' wrapper: PSBoundParameters: $($PSBoundParameters.Keys | % { "$($_) = $($PSBoundParameters[$_]); " })" -Verbose
Write-BoxstarterMessage "'choco' wrapper: args: $($args | % { "$($_); " })" -Verbose
chocolatey @PSBoundParameters @args
}
I created an additional unit-test in Chocolatey.tests.p1 to check if parameters are passed in the correct order ..
Describe "Call-Chocolatey" {
Mock Invoke-Reboot
Mock Test-PendingReboot {return $false}
context "package parameters" {
$script:passedArgs = ""
$global:VerbosePreference="Continue"
Mock Invoke-LocalChocolatey { $script:passedArgs = $chocoArgs }
choco Install -y pkg --source blah --installargs "ADD_CMAKE_TO_PATH=System"
$passedArgs | Should Be $null
it "passes expected params" {
$passedArgs.count | Should Be 8 # actually 7 + 1 "-y" is always appended
}
it "passes all parameters in correct order" {
$passedArgs[0] | Should Be "Install"
$passedArgs[1] | Should Be "-y"
$passedArgs[2] | Should Be "pkg"
$passedArgs[3] | Should Be "--source"
$passedArgs[4] | Should Be "blah"
$passedArgs[5] | Should Be "--installargs"
$passedArgs[6] | Should Be "ADD_CMAKE_TO_PATH=System"
$passedArgs[7] | Should Be "-y" # mw: why?
}
}
}
I would expect the parameters to be passed in the correct order, but somehow --source
gets bound as packageNames
here is the output of the unittest:
Context package parameters
AUSFÜHRLICH: Boxstarter: 'choco' wrapper: command: 'Install' packageNames: --source;
AUSFÜHRLICH: Boxstarter: 'choco' wrapper: PSBoundParameters: command = Install; packageNames = --source;
AUSFÜHRLICH: Boxstarter: 'choco' wrapper: args: -y; pkg; blah; --installargs; ADD_CMAKE_TO_PATH=System;
...
AUSFÜHRLICH: Boxstarter: Passing the following args to Chocolatey: Install --source -y pkg blah --installargs ADD_CMAKE_TO_PATH=System -Verbose -y
how come the parameter order is swapped when function 'choco' is being called?