MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Configuration file locations" -tags "CI","Slow" {4 5 BeforeAll {6 $powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"7 $profileName = "Microsoft.PowerShell_profile.ps1"8 }9 10 Context "Default configuration file locations" {11 12 BeforeAll {13 14 if ($IsWindows) {15 $ProductName = "WindowsPowerShell"16 if ($IsCoreCLR -and ($PSHOME -notlike "*Windows\System32\WindowsPowerShell\v1.0"))17 {18 $ProductName = "PowerShell"19 }20 $expectedCache = [IO.Path]::Combine($env:LOCALAPPDATA, "Microsoft", "Windows", "PowerShell", "StartupProfileData-NonInteractive")21 $expectedModule = [IO.Path]::Combine($env:USERPROFILE, "Documents", $ProductName, "Modules")22 $expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents", $ProductName, $profileName)23 $expectedReadline = [IO.Path]::Combine($env:AppData, "Microsoft", "Windows", "PowerShell", "PSReadline", "ConsoleHost_history.txt")24 } else {25 $expectedCache = [IO.Path]::Combine($env:HOME, ".cache", "powershell", "StartupProfileData-NonInteractive")26 $expectedModule = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")27 $expectedProfile = [io.path]::Combine($env:HOME,".config","powershell",$profileName)28 $expectedReadline = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")29 }30 31 $ItArgs = @{}32 }33 34 BeforeEach {35 $original_PSModulePath = $env:PSModulePath36 }37 38 AfterEach {39 $env:PSModulePath = $original_PSModulePath40 }41 42 It @ItArgs "Profile location should be correct" {43 & $powershell -noprofile -c `$PROFILE | Should -Be $expectedProfile44 }45 46 It @ItArgs "PSModulePath should contain the correct path" {47 $env:PSModulePath = $null48 $actual = & $powershell -noprofile -c `$env:PSModulePath49 $actual | Should -Match ([regex]::Escape($expectedModule))50 }51 52 It @ItArgs "PSReadLine history save location should be correct" {53 & $powershell -noprofile { (Get-PSReadLineOption).HistorySavePath } | Should -Be $expectedReadline54 }55 56 # This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario57 It "JIT cache should be created correctly" -Skip {58 Remove-Item -ErrorAction SilentlyContinue $expectedCache59 & $powershell -noprofile { exit }60 $expectedCache | Should -Exist61 }62 63 # The ModuleAnalysisCache cannot be forced to exist, thus we cannot test it64 }65 66 Context "XDG Base Directory Specification is supported on Linux" {67 BeforeAll {68 # Using It @ItArgs, we automatically skip on Windows for all these tests69 if ($IsWindows) {70 $ItArgs = @{ skip = $true }71 } else {72 $ItArgs = @{}73 }74 }75 76 BeforeEach {77 $original_PSModulePath = $env:PSModulePath78 $original_XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME79 $original_XDG_CACHE_HOME = $env:XDG_CACHE_HOME80 $original_XDG_DATA_HOME = $env:XDG_DATA_HOME81 }82 83 AfterEach {84 $env:PSModulePath = $original_PSModulePath85 $env:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME86 $env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME87 $env:XDG_DATA_HOME = $original_XDG_DATA_HOME88 }89 90 It @ItArgs "Profile should respect XDG_CONFIG_HOME" {91 $env:XDG_CONFIG_HOME = $TestDrive92 $expected = [IO.Path]::Combine($TestDrive, "powershell", $profileName)93 & $powershell -noprofile -c `$PROFILE | Should -Be $expected94 }95 96 It @ItArgs "PSModulePath should respect XDG_DATA_HOME" {97 $env:PSModulePath = $null98 $env:XDG_DATA_HOME = $TestDrive99 $expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")100 $actual = & $powershell -noprofile -c `$env:PSModulePath101 $actual | Should -Match $expected102 }103 104 It @ItArgs "PSReadLine history should respect XDG_DATA_HOME" {105 $env:XDG_DATA_HOME = $TestDrive106 $expected = [IO.Path]::Combine($TestDrive, "powershell", "PSReadLine", "ConsoleHost_history.txt")107 & $powershell -noprofile { (Get-PSReadLineOption).HistorySavePath } | Should -Be $expected108 }109 110 # This feature (and thus test) has been disabled because of the AssemblyLoadContext scenario111 It -Skip "JIT cache should respect XDG_CACHE_HOME" {112 $env:XDG_CACHE_HOME = $TestDrive113 $expected = [IO.Path]::Combine($TestDrive, "powershell", "StartupProfileData-NonInteractive")114 Remove-Item -ErrorAction SilentlyContinue $expected115 & $powershell -noprofile { exit }116 $expected | Should -Exist117 }118 }119}120 121Describe "Working directory on startup" -Tag "CI" {122 BeforeAll {123 $powershell = Join-Path -Path $PSHOME -ChildPath "pwsh"124 $testPath = New-Item -ItemType Directory -Path "$TestDrive\test[dir]"125 $currentDirectory = Get-Location126 }127 128 AfterAll {129 Set-Location $currentDirectory130 }131 132 # https://github.com/PowerShell/PowerShell/issues/5752133 It "Can start in directory where name contains wildcard characters" -Pending {134 Set-Location -LiteralPath $testPath.FullName135 if ($IsMacOS) {136 # on macOS, /tmp is a symlink to /private so the real path is under /private/tmp137 $expectedPath = "/private" + $testPath.FullName138 } else {139 $expectedPath = $testPath.FullName140 }141 & $powershell -noprofile -c { $PWD.Path } | Should -BeExactly $expectedPath142 }143}144 