diff --git a/.github/workflows/pwsh.yaml b/.github/workflows/pwsh.yaml index 89678f5e5d..87d161ed4b 100644 --- a/.github/workflows/pwsh.yaml +++ b/.github/workflows/pwsh.yaml @@ -12,7 +12,11 @@ jobs: test: name: Test Generated PowerShell Cmdlets - runs-on: windows-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/pwsh_module/command.tests.ps1 b/pwsh_module/command.tests.ps1 index 2240946730..430f60d0ff 100644 --- a/pwsh_module/command.tests.ps1 +++ b/pwsh_module/command.tests.ps1 @@ -191,7 +191,14 @@ Describe "test all bolt command examples" { It "bolt plan run canary --targets target1,target2 command=hostname" { Write-Warning 'requires params to not be positionl...is that a problem' $result = Invoke-BoltPlan -name 'canary' -targets 'target1,target2' -params @{ 'command' = 'hostname' } - $result | Should -Be "bolt plan run canary --targets target1,target2 --params '{`"command`":`"hostname`"}'" + # Linux platforms and windows platforms will format the param strings differently: + # on windows the format is wrapped in single qoutes with no backslash, while linux + # variants require backslash escaped quotes and no single quote wrapping + if ($IsWindows) { + $result | Should -Be "bolt plan run canary --targets target1,target2 --params '{`"command`":`"hostname`"}'" + } else { + $result | Should -Be "bolt plan run canary --targets target1,target2 --params {\`"command\`":\`"hostname\`"}" + } } It "bolt plan new myproject::myplan" { $result = New-BoltPlan -name 'myproject::myplan' @@ -274,11 +281,20 @@ Describe "test all bolt command examples" { $results | Should -Be "bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'" $results = Invoke-BoltTask -name 'package' -targets 'target1,target2' -params @{ 'name' = 'bash'; 'action' = 'status' } - # We don't care about the order of JSON keys, and they might become out - # of order due to ConvertToJson - $results | Should -BeIn @("bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'", - "bolt task run package --targets target1,target2 --params '{`"action`":`"status`",`"name`":`"bash`"}'") - + # Linux platforms and windows platforms will format the param strings differently: + # on windows the format is wrapped in single qoutes with no backslash, while linux + # variants require backslash escaped quotes and no single quote wrapping + if ($IsWindows) { + # We don't care about the order of JSON keys, and they might become out + # of order due to ConvertToJson + $results | Should -BeIn @("bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'", + "bolt task run package --targets target1,target2 --params '{`"action`":`"status`",`"name`":`"bash`"}'") + } else { + # We don't care about the order of JSON keys, and they might become out + # of order due to ConvertToJson + $results | Should -BeIn @("bolt task run package --targets target1,target2 --params {\`"name\`":\`"bash\`",\`"action\`":\`"status\`"}", + "bolt task run package --targets target1,target2 --params {\`"action\`":\`"status\`",\`"name\`":\`"bash\`"}") + } } It "bolt task show" { $results = Get-BoltTask diff --git a/pwsh_module/pwsh_bolt_internal.ps1 b/pwsh_module/pwsh_bolt_internal.ps1 index 2a4d20368c..88299fe352 100644 --- a/pwsh_module/pwsh_bolt_internal.ps1 +++ b/pwsh_module/pwsh_bolt_internal.ps1 @@ -42,7 +42,21 @@ function Get-BoltCommandline { Write-Verbose "Parsing $($kvp.key) as hashtable parameter" $v = ConvertTo-Json -InputObject $pwshValue -Compress $params += "--$($rubyParameter)" - $params += "'$($v)'" + # $IsLinux/IsMacOS are an automatic variables from powershellcore: + # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.1#islinux + $IsLinuxEnv = (Get-Variable -Name "IsLinux" -ErrorAction Ignore) -and $IsLinux + $IsMacOSEnv = (Get-Variable -Name "IsMacOS" -ErrorAction Ignore) -and $IsMacOS + $IsWinEnv = !$IsLinuxEnv -and !$IsMacOSEnv + if($IsWinEnv){ + $params += "'$($v)'" + } else { + # Commands run on Linux/Mac platforms will fail because the + # the interpolation of the command from powershell -> .NET -> Ruby + # will end up stripping out quotes that aren't baskslash-escaped. + # + # See https://github.com/MicrosoftDocs/PowerShell-Docs/issues/2361 + $params += $v -replace '"', '\"' + } } elseif ($pwshValue.GetType().Name -eq 'List`1') { Write-Verbose "Parsing $($kvp.key) as array parameter" diff --git a/testResults.xml b/testResults.xml new file mode 100644 index 0000000000..6b39e945ea --- /dev/null +++ b/testResults.xml @@ -0,0 +1,2172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Expected strings to be the same, but they were different. +Expected length: 80 +Actual length: 82 +Strings differ at index 56. +Expected: '...rams '{"co...' +But was: '...rams {\"co...' +at $result | Should -Be "bolt plan run canary --targets target1,target2 --params '{`"command`":`"hostname`"}'", /home/mcdonaldseanp/Workspace/orchestration/bolt/pwsh_module/command.tests.ps1:194 + at <ScriptBlock>, /home/mcdonaldseanp/Workspace/orchestration/bolt/pwsh_module/command.tests.ps1:194 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Expected collection @('bolt task run package --targets target1,target2 --params '{"name":"bash","action":"status"}'', 'bolt task run package --targets target1,target2 --params '{"action":"status","name":"bash"}'') to contain 'bolt task run package --targets target1,target2 --params {\"action\":\"status\",\"name\":\"bash\"}', but it was not found. +at $results | Should -BeIn @("bolt task run package --targets target1,target2 --params '{`"name`":`"bash`",`"action`":`"status`"}'",, /home/mcdonaldseanp/Workspace/orchestration/bolt/pwsh_module/command.tests.ps1:279 + at <ScriptBlock>, /home/mcdonaldseanp/Workspace/orchestration/bolt/pwsh_module/command.tests.ps1:279 + + + + + + + + + + + + + \ No newline at end of file