From 7d9f43966690aa69fea1735af24106858ee4199a Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 7 Apr 2016 16:05:06 -0700 Subject: [PATCH 1/4] Remove conflicting aliases for Linux and OS X The aliases which conflict with Linux native commands were consolidated and removed with the pre-processor definition `LINUX`. Additionally, several "conflicts" are purposefully kept and likewise consolidated. They are kept because Bash itself stomps on the native commands with its own built-ins, and so we're adopting the same behavior. The `clear` and `more` aliases are edge cases where the functions they call are already fixed for Linux, and so we keep these too. Resolves #567. --- .../engine/InitialSessionState.cs | 107 ++++++++++-------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 4e853cbb22..814079e346 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5121,8 +5121,6 @@ end "Where-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("?", "Where-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("ac", - "Add-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("clc", "Clear-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("cli", @@ -5131,26 +5129,18 @@ end "Clear-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("clv", "Clear-Variable", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("compare", - "Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("cpi", "Copy-Item", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("cpp", - "Copy-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("cvpa", "Convert-Path", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("dbp", "Disable-PSBreakpoint", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("diff", - "Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("ebp", "Enable-PSBreakpoint", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("epal", "Export-Alias", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("epcsv", "Export-Csv", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("fc", - "Format-Custom", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("fl", "Format-List", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("ft", @@ -5260,26 +5250,75 @@ end "Set-Item", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("sl", "Set-Location", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("sleep", - "Start-Sleep", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("sort", - "Sort-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("sp", "Set-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("saps", "Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), - new SessionStateAliasEntry("start", - "Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("spps", "Stop-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("spsv", "Stop-Service", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("sv", "Set-Variable", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), +// Porting note: #if !LINUX is used to disable alises for cmdlets which conflict with Linux / OS X +#if !LINUX + // ac is a native command on OS X + new SessionStateAliasEntry("ac", + "Add-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("compare", + "Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("cpp", + "Copy-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("diff", + "Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("sleep", + "Start-Sleep", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("sort", + "Sort-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("start", + "Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("tee", "Tee-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), new SessionStateAliasEntry("write", "Write-Output", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + // These were traqnsferred from the "transferred from the profile" section + new SessionStateAliasEntry("cat", + "Get-Content", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("cp", + "Copy-Item", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("ls", + "Get-ChildItem", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("man", + "help", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("mount", + "New-PSDrive", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("mv", + "Move-Item", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("ps", + "Get-Process", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("rm", + "Remove-Item", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("rmdir", + "Remove-Item", "", ScopedItemOptions.AllScope), +#endif + // Bash built-ins we purposefully keep even if they override native commands + new SessionStateAliasEntry("cd", + "Set-Location", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("dir", + "Get-ChildItem", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("echo", + "Write-Output", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("fc", + "Format-Custom", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + new SessionStateAliasEntry("kill", + "Stop-Process", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("pwd", + "Get-Location", "", ScopedItemOptions.AllScope), + new SessionStateAliasEntry("type", + "Get-Content", "", ScopedItemOptions.AllScope), + // Native commands we keep because the functions act correctly on Linux + new SessionStateAliasEntry("clear", + "Clear-Host", "", ScopedItemOptions.AllScope), //#if !CORECLR is used to disable aliases for cmdlets which are not available on OneCore #if !CORECLR new SessionStateAliasEntry("asnp", @@ -5316,46 +5355,18 @@ end "Out-Printer", "", ScopedItemOptions.AllScope), #endif // Aliases transferred from the profile - new SessionStateAliasEntry("cat", - "Get-Content", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("cd", - "Set-Location", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("clear", - "Clear-Host", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("cp", - "Copy-Item", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("h", "Get-History", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("history", "Get-History", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("kill", - "Stop-Process", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("ls", - "Get-ChildItem", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("man", - "help", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("mount", - "New-PSDrive", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("md", "mkdir", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("mv", - "Move-Item", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("popd", "Pop-Location", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("ps", - "Get-Process", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("pushd", "Push-Location", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("pwd", - "Get-Location", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("r", "Invoke-History", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("rm", - "Remove-Item", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("rmdir", - "Remove-Item", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("echo", - "Write-Output", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("cls", "Clear-Host", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("chdir", @@ -5364,8 +5375,6 @@ end "Copy-Item", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("del", "Remove-Item", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("dir", - "Get-ChildItem", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("erase", "Remove-Item", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("move", @@ -5376,8 +5385,6 @@ end "Rename-Item", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("set", "Set-Variable", "", ScopedItemOptions.AllScope), - new SessionStateAliasEntry("type", - "Get-Content", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("icm", "Invoke-Command", "", ScopedItemOptions.AllScope), new SessionStateAliasEntry("clhy", @@ -5460,9 +5467,13 @@ if($paths) { SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", TabExpansionFunctionText), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText()), + // Porting note: we keep more because the function acts correctly on Linux SessionStateFunctionEntry.GetDelayParsedFunctionEntry("more", DefaultMoreFunctionText), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText()), + // Porting note: we remove mkdir on Linux because it is a conflict + #if !LINUX SessionStateFunctionEntry.GetDelayParsedFunctionEntry("mkdir", GetMkdirFunctionText()), + #endif SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Get-Verb", GetGetVerbText()), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("oss", GetOSTFunctionText()), From 47a8ee5bcfb55c335d774a60f5d621b1aa13297d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 12:50:53 -0700 Subject: [PATCH 2/4] Remove A:...Z: drive functions on Linux / OS X Resolves #612. --- src/System.Management.Automation/engine/InitialSessionState.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 814079e346..caff5c2ea9 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5477,6 +5477,8 @@ if($paths) { SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Get-Verb", GetGetVerbText()), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("oss", GetOSTFunctionText()), + // Porting note: we remove the drive functions from Linux because they make no sense + #if !LINUX // Default drives SessionStateFunctionEntry.GetDelayParsedFunctionEntry("A:", DefaultSetDriveFunctionText, SetDriveScriptBlock), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("B:", DefaultSetDriveFunctionText, SetDriveScriptBlock), @@ -5504,6 +5506,7 @@ if($paths) { SessionStateFunctionEntry.GetDelayParsedFunctionEntry("X:", DefaultSetDriveFunctionText, SetDriveScriptBlock), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Y:", DefaultSetDriveFunctionText, SetDriveScriptBlock), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Z:", DefaultSetDriveFunctionText, SetDriveScriptBlock), + #endif SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd..", "Set-Location .."), SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd\\", "Set-Location \\"), From 2bd274f5d7c656cf8dc42d4dcc82568c858b4a9f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 13:36:54 -0700 Subject: [PATCH 3/4] Fix tests broken by removal of aliases --- test/powershell/Compare-Object.Tests.ps1 | 29 ------------------- test/powershell/Export-Alias.Tests.ps1 | 2 +- test/powershell/Get-ChildItem.Tests.ps1 | 4 --- test/powershell/Get-Content.Tests.ps1 | 12 ++------ test/powershell/Get-Item.Tests.ps1 | 2 +- test/powershell/NativeLinuxCommands.Tests.ps1 | 28 +++++++----------- test/powershell/Start-Sleep.Tests.ps1 | 5 ---- test/powershell/Tee-Object.Tests.ps1 | 18 ++---------- 8 files changed, 17 insertions(+), 83 deletions(-) diff --git a/test/powershell/Compare-Object.Tests.ps1 b/test/powershell/Compare-Object.Tests.ps1 index 9640105a6a..db61154a81 100644 --- a/test/powershell/Compare-Object.Tests.ps1 +++ b/test/powershell/Compare-Object.Tests.ps1 @@ -35,35 +35,6 @@ Describe "Compare-Object" { { Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw } - It "Should be able to execute compare object using the compare alias" { - { compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw - } - - It "Should produce the same output when the compare alias is used" { - $alias = compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) - $fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) - - $alias[0].InputObject | Should Be $fullname[0].InputObject - $alias[0].SideIndicator | Should Be $fullname[0].SideIndicator - $alias[1].InputObject | Should Be $fullname[1].InputObject - $alias[1].SideIndicator | Should Be $fullname[1].SideIndicator - - $alias.Length | Should Be 2 # There should be no other elements to test - - } - - It "Should be able to execute compare object using the diff alias" { - $alias = diff -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) - $fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) - - $alias[0].InputObject | Should Be $fullname[0].InputObject - $alias[0].SideIndicator | Should Be $fullname[0].SideIndicator - $alias[1].InputObject | Should Be $fullname[1].InputObject - $alias[1].SideIndicator | Should Be $fullname[1].SideIndicator - - $alias.Length | Should Be 2 # There should be no other elements to test - } - It "Should indicate data that exists only in the reference dataset" { $actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) diff --git a/test/powershell/Export-Alias.Tests.ps1 b/test/powershell/Export-Alias.Tests.ps1 index 7a7a459de9..a51ad64ef2 100644 --- a/test/powershell/Export-Alias.Tests.ps1 +++ b/test/powershell/Export-Alias.Tests.ps1 @@ -144,7 +144,7 @@ Describe "Export-Alias" { Test-Path $fulltestpath | Should Be $true - $actual = Get-Content $fulltestpath | Sort + $actual = Get-Content $fulltestpath | Sort-Object $expected = Get-Command -CommandType Alias for ( $i=0; $i -lt $expected.Length; $i++) diff --git a/test/powershell/Get-ChildItem.Tests.ps1 b/test/powershell/Get-ChildItem.Tests.ps1 index 331a6259c5..6925f6b64d 100644 --- a/test/powershell/Get-ChildItem.Tests.ps1 +++ b/test/powershell/Get-ChildItem.Tests.ps1 @@ -9,10 +9,6 @@ Describe "Get-ChildItem" { popd } - It "Should be able to use the ls alias" { - $(ls .).Name.Length | Should Be $(Get-ChildItem .).Name.Length - } - It "Should have a the proper fields and be populated" { $var = Get-Childitem . diff --git a/test/powershell/Get-Content.Tests.ps1 b/test/powershell/Get-Content.Tests.ps1 index 931cc5888c..4466838782 100644 --- a/test/powershell/Get-Content.Tests.ps1 +++ b/test/powershell/Get-Content.Tests.ps1 @@ -40,10 +40,6 @@ Describe "Get-Content" { (Get-Content -Path $testPath) | Should Be $testString } - It "Should be able to call using the cat alias" { - { cat -Path $testPath } | Should Not Throw - } - It "Should be able to call using the gc alias" { { gc -Path $testPath } | Should Not Throw } @@ -55,11 +51,9 @@ Describe "Get-Content" { It "Should return the same values for aliases" { $getContentAlias = Get-Content -Path $testPath $gcAlias = gc -Path $testPath - $catAlias = cat -Path $testPath $typeAlias = type -Path $testPath $getContentAlias | Should Be $gcAlias - $getContentAlias | Should Be $catAlias $getContentAlias | Should Be $typeAlias } @@ -68,21 +62,21 @@ Describe "Get-Content" { } It "Should be able to specify the number of lines to get the content of using the TotalCount switch" { - $returnArray = (cat -Path $testPath2 -TotalCount 2) + $returnArray = (Get-Content -Path $testPath2 -TotalCount 2) $returnArray[0] | Should Be $firstline $returnArray[1] | Should Be $secondline } It "Should be able to specify the number of lines to get the content of using the Head switch" { - $returnArray = (cat -Path $testPath2 -Head 2) + $returnArray = (Get-Content -Path $testPath2 -Head 2) $returnArray[0] | Should Be $firstline $returnArray[1] | Should Be $secondline } It "Should be able to specify the number of lines to get the content of using the First switch" { - $returnArray = (cat -Path $testPath2 -First 2) + $returnArray = (Get-Content -Path $testPath2 -First 2) $returnArray[0] | Should Be $firstline $returnArray[1] | Should Be $secondline diff --git a/test/powershell/Get-Item.Tests.ps1 b/test/powershell/Get-Item.Tests.ps1 index 92e7750060..298236636e 100644 --- a/test/powershell/Get-Item.Tests.ps1 +++ b/test/powershell/Get-Item.Tests.ps1 @@ -15,6 +15,6 @@ Describe "Get-Item" { } It "Should have mode flags set" { - ls $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty } + Get-ChildItem $PSScriptRoot | foreach-object { $_.Mode | Should Not BeNullOrEmpty } } } diff --git a/test/powershell/NativeLinuxCommands.Tests.ps1 b/test/powershell/NativeLinuxCommands.Tests.ps1 index c765ef722c..07b7760090 100644 --- a/test/powershell/NativeLinuxCommands.Tests.ps1 +++ b/test/powershell/NativeLinuxCommands.Tests.ps1 @@ -1,30 +1,22 @@ Describe "NativeLinuxCommands" { It "Should return a type of System.Object for hostname cmdlet" { - (hostname).GetType().BaseType | Should Be 'System.Object' - (hostname).GetType().Name | Should Be String + (hostname).GetType().BaseType | Should Be 'System.Object' + (hostname).GetType().Name | Should Be String } It "Should have not empty Name flags set for ps object" { - ps | foreach-object { $_.ProcessName | Should Not BeNullOrEmpty } + Get-Process | foreach-object { $_.ProcessName | Should Not BeNullOrEmpty } } - - It "Should find Application grep" -Skip:$IsWindows { - (get-command grep).CommandType | Should Be Application + + It "Should find Application grep" -Skip:$IsWindows { + (get-command grep).CommandType | Should Be Application } It "Should pipe to grep and get result" -Skip:$IsWindows { - "hello world" | grep hello | Should Be "hello world" + "hello world" | grep hello | Should Be "hello world" } - - It "Should find Application touch" -Skip:$IsWindows { - (get-command touch).CommandType | Should Be Application - } - - It "Should find Alias ls" -Skip:$IsWindows { - (get-command ls).CommandType | Should Be Alias - } - - It "Should find Function mkdir" -Skip:$IsWindows { - (get-command mkdir).CommandType | Should Be Function + + It "Should find Application touch" -Skip:$IsWindows { + (get-command touch).CommandType | Should Be Application } } diff --git a/test/powershell/Start-Sleep.Tests.ps1 b/test/powershell/Start-Sleep.Tests.ps1 index e97cfad808..42166de94c 100644 --- a/test/powershell/Start-Sleep.Tests.ps1 +++ b/test/powershell/Start-Sleep.Tests.ps1 @@ -24,10 +24,5 @@ Describe "Start-Sleep" { $result = Measure-Command { Start-Sleep -s 1 } $result.TotalSeconds | Should BeGreaterThan 0.25 } - - It "Should sleep for at least 1 second using the alias" { - $result = Measure-Command { sleep -s 1 } - $result.TotalSeconds | Should BeGreaterThan 0.25 - } } } diff --git a/test/powershell/Tee-Object.Tests.ps1 b/test/powershell/Tee-Object.Tests.ps1 index b7b5c8b652..8bd22f45cf 100644 --- a/test/powershell/Tee-Object.Tests.ps1 +++ b/test/powershell/Tee-Object.Tests.ps1 @@ -6,15 +6,8 @@ Describe "Tee-Object" { It "Should return the output to the screen and to the variable" { $teefile = $testfile - echo teeobjecttest1 | Tee-Object -variable teeresults - $teeresults | Should Be "teeobjecttest1" - Remove-Item $teefile -ErrorAction SilentlyContinue - } - - It "Should return the output to the screen and to the variable from the alias" { - $teefile = $testfile - echo teeobjecttest2 | tee -variable teeresults - $teeresults | Should Be "teeobjecttest2" + echo teeobjecttest1 | Tee-Object -variable teeresults + $teeresults | Should Be "teeobjecttest1" Remove-Item $teefile -ErrorAction SilentlyContinue } @@ -24,12 +17,5 @@ Describe "Tee-Object" { Get-Content $teefile | Should Be "teeobjecttest3" Remove-Item $teefile -ErrorAction SilentlyContinue } - - It "Should tee the output to a file using the alias" { - $teefile = $testfile - echo teeobjecttest4 | tee $teefile - Get-Content $teefile | Should Be "teeobjecttest4" - Remove-item $teefile -ErrorAction SilentlyContinue - } } } From 73fe95feb8a4f661a8166f5a505fa4a8cb0f6d59 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:51:11 -0700 Subject: [PATCH 4/4] Add tests for removal of aliases --- test/powershell/Default-Aliases.Tests.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/powershell/Default-Aliases.Tests.ps1 diff --git a/test/powershell/Default-Aliases.Tests.ps1 b/test/powershell/Default-Aliases.Tests.ps1 new file mode 100644 index 0000000000..b1b87472d9 --- /dev/null +++ b/test/powershell/Default-Aliases.Tests.ps1 @@ -0,0 +1,19 @@ +$removeAliasList = @("ac","compare","cpp","diff","sleep","sort","start","cat","cp","ls","man","mount","mv","ps","rm","rmdir") +$keepAliasList = @{cd="Set-Location"},@{dir="Get-ChildItem"},@{echo="Write-output"},@{fc="format-custom"},@{kill="stop-process"},@{clear="clear-host"} +Describe "Windows aliases do not conflict with Linux commands" { + foreach ($alias in $removeAliasList) { + It "Should not have certain aliases on Linux" -Skip:$IsWindows { + Test-Path Alias:$alias | Should Be $false + } + } + + foreach ($alias in $keepAliasList) { + It "Should have aliases that are Bash built-ins on Linux" { + (Get-Alias $alias.Keys).Definition | Should Be $alias.Values + } + } + + It "Should have more as a function" { + Test-Path Function:more | Should Be $true + } +}