Skip to content
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

Use encodedCommand in Invoke-InNewProcress for P-tests #2267

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions tst/Pester.RSpec.InNewProcess.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function Invoke-InNewProcess ([ScriptBlock] $ScriptBlock) {
. $ScriptBlock
}.ToString()

# we need to escape " with \" because otherwise the " are eaten when the process we are starting recieves them
$cmd = "& { $command } -PesterPath ""$PesterPath"" -ScriptBlock { $($ScriptBlock -replace '"','\"') }"
& $powershell -NoProfile -ExecutionPolicy Bypass -Command $cmd
# using base64 because we need to escape quotes in $ScriptBlock and previous method using \" stopped working in PS7.3
$cmd = "& { $command } -PesterPath ""$PesterPath"" -ScriptBlock { $ScriptBlock }"
$encodedcommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($cmd))
& $powershell -NoProfile -ExecutionPolicy Bypass -encodedCommand $encodedcommand
}

i -PassThru:$PassThru {
Expand Down
9 changes: 4 additions & 5 deletions tst/Pester.RSpec.Output.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ function Invoke-InNewProcess ([ScriptBlock] $ScriptBlock) {
. $ScriptBlock
}.ToString()

# we need to escape " with \" because otherwise the " are eaten when the process we are starting recieves them
$cmd = "& { $command } -PesterPath ""$PesterPath"" -ScriptBlock { $($ScriptBlock -replace '"','\"') }"
& $powershell -NoProfile -ExecutionPolicy Bypass -Command $cmd
# using base64 because we need to escape quotes in $ScriptBlock and previous method using \" stopped working in PS7.3
$cmd = "& { $command } -PesterPath ""$PesterPath"" -ScriptBlock { $ScriptBlock }"
$encodedcommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($cmd))
& $powershell -NoProfile -ExecutionPolicy Bypass -encodedCommand $encodedcommand
}



i -PassThru:$PassThru {
b 'Output in VSCode mode' {
# VSCode-powershell Problem Matcher pattern
Expand Down