mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +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'
100 lines
3.6 KiB
PowerShell
100 lines
3.6 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
Describe "Set-Alias DRT Unit Tests" -Tags "CI" {
|
|
It "Set-Alias Invalid Scope Name should throw PSArgumentException"{
|
|
{ Set-Alias -Name "ABCD" -Value "foo" -Scope "bogus" } | Should -Throw -ErrorId "Argument,Microsoft.PowerShell.Commands.SetAliasCommand"
|
|
}
|
|
|
|
It "Set-Alias ReadOnly Force"{
|
|
Set-Alias -Name ABCD -Value "foo" -Option ReadOnly -Force:$true
|
|
$result=Get-Alias -Name ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "foo"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "ReadOnly"
|
|
|
|
Set-Alias -Name ABCD -Value "foo" -Force:$true
|
|
$result=Get-Alias -Name ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "foo"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
}
|
|
|
|
It "Set-Alias Name And Value Valid"{
|
|
Set-Alias -Name ABCD -Value "MyCommand"
|
|
$result=Get-Alias -Name ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "MyCommand"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
}
|
|
It "Set-Alias Name And Value Positional Valid"{
|
|
Set-Alias -Name ABCD "foo"
|
|
$result=Get-Alias ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "foo"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
}
|
|
It "Set-Alias Description Valid"{
|
|
Set-Alias -Name ABCD -Value "MyCommand" -Description "test description"
|
|
$result=Get-Alias -Name ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "MyCommand"
|
|
$result.Description | Should -BeExactly "test description"
|
|
$result.Options | Should -BeExactly "None"
|
|
}
|
|
It "Set-Alias Scope Valid"{
|
|
Set-Alias -Name ABCD -Value "localfoo" -scope local -Force:$true
|
|
Set-Alias -Name ABCD -Value "foo1" -scope "1" -Force:$true
|
|
|
|
$result=Get-Alias -Name ABCD
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "localfoo"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
|
|
$result=Get-Alias -Name ABCD -scope local
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "localfoo"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
|
|
$result=Get-Alias -Name ABCD -scope "1"
|
|
$result.Name | Should -BeExactly "ABCD"
|
|
$result.Definition | Should -BeExactly "foo1"
|
|
$result.Description | Should -BeNullOrEmpty
|
|
$result.Options | Should -BeExactly "None"
|
|
}
|
|
It "Set-Alias Expose Bug 1062958, BugId:905449"{
|
|
{ Set-Alias -Name "ABCD" -Value "foo" -Scope "-1" } | Should -Throw -ErrorId "ArgumentOutOfRange,Microsoft.PowerShell.Commands.SetAliasCommand"
|
|
}
|
|
}
|
|
|
|
Describe "Set-Alias" -Tags "CI" {
|
|
Mock Get-Date { return "Friday, October 30, 2015 3:38:08 PM" }
|
|
It "Should be able to set alias without error" {
|
|
|
|
{ set-alias -Name gd -Value Get-Date } | Should -Not -Throw
|
|
}
|
|
|
|
It "Should be able to have the same output between set-alias and the output of the function being aliased" {
|
|
set-alias -Name gd -Value Get-Date
|
|
gd | Should -Be $(Get-Date)
|
|
}
|
|
|
|
It "Should be able to use the sal alias" {
|
|
{ sal gd Get-Date } | Should -Not -Throw
|
|
}
|
|
|
|
It "Should have the same output between the sal alias and the original set-alias cmdlet" {
|
|
sal -Name gd -Value Get-Date
|
|
|
|
Set-Alias -Name gd2 -Value Get-Date
|
|
|
|
gd2 | Should -Be $(gd)
|
|
}
|
|
}
|