mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix preview build test failures
This commit is contained in:
+24
-13
@@ -10,18 +10,23 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||
$systemConfigPath = (Get-PowerShellConfiguration -Scope AllUsers).Path
|
||||
$userConfigPath = (Get-PowerShellConfiguration -Scope CurrentUser).Path
|
||||
|
||||
# The legacy $PSHOME config may exist (e.g., preview builds).
|
||||
# Back it up so tests start clean. Also track it separately because
|
||||
# writes go to the new platform location, not the legacy path.
|
||||
$legacyConfigPath = Join-Path $PSHOME "powershell.config.json"
|
||||
$legacyConfigExists = $false
|
||||
if (($legacyConfigPath -ne $systemConfigPath) -and (Test-Path $legacyConfigPath)) {
|
||||
$legacyConfigExists = $true
|
||||
Move-Item $legacyConfigPath "$legacyConfigPath.backup" -Force -ErrorAction SilentlyContinue
|
||||
# Enable/Disable-ExperimentalFeature always writes to the new platform
|
||||
# location via GetConfigFilePathForWrite(), even when the effective read
|
||||
# path (from Get-PowerShellConfiguration) points to legacy $PSHOME.
|
||||
# Track both so AfterEach can clean up writes that land at a different path.
|
||||
if ($IsWindows) {
|
||||
$systemWritePath = Join-Path $env:ProgramData "Microsoft\PowerShell\powershell.config.json"
|
||||
} else {
|
||||
$systemWritePath = "/etc/powershell/powershell.config.json"
|
||||
}
|
||||
|
||||
$systemWriteDir = Split-Path $systemWritePath
|
||||
if (!(Test-Path $systemWriteDir)) {
|
||||
$null = New-Item -ItemType Directory -Path $systemWriteDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemConfigDir = Split-Path $systemConfigPath
|
||||
if (!(Test-Path $systemConfigDir)) {
|
||||
if (($systemConfigDir -ne $systemWriteDir) -and !(Test-Path $systemConfigDir)) {
|
||||
$null = New-Item -ItemType Directory -Path $systemConfigDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
@@ -30,6 +35,12 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||
$null = New-Item -ItemType Directory -Path $userConfigDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemWriteExists = $false
|
||||
if (($systemWritePath -ne $systemConfigPath) -and (Test-Path $systemWritePath)) {
|
||||
$systemWriteExists = $true
|
||||
Move-Item $systemWritePath "$systemWritePath.backup" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemConfigExists = $false
|
||||
if (Test-Path $systemConfigPath) {
|
||||
$systemConfigExists = $true
|
||||
@@ -48,8 +59,8 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
if ($legacyConfigExists) {
|
||||
Move-Item "$legacyConfigPath.backup" $legacyConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($systemWriteExists) {
|
||||
Move-Item "$systemWritePath.backup" $systemWritePath -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($systemConfigExists) {
|
||||
@@ -66,8 +77,8 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag
|
||||
AfterEach {
|
||||
Remove-Item $systemConfigPath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($legacyConfigPath -ne $systemConfigPath) {
|
||||
Remove-Item $legacyConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($systemWritePath -ne $systemConfigPath) {
|
||||
Remove-Item $systemWritePath -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,19 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||
$systemConfigPath = (Get-PowerShellConfiguration -Scope AllUsers).Path
|
||||
$userConfigPath = (Get-PowerShellConfiguration -Scope CurrentUser).Path
|
||||
|
||||
$legacyConfigPath = Join-Path $PSHOME "powershell.config.json"
|
||||
$legacyConfigExists = $false
|
||||
if (($legacyConfigPath -ne $systemConfigPath) -and (Test-Path $legacyConfigPath)) {
|
||||
$legacyConfigExists = $true
|
||||
Move-Item $legacyConfigPath "$legacyConfigPath.backup" -Force -ErrorAction SilentlyContinue
|
||||
if ($IsWindows) {
|
||||
$systemWritePath = Join-Path $env:ProgramData "Microsoft\PowerShell\powershell.config.json"
|
||||
} else {
|
||||
$systemWritePath = "/etc/powershell/powershell.config.json"
|
||||
}
|
||||
|
||||
$systemWriteDir = Split-Path $systemWritePath
|
||||
if (!(Test-Path $systemWriteDir)) {
|
||||
$null = New-Item -ItemType Directory -Path $systemWriteDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemConfigDir = Split-Path $systemConfigPath
|
||||
if (!(Test-Path $systemConfigDir)) {
|
||||
if (($systemConfigDir -ne $systemWriteDir) -and !(Test-Path $systemConfigDir)) {
|
||||
$null = New-Item -ItemType Directory -Path $systemConfigDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
@@ -27,6 +31,12 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||
$null = New-Item -ItemType Directory -Path $userConfigDir -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemWriteExists = $false
|
||||
if (($systemWritePath -ne $systemConfigPath) -and (Test-Path $systemWritePath)) {
|
||||
$systemWriteExists = $true
|
||||
Move-Item $systemWritePath "$systemWritePath.backup" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
$systemConfigExists = $false
|
||||
if (Test-Path $systemConfigPath) {
|
||||
$systemConfigExists = $true
|
||||
@@ -46,8 +56,8 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
if ($legacyConfigExists) {
|
||||
Move-Item "$legacyConfigPath.backup" $legacyConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($systemWriteExists) {
|
||||
Move-Item "$systemWritePath.backup" $systemWritePath -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if ($systemConfigExists -and (Test-CanWriteToSystemConfigDir)) {
|
||||
@@ -67,8 +77,8 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows"
|
||||
}
|
||||
|
||||
Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($legacyConfigPath -ne $systemConfigPath) {
|
||||
Remove-Item $legacyConfigPath -Force -ErrorAction SilentlyContinue
|
||||
if ($systemWritePath -ne $systemConfigPath) {
|
||||
Remove-Item $systemWritePath -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user