Update tests in Modules/Microsoft.PowerShell.Core to use new Pester syntax. (#6349)
This commit is contained in:
parent
eeb03c89e6
commit
ff2486416d
13 changed files with 179 additions and 237 deletions
|
@ -21,20 +21,20 @@ Describe "History cmdlet test cases" -Tags "CI" {
|
||||||
It "Get-History returns proper history" {
|
It "Get-History returns proper history" {
|
||||||
# for this case, we'll *not* add to history
|
# for this case, we'll *not* add to history
|
||||||
$result = $ps.AddCommand("Get-History").Invoke()
|
$result = $ps.AddCommand("Get-History").Invoke()
|
||||||
$result.Count | should be 3
|
$result.Count | Should -Be 3
|
||||||
$result[0].CommandLine | should be "Get-Date"
|
$result[0].CommandLine | Should -BeExactly "Get-Date"
|
||||||
$result[1].CommandLine | should be "1+1"
|
$result[1].CommandLine | Should -Be "1+1"
|
||||||
$result[2].CommandLine | should be "Get-Location"
|
$result[2].CommandLine | Should -BeExactly "Get-Location"
|
||||||
}
|
}
|
||||||
It "Invoke-History invokes proper command" {
|
It "Invoke-History invokes proper command" {
|
||||||
$result = $ps.AddScript("Invoke-History 2").Invoke()
|
$result = $ps.AddScript("Invoke-History 2").Invoke()
|
||||||
$result | Should be 2
|
$result | Should -Be 2
|
||||||
}
|
}
|
||||||
It "Clear-History removes history" {
|
It "Clear-History removes history" {
|
||||||
$ps.AddCommand("Clear-History").Invoke()
|
$ps.AddCommand("Clear-History").Invoke()
|
||||||
$ps.commands.clear()
|
$ps.commands.clear()
|
||||||
$result = $ps.AddCommand("Get-History").Invoke()
|
$result = $ps.AddCommand("Get-History").Invoke()
|
||||||
$result | should BeNullOrEmpty
|
$result | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
It "Add-History actually adds to history" {
|
It "Add-History actually adds to history" {
|
||||||
# add this invocation to history
|
# add this invocation to history
|
||||||
|
@ -42,9 +42,9 @@ Describe "History cmdlet test cases" -Tags "CI" {
|
||||||
# that's 4 history lines * 2
|
# that's 4 history lines * 2
|
||||||
$ps.Commands.Clear()
|
$ps.Commands.Clear()
|
||||||
$result = $ps.AddCommand("Get-History").Invoke()
|
$result = $ps.AddCommand("Get-History").Invoke()
|
||||||
$result.Count | Should be 8
|
$result.Count | Should -Be 8
|
||||||
for($i = 0; $i -lt 4; $i++) {
|
for($i = 0; $i -lt 4; $i++) {
|
||||||
$result[$i+4].CommandLine | Should be $result[$i].CommandLine
|
$result[$i+4].CommandLine | Should -BeExactly $result[$i].CommandLine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ Describe "History cmdlet test cases" -Tags "CI" {
|
||||||
$ps.Dispose()
|
$ps.Dispose()
|
||||||
|
|
||||||
## Twice per stream - once for the original invocation, and once for the re-invocation
|
## Twice per stream - once for the original invocation, and once for the re-invocation
|
||||||
$outputCount | Should be 12
|
$outputCount | Should -Be 12
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Tests Invoke-History on a private command" {
|
It "Tests Invoke-History on a private command" {
|
||||||
|
@ -108,6 +108,6 @@ Describe "History cmdlet test cases" -Tags "CI" {
|
||||||
$errorResult = $ps.Streams.Error[0].FullyQualifiedErrorId
|
$errorResult = $ps.Streams.Error[0].FullyQualifiedErrorId
|
||||||
$ps.Dispose()
|
$ps.Dispose()
|
||||||
|
|
||||||
$errorResult | Should be CommandNotFoundException
|
$errorResult | Should -BeExactly 'CommandNotFoundException'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,34 +17,34 @@ Describe "Import-Module" -Tags "CI" {
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
Remove-Module -Name $moduleName -Force
|
Remove-Module -Name $moduleName -Force
|
||||||
(Get-Module -Name $moduleName).Name | Should BeNullOrEmpty
|
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach {
|
AfterEach {
|
||||||
Import-Module -Name $moduleName -Force
|
Import-Module -Name $moduleName -Force
|
||||||
(Get-Module -Name $moduleName).Name | Should Be $moduleName
|
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should be able to add a module with using Name switch" {
|
It "should be able to add a module with using Name switch" {
|
||||||
{ Import-Module -Name $moduleName } | Should Not Throw
|
{ Import-Module -Name $moduleName } | Should -Not -Throw
|
||||||
(Get-Module -Name $moduleName).Name | Should Be $moduleName
|
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should be able to add a module with using ModuleInfo switch" {
|
It "should be able to add a module with using ModuleInfo switch" {
|
||||||
$a = Get-Module -ListAvailable $moduleName
|
$a = Get-Module -ListAvailable $moduleName
|
||||||
{ Import-Module -ModuleInfo $a } | Should Not Throw
|
{ Import-Module -ModuleInfo $a } | Should -Not -Throw
|
||||||
(Get-Module -Name $moduleName).Name | Should Be $moduleName
|
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should be able to load an already loaded module" {
|
It "should be able to load an already loaded module" {
|
||||||
Import-Module $moduleName
|
Import-Module $moduleName
|
||||||
{ $script:module = Import-Module $moduleName -PassThru -ErrorAction Stop } | Should Not Throw
|
{ $script:module = Import-Module $moduleName -PassThru -ErrorAction Stop } | Should -Not -Throw
|
||||||
Get-Module -Name $moduleName | Should Be $script:module
|
Get-Module -Name $moduleName | Should -BeExactly $script:module
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should only load the specified version" {
|
It "should only load the specified version" {
|
||||||
Import-Module TestModule -RequiredVersion 1.1
|
Import-Module TestModule -RequiredVersion 1.1
|
||||||
(Get-Module TestModule).Version | Should BeIn "1.1"
|
(Get-Module TestModule).Version | Should -BeIn "1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ Describe "Import-Module with ScriptsToProcess" -Tags "CI" {
|
||||||
It "Verify ScriptsToProcess are executed <TestNameSuffix>" -TestCases $testCases {
|
It "Verify ScriptsToProcess are executed <TestNameSuffix>" -TestCases $testCases {
|
||||||
param($TestNameSuffix,$ipmoParms,$Expected)
|
param($TestNameSuffix,$ipmoParms,$Expected)
|
||||||
Import-Module @ipmoParms
|
Import-Module @ipmoParms
|
||||||
Get-Content out.txt | Should Be $Expected
|
Get-Content out.txt | Should -BeExactly $Expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ Describe "Import-Module for Binary Modules in GAC" -Tags 'CI' {
|
||||||
It "Load PSScheduledJob from Windows Powershell Modules folder" -Skip:(-not $IsWindows) {
|
It "Load PSScheduledJob from Windows Powershell Modules folder" -Skip:(-not $IsWindows) {
|
||||||
$modulePath = Join-Path $env:windir "System32/WindowsPowershell/v1.0/Modules/PSScheduledJob"
|
$modulePath = Join-Path $env:windir "System32/WindowsPowershell/v1.0/Modules/PSScheduledJob"
|
||||||
Import-Module $modulePath
|
Import-Module $modulePath
|
||||||
(Get-Command New-JobTrigger).Name | Should Be 'New-JobTrigger'
|
(Get-Command New-JobTrigger).Name | Should -BeExactly 'New-JobTrigger'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,8 @@ namespace ModuleCmdlets
|
||||||
|
|
||||||
#Ignore slash format difference under windows/Unix
|
#Ignore slash format difference under windows/Unix
|
||||||
$path = (Get-ChildItem $TESTDRIVE\System.dll).FullName
|
$path = (Get-ChildItem $TESTDRIVE\System.dll).FullName
|
||||||
$results[0] | Should Be $path
|
$results[0] | Should -BeExactly $path
|
||||||
$results[1] | Should BeExactly "BinaryModuleCmdlet1 exported by the ModuleCmdlets module."
|
$results[1] | Should -BeExactly "BinaryModuleCmdlet1 exported by the ModuleCmdlets module."
|
||||||
}
|
}
|
||||||
|
|
||||||
It "PS should try to load the assembly from assembly name if file path doesn't exist" {
|
It "PS should try to load the assembly from assembly name if file path doesn't exist" {
|
||||||
|
@ -150,9 +150,9 @@ namespace ModuleCmdlets
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$module = Import-Module $psdFile -PassThru
|
$module = Import-Module $psdFile -PassThru
|
||||||
$module.NestedModules | Should Not BeNullOrEmpty
|
$module.NestedModules | Should -Not -BeNullOrEmpty
|
||||||
$assemblyLocation = [Microsoft.PowerShell.Commands.AddTypeCommand].Assembly.Location
|
$assemblyLocation = [Microsoft.PowerShell.Commands.AddTypeCommand].Assembly.Location
|
||||||
$module.NestedModules.ImplementingAssembly.Location | Should Be $assemblyLocation
|
$module.NestedModules.ImplementingAssembly.Location | Should -Be $assemblyLocation
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -193,10 +193,10 @@ Describe "Import-Module should be case insensitive" -Tags 'CI' {
|
||||||
Set-Content -Path "$modulesPath/$modulePath/TESTMODULE.psm1" -Value "function mytest { 'hello' }"
|
Set-Content -Path "$modulesPath/$modulePath/TESTMODULE.psm1" -Value "function mytest { 'hello' }"
|
||||||
Import-Module testMODULE
|
Import-Module testMODULE
|
||||||
$m = Get-Module TESTmodule
|
$m = Get-Module TESTmodule
|
||||||
$m | Should BeOfType "System.Management.Automation.PSModuleInfo"
|
$m | Should -BeOfType "System.Management.Automation.PSModuleInfo"
|
||||||
$m.Name | Should BeIn "TESTMODULE"
|
$m.Name | Should -BeIn "TESTMODULE"
|
||||||
mytest | Should BeExactly "hello"
|
mytest | Should -BeExactly "hello"
|
||||||
Remove-Module TestModule
|
Remove-Module TestModule
|
||||||
Get-Module tESTmODULE | Should BeNullOrEmpty
|
Get-Module tESTmODULE | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,19 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
|
||||||
Get-Job | Remove-Job -Force
|
Get-Job | Remove-Job -Force
|
||||||
}
|
}
|
||||||
It "Start-Job produces a job object" {
|
It "Start-Job produces a job object" {
|
||||||
$j | Should BeOfType "System.Management.Automation.Job"
|
$j | Should -BeOfType "System.Management.Automation.Job"
|
||||||
$j.Name | Should Be "My Job"
|
$j.Name | Should -BeExactly "My Job"
|
||||||
}
|
}
|
||||||
It "Get-Job retrieves a job object" {
|
It "Get-Job retrieves a job object" {
|
||||||
(Get-Job -Id $j.Id) | Should BeOfType "System.Management.Automation.Job"
|
(Get-Job -Id $j.Id) | Should -BeOfType "System.Management.Automation.Job"
|
||||||
}
|
}
|
||||||
It "Get-Job retrieves an array of job objects" {
|
It "Get-Job retrieves an array of job objects" {
|
||||||
Start-Job -ScriptBlock { 2 * 2 }
|
Start-Job -ScriptBlock { 2 * 2 }
|
||||||
$jobs = Get-Job
|
$jobs = Get-Job
|
||||||
$jobs.Count | Should Be 2
|
$jobs.Count | Should -Be 2
|
||||||
foreach ($job in $jobs)
|
foreach ($job in $jobs)
|
||||||
{
|
{
|
||||||
$job | Should BeOfType "System.Management.Automation.Job"
|
$job | Should -BeOfType "System.Management.Automation.Job"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
It "Remove-Job can remove a job" {
|
It "Remove-Job can remove a job" {
|
||||||
|
@ -29,17 +29,17 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
|
||||||
{ Get-Job $j -ErrorAction Stop } | ShouldBeErrorId "JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.GetJobCommand"
|
{ Get-Job $j -ErrorAction Stop } | ShouldBeErrorId "JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.GetJobCommand"
|
||||||
}
|
}
|
||||||
It "Receive-Job can retrieve job results" {
|
It "Receive-Job can retrieve job results" {
|
||||||
Wait-Job -Timeout 60 -id $j.id | Should Not BeNullOrEmpty
|
Wait-Job -Timeout 60 -id $j.id | Should -Not -BeNullOrEmpty
|
||||||
receive-job -id $j.id | Should be 2
|
receive-job -id $j.id | Should -Be 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Context "Jobs with arguments" {
|
Context "Jobs with arguments" {
|
||||||
It "Start-Job accepts arguments" {
|
It "Start-Job accepts arguments" {
|
||||||
$sb = { Write-Output $args[1]; Write-Output $args[0] }
|
$sb = { Write-Output $args[1]; Write-Output $args[0] }
|
||||||
$j = Start-Job -ScriptBlock $sb -ArgumentList "$TestDrive", 42
|
$j = Start-Job -ScriptBlock $sb -ArgumentList "$TestDrive", 42
|
||||||
Wait-job -Timeout (5 * 60) $j | Should Be $j
|
Wait-job -Timeout (5 * 60) $j | Should -Be $j
|
||||||
$r = Receive-Job $j
|
$r = Receive-Job $j
|
||||||
$r -Join "," | Should Be "42,$TestDrive"
|
$r -Join "," | Should -Be "42,$TestDrive"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Context "jobs which take time" {
|
Context "jobs which take time" {
|
||||||
|
@ -51,28 +51,28 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
|
||||||
}
|
}
|
||||||
It "Wait-Job will wait for a job" {
|
It "Wait-Job will wait for a job" {
|
||||||
$result = Wait-Job $j
|
$result = Wait-Job $j
|
||||||
$result | Should Be $j
|
$result | Should -Be $j
|
||||||
$j.State | Should Be "Completed"
|
$j.State | Should -BeExactly "Completed"
|
||||||
}
|
}
|
||||||
It "Wait-Job will timeout waiting for a job" {
|
It "Wait-Job will timeout waiting for a job" {
|
||||||
$result = Wait-Job -Timeout 2 $j
|
$result = Wait-Job -Timeout 2 $j
|
||||||
$result | Should Be $null
|
$result | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
It "Stop-Job will stop a job" {
|
It "Stop-Job will stop a job" {
|
||||||
Stop-Job -Id $j.Id
|
Stop-Job -Id $j.Id
|
||||||
$j.State | Should Be "Stopped"
|
$j.State | Should -BeExactly "Stopped"
|
||||||
}
|
}
|
||||||
It "Remove-Job will not remove a running job" {
|
It "Remove-Job will not remove a running job" {
|
||||||
$id = $j.Id
|
$id = $j.Id
|
||||||
Remove-Job $j -ErrorAction SilentlyContinue
|
Remove-Job $j -ErrorAction SilentlyContinue
|
||||||
$job = Get-Job -Id $id
|
$job = Get-Job -Id $id
|
||||||
$job | Should Be $j
|
$job | Should -Be $j
|
||||||
}
|
}
|
||||||
It "Remove-Job -Force will remove a running job" {
|
It "Remove-Job -Force will remove a running job" {
|
||||||
$id = $j.Id
|
$id = $j.Id
|
||||||
Remove-Job $j -Force
|
Remove-Job $j -Force
|
||||||
$job = Get-Job -Id $id -ErrorAction SilentlyContinue
|
$job = Get-Job -Id $id -ErrorAction SilentlyContinue
|
||||||
$job | Should Be $null
|
$job | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Context "Retrieving partial output from jobs" {
|
Context "Retrieving partial output from jobs" {
|
||||||
|
@ -130,13 +130,13 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
|
||||||
It "Receive-Job will retrieve partial output" {
|
It "Receive-Job will retrieve partial output" {
|
||||||
$result1 = GetResults $j 5 $false
|
$result1 = GetResults $j 5 $false
|
||||||
$result2 = GetResults $j 5 $false
|
$result2 = GetResults $j 5 $false
|
||||||
CheckContent ($result1 + $result2) | Should Be $true
|
CheckContent ($result1 + $result2) | Should -BeTrue
|
||||||
}
|
}
|
||||||
It "Receive-Job will retrieve partial output, including -Keep results" {
|
It "Receive-Job will retrieve partial output, including -Keep results" {
|
||||||
$result1 = GetResults $j 5 $true
|
$result1 = GetResults $j 5 $true
|
||||||
$result2 = GetResults $j ($result1.Count + 5) $false
|
$result2 = GetResults $j ($result1.Count + 5) $false
|
||||||
Compare-Object -SyncWindow 0 -PassThru $result1 $result2[0..($result1.Count-1)] | Should Be $null
|
Compare-Object -SyncWindow 0 -PassThru $result1 $result2[0..($result1.Count-1)] | Should -BeNullOrEmpty
|
||||||
$result2[$result1.Count - 1] + 1 | Should Be $result2[$result1.Count]
|
$result2[$result1.Count - 1] + 1 | Should -Be $result2[$result1.Count]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,13 +158,13 @@ Describe "Debug-job test" -tag "Feature" {
|
||||||
It "Debug-Job will break into debugger" -pending {
|
It "Debug-Job will break into debugger" -pending {
|
||||||
$ps.AddScript('$job = start-job { 1..300 | ForEach-Object { sleep 1 } }').Invoke()
|
$ps.AddScript('$job = start-job { 1..300 | ForEach-Object { sleep 1 } }').Invoke()
|
||||||
$ps.Commands.Clear()
|
$ps.Commands.Clear()
|
||||||
$ps.Runspace.Debugger.GetCallStack() | Should BeNullOrEmpty
|
$ps.Runspace.Debugger.GetCallStack() | Should -BeNullOrEmpty
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
||||||
$asyncResult = $ps.AddScript('debug-job $job').BeginInvoke()
|
$asyncResult = $ps.AddScript('debug-job $job').BeginInvoke()
|
||||||
$ps.commands.clear()
|
$ps.commands.clear()
|
||||||
Start-Sleep 2
|
Start-Sleep 2
|
||||||
$result = $ps.runspace.Debugger.GetCallStack()
|
$result = $ps.runspace.Debugger.GetCallStack()
|
||||||
$result.Command | Should be "<ScriptBlock>"
|
$result.Command | Should -BeExactly "<ScriptBlock>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ Describe "Ampersand background test" -tag "CI","Slow" {
|
||||||
}
|
}
|
||||||
It "Background with & produces a job object" {
|
It "Background with & produces a job object" {
|
||||||
$j = Write-Output Hi &
|
$j = Write-Output Hi &
|
||||||
$j | Should BeOfType System.Management.Automation.Job
|
$j | Should -BeOfType System.Management.Automation.Job
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Context "Variable tests" {
|
Context "Variable tests" {
|
||||||
|
@ -185,38 +185,38 @@ Describe "Ampersand background test" -tag "CI","Slow" {
|
||||||
It "doesn't cause error when variable is missing" {
|
It "doesn't cause error when variable is missing" {
|
||||||
Remove-Item variable:name -ErrorAction Ignore
|
Remove-Item variable:name -ErrorAction Ignore
|
||||||
$j = write-output "Hi $name" &
|
$j = write-output "Hi $name" &
|
||||||
Receive-Job $j -Wait | Should BeExactly "Hi "
|
Receive-Job $j -Wait | Should -BeExactly "Hi "
|
||||||
}
|
}
|
||||||
It "Copies variables to the child process" {
|
It "Copies variables to the child process" {
|
||||||
$n1 = "Bob"
|
$n1 = "Bob"
|
||||||
$n2 = "Mary"
|
$n2 = "Mary"
|
||||||
${n 3} = "Bill"
|
${n 3} = "Bill"
|
||||||
$j = Write-Output "Hi $n1! Hi ${n2}! Hi ${n 3}!" &
|
$j = Write-Output "Hi $n1! Hi ${n2}! Hi ${n 3}!" &
|
||||||
Receive-Job $j -Wait | Should BeExactly "Hi Bob! Hi Mary! Hi Bill!"
|
Receive-Job $j -Wait | Should -BeExactly "Hi Bob! Hi Mary! Hi Bill!"
|
||||||
}
|
}
|
||||||
It 'Make sure that $PID from the parent process does not overwrite $PID in the child process' {
|
It 'Make sure that $PID from the parent process does not overwrite $PID in the child process' {
|
||||||
$j = Write-Output $pid &
|
$j = Write-Output $pid &
|
||||||
$cpid = Receive-Job $j -Wait
|
$cpid = Receive-Job $j -Wait
|
||||||
$pid | Should Not BeExactly $cpid
|
$pid | Should -Not -BeExactly $cpid
|
||||||
}
|
}
|
||||||
It 'Make sure that $global:PID from the parent process does not overwrite $global:PID in the child process' {
|
It 'Make sure that $global:PID from the parent process does not overwrite $global:PID in the child process' {
|
||||||
$j = Write-Output $global:pid &
|
$j = Write-Output $global:pid &
|
||||||
$cpid = Receive-Job -Wait $j
|
$cpid = Receive-Job -Wait $j
|
||||||
$pid | Should Not BeExactly $cpid
|
$pid | Should -Not -BeExactly $cpid
|
||||||
}
|
}
|
||||||
It "starts in the current directory" {
|
It "starts in the current directory" {
|
||||||
$j = Get-Location | Foreach-Object -MemberName Path &
|
$j = Get-Location | Foreach-Object -MemberName Path &
|
||||||
Receive-Job -Wait $j | Should Be ($pwd.Path)
|
Receive-Job -Wait $j | Should -Be ($pwd.Path)
|
||||||
}
|
}
|
||||||
It "Test that output redirection is done in the background job" {
|
It "Test that output redirection is done in the background job" {
|
||||||
$j = Write-Output hello > $TESTDRIVE/hello.txt &
|
$j = Write-Output hello > $TESTDRIVE/hello.txt &
|
||||||
Receive-Job -Wait $j | Should Be $null
|
Receive-Job -Wait $j | Should -BeNullOrEmpty
|
||||||
Get-Content $TESTDRIVE/hello.txt | Should BeExactly "hello"
|
Get-Content $TESTDRIVE/hello.txt | Should -BeExactly "hello"
|
||||||
}
|
}
|
||||||
It "Test that error redirection is done in the background job" {
|
It "Test that error redirection is done in the background job" {
|
||||||
$j = Write-Error MyError 2> $TESTDRIVE/myerror.txt &
|
$j = Write-Error MyError 2> $TESTDRIVE/myerror.txt &
|
||||||
Receive-Job -Wait $j | Should Be $null
|
Receive-Job -Wait $j | Should -BeNullOrEmpty
|
||||||
Get-Content -Raw $TESTDRIVE/myerror.txt | Should Match "MyError"
|
Get-Content -Raw $TESTDRIVE/myerror.txt | Should -Match "MyError"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Context "Backgrounding expressions" {
|
Context "Backgrounding expressions" {
|
||||||
|
@ -225,11 +225,11 @@ Describe "Ampersand background test" -tag "CI","Slow" {
|
||||||
}
|
}
|
||||||
It "handles backgrounding expressions" {
|
It "handles backgrounding expressions" {
|
||||||
$j = 2+3 &
|
$j = 2+3 &
|
||||||
Receive-Job $j -Wait | Should Be 5
|
Receive-Job $j -Wait | Should -Be 5
|
||||||
}
|
}
|
||||||
It "handles backgrounding mixed expressions" {
|
It "handles backgrounding mixed expressions" {
|
||||||
$j = 1..10 | ForEach-Object -Begin {$s=0} -Process {$s += $_} -End {$s} &
|
$j = 1..10 | ForEach-Object -Begin {$s=0} -Process {$s += $_} -End {$s} &
|
||||||
Receive-Job -Wait $j | Should Be 55
|
Receive-Job -Wait $j | Should -Be 55
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ Describe "Out-Default Tests" -tag CI {
|
||||||
`$null = Stop-Transcript
|
`$null = Stop-Transcript
|
||||||
"@
|
"@
|
||||||
|
|
||||||
& $powershell -noprofile -command $script | Should BeExactly 'bye'
|
& $powershell -noprofile -command $script | Should -BeExactly 'bye'
|
||||||
"TestDrive:\transcript.txt" | Should FileContentMatch 'hello'
|
"TestDrive:\transcript.txt" | Should -FileContentMatch 'hello'
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Out-Default reverts transcription state when used more than once in a pipeline" {
|
It "Out-Default reverts transcription state when used more than once in a pipeline" {
|
||||||
& $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should BeExactly "Hello"
|
& $powershell -noprofile -command "Out-Default -Transcript | Out-Default -Transcript; 'Hello'" | Should -BeExactly "Hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Out-Default reverts transcription state when exception occurs in pipeline" {
|
It "Out-Default reverts transcription state when exception occurs in pipeline" {
|
||||||
& $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should BeExactly "Hello"
|
& $powershell -noprofile -command "try { & { throw } | Out-Default -Transcript } catch {}; 'Hello'" | Should -BeExactly "Hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Out-Default reverts transcription state even if Dispose() isn't called" {
|
It "Out-Default reverts transcription state even if Dispose() isn't called" {
|
||||||
|
@ -37,6 +37,6 @@ Describe "Out-Default Tests" -tag CI {
|
||||||
[GC]::WaitForPendingFinalizers();
|
[GC]::WaitForPendingFinalizers();
|
||||||
'hello'
|
'hello'
|
||||||
"@
|
"@
|
||||||
& $powershell -noprofile -command $script | Should BeExactly 'hello'
|
& $powershell -noprofile -command $script | Should -BeExactly 'hello'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ Describe "Out-Host Tests" -tag CI {
|
||||||
$stringToWrite = "thing to write"
|
$stringToWrite = "thing to write"
|
||||||
$stringExpected = "::$($stringToWrite):NewLine"
|
$stringExpected = "::$($stringToWrite):NewLine"
|
||||||
$result = $ps.AddScript("Out-Host -inputobject '$stringToWrite'").Invoke()
|
$result = $ps.AddScript("Out-Host -inputobject '$stringToWrite'").Invoke()
|
||||||
$th.UI.Streams.ConsoleOutput.Count | should be 1
|
$th.UI.Streams.ConsoleOutput.Count | Should -Be 1
|
||||||
$th.UI.Streams.ConsoleOutput[0] | should be $stringExpected
|
$th.UI.Streams.ConsoleOutput[0] | Should -BeExactly $stringExpected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@ try
|
||||||
$null = Register-PSSessionConfiguration -Name $ConfigurationName -TransportOption $Transport
|
$null = Register-PSSessionConfiguration -Name $ConfigurationName -TransportOption $Transport
|
||||||
$result = Get-PSSessionConfiguration -Name $ConfigurationName
|
$result = Get-PSSessionConfiguration -Name $ConfigurationName
|
||||||
|
|
||||||
$result.MaxShells | Should Be 40
|
$result.MaxShells | Should -Be 40
|
||||||
$result.IdleTimeoutms | Should Be 3600000
|
$result.IdleTimeoutms | Should -Be 3600000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Describe "Validate Get-PSSessionConfiguration, Enable-PSSessionConfiguration, Disable-PSSessionConfiguration, Unregister-PSSessionConfiguration cmdlets" -Tags @("CI", 'RequireAdminOnWindows') {
|
Describe "Validate Get-PSSessionConfiguration, Enable-PSSessionConfiguration, Disable-PSSessionConfiguration, Unregister-PSSessionConfiguration cmdlets" -Tags @("CI", 'RequireAdminOnWindows') {
|
||||||
|
@ -128,16 +128,16 @@ try
|
||||||
|
|
||||||
$Result = Get-PSSessionConfiguration
|
$Result = Get-PSSessionConfiguration
|
||||||
|
|
||||||
$Result.Name -contains $endpointName | Should Be $true
|
$Result.Name -contains $endpointName | Should -BeTrue
|
||||||
$Result.PSVersion | Should BeExactly $expectedPSVersion
|
$Result.PSVersion | Should -BeExactly $expectedPSVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-PSSessionConfiguration with Name parameter" {
|
It "Get-PSSessionConfiguration with Name parameter" {
|
||||||
|
|
||||||
$Result = Get-PSSessionConfiguration -Name $endpointName
|
$Result = Get-PSSessionConfiguration -Name $endpointName
|
||||||
|
|
||||||
$Result.Name | Should Be $endpointName
|
$Result.Name | Should -BeExactly $endpointName
|
||||||
$Result.PSVersion | Should BeExactly $expectedPSVersion
|
$Result.PSVersion | Should -BeExactly $expectedPSVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-PSSessionConfiguration -Name with wildcard character" {
|
It "Get-PSSessionConfiguration -Name with wildcard character" {
|
||||||
|
@ -146,21 +146,12 @@ try
|
||||||
|
|
||||||
$Result = Get-PSSessionConfiguration -Name $endpointWildcard
|
$Result = Get-PSSessionConfiguration -Name $endpointWildcard
|
||||||
|
|
||||||
$Result.Name -contains $endpointName | Should Be $true
|
$Result.Name -contains $endpointName | Should -BeTrue
|
||||||
$Result.PSVersion | Should BeExactly $expectedPSVersion
|
$Result.PSVersion | Should -BeExactly $expectedPSVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-PSSessionConfiguration -Name with Non-Existent session configuration" {
|
It "Get-PSSessionConfiguration -Name with Non-Existent session configuration" {
|
||||||
|
{ Get-PSSessionConfiguration -Name "NonExistantSessionConfiguration" -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.WriteErrorException"
|
||||||
try
|
|
||||||
{
|
|
||||||
Get-PSSessionConfiguration -Name "NonExistantSessionConfiguration" -ErrorAction Stop
|
|
||||||
throw "No Exception!"
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.WriteErrorException"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +200,8 @@ try
|
||||||
|
|
||||||
UnregisterPSSessionConfiguration -Name $SessionConfigName
|
UnregisterPSSessionConfiguration -Name $SessionConfigName
|
||||||
|
|
||||||
$TestConfigStateBeforeChange | Should be "$InitialSessionStateEnabled"
|
$TestConfigStateBeforeChange | Should -Be "$InitialSessionStateEnabled"
|
||||||
$TestConfigStateAfterChange | Should be "$FinalSessionStateEnabled"
|
$TestConfigStateAfterChange | Should -Be "$FinalSessionStateEnabled"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,8 +281,8 @@ try
|
||||||
$Result.Output = $false
|
$Result.Output = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
$Result.Output | Should Match $ExpectedOutput
|
$Result.Output | Should -Match $ExpectedOutput
|
||||||
$Result.Error | Should Match $ExpectedError
|
$Result.Error | Should -Match $ExpectedError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,8 +356,8 @@ try
|
||||||
$sn = $null
|
$sn = $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$Result.Output | Should be $ExpectedOutput
|
$Result.Output | Should -Be $ExpectedOutput
|
||||||
$Result.Error | Should be $null
|
$Result.Error | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create Test Startup Script
|
# Create Test Startup Script
|
||||||
|
@ -492,15 +483,15 @@ namespace PowershellTestConfigNamespace
|
||||||
Register-PSSessionConfiguration -Name $TestSessionConfigName -path $LocalConfigFilePath -MaximumReceivedObjectSizeMB $psmaximumreceivedobjectsizemb -MaximumReceivedDataSizePerCommandMB $psmaximumreceiveddatasizepercommandmb -UseSharedProcess:$UseSharedProcess -ThreadOptions $pssessionthreadoptions
|
Register-PSSessionConfiguration -Name $TestSessionConfigName -path $LocalConfigFilePath -MaximumReceivedObjectSizeMB $psmaximumreceivedobjectsizemb -MaximumReceivedDataSizePerCommandMB $psmaximumreceiveddatasizepercommandmb -UseSharedProcess:$UseSharedProcess -ThreadOptions $pssessionthreadoptions
|
||||||
$Result = [PSObject]@{Session = Get-PSSessionConfiguration -Name $TestSessionConfigName; Culture = (Get-Item WSMan:\localhost\Plugin\$endpointName\lang -ea SilentlyContinue).value}
|
$Result = [PSObject]@{Session = Get-PSSessionConfiguration -Name $TestSessionConfigName; Culture = (Get-Item WSMan:\localhost\Plugin\$endpointName\lang -ea SilentlyContinue).value}
|
||||||
|
|
||||||
$Result.Session.Name | Should be $TestSessionConfigName
|
$Result.Session.Name | Should -Be $TestSessionConfigName
|
||||||
$Result.Session.SessionType | Should be "Default"
|
$Result.Session.SessionType | Should -Be "Default"
|
||||||
$Result.Session.PSVersion | Should BeExactly $expectedPSVersion
|
$Result.Session.PSVersion | Should -BeExactly $expectedPSVersion
|
||||||
$Result.Session.Enabled | Should be $true
|
$Result.Session.Enabled | Should -BeTrue
|
||||||
$Result.Session.lang | Should be $Result.Culture
|
$Result.Session.lang | Should -Be $Result.Culture
|
||||||
$Result.Session.pssessionthreadoptions | Should be $pssessionthreadoptions
|
$Result.Session.pssessionthreadoptions | Should -Be $pssessionthreadoptions
|
||||||
$Result.Session.psmaximumreceivedobjectsizemb | Should be $psmaximumreceivedobjectsizemb
|
$Result.Session.psmaximumreceivedobjectsizemb | Should -Be $psmaximumreceivedobjectsizemb
|
||||||
$Result.Session.psmaximumreceiveddatasizepercommandmb | Should be $psmaximumreceiveddatasizepercommandmb
|
$Result.Session.psmaximumreceiveddatasizepercommandmb | Should -Be $psmaximumreceiveddatasizepercommandmb
|
||||||
$Result.Session.UseSharedProcess | Should be $UseSharedProcess
|
$Result.Session.UseSharedProcess | Should -Be $UseSharedProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate Register-PSSessionConfiguration -PSVersion" {
|
It "Validate Register-PSSessionConfiguration -PSVersion" {
|
||||||
|
@ -508,8 +499,8 @@ namespace PowershellTestConfigNamespace
|
||||||
Register-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
|
Register-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
|
||||||
$Session = Get-PSSessionConfiguration -Name $TestSessionConfigName
|
$Session = Get-PSSessionConfiguration -Name $TestSessionConfigName
|
||||||
|
|
||||||
$Session.Name | Should be $TestSessionConfigName
|
$Session.Name | Should -Be $TestSessionConfigName
|
||||||
$Session.PSVersion | Should BeExactly 5.1
|
$Session.PSVersion | Should -BeExactly 5.1
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate Register-PSSessionConfiguration -startupscript parameter" -Pending {
|
It "Validate Register-PSSessionConfiguration -startupscript parameter" -Pending {
|
||||||
|
@ -569,14 +560,14 @@ namespace PowershellTestConfigNamespace
|
||||||
Set-PSSessionConfiguration -Name $TestSessionConfigName -MaximumReceivedObjectSizeMB $psmaximumreceivedobjectsizemb -MaximumReceivedDataSizePerCommandMB $psmaximumreceiveddatasizepercommandmb -UseSharedProcess:$UseSharedProcess -ThreadOptions $pssessionthreadoptions -NoServiceRestart
|
Set-PSSessionConfiguration -Name $TestSessionConfigName -MaximumReceivedObjectSizeMB $psmaximumreceivedobjectsizemb -MaximumReceivedDataSizePerCommandMB $psmaximumreceiveddatasizepercommandmb -UseSharedProcess:$UseSharedProcess -ThreadOptions $pssessionthreadoptions -NoServiceRestart
|
||||||
$Result = [PSObject]@{Session = (Get-PSSessionConfiguration -Name $TestSessionConfigName) ; Culture = (Get-Item WSMan:\localhost\Plugin\microsoft.powershell\lang -ea SilentlyContinue).value}
|
$Result = [PSObject]@{Session = (Get-PSSessionConfiguration -Name $TestSessionConfigName) ; Culture = (Get-Item WSMan:\localhost\Plugin\microsoft.powershell\lang -ea SilentlyContinue).value}
|
||||||
|
|
||||||
$Result.Session.Name | Should be $TestSessionConfigName
|
$Result.Session.Name | Should -Be $TestSessionConfigName
|
||||||
$Result.Session.PSVersion | Should BeExactly $expectedPSVersion
|
$Result.Session.PSVersion | Should -BeExactly $expectedPSVersion
|
||||||
$Result.Session.Enabled | Should be $true
|
$Result.Session.Enabled | Should -BeTrue
|
||||||
$Result.Session.lang | Should be $result.Culture
|
$Result.Session.lang | Should -Be $result.Culture
|
||||||
$Result.Session.pssessionthreadoptions | Should be $pssessionthreadoptions
|
$Result.Session.pssessionthreadoptions | Should -Be $pssessionthreadoptions
|
||||||
$Result.Session.psmaximumreceivedobjectsizemb | Should be $psmaximumreceivedobjectsizemb
|
$Result.Session.psmaximumreceivedobjectsizemb | Should -Be $psmaximumreceivedobjectsizemb
|
||||||
$Result.Session.psmaximumreceiveddatasizepercommandmb | Should be $psmaximumreceiveddatasizepercommandmb
|
$Result.Session.psmaximumreceiveddatasizepercommandmb | Should -Be $psmaximumreceiveddatasizepercommandmb
|
||||||
$Result.Session.UseSharedProcess | Should be $UseSharedProcess
|
$Result.Session.UseSharedProcess | Should -Be $UseSharedProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate Set-PSSessionConfiguration -PSVersion" {
|
It "Validate Set-PSSessionConfiguration -PSVersion" {
|
||||||
|
@ -584,8 +575,8 @@ namespace PowershellTestConfigNamespace
|
||||||
Set-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
|
Set-PSSessionConfiguration -Name $TestSessionConfigName -PSVersion 5.1
|
||||||
$Session = (Get-PSSessionConfiguration -Name $TestSessionConfigName)
|
$Session = (Get-PSSessionConfiguration -Name $TestSessionConfigName)
|
||||||
|
|
||||||
$Session.Name | Should be $TestSessionConfigName
|
$Session.Name | Should -Be $TestSessionConfigName
|
||||||
$Session.PSVersion | Should BeExactly 5.1
|
$Session.PSVersion | Should -BeExactly 5.1
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate Set-PSSessionConfiguration -startupscript parameter" -Pending {
|
It "Validate Set-PSSessionConfiguration -startupscript parameter" -Pending {
|
||||||
|
@ -642,28 +633,19 @@ namespace PowershellTestConfigNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
$resultContent = invoke-expression ($result)
|
$resultContent = invoke-expression ($result)
|
||||||
$resultContent.GetType().ToString() | Should Be "System.Collections.Hashtable"
|
$resultContent | Should -BeOfType "System.Collections.Hashtable"
|
||||||
|
|
||||||
# The default created hashtable in the session configuration file would have the
|
# The default created hashtable in the session configuration file would have the
|
||||||
# following keys which we are validating below.
|
# following keys which we are validating below.
|
||||||
$resultContent.ContainsKey("SessionType") -and $resultContent.ContainsKey("SchemaVersion") -and $resultContent.ContainsKey("Guid") -and $resultContent.ContainsKey("Author") | Should Be $true
|
$resultContent.ContainsKey("SessionType") -and $resultContent.ContainsKey("SchemaVersion") -and $resultContent.ContainsKey("Guid") -and $resultContent.ContainsKey("Author") | Should -BeTrue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "Feature tests for New-PSSessionConfigurationFile Cmdlet" -Tags @("Feature", 'RequireAdminOnWindows') {
|
Describe "Feature tests for New-PSSessionConfigurationFile Cmdlet" -Tags @("Feature", 'RequireAdminOnWindows') {
|
||||||
|
|
||||||
It "Validate FullyQualifiedErrorId from New-PSSessionConfigurationFile when invalid path is provided as input" {
|
It "Validate FullyQualifiedErrorId from New-PSSessionConfigurationFile when invalid path is provided as input" {
|
||||||
|
{ New-PSSessionConfigurationFile "cert:\foo.pssc" } |
|
||||||
try
|
Should -Throw -ErrorId "InvalidPSSessionConfigurationFilePath,Microsoft.PowerShell.Commands.NewPSSessionConfigurationFileCommand"
|
||||||
{
|
|
||||||
$filePath = "cert:\foo.pssc"
|
|
||||||
New-PSSessionConfigurationFile $filePath
|
|
||||||
throw "No Exception!"
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "InvalidPSSessionConfigurationFilePath,Microsoft.PowerShell.Commands.NewPSSessionConfigurationFileCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,16 +748,7 @@ namespace PowershellTestConfigNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate FullyQualifiedErrorId from Test-PSSessionConfigurationFile when invalid path is provided as input" {
|
It "Validate FullyQualifiedErrorId from Test-PSSessionConfigurationFile when invalid path is provided as input" {
|
||||||
|
{ Test-PSSessionConfigurationFile "cert:\foo.pssc" -ErrorAction Stop } | Should -Throw -ErrorId "PSSessionConfigurationFileNotFound,Microsoft.PowerShell.Commands.TestPSSessionConfigurationFileCommand"
|
||||||
try
|
|
||||||
{
|
|
||||||
Test-PSSessionConfigurationFile "cert:\foo.pssc" -ErrorAction Stop
|
|
||||||
throw "No Exception!"
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "PSSessionConfigurationFileNotFound,Microsoft.PowerShell.Commands.TestPSSessionConfigurationFileCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Validate FullyQualifiedErrorId from Test-PSSessionConfigurationFile when an invalid pssc file is provided as input and -Verbose parameter is specified" {
|
It "Validate FullyQualifiedErrorId from Test-PSSessionConfigurationFile when an invalid pssc file is provided as input and -Verbose parameter is specified" {
|
||||||
|
@ -783,7 +756,7 @@ namespace PowershellTestConfigNamespace
|
||||||
$configFilePath = join-path $TestDrive "SamplePSSessionConfigurationFile.pssc"
|
$configFilePath = join-path $TestDrive "SamplePSSessionConfigurationFile.pssc"
|
||||||
"InvalidData" | Out-File $configFilePath
|
"InvalidData" | Out-File $configFilePath
|
||||||
|
|
||||||
Test-PSSessionConfigurationFile $configFilePath -Verbose -ErrorAction Stop | Should Be $false
|
Test-PSSessionConfigurationFile $configFilePath -Verbose -ErrorAction Stop | Should -BeFalse
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Test case verifies that the generated config file passes validation" {
|
It "Test case verifies that the generated config file passes validation" {
|
||||||
|
@ -862,7 +835,7 @@ namespace PowershellTestConfigNamespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result | Should Be $true
|
$result | Should -BeTrue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,16 +21,16 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
|
||||||
$driveOffset = $pathName.IndexOf(":")
|
$driveOffset = $pathName.IndexOf(":")
|
||||||
$pathName = $pathName.Substring($driveOffset + 1)
|
$pathName = $pathName.Substring($driveOffset + 1)
|
||||||
$result = Get-Command -Name $pathName
|
$result = Get-Command -Name $pathName
|
||||||
$result | Should Not Be $null
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result.Name | Should Be WildCardCommandA.exe
|
$result.Name | Should -Be WildCardCommandA.exe
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Test wildcard with relative directory path" {
|
It "Test wildcard with relative directory path" {
|
||||||
push-location $TestDrive
|
push-location $TestDrive
|
||||||
$result = Get-Command -Name .\WildCardCommandA*
|
$result = Get-Command -Name .\WildCardCommandA*
|
||||||
pop-location
|
pop-location
|
||||||
$result | Should Not Be $null
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result | Should Be WildCardCommandA.exe
|
$result | Should -Be WildCardCommandA.exe
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Test with PowerShell wildcard and relative path" {
|
It "Test with PowerShell wildcard and relative path" {
|
||||||
|
@ -38,13 +38,13 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
|
||||||
|
|
||||||
# This should use the wildcard to find WildCardCommandA.exe
|
# This should use the wildcard to find WildCardCommandA.exe
|
||||||
$result = Get-Command -Name .\WildCardCommand[A].exe
|
$result = Get-Command -Name .\WildCardCommand[A].exe
|
||||||
$result | Should Not Be $null
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result | Should Be WildCardCommandA.exe
|
$result | Should -Be WildCardCommandA.exe
|
||||||
|
|
||||||
# This should find the file WildCardCommand[B].exe
|
# This should find the file WildCardCommand[B].exe
|
||||||
$result = Get-Command -Name .\WildCardCommand[B].exe
|
$result = Get-Command -Name .\WildCardCommand[B].exe
|
||||||
$result | Should Not Be $null
|
$result | Should -Not -BeNullOrEmpty
|
||||||
$result | Should Be WildCardCommand[B].exe
|
$result | Should -Be WildCardCommand[B].exe
|
||||||
|
|
||||||
Pop-Location
|
Pop-Location
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,12 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
|
||||||
It "Get-Command -ShowCommandInfo property field test" {
|
It "Get-Command -ShowCommandInfo property field test" {
|
||||||
$properties = ($commandInfo | Get-Member -MemberType NoteProperty)
|
$properties = ($commandInfo | Get-Member -MemberType NoteProperty)
|
||||||
$propertiesAsString = $properties.name | out-string
|
$propertiesAsString = $properties.name | out-string
|
||||||
$propertiesAsString | Should MatchExactly 'CommandType'
|
$propertiesAsString | Should -MatchExactly 'CommandType'
|
||||||
$propertiesAsString | Should MatchExactly 'Definition'
|
$propertiesAsString | Should -MatchExactly 'Definition'
|
||||||
$propertiesAsString | Should MatchExactly 'Module'
|
$propertiesAsString | Should -MatchExactly 'Module'
|
||||||
$propertiesAsString | Should MatchExactly 'ModuleName'
|
$propertiesAsString | Should -MatchExactly 'ModuleName'
|
||||||
$propertiesAsString | Should MatchExactly 'Name'
|
$propertiesAsString | Should -MatchExactly 'Name'
|
||||||
$propertiesAsString | Should MatchExactly 'ParameterSets'
|
$propertiesAsString | Should -MatchExactly 'ParameterSets'
|
||||||
}
|
}
|
||||||
|
|
||||||
$testcases = @(
|
$testcases = @(
|
||||||
|
@ -73,27 +73,27 @@ Describe "Tests Get-Command with relative paths and wildcards" -Tag "CI" {
|
||||||
$observed,
|
$observed,
|
||||||
$result
|
$result
|
||||||
)
|
)
|
||||||
$observed | Should BeExactly $result
|
$observed | Should -BeExactly $result
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-Command -ShowCommandInfo ParameterSets property field test" {
|
It "Get-Command -ShowCommandInfo ParameterSets property field test" {
|
||||||
$properties = ($commandInfo.ParameterSets[0] | Get-Member -MemberType NoteProperty)
|
$properties = ($commandInfo.ParameterSets[0] | Get-Member -MemberType NoteProperty)
|
||||||
$propertiesAsString = $properties.name | out-string
|
$propertiesAsString = $properties.name | out-string
|
||||||
$propertiesAsString | Should MatchExactly 'IsDefault'
|
$propertiesAsString | Should -MatchExactly 'IsDefault'
|
||||||
$propertiesAsString | Should MatchExactly 'Name'
|
$propertiesAsString | Should -MatchExactly 'Name'
|
||||||
$propertiesAsString | Should MatchExactly 'Parameters'
|
$propertiesAsString | Should -MatchExactly 'Parameters'
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-Command -ShowCommandInfo Parameters property field test" {
|
It "Get-Command -ShowCommandInfo Parameters property field test" {
|
||||||
$properties = ($commandInfo.ParameterSets[0].Parameters | Get-Member -MemberType NoteProperty)
|
$properties = ($commandInfo.ParameterSets[0].Parameters | Get-Member -MemberType NoteProperty)
|
||||||
$propertiesAsString = $properties.name | out-string
|
$propertiesAsString = $properties.name | out-string
|
||||||
$propertiesAsString | Should MatchExactly 'HasParameterSet'
|
$propertiesAsString | Should -MatchExactly 'HasParameterSet'
|
||||||
$propertiesAsString | Should MatchExactly 'IsMandatory'
|
$propertiesAsString | Should -MatchExactly 'IsMandatory'
|
||||||
$propertiesAsString | Should MatchExactly 'Name'
|
$propertiesAsString | Should -MatchExactly 'Name'
|
||||||
$propertiesAsString | Should MatchExactly 'ParameterType'
|
$propertiesAsString | Should -MatchExactly 'ParameterType'
|
||||||
$propertiesAsString | Should MatchExactly 'Position'
|
$propertiesAsString | Should -MatchExactly 'Position'
|
||||||
$propertiesAsString | Should MatchExactly 'ValidParamSetValues'
|
$propertiesAsString | Should -MatchExactly 'ValidParamSetValues'
|
||||||
$propertiesAsString | Should MatchExactly 'ValueFromPipeline'
|
$propertiesAsString | Should -MatchExactly 'ValueFromPipeline'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
$parameters += @{name=$name}
|
$parameters += @{name=$name}
|
||||||
}
|
}
|
||||||
$modules = Get-Module @parameters
|
$modules = Get-Module @parameters
|
||||||
$modules | Should Not BeNullOrEmpty
|
$modules | Should -Not -BeNullOrEmpty
|
||||||
$modules[0] | Should BeOfType "System.Management.Automation.PSModuleInfo"
|
$modules[0] | Should -BeOfType "System.Management.Automation.PSModuleInfo"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Get-Module can be called as an API with '<parameter>' = '<value>'" -TestCases @(
|
It "Get-Module can be called as an API with '<parameter>' = '<value>'" -TestCases @(
|
||||||
|
@ -64,11 +64,11 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
$getModuleCommand = [Microsoft.PowerShell.Commands.GetModuleCommand]::new()
|
$getModuleCommand = [Microsoft.PowerShell.Commands.GetModuleCommand]::new()
|
||||||
$getModuleCommand.$parameter = $value
|
$getModuleCommand.$parameter = $value
|
||||||
if ($parameter -eq "FullyQualifiedName") {
|
if ($parameter -eq "FullyQualifiedName") {
|
||||||
$getModuleCommand.FullyQualifiedName | Should BeOfType "Microsoft.PowerShell.Commands.ModuleSpecification"
|
$getModuleCommand.FullyQualifiedName | Should -BeOfType "Microsoft.PowerShell.Commands.ModuleSpecification"
|
||||||
$getModuleCommand.FullyQualifiedName.Name | Should Be "foo"
|
$getModuleCommand.FullyQualifiedName.Name | Should -BeExactly "foo"
|
||||||
$getModuleCommand.FullyQualifiedName.Version | Should Be "1.2.3"
|
$getModuleCommand.FullyQualifiedName.Version | Should -Be "1.2.3"
|
||||||
} else {
|
} else {
|
||||||
$getModuleCommand.$parameter | Should Be $value
|
$getModuleCommand.$parameter | Should -Be $value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ Describe "Remote module tests" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
|
|
||||||
It "Get-Module supports pipeline" {
|
It "Get-Module supports pipeline" {
|
||||||
$module = Get-Module -Name Microsoft.PowerShell.Utility
|
$module = Get-Module -Name Microsoft.PowerShell.Utility
|
||||||
Compare-Object $module ($module | Get-Module) | Should BeNullOrEmpty
|
Compare-Object $module ($module | Get-Module) | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
It "New-CimSession works" -Pending {
|
It "New-CimSession works" -Pending {
|
||||||
|
|
|
@ -70,14 +70,14 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
}
|
}
|
||||||
$importModuleCommand.$parameter = $value
|
$importModuleCommand.$parameter = $value
|
||||||
if ($parameter -eq "FullyQualifiedName") {
|
if ($parameter -eq "FullyQualifiedName") {
|
||||||
$importModuleCommand.FullyQualifiedName.Count | Should BeExactly 2
|
$importModuleCommand.FullyQualifiedName.Count | Should -BeExactly 2
|
||||||
$importModuleCommand.FullyQualifiedName | Should BeOfType "Microsoft.PowerShell.Commands.ModuleSpecification"
|
$importModuleCommand.FullyQualifiedName | Should -BeOfType "Microsoft.PowerShell.Commands.ModuleSpecification"
|
||||||
$importModuleCommand.FullyQualifiedName[0].Name | Should Be "foo"
|
$importModuleCommand.FullyQualifiedName[0].Name | Should -BeExactly "foo"
|
||||||
$importModuleCommand.FullyQualifiedName[0].RequiredVersion | Should Be "0.0"
|
$importModuleCommand.FullyQualifiedName[0].RequiredVersion | Should -Be "0.0"
|
||||||
$importModuleCommand.FullyQualifiedName[1].Name | Should Be "bar"
|
$importModuleCommand.FullyQualifiedName[1].Name | Should -BeExactly "bar"
|
||||||
$importModuleCommand.FullyQualifiedName[1].RequiredVersion | Should Be "1.1"
|
$importModuleCommand.FullyQualifiedName[1].RequiredVersion | Should -Be "1.1"
|
||||||
} else {
|
} else {
|
||||||
$importModuleCommand.$parameter | Should BeExactly $value
|
$importModuleCommand.$parameter | Should -BeExactly $value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,18 +96,18 @@ Describe "Remote import-module tests" -Tags 'Feature','RequireAdminOnWindows' {
|
||||||
param ($test, $parameters, $errorid)
|
param ($test, $parameters, $errorid)
|
||||||
|
|
||||||
Invoke-Command -Session $pssession -ScriptBlock { $env:PSModulePath += ";$(Split-Path $using:modulePath)"}
|
Invoke-Command -Session $pssession -ScriptBlock { $env:PSModulePath += ";$(Split-Path $using:modulePath)"}
|
||||||
Get-Module TestImport | Should BeNullOrEmpty
|
Get-Module TestImport | Should -BeNullOrEmpty
|
||||||
if ($errorid) {
|
if ($errorid) {
|
||||||
{ Import-Module @parameters -ErrorAction Stop } | ShouldBeErrorId $errorid
|
{ Import-Module @parameters -ErrorAction Stop } | ShouldBeErrorId $errorid
|
||||||
} else {
|
} else {
|
||||||
Import-Module @parameters
|
Import-Module @parameters
|
||||||
$module = Get-Module TestImport
|
$module = Get-Module TestImport
|
||||||
$module.Name | Should BeExactly "TestImport"
|
$module.Name | Should -BeExactly "TestImport"
|
||||||
|
|
||||||
# generated proxy module always uses 1.0
|
# generated proxy module always uses 1.0
|
||||||
$module.Version | Should BeExactly "1.0"
|
$module.Version | Should -BeExactly "1.0"
|
||||||
|
|
||||||
test-hello | Should BeExactly "world"
|
test-hello | Should -BeExactly "world"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,41 +3,17 @@
|
||||||
Describe "SSH Remoting Cmdlet Tests" -Tags "Feature" {
|
Describe "SSH Remoting Cmdlet Tests" -Tags "Feature" {
|
||||||
|
|
||||||
It "Enter-PSSession HostName parameter set should throw error for invalid key path" {
|
It "Enter-PSSession HostName parameter set should throw error for invalid key path" {
|
||||||
|
{ Enter-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
|
||||||
try
|
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.EnterPSSessionCommand"
|
||||||
{
|
|
||||||
Enter-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile
|
|
||||||
throw "Enter-PSSession did not throw expected PathNotFound exception."
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.EnterPSSessionCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "New-PSSession HostName parameter set should throw error for invalid key path" {
|
It "New-PSSession HostName parameter set should throw error for invalid key path" {
|
||||||
|
{ New-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile } |
|
||||||
try
|
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.NewPSSessionCommand"
|
||||||
{
|
|
||||||
New-PSSession -HostName localhost -UserName User -KeyFilePath NoKeyFile
|
|
||||||
throw "New-PSSession did not throw expected PathNotFound exception."
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.NewPSSessionCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Invoke-Command HostName parameter set should throw error for invalid key path" {
|
It "Invoke-Command HostName parameter set should throw error for invalid key path" {
|
||||||
|
{ Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock {1} } |
|
||||||
try
|
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand"
|
||||||
{
|
|
||||||
Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock {1}
|
|
||||||
throw "Invoke-Command did not throw expected PathNotFound exception."
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,18 @@ Describe "Remove-Module" -Tags "CI" {
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
Import-Module -Name $moduleName -Force
|
Import-Module -Name $moduleName -Force
|
||||||
(Get-Module -Name $moduleName).Name | Should be $moduleName
|
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should be able to remove a module with using Name switch" {
|
It "should be able to remove a module with using Name switch" {
|
||||||
{ Remove-Module -Name $moduleName } | Should Not Throw
|
{ Remove-Module -Name $moduleName } | Should -Not -Throw
|
||||||
(Get-Module -Name $moduleName).Name | Should BeNullOrEmpty
|
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
It "should be able to remove a module with using ModuleInfo switch" {
|
It "should be able to remove a module with using ModuleInfo switch" {
|
||||||
$a = Get-Module -Name $moduleName
|
$a = Get-Module -Name $moduleName
|
||||||
{ Remove-Module -ModuleInfo $a } | Should Not Throw
|
{ Remove-Module -ModuleInfo $a } | Should -Not -Throw
|
||||||
(Get-Module -Name $moduleName).Name | Should BeNullOrEmpty
|
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach {
|
AfterEach {
|
||||||
|
|
|
@ -7,13 +7,13 @@ Describe "Set-PSDebug" -Tags "CI" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to go through the tracing options" -Skip:($env:APPVEYOR -eq "TRUE") {
|
It "Should be able to go through the tracing options" -Skip:($env:APPVEYOR -eq "TRUE") {
|
||||||
{ Set-PSDebug -Trace 0 } | Should Not Throw
|
{ Set-PSDebug -Trace 0 } | Should -Not -Throw
|
||||||
{ Set-PSDebug -Trace 1 } | Should Not Throw
|
{ Set-PSDebug -Trace 1 } | Should -Not -Throw
|
||||||
{ Set-PSDebug -Trace 2 } | Should Not Throw
|
{ Set-PSDebug -Trace 2 } | Should -Not -Throw
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should be able to set strict" -Skip:($env:APPVEYOR -eq "TRUE") {
|
It "Should be able to set strict" -Skip:($env:APPVEYOR -eq "TRUE") {
|
||||||
{ Set-PSDebug -Strict } | Should Not Throw
|
{ Set-PSDebug -Strict } | Should -Not -Throw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,14 +150,14 @@ Describe "Get-Command Tests" -Tags "CI" {
|
||||||
foreach($paramName in $parameterNames)
|
foreach($paramName in $parameterNames)
|
||||||
{
|
{
|
||||||
$foundParam = GetDynamicParameter -cmdlet $cmdlet -parameterName $paramName
|
$foundParam = GetDynamicParameter -cmdlet $cmdlet -parameterName $paramName
|
||||||
$foundParam.Name | Should Be $paramName
|
$foundParam.Name | Should -BeExactly $paramName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function VerifyParameterType($cmdlet, $parameterName, $ParameterType)
|
function VerifyParameterType($cmdlet, $parameterName, $ParameterType)
|
||||||
{
|
{
|
||||||
$foundParam = GetDynamicParameter -cmdlet $cmdlet -parameterName $parameterName
|
$foundParam = GetDynamicParameter -cmdlet $cmdlet -parameterName $parameterName
|
||||||
$foundParam.ParameterType | Should Be $ParameterType
|
$foundParam.ParameterType | Should -Be $ParameterType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ Describe "Get-Command Tests" -Tags "CI" {
|
||||||
$dynamicParameter = "Wait", "Encoding", "Delimiter"
|
$dynamicParameter = "Wait", "Encoding", "Delimiter"
|
||||||
foreach ($dynamicPara in $dynamicParameter)
|
foreach ($dynamicPara in $dynamicParameter)
|
||||||
{
|
{
|
||||||
$results[0].ParameterSets.Parameters.Name -contains $dynamicPara | Should be $false
|
$results[0].ParameterSets.Parameters.Name -contains $dynamicPara | Should -BeFalse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,9 +216,9 @@ Describe "Get-Command Tests" -Tags "CI" {
|
||||||
|
|
||||||
It "Verify Single Cmdlet Using Verb&Noun ParameterSet With Usage" {
|
It "Verify Single Cmdlet Using Verb&Noun ParameterSet With Usage" {
|
||||||
$results = Get-Command -Verb get -Noun content -Encoding Unicode -Syntax
|
$results = Get-Command -Verb get -Noun content -Encoding Unicode -Syntax
|
||||||
$results.ToString() | Should Match "-Encoding"
|
$results.ToString() | Should -Match "-Encoding"
|
||||||
$results.ToString() | Should Match "-Wait"
|
$results.ToString() | Should -Match "-Wait"
|
||||||
$results.ToString() | Should Match "-Delimiter"
|
$results.ToString() | Should -Match "-Delimiter"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Test Script Lookup Positive Script Info" {
|
It "Test Script Lookup Positive Script Info" {
|
||||||
|
@ -227,8 +227,8 @@ Describe "Get-Command Tests" -Tags "CI" {
|
||||||
"$a = dir" > $fullPath
|
"$a = dir" > $fullPath
|
||||||
$results = Get-Command $fullPath
|
$results = Get-Command $fullPath
|
||||||
|
|
||||||
$results.Name | Should Be $tempFile
|
$results.Name | Should -BeExactly $tempFile
|
||||||
$results.Definition | Should Be $fullPath
|
$results.Definition | Should -BeExactly $fullPath
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Two dynamic parameters are created properly" {
|
It "Two dynamic parameters are created properly" {
|
||||||
|
@ -240,15 +240,8 @@ Describe "Get-Command Tests" -Tags "CI" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Throw an Exception when set TestToRun to 'returnduplicateparameter'" {
|
It "Throw an Exception when set TestToRun to 'returnduplicateparameter'" {
|
||||||
try
|
{ Get-Command TestGetCommand-DynamicParametersDCR -TestToRun returnduplicateparameter -ErrorAction Stop } |
|
||||||
{
|
Should -Throw -ErrorId "GetCommandMetadataError,Microsoft.PowerShell.Commands.GetCommandCommand"
|
||||||
Get-Command TestGetCommand-DynamicParametersDCR -TestToRun returnduplicateparameter -ErrorAction Stop
|
|
||||||
throw "No Exception!"
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "GetCommandMetadataError,Microsoft.PowerShell.Commands.GetCommandCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "verify if get the proper dynamic parameter type skipped by issue #1430" -Pending {
|
It "verify if get the proper dynamic parameter type skipped by issue #1430" -Pending {
|
||||||
|
|
Loading…
Reference in a new issue