mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-18 05:05:36 +00:00
* Capitalize 'Should' command and fix whitespace ```powershell $_ -ireplace '\s?\|\s?should\b',' | Should' ``` * Capitalise and apply hyphen to 'Not' parameter ```powershell $_ -ireplace '(\| Should) not\b','$1 -Not' ``` * Capitalise and apply hyphen to 'Be' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be' ``` * Capitalise and apply hyphen to 'BeExactly' parameter $_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly' * Capitalise and apply hyphen to 'BeGreaterThan' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan' ``` * Use 'BeTrue' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue' ``` * Use 'BeFalse' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse' ``` * Capitalise and apply hyphen to 'Match' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match' ``` * Capitalise and apply hyphen to 'Throw' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw' ``` * Capitalise and apply hyphen to 'BeNullOrEmpty' parameter ```powershell $_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty' ``` * Capitalise 'Because' parameter ```powershell $_ -ireplace '\s-because\b',' -Because' ``` * Fix 'BeNullOrEmpty'
66 lines
3.3 KiB
PowerShell
66 lines
3.3 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
Describe "Remove-Alias" -Tags "CI" {
|
|
|
|
BeforeAll {
|
|
$testAliasName = (New-Guid).Guid
|
|
}
|
|
|
|
It "Remove-Alias should remove a non-readonly alias"{
|
|
{
|
|
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
|
|
Remove-Alias -Name $testAliasName -ErrorAction Stop
|
|
Get-Alias -Name $testAliasName -ErrorAction Stop
|
|
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
}
|
|
|
|
It "Remove-Alias should throw on a readonly alias"{
|
|
{
|
|
Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop
|
|
Remove-Alias -Name $testAliasName -ErrorAction Stop
|
|
} | Should -Throw -ErrorId 'AliasNotRemovable,Microsoft.PowerShell.Commands.RemoveAliasCommand'
|
|
}
|
|
|
|
It "Remove-Alias should remove a non-readonly alias with force"{
|
|
{
|
|
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
|
|
Remove-Alias -Name $testAliasName -Force -ErrorAction Stop
|
|
Get-Alias -Name $testAliasName -ErrorAction Stop
|
|
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
}
|
|
|
|
It "Remove-Alias should remove a readonly alias with force"{
|
|
{
|
|
Set-Alias -Name $testAliasName -Value "Remove-Alias" -Option ReadOnly -ErrorAction Stop
|
|
Remove-Alias -Name $testAliasName -Force -ErrorAction Stop
|
|
Get-Alias -Name $testAliasName -ErrorAction Stop
|
|
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
}
|
|
|
|
It "Remove-Alias should throw if alias does not exist"{
|
|
{
|
|
Get-Alias -Name $testAliasName -ErrorAction SilentlyContinue | Should -BeNullOrEmpty
|
|
Remove-Alias -Name $testAliasName -ErrorAction Stop
|
|
} | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.RemoveAliasCommand'
|
|
}
|
|
|
|
It "Remove-Alias should remove multiple alias at once"{
|
|
{
|
|
Set-Alias -Name "$testAliasName" -Value "Remove-Alias" -ErrorAction Stop
|
|
Set-Alias -Name "$testAliasName-2" -Value "Remove-Alias" -ErrorAction Stop
|
|
Set-Alias -Name "$testAliasName-3" -Value "Remove-Alias" -ErrorAction Stop
|
|
Remove-Alias -Name "$testAliasName","$testAliasName-2","$testAliasName-3" -ErrorAction Stop
|
|
Get-Alias -Name "$testAliasName" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
Get-Alias -Name "$testAliasName-2" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
Get-Alias -Name "$testAliasName-3" -ErrorAction Stop | Should -Throw -ErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
}
|
|
}
|
|
|
|
It "Remove-Alias should throw on out-of-range scope"{
|
|
{
|
|
Set-Alias -Name $testAliasName -Value "Remove-Alias" -ErrorAction Stop
|
|
Remove-Alias -Name $testAliasName -Scope 99999 -ErrorAction Stop
|
|
} | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.RemoveAliasCommand"
|
|
}
|
|
}
|