Update XDG BDS tests to specifications
This renames the tests and updates for better requirement specifications. The profile, modules, history, and startup cache data are tested for not breaking Windows behavior, new Linux behavior, and respecting set variables on launch. This also corrects some erroneous assumptions I had previously made. The ModuleAnalysisCache cannot be tested, and the startup cache data might not be testable on Windows.
This commit is contained in:
parent
caa4c3f163
commit
41c7f9e469
|
@ -1,62 +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) {
|
||||
# Assuming this is run outside the OPS host on Windows
|
||||
& $powershell -noprofile `$PROFILE | Should Be $PROFILE
|
||||
}
|
||||
|
||||
It "Should start with the default profile" -Skip:$IsWindows {
|
||||
$expected = [IO.Path]::Combine($env:HOME, "Documents", "WindowsPowerShell", $PROFILE)
|
||||
# Escape variable with backtick so new process interpolates it
|
||||
& $powershell -noprofile `$PROFILE | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should respect XDG_CONFIG_HOME" -Skip:$IsWindows {
|
||||
$env:XDG_CONFIG_HOME = [IO.Path]::Combine($pwd, "test", "path")
|
||||
# Escape variable with backtick so new process interpolates it
|
||||
$profileDir = [IO.Path]::Combine($env:XDG_CONFIG_HOME, "powershell", $profileName)
|
||||
& $powershell -noprofile `$PROFILE | Should Be $profileDir
|
||||
}
|
||||
}
|
||||
|
||||
Context "Modules" {
|
||||
|
||||
It "Should respect XDG_DATA_HOME" -Skip:$IsWindows {
|
||||
$env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "Modules")
|
||||
$modulepath = & $powershell -noprofile `$env:PSMODULEPATH
|
||||
$modulepath = $modulepath.split(';')[0]
|
||||
$modulepath | Should Be $env:XDG_DATA_HOME
|
||||
}
|
||||
|
||||
It "Should respect XDG_CACHE_HOME" -Skip:$IsWindows {
|
||||
$env:XDG_CACHE_HOME = [IO.Path]::Combine($pwd, "test", "path")
|
||||
$expected = [IO.Path]::Combine($HOME, "Powershell", "test", "path")
|
||||
& $powershell -noprofile `$env:XDG_CACHE_HOME | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should respect PSReadLine history" -Skip:$IsWindows {
|
||||
$env:XDG_DATA_HOME = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
|
||||
"a" | Should Be $expected
|
||||
}
|
||||
}
|
||||
}
|
112
test/powershell/XDGBDS.Tests.ps1
Normal file
112
test/powershell/XDGBDS.Tests.ps1
Normal file
|
@ -0,0 +1,112 @@
|
|||
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:HOME, "Documents", "WindowsPowerShell", $profileName)
|
||||
& $powershell -noprofile `$PROFILE | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should start with the default profile on Linux" -Skip:($IsWindows) {
|
||||
$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 {
|
||||
$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:HOME, "Documents", "WindowsPowerShell", "Modules")
|
||||
$actual = & $powershell -noprofile `$env:PSMODULEPATH
|
||||
$actual.split(';')[0] | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should start with the default module path on Linux" -Skip:$IsWindows {
|
||||
$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 {
|
||||
$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 {
|
||||
$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 {
|
||||
$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:HOME, "Documents", "WindowsPowerShell", "StartupProfileData-NonInteractive")
|
||||
Remove-Item -ErrorAction SilentlyContinue $expected
|
||||
& $powershell -noprofile { exit }
|
||||
$expected | Should Exist
|
||||
}
|
||||
|
||||
It "Should start with the default StartupProfileData on Linux" -Skip:$IsWindows {
|
||||
$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 {
|
||||
$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
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue