mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Refactor base directory tests
This commit is contained in:
1 parent
a48c5281a5
commit
560bcaf736
2 files changed
+116
-112
No files matched your search
@@ -0,0 +1,116 @@
|
|||||||
|
Describe "Configuration file locations" {
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
|
||||||
|
$profileName = "Microsoft.PowerShell_profile.ps1"
|
||||||
|
}
|
||||||
|
|
||||||
|
Context "Default configuration file locations" {
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
|
||||||
|
if ($IsWindows) {
|
||||||
|
$expectedCache = [IO.Path]::Combine($env:LOCALAPPDATA, "Microsoft", "Windows", "PowerShell", "StartupProfileData-NonInteractive")
|
||||||
|
$expectedModule = [IO.Path]::Combine($env:USERPROFILE, "Documents", "WindowsPowerShell", "Modules")
|
||||||
|
$expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents","WindowsPowerShell",$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")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($env:TRAVIS_OS_NAME -eq "osx") {
|
||||||
|
$ItArgs = @{ pending = $true }
|
||||||
|
} else {
|
||||||
|
$ItArgs = @{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BeforeEach {
|
||||||
|
$original_PSMODULEPATH = $env:PSMODULEPATH
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterEach {
|
||||||
|
$env:PSMODULEPATH = $original_PSMODULEPATH
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Profile location should be correct" {
|
||||||
|
& $powershell -noprofile `$PROFILE | Should Be $expectedProfile
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "PSMODULEPATH should contain the correct path" {
|
||||||
|
$env:PSMODULEPATH = ""
|
||||||
|
$actual = & $powershell -noprofile `$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
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "JIT cache should be created correctly" {
|
||||||
|
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 }
|
||||||
|
} elseif ($env:TRAVIS_OS_NAME -eq "osx") {
|
||||||
|
$ItArgs = @{ pending = $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 `$PROFILE | Should Be $expected
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "PSMODULEPATH should respect XDG_DATA_HOME" {
|
||||||
|
$env:PSMODULEPATH = ""
|
||||||
|
$env:XDG_DATA_HOME = $TestDrive
|
||||||
|
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
|
||||||
|
$actual = & $powershell -noprofile `$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
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
Describe "XDG Base Directory Specification" {
|
|
||||||
|
|
||||||
BeforeAll {
|
|
||||||
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
|
|
||||||
$profileName = "Microsoft.PowerShell_profile.ps1"
|
|
||||||
}
|
|
||||||
|
|
||||||
BeforeEach {
|
|
||||||
$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:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME
|
|
||||||
$env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME
|
|
||||||
$env:XDG_DATA_HOME = $original_XDG_DATA_HOME
|
|
||||||
}
|
|
||||||
|
|
||||||
Context "Profile" {
|
|
||||||
|
|
||||||
It "Should not change Windows behavior" -Skip:($IsLinux -or $IsOSX) {
|
|
||||||
$expected = [IO.Path]::Combine($env:USERPROFILE, "Documents", "WindowsPowerShell", $profileName)
|
|
||||||
& $powershell -noprofile `$PROFILE | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should start with the default profile on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$expected = [IO.Path]::Combine($env:HOME, ".config", "powershell", $profileName)
|
|
||||||
& $powershell -noprofile `$PROFILE | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should respect XDG_CONFIG_HOME on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$env:XDG_CONFIG_HOME = $TestDrive
|
|
||||||
$expected = [IO.Path]::Combine($TestDrive, "powershell", $profileName)
|
|
||||||
& $powershell -noprofile `$PROFILE | Should Be $expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Context "Modules" {
|
|
||||||
|
|
||||||
It "Should not change Windows behavior" -Skip:($IsLinux -or $IsOSX) {
|
|
||||||
$expected = [IO.Path]::Combine($env:USERPROFILE, "Documents", "WindowsPowerShell", "Modules")
|
|
||||||
$actual = & $powershell -noprofile `$env:PSMODULEPATH
|
|
||||||
# Windows prepends the system path, so the user path is second
|
|
||||||
$actual.split(';')[1] | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should start with the default module path on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$env:PSMODULEPATH = "" # must not be sent to child process
|
|
||||||
$expected = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")
|
|
||||||
$actual = & $powershell -noprofile `$env:PSMODULEPATH
|
|
||||||
$actual.split(';')[0] | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should respect XDG_DATA_HOME on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$env:PSMODULEPATH = "" # must not be sent to child process
|
|
||||||
$env:XDG_DATA_HOME = $TestDrive
|
|
||||||
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
|
|
||||||
$actual = & $powershell -noprofile `$env:PSMODULEPATH
|
|
||||||
$actual.split(';')[0] | Should Be $expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Context "PSReadLine" {
|
|
||||||
|
|
||||||
It "Should not change Windows behavior" -Skip:($IsLinux -or $IsOSX) {
|
|
||||||
$expected = [IO.Path]::Combine($env:AppData, "Microsoft", "Windows", "PowerShell", "PSReadline", "ConsoleHost_history.txt")
|
|
||||||
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should start with the default history save path on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$expected = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
|
|
||||||
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should respect XDG_DATA_HOME on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$env:XDG_DATA_HOME = $TestDrive
|
|
||||||
$expected = [IO.Path]::Combine($TestDrive, "powershell", "PSReadLine", "ConsoleHost_history.txt")
|
|
||||||
& $powershell -noprofile { (Get-PSReadlineOption).HistorySavePath } | Should Be $expected
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Context "Cache" {
|
|
||||||
|
|
||||||
It "Should not change Windows behavior" -Skip:($IsLinux -or $IsOSX) {
|
|
||||||
$expected = [IO.Path]::Combine($env:LOCALAPPDATA, "Microsoft", "Windows", "PowerShell", "StartupProfileData-NonInteractive")
|
|
||||||
Remove-Item -ErrorAction SilentlyContinue $expected
|
|
||||||
& $powershell -noprofile { exit }
|
|
||||||
$expected | Should Exist
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should start with the default StartupProfileData on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$expected = [IO.Path]::Combine($env:HOME, ".cache", "powershell", "StartupProfileData-NonInteractive")
|
|
||||||
Remove-Item -ErrorAction SilentlyContinue $expected
|
|
||||||
& $powershell -noprofile { exit }
|
|
||||||
$expected | Should Exist
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should respect XDG_CACHE_HOME on Linux" -Skip:($IsWindows -or ($env:TRAVIS_OS_NAME -eq "osx")) {
|
|
||||||
$env:XDG_CACHE_HOME = $TestDrive
|
|
||||||
$expected = [IO.Path]::Combine($TestDrive, "powershell", "StartupProfileData-NonInteractive")
|
|
||||||
Remove-Item -ErrorAction SilentlyContinue $expected
|
|
||||||
& $powershell -noprofile { exit }
|
|
||||||
$expected | Should Exist
|
|
||||||
}
|
|
||||||
|
|
||||||
# The ModuleAnalysisCache cannot be forced to exist, thus we cannot test it
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user