File size: 6,045 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Configuration file locations" -tags "CI","Slow" {
BeforeAll {
$powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"
$profileName = "Microsoft.PowerShell_profile.ps1"
}
Context "Default configuration file locations" {
BeforeAll {
if ($IsWindows) {
$ProductName = "WindowsPowerShell"
if ($IsCoreCLR -and ($PSHOME -notlike "*Windows\System32\WindowsPowerShell\v1.0"))
{
$ProductName = "PowerShell"
}
$expectedCache = [IO.Path]::Combine($env:LOCALAPPDATA, "Microsoft", "Windows", "PowerShell", "StartupProfileData-NonInteractive")
$expectedModule = [IO.Path]::Combine($env:USERPROFILE, "Documents", $ProductName, "Modules")
$expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents", $ProductName, $profileName)
$expectedReadline = [IO.Path]::Combine($env:AppData, "Microsoft", "Windows", "PowerShell", "PSReadline", "ConsoleHost_history.txt")
} else {
$expectedCache = [IO.Path]::Combine($env:HOME, ".cache", "powershell", "StartupProfileData-NonInteractive")
$expectedModule = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")
$expectedProfile = [io.path]::Combine($env:HOME,".config","powershell",$profileName)
$expectedReadline = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
}
$ItArgs = @{}
}
BeforeEach {
$original_PSModulePath = $env:PSModulePath
}
AfterEach {
$env:PSModulePath = $original_PSModulePath
}
It @ItArgs "Profile location should be correct" {
& $powershell -noprofile -c `$PROFILE | Should -Be $expectedProfile
}
It @ItArgs "PSModulePath should contain the correct path" {
$env:PSModulePath = $null
$actual = & $powershell -noprofile -c `$env:PSModulePath
$actual | Should -Match ([regex]::Escape($expectedModule))
}
It @ItArgs "PSReadLine history save location should be correct" {
& $powershell -noprofile { (Get-PSReadLineOption).HistorySavePath } | Should -Be $expectedReadline
}
# This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario
It "JIT cache should be created correctly" -Skip {
Remove-Item -ErrorAction SilentlyContinue $expectedCache
& $powershell -noprofile { exit }
$expectedCache | Should -Exist
}
# The ModuleAnalysisCache cannot be forced to exist, thus we cannot test it
}
Context "XDG Base Directory Specification is supported on Linux" {
BeforeAll {
# Using It @ItArgs, we automatically skip on Windows for all these tests
if ($IsWindows) {
$ItArgs = @{ skip = $true }
} else {
$ItArgs = @{}
}
}
BeforeEach {
$original_PSModulePath = $env:PSModulePath
$original_XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME
$original_XDG_CACHE_HOME = $env:XDG_CACHE_HOME
$original_XDG_DATA_HOME = $env:XDG_DATA_HOME
}
AfterEach {
$env:PSModulePath = $original_PSModulePath
$env:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME
$env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME
$env:XDG_DATA_HOME = $original_XDG_DATA_HOME
}
It @ItArgs "Profile should respect XDG_CONFIG_HOME" {
$env:XDG_CONFIG_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", $profileName)
& $powershell -noprofile -c `$PROFILE | Should -Be $expected
}
It @ItArgs "PSModulePath should respect XDG_DATA_HOME" {
$env:PSModulePath = $null
$env:XDG_DATA_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
$actual = & $powershell -noprofile -c `$env:PSModulePath
$actual | Should -Match $expected
}
It @ItArgs "PSReadLine history should respect XDG_DATA_HOME" {
$env:XDG_DATA_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "PSReadLine", "ConsoleHost_history.txt")
& $powershell -noprofile { (Get-PSReadLineOption).HistorySavePath } | Should -Be $expected
}
# This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario
It -Skip "JIT cache should respect XDG_CACHE_HOME" {
$env:XDG_CACHE_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "StartupProfileData-NonInteractive")
Remove-Item -ErrorAction SilentlyContinue $expected
& $powershell -noprofile { exit }
$expected | Should -Exist
}
}
}
Describe "Working directory on startup" -Tag "CI" {
BeforeAll {
$powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"
$testPath = New-Item -ItemType Directory -Path "$TestDrive\test[dir]"
$currentDirectory = Get-Location
}
AfterAll {
Set-Location $currentDirectory
}
# https://github.com/PowerShell/PowerShell/issues/5752
It "Can start in directory where name contains wildcard characters" -Pending {
Set-Location -LiteralPath $testPath.FullName
if ($IsMacOS) {
# on macOS, /tmp is a symlink to /private so the real path is under /private/tmp
$expectedPath = "/private" + $testPath.FullName
} else {
$expectedPath = $testPath.FullName
}
& $powershell -noprofile -c { $PWD.Path } | Should -BeExactly $expectedPath
}
}
|