Skip to content

Commit e95f7fb

Browse files
Test fixes for stabilizing tests (#19068)
1 parent 01e7b92 commit e95f7fb

19 files changed

Lines changed: 305 additions & 62 deletions

build.psm1

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,17 +1118,6 @@ function Publish-CustomConnectionTestModule
11181118
$sourcePath = "${PSScriptRoot}/test/tools/NamedPipeConnection"
11191119
$outPath = "${PSScriptRoot}/test/tools/NamedPipeConnection/out/Microsoft.PowerShell.NamedPipeConnection"
11201120
$publishPath = "${PSScriptRoot}/test/tools/Modules"
1121-
$refPath = "${sourcePath}/src/code/Ref"
1122-
1123-
# Copy the current SMA build to the refPath.
1124-
$smaPath = Join-Path -Path (Split-Path -Path (Get-PSOutput)) -ChildPath 'System.Management.Automation.dll'
1125-
if (! (Test-Path -Path $smaPath)) {
1126-
throw "Publish-CustomConnectionTestModule: Cannot find reference SMA at: ${smaPath}"
1127-
}
1128-
if (! (Test-Path -Path $refPath)) {
1129-
$null = New-Item -Path $refPath -ItemType Directory -Force
1130-
}
1131-
Copy-Item -Path $smapath -Destination $refPath -Force
11321121

11331122
Find-DotNet
11341123

@@ -1146,7 +1135,6 @@ function Publish-CustomConnectionTestModule
11461135

11471136
# Clean up build artifacts
11481137
./build.ps1 -Clean
1149-
Remove-Item -Path $refPath -Recurse -Force -ErrorAction SilentlyContinue
11501138
}
11511139
finally {
11521140
Pop-Location
@@ -1219,6 +1207,9 @@ function Publish-PSTestTools {
12191207

12201208
# `dotnet restore` on test project is not called if product projects have been restored unless -Force is specified.
12211209
Copy-PSGalleryModules -Destination "${PSScriptRoot}/test/tools/Modules" -CsProjPath "$PSScriptRoot/test/tools/Modules/PSGalleryTestModules.csproj" -Force
1210+
1211+
# Publish the Microsoft.PowerShell.NamedPipeConnection module
1212+
Publish-CustomConnectionTestModule
12221213
}
12231214

12241215
function Get-ExperimentalFeatureTests {

experimental-feature-linux.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"PSNativeCommandErrorActionPreference",
66
"PSSubsystemPluginModel",
77
"PSModuleAutoLoadSkipOfflineFiles",
8-
"PSFeedbackProvider"
8+
"PSFeedbackProvider",
9+
"PSCommandWithArgs"
910
]

experimental-feature-windows.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"PSNativeCommandErrorActionPreference",
66
"PSSubsystemPluginModel",
77
"PSModuleAutoLoadSkipOfflineFiles",
8-
"PSFeedbackProvider"
8+
"PSFeedbackProvider",
9+
"PSCommandWithArgs"
910
]

test/powershell/Host/HostUtilities.Tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Describe "InvokeOnRunspace method as nested command" -tags "Feature" {
3535
Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAdminOnWindows" {
3636

3737
BeforeAll {
38+
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
39+
40+
if (Test-IsWinWow64) {
41+
$global:PSDefaultParameterValues["it:skip"] = $true
42+
return
43+
}
3844

3945
if ($IsWindows) {
4046
$script:remoteRunspace = New-RemoteRunspace
@@ -46,6 +52,8 @@ Describe "InvokeOnRunspace method on remote runspace" -tags "Feature","RequireAd
4652
{
4753
$script:remoteRunspace.Dispose();
4854
}
55+
56+
$global:PSDefaultParameterValues = $originalDefaultParameterValues
4957
}
5058

5159
It "Method should successfully invoke command on remote runspace" -Skip:(!$IsWindows) {

test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,16 @@ using `
541541
It 'Should show multiple constructors in the tooltip' {
542542
$res = TabExpansion2 -inputScript 'class ConstructorTestClass{ConstructorTestClass ([string] $s){}ConstructorTestClass ([int] $i){}ConstructorTestClass ([int] $i, [bool]$b){}};[ConstructorTestClass]::new'
543543
$res.CompletionMatches | Should -HaveCount 1
544-
$completionText = $res.CompletionMatches.ToolTip | Should -BeExactly @'
544+
$completionText = $res.CompletionMatches.ToolTip
545+
$completionText.replace("`r`n", [System.Environment]::NewLine).trim()
546+
547+
$expected = @'
545548
ConstructorTestClass(string s)
546549
ConstructorTestClass(int i)
547550
ConstructorTestClass(int i, bool b)
548551
'@
552+
$expected.replace("`r`n", [System.Environment]::NewLine).trim()
553+
$completionText.replace("`r`n", [System.Environment]::NewLine).trim() | Should -BeExactly $expected
549554
}
550555

551556
It 'Should complete parameter in param block' {
@@ -1229,12 +1234,8 @@ class InheritedClassTest : System.Attribute
12291234
}
12301235

12311236
It "Tab completion UNC path" -Skip:(!$IsWindows) {
1232-
if (!$env:HOMEDRIVE) {
1233-
Set-ItResult -Skipped -Because "Homerdrive is not set"
1234-
}
1235-
$homeDrive = $env:HOMEDRIVE.Replace(":", "$")
1236-
$beforeTab = "\\localhost\$homeDrive\wind"
1237-
$afterTab = "& '\\localhost\$homeDrive\Windows'"
1237+
$beforeTab = "\\localhost\ADMIN$\boo"
1238+
$afterTab = "& '\\localhost\ADMIN$\Boot'"
12381239
$res = TabExpansion2 -inputScript $beforeTab -cursorColumn $beforeTab.Length
12391240
$res.CompletionMatches.Count | Should -BeGreaterThan 0
12401241
$res.CompletionMatches[0].CompletionText | Should -BeExactly $afterTab
@@ -2101,7 +2102,7 @@ dir -Recurse `
21012102

21022103
Context "Tab completion help test" {
21032104
BeforeAll {
2104-
if ([System.Management.Automation.Platform]::IsWindows) {
2105+
if ($IsWindows) {
21052106
$userHelpRoot = Join-Path $HOME "Documents/PowerShell/Help/"
21062107
} else {
21072108
$userModulesRoot = [System.Management.Automation.Platform]::SelectProductNameForDirectory([System.Management.Automation.Platform+XDG_Type]::USER_MODULES)
@@ -2110,33 +2111,89 @@ dir -Recurse `
21102111
}
21112112

21122113
It 'Should complete about help topic' {
2113-
$aboutHelpPathUserScope = Join-Path $userHelpRoot (Get-Culture).Name
2114-
$aboutHelpPathAllUsersScope = Join-Path $PSHOME (Get-Culture).Name
2114+
$helpName = "about_Splatting"
2115+
$helpFileName = "${helpName}.help.txt"
2116+
$inputScript = "get-help about_spla"
2117+
$culture = "en-US"
2118+
$aboutHelpPathUserScope = Join-Path $userHelpRoot $culture
2119+
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $culture
2120+
$expectedCompletionCount = 0
21152121

21162122
## If help content does not exist, tab completion will not work. So update it first.
2117-
$userScopeHelp = Test-Path (Join-Path $aboutHelpPathUserScope "about_Splatting.help.txt")
2118-
$allUserScopeHelp = Test-Path (Join-Path $aboutHelpPathAllUsersScope "about_Splatting.help.txt")
2119-
if ((-not $userScopeHelp) -and (-not $aboutHelpPathAllUsersScope)) {
2123+
$userHelpPath = Join-Path $aboutHelpPathUserScope $helpFileName
2124+
$userScopeHelp = Test-Path $userHelpPath
2125+
if ($userScopeHelp) {
2126+
$expectedCompletionCount++
2127+
} else {
21202128
Update-Help -Force -ErrorAction SilentlyContinue -Scope 'CurrentUser'
2129+
if (Test-Path $userHelpPath) {
2130+
$expectedCompletionCount++
2131+
}
21212132
}
21222133

2123-
# If help content is present on both scopes, expect 2 or else expect 1 completion.
2124-
$expectedCompletions = if ($userScopeHelp -and $allUserScopeHelp) { 2 } else { 1 }
2134+
$allUserScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersScope $helpFileName)
2135+
if ($allUserScopeHelpPath) {
2136+
$expectedCompletionCount++
2137+
}
21252138

2126-
$res = TabExpansion2 -inputScript 'get-help about_spla' -cursorColumn 'get-help about_spla'.Length
2127-
$res.CompletionMatches | Should -HaveCount $expectedCompletions
2128-
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'about_Splatting'
2139+
$res = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length
2140+
$res.CompletionMatches | Should -HaveCount $expectedCompletionCount
2141+
$res.CompletionMatches[0].CompletionText | Should -BeExactly $helpName
21292142
}
2143+
21302144
It 'Should complete about help topic regardless of culture' {
21312145
try
21322146
{
21332147
## Save original culture and temporarily set it to da-DK because there's no localized help for da-DK.
21342148
$OriginalCulture = [cultureinfo]::CurrentCulture
2135-
[cultureinfo]::CurrentCulture="da-DK"
2149+
$defaultCulture = "en-US"
2150+
$culture = "da-DK"
2151+
[cultureinfo]::CurrentCulture = $culture
2152+
$helpName = "about_Splatting"
2153+
$helpFileName = "${helpName}.help.txt"
2154+
2155+
$aboutHelpPathUserScope = Join-Path $userHelpRoot $culture
2156+
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $culture
2157+
$expectedCompletionCount = 0
2158+
2159+
## If help content does not exist, tab completion will not work. So update it first.
2160+
$userHelpPath = Join-Path $aboutHelpPathUserScope $helpFileName
2161+
$userScopeHelp = Test-Path $userHelpPath
2162+
if ($userScopeHelp) {
2163+
$expectedCompletionCount++
2164+
}
2165+
else { Update-Help -Force -ErrorAction SilentlyContinue -Scope 'CurrentUser'
2166+
if (Test-Path $userHelpPath) {
2167+
$expectedCompletionCount++
2168+
}
2169+
else {
2170+
$aboutHelpPathUserScope = Join-Path $userHelpRoot $defaultCulture
2171+
$aboutHelpPathAllUsersScope = Join-Path $PSHOME $defaultCulture
2172+
$userHelpDefaultPath = Join-Path $aboutHelpPathUserScope $helpFileName
2173+
$userDefaultScopeHelp = Test-Path $userHelpDefaultPath
2174+
2175+
if ($userDefaultScopeHelp) {
2176+
$expectedCompletionCount++
2177+
}
2178+
}
2179+
}
2180+
2181+
$allUserScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersScope $helpFileName)
2182+
if ($allUserScopeHelpPath) {
2183+
$expectedCompletionCount++
2184+
}
2185+
else {
2186+
$aboutHelpPathAllUsersDefaultScope = Join-Path $PSHOME $defaultCulture
2187+
$allUsersDefaultScopeHelpPath = Test-Path (Join-Path $aboutHelpPathAllUsersDefaultScope $helpFileName)
2188+
2189+
if ($allUsersDefaultScopeHelpPath) {
2190+
$expectedCompletionCount++
2191+
}
2192+
}
21362193

21372194
$res = TabExpansion2 -inputScript 'get-help about_spla' -cursorColumn 'get-help about_spla'.Length
2138-
$res.CompletionMatches | Should -HaveCount 1
2139-
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'about_Splatting'
2195+
$res.CompletionMatches | Should -HaveCount $expectedCompletionCount
2196+
$res.CompletionMatches[0].CompletionText | Should -BeExactly $helpName
21402197
}
21412198
finally
21422199
{
@@ -2351,7 +2408,7 @@ function MyFunction ($param1, $param2)
23512408

23522409
Describe "Tab completion tests with remote Runspace" -Tags Feature,RequireAdminOnWindows {
23532410
BeforeAll {
2354-
if ($IsWindows) {
2411+
if ($IsWindows -and -not (Test-IsWinWow64)) {
23552412
$session = New-RemoteSession
23562413
$powershell = [powershell]::Create()
23572414
$powershell.Runspace = $session.Runspace

test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ Describe "Run native command from a mounted FAT-format VHD" -tags @("Feature", "
312312
if (-not $IsWindows) {
313313
return;
314314
}
315+
else {
316+
$storageModule = Get-Module -Name 'Storage' -ListAvailable -ErrorAction SilentlyContinue
317+
318+
if (-not $storageModule) {
319+
Write-Verbose -Verbose "Storage module is not available."
320+
return;
321+
}
322+
}
315323

316324
$vhdx = Join-Path -Path $TestDrive -ChildPath ncp.vhdx
317325

@@ -335,11 +343,18 @@ Describe "Run native command from a mounted FAT-format VHD" -tags @("Feature", "
335343
diskpart.exe /s $create_vhdx
336344
Mount-DiskImage -ImagePath $vhdx > $null
337345

338-
Copy-Item "$env:WinDir\System32\whoami.exe" T:\whoami.exe
346+
Copy-Item "$env:WinDir\System32\whoami.exe" "T:\whoami.exe"
339347
}
340348

341349
AfterAll {
342350
if ($IsWindows) {
351+
$storageModule = Get-Module -Name 'Storage' -ListAvailable -ErrorAction SilentlyContinue
352+
353+
if (-not $storageModule) {
354+
Write-Verbose -Verbose "Storage module is not available."
355+
return;
356+
}
357+
343358
Dismount-DiskImage -ImagePath $vhdx
344359
Remove-Item $vhdx, $create_vhdx -Force
345360
}

test/powershell/Modules/Microsoft.PowerShell.Core/RemoteGetModule.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {
44

55
BeforeAll {
66

7-
if (!$IsWindows)
7+
if (!$IsWindows -or (Test-IsWinWow64))
88
{
99
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
1010
$PSDefaultParameterValues["it:skip"] = $true

test/powershell/Modules/Microsoft.PowerShell.Core/RemoteImportModule.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' {
55
BeforeAll {
66
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
77
$modulePath = "$testdrive\Modules\TestImport"
8-
if (!$IsWindows) {
8+
if (!$IsWindows -or (Test-IsWinWow64)) {
99
$PSDefaultParameterValues["it:skip"] = $true
1010
} else {
1111
$pssession = New-RemoteSession

0 commit comments

Comments
 (0)