mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
- Add VSTS CI for Windows
- Disable `Access-denied test for Get-Item C:\windows\appcompat\Programs\Install -ErrorAction Stop`, because the path does not always exist
- https://github.com/PowerShell/PowerShell/issues/7553
- Disable `Should give .sys file if the fullpath is specified with hidden and force parameter`, because pagefile.sys doesn't always exist and other files don't meet test's requirement.
- https://github.com/PowerShell/PowerShell/issues/7554
- Disable some `Test-Connection` tests for same reasons they failed on VSTS Linux
- https://github.com/PowerShell/PowerShell/issues/7555
- Disable `Test-FileCatalog should pass when catalog is in the same folder as files being tested`, because the CmdLet does not work in that scenario
- Also, give details needed to investigate when the test fails
- https://github.com/PowerShell/PowerShell/issues/7556
- Update `appveyor.psm1` to work with VSTS
- Update `HelpersRemoting.psm1` `New-RemoteSession` to work for CimSession (discovered an issue during the investigation)
- Update `Test wildcard with drive relative directory path` to work when there are multiple drives
- Disable on non-windows machines since the test is assuming drive letters
- Update `New-CimSession` Tests to requireAdmin
- Also, make sure session name is a string
- Add functions to save and restore psoptions
- update `.gitatttributes` so files clone like they do on appveyor
108 lines
4.6 KiB
PowerShell
108 lines
4.6 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
|
|
|
|
BeforeAll {
|
|
# Create temporary EXE command files
|
|
$file1 = Setup -f WildCardCommandA.exe -pass
|
|
$file2 = Setup -f WildCardCommand[B].exe -pass
|
|
#$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 $IsMacOS ) {
|
|
/bin/chmod 777 "$file1"
|
|
/bin/chmod 777 "$file2"
|
|
}
|
|
$commandInfo = Get-Command Get-Date -ShowCommandInfo
|
|
}
|
|
|
|
# this test doesn't test anything on non-windows platforms
|
|
It "Test wildcard with drive relative directory path" -Skip:(!$IsWindows) {
|
|
$pathName = Join-Path $TestDrive "WildCardCommandA*"
|
|
$driveOffset = $pathName.IndexOf(":")
|
|
$driveName = $pathName.Substring(0,$driveOffset + 1)
|
|
Push-Location -Path $driveName
|
|
try {
|
|
$pathName = $pathName.Substring($driveOffset + 1)
|
|
$result = Get-Command -Name $pathName
|
|
$result | Should -Not -BeNullOrEmpty
|
|
$result.Name | Should -Be WildCardCommandA.exe
|
|
}
|
|
catch {
|
|
Pop-Location
|
|
}
|
|
}
|
|
|
|
It "Test wildcard with relative directory path" {
|
|
push-location $TestDrive
|
|
$result = Get-Command -Name .\WildCardCommandA*
|
|
pop-location
|
|
$result | Should -Not -BeNullOrEmpty
|
|
$result | Should -Be WildCardCommandA.exe
|
|
}
|
|
|
|
It "Test with PowerShell wildcard and relative path" {
|
|
push-location $TestDrive
|
|
|
|
# This should use the wildcard to find WildCardCommandA.exe
|
|
$result = Get-Command -Name .\WildCardCommand[A].exe
|
|
$result | Should -Not -BeNullOrEmpty
|
|
$result | Should -Be WildCardCommandA.exe
|
|
|
|
# This should find the file WildCardCommand[B].exe
|
|
$result = Get-Command -Name .\WildCardCommand[B].exe
|
|
$result | Should -Not -BeNullOrEmpty
|
|
$result | Should -Be WildCardCommand[B].exe
|
|
|
|
Pop-Location
|
|
}
|
|
|
|
It "Get-Command -ShowCommandInfo property field test" {
|
|
$properties = ($commandInfo | Get-Member -MemberType NoteProperty)
|
|
$propertiesAsString = $properties.name | out-string
|
|
$propertiesAsString | Should -MatchExactly 'CommandType'
|
|
$propertiesAsString | Should -MatchExactly 'Definition'
|
|
$propertiesAsString | Should -MatchExactly 'Module'
|
|
$propertiesAsString | Should -MatchExactly 'ModuleName'
|
|
$propertiesAsString | Should -MatchExactly 'Name'
|
|
$propertiesAsString | Should -MatchExactly 'ParameterSets'
|
|
}
|
|
|
|
$testcases = @(
|
|
@{observed = $commandInfo.Name; testname = "Name"; result = "Get-Date"}
|
|
@{observed = $commandInfo.ModuleName; testname = "Name"; result = "Microsoft.PowerShell.Utility"}
|
|
@{observed = $commandInfo.Module.Name; testname = "ModuleName"; result = "Microsoft.PowerShell.Utility"}
|
|
@{observed = $commandInfo.CommandType; testname = "CommandType"; result = "Cmdlet"}
|
|
@{observed = $commandInfo.Definition.Count; testname = "Definition"; result = 1}
|
|
)
|
|
|
|
It "Get-Command -ShowCommandInfo property test - <testname>" -TestCases $testcases{
|
|
param (
|
|
$observed,
|
|
$result
|
|
)
|
|
$observed | Should -BeExactly $result
|
|
}
|
|
|
|
It "Get-Command -ShowCommandInfo ParameterSets property field test" {
|
|
$properties = ($commandInfo.ParameterSets[0] | Get-Member -MemberType NoteProperty)
|
|
$propertiesAsString = $properties.name | out-string
|
|
$propertiesAsString | Should -MatchExactly 'IsDefault'
|
|
$propertiesAsString | Should -MatchExactly 'Name'
|
|
$propertiesAsString | Should -MatchExactly 'Parameters'
|
|
}
|
|
|
|
It "Get-Command -ShowCommandInfo Parameters property field test" {
|
|
$properties = ($commandInfo.ParameterSets[0].Parameters | Get-Member -MemberType NoteProperty)
|
|
$propertiesAsString = $properties.name | out-string
|
|
$propertiesAsString | Should -MatchExactly 'HasParameterSet'
|
|
$propertiesAsString | Should -MatchExactly 'IsMandatory'
|
|
$propertiesAsString | Should -MatchExactly 'Name'
|
|
$propertiesAsString | Should -MatchExactly 'ParameterType'
|
|
$propertiesAsString | Should -MatchExactly 'Position'
|
|
$propertiesAsString | Should -MatchExactly 'ValidParamSetValues'
|
|
$propertiesAsString | Should -MatchExactly 'ValueFromPipeline'
|
|
}
|
|
|
|
}
|