Merge pull request #1554 from PowerShell/vors/env
Make Get-Item env: case-aware on Unix
This commit is contained in:
commit
d691712c01
|
@ -190,8 +190,15 @@ namespace Microsoft.PowerShell.Commands
|
||||||
///
|
///
|
||||||
internal override IDictionary GetSessionStateTable ()
|
internal override IDictionary GetSessionStateTable ()
|
||||||
{
|
{
|
||||||
|
// Environment variables are case-sensitive on Unix and
|
||||||
|
// case-insensitive on Windows
|
||||||
|
#if UNIX
|
||||||
|
Dictionary<string, DictionaryEntry> providerTable =
|
||||||
|
new Dictionary<string, DictionaryEntry>(StringComparer.Ordinal);
|
||||||
|
#else
|
||||||
Dictionary<string, DictionaryEntry> providerTable =
|
Dictionary<string, DictionaryEntry> providerTable =
|
||||||
new Dictionary<string, DictionaryEntry>(StringComparer.OrdinalIgnoreCase);
|
new Dictionary<string, DictionaryEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
#endif
|
||||||
|
|
||||||
// The environment variables returns a dictionary of keys and values that are
|
// The environment variables returns a dictionary of keys and values that are
|
||||||
// both strings. We want to return a dictionary with the key as a string and
|
// both strings. We want to return a dictionary with the key as a string and
|
||||||
|
|
|
@ -1,36 +1,59 @@
|
||||||
Describe "Get-ChildItem" -Tags "CI" {
|
Describe "Get-ChildItem" -Tags "CI" {
|
||||||
It "Should list the contents of the current folder" {
|
|
||||||
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
Context 'FileSystem provider' {
|
||||||
|
|
||||||
|
It "Should list the contents of the current folder" {
|
||||||
|
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should list the contents of the home directory" {
|
||||||
|
pushd $HOME
|
||||||
|
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should have a the proper fields and be populated" {
|
||||||
|
$var = Get-Childitem .
|
||||||
|
|
||||||
|
$var.Name.Length | Should BeGreaterThan 0
|
||||||
|
$var.Mode.Length | Should BeGreaterThan 0
|
||||||
|
$var.LastWriteTime | Should BeGreaterThan 0
|
||||||
|
$var.Length.Length | Should BeGreaterThan 0
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should list files in sorted order" {
|
||||||
|
New-Item -Path $TestDrive -Name "a" -ItemType "File" -Force
|
||||||
|
New-Item -Path $TestDrive -Name "B" -ItemType "File" -Force
|
||||||
|
New-Item -Path $TestDrive -Name "c" -ItemType "File" -Force
|
||||||
|
New-Item -Path $TestDrive -Name "D" -ItemType "File" -Force
|
||||||
|
New-Item -Path $TestDrive -Name "E" -ItemType "Directory" -Force
|
||||||
|
|
||||||
|
$files = Get-ChildItem -Path $TestDrive
|
||||||
|
$files[0].Name | Should Be "E"
|
||||||
|
$files[1].Name | Should Be "a"
|
||||||
|
$files[2].Name | Should Be "B"
|
||||||
|
$files[3].Name | Should Be "c"
|
||||||
|
$files[4].Name | Should Be "D"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should list the contents of the home directory" {
|
Context 'Env: Provider' {
|
||||||
pushd $HOME
|
|
||||||
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Should have a the proper fields and be populated" {
|
It 'can handle mixed case in Env variables' {
|
||||||
$var = Get-Childitem .
|
try
|
||||||
|
{
|
||||||
|
$env:__FOOBAR = 'foo'
|
||||||
|
$env:__foobar = 'bar'
|
||||||
|
|
||||||
$var.Name.Length | Should BeGreaterThan 0
|
$foobar = Get-Childitem env: | ? {$_.Name -eq '__foobar'}
|
||||||
$var.Mode.Length | Should BeGreaterThan 0
|
$count = if ($IsWindows) { 1 } else { 2 }
|
||||||
$var.LastWriteTime | Should BeGreaterThan 0
|
($foobar | measure).Count | Should Be $count
|
||||||
$var.Length.Length | Should BeGreaterThan 0
|
}
|
||||||
|
catch
|
||||||
}
|
{
|
||||||
|
Get-ChildItem env: | ? {$_.Name -eq '__foobar'} | Remove-Item -ErrorAction SilentlyContinue
|
||||||
It "Should list files in sorted order" {
|
}
|
||||||
New-Item -Path $TestDrive -Name "a" -ItemType "File" -Force
|
}
|
||||||
New-Item -Path $TestDrive -Name "B" -ItemType "File" -Force
|
|
||||||
New-Item -Path $TestDrive -Name "c" -ItemType "File" -Force
|
|
||||||
New-Item -Path $TestDrive -Name "D" -ItemType "File" -Force
|
|
||||||
New-Item -Path $TestDrive -Name "E" -ItemType "Directory" -Force
|
|
||||||
|
|
||||||
$files = Get-ChildItem -Path $TestDrive
|
|
||||||
$files[0].Name | Should Be "E"
|
|
||||||
$files[1].Name | Should Be "a"
|
|
||||||
$files[2].Name | Should Be "B"
|
|
||||||
$files[3].Name | Should Be "c"
|
|
||||||
$files[4].Name | Should Be "D"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue