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

Prevent PowerShell 7.3 from breaking tests #951

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pwsh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
run: |
Import-Module Pester -PassThru
$ErrorActionPreference = 'Continue'

"Currently, PSNativeCommandArgumentPassing: '$PSNativeCommandArgumentPassing'"
"Forcing PowerShell 7.3 behavior with value: 'Standard'..."
$PSNativeCommandArgumentPassing = 'Standard'

$res = Invoke-Pester -Path test -Output Detailed -PassThru -ErrorAction SilentlyContinue
if (!$res -or ($res.FailedCount -gt 0)) {
$Error | Format-List * -Force
Expand Down
5 changes: 1 addition & 4 deletions test/GitParamTabExpansionVsts.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Describe 'ParamsTabExpansion VSTS Tests' {
# Create a git alias for 'pr', as if we'd installed vsts-cli
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$repoPath = NewGitTempRepo

# Test with non-standard vsts pr alias name
&$gitbin config alias.test-vsts-pr "!f() { exec vsts code pr \`"`$`@\`"; }; f"
$repoPath = NewGitTempRepo -WithAliasTestVstsPr
}
AfterEach {
RemoveGitTempRepo $repoPath
Expand Down
14 changes: 13 additions & 1 deletion test/Shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function MakeGitPath([string]$Path) {
$Path -replace '\\', '/'
}

function NewGitTempRepo([switch]$MakeInitialCommit) {
function NewGitTempRepo([switch]$MakeInitialCommit, [switch]$WithAliasTestVstsPr) {
Push-Location
$temp = [System.IO.Path]::GetTempPath()
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName())
Expand All @@ -142,6 +142,18 @@ function NewGitTempRepo([switch]$MakeInitialCommit) {
&$gitbin commit -m "initial commit." *>$null
}

if ($WithAliasTestVstsPr) {
# Test with non-standard vsts pr alias name
$value = "!f() { exec vsts code pr `"$@`"; }; f"

if (-not (Test-Path Variable:PSNativeCommandArgumentPassing) `
-or $PSNativeCommandArgumentPassing -eq 'Legacy') {
$value = $value.Replace("`"", "\`"")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've debated with oneself, if explicit version should be used here:

Suggested change
$value = $value.Replace("`"", "\`"")
$value = "!f() { exec vsts code pr \`"`$`@\`"; }; f"

}

&$gitbin config alias.test-vsts-pr $value
}

$repoPath
}

Expand Down
5 changes: 1 addition & 4 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ Describe 'TabExpansion Tests' {
Context 'Vsts' {
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$repoPath = NewGitTempRepo

# Test with non-standard vsts pr alias name
&$gitbin config alias.test-vsts-pr "!f() { exec vsts code pr \`"`$`@\`"; }; f"
$repoPath = NewGitTempRepo -WithAliasTestVstsPr
}
AfterEach {
RemoveGitTempRepo $repoPath
Expand Down