Files
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/Pester.Commands.Cmdlets.GetCommand.ps1
T

50 lines
1.7 KiB
PowerShell
Raw Normal View History

2016-07-20 14:28:19 -07:00
##
## Copyright (c) Microsoft Corporation, 2015
##
Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
2016-07-20 14:28:19 -07:00
BeforeAll {
# Create temporary EXE command files
$file1 = Setup -f WildCardCommandA.exe -pass
$file2 = Setup -f WildCard
$null = New-Item -ItemType File -Path (Join-Path $TestDrive WildCardCommandA.exe) -ErrorAction Ignore
$null = New-Item -ItemType File -Path (Join-Path $TestDRive WildCardCommand[B].exe) -ErrorAction Ignore
if ( $IsLinux -or $IsOSX ) {
/bin/chmod +x
}
2016-07-20 14:28:19 -07:00
}
It "Test wildcard with drive relative directory path" {
$pathName = Join-Path $TestDrive "WildCardCommandA*"
2016-07-20 14:28:19 -07:00
$pathName = $pathName.Substring(2, ($pathName.Length - 2))
$result = Get-Command -Name $pathName
$result | Should Not Be $null
$result.Name | Should Be WildCardCommandA.exe
}
It "Test wildcard with relative directory path" {
push-location $TestDrive
2016-07-20 14:28:19 -07:00
$result = Get-Command -Name .\WildCardCommandA*
pop-location
2016-07-20 14:28:19 -07:00
$result | Should Not Be $null
$result | Should Be WildCardCommandA.exe
}
It "Test with PowerShell wildcard and relative path" {
push-location $TestDrive
2016-07-20 14:28:19 -07:00
# This should use the wildcard to find WildCardCommandA.exe
$result = Get-Command -Name .\WildCardCommand[A].exe
$result | Should Not Be $null
$result | Should Be WildCardCommandA.exe
# This should find the file WildCardCommand[B].exe
$result = Get-Command -Name .\WildCardCommand[B].exe
$result | Should Not Be $null
$result | Should Be WildCardCommand[B].exe
Pop-Location
2016-07-20 14:28:19 -07:00
}
}