mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files. Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks. Separate PR coming to update contribution document for new source files: #6140 Manually reviewed each change. Fix #6073
66 lines
3.2 KiB
PowerShell
66 lines
3.2 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
|
|
} | ShouldBeErrorId '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
|
|
} | ShouldBeErrorId '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
|
|
} | ShouldBeErrorId '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
|
|
} | ShouldBeErrorId '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
|
|
} | ShouldBeErrorId '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 | ShouldBeErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
Get-Alias -Name "$testAliasName-2" -ErrorAction Stop | ShouldBeErrorId 'ItemNotFoundException,Microsoft.PowerShell.Commands.GetAliasCommand'
|
|
Get-Alias -Name "$testAliasName-3" -ErrorAction Stop | ShouldBeErrorId '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
|
|
} | ShouldBeErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.RemoveAliasCommand"
|
|
}
|
|
}
|