Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test/powershell/Modules/Microsoft.PowerShell.Core/History.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ Describe "History cmdlet test cases" -Tags "CI" {
It "Get-History returns proper history" {
# for this case, we'll *not* add to history
$result = $ps.AddCommand("Get-History").Invoke()
$result.Count | should be 3
$result[0].CommandLine | should be "Get-Date"
$result[1].CommandLine | should be "1+1"
$result[2].CommandLine | should be "Get-Location"
$result.Count | Should -Be 3
$result[0].CommandLine | Should -BeExactly "Get-Date"
$result[1].CommandLine | Should -Be "1+1"
$result[2].CommandLine | Should -BeExactly "Get-Location"
}
It "Invoke-History invokes proper command" {
$result = $ps.AddScript("Invoke-History 2").Invoke()
$result | Should be 2
$result | Should -Be 2
}
It "Clear-History removes history" {
$ps.AddCommand("Clear-History").Invoke()
$ps.commands.clear()
$result = $ps.AddCommand("Get-History").Invoke()
$result | should BeNullOrEmpty
$result | Should -BeNullOrEmpty
}
It "Add-History actually adds to history" {
# add this invocation to history
$ps.AddScript("Get-History|Add-History").Invoke($null,$setting)
# that's 4 history lines * 2
$ps.Commands.Clear()
$result = $ps.AddCommand("Get-History").Invoke()
$result.Count | Should be 8
$result.Count | Should -Be 8
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
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ Describe "History cmdlet test cases" -Tags "CI" {
$ps.Dispose()

## 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" {
Expand All @@ -108,6 +108,6 @@ Describe "History cmdlet test cases" -Tags "CI" {
$errorResult = $ps.Streams.Error[0].FullyQualifiedErrorId
$ps.Dispose()

$errorResult | Should be CommandNotFoundException
$errorResult | Should -BeExactly 'CommandNotFoundException'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ Describe "Import-Module" -Tags "CI" {

BeforeEach {
Remove-Module -Name $moduleName -Force
(Get-Module -Name $moduleName).Name | Should BeNullOrEmpty
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
}

AfterEach {
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" {
{ Import-Module -Name $moduleName } | Should Not Throw
(Get-Module -Name $moduleName).Name | Should Be $moduleName
{ Import-Module -Name $moduleName } | Should -Not -Throw
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
}

It "should be able to add a module with using ModuleInfo switch" {
$a = Get-Module -ListAvailable $moduleName
{ Import-Module -ModuleInfo $a } | Should Not Throw
(Get-Module -Name $moduleName).Name | Should Be $moduleName
{ Import-Module -ModuleInfo $a } | Should -Not -Throw
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
}

It "should be able to load an already loaded module" {
Import-Module $moduleName
{ $script:module = Import-Module $moduleName -PassThru -ErrorAction Stop } | Should Not Throw
Get-Module -Name $moduleName | Should Be $script:module
{ $script:module = Import-Module $moduleName -PassThru -ErrorAction Stop } | Should -Not -Throw
Get-Module -Name $moduleName | Should -BeExactly $script:module
}

It "should only load the specified version" {
Import-Module TestModule -RequiredVersion 1.1
(Get-Module TestModule).Version | Should BeIn "1.1"
(Get-Module TestModule).Version | Should -BeIn "1.1"
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ Describe "Import-Module with ScriptsToProcess" -Tags "CI" {
It "Verify ScriptsToProcess are executed <TestNameSuffix>" -TestCases $testCases {
param($TestNameSuffix,$ipmoParms,$Expected)
Import-Module @ipmoParms
Get-Content out.txt | Should Be $Expected
Get-Content out.txt | Should -BeExactly $Expected
}
}

Expand All @@ -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) {
$modulePath = Join-Path $env:windir "System32/WindowsPowershell/v1.0/Modules/PSScheduledJob"
Import-Module $modulePath
(Get-Command New-JobTrigger).Name | Should Be 'New-JobTrigger'
(Get-Command New-JobTrigger).Name | Should -BeExactly 'New-JobTrigger'
}
}
}
Expand Down Expand Up @@ -138,8 +138,8 @@ namespace ModuleCmdlets

#Ignore slash format difference under windows/Unix
$path = (Get-ChildItem $TESTDRIVE\System.dll).FullName
$results[0] | Should Be $path
$results[1] | Should BeExactly "BinaryModuleCmdlet1 exported by the ModuleCmdlets module."
$results[0] | Should -BeExactly $path
$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" {
Expand All @@ -150,9 +150,9 @@ namespace ModuleCmdlets
try
{
$module = Import-Module $psdFile -PassThru
$module.NestedModules | Should Not BeNullOrEmpty
$module.NestedModules | Should -Not -BeNullOrEmpty
$assemblyLocation = [Microsoft.PowerShell.Commands.AddTypeCommand].Assembly.Location
$module.NestedModules.ImplementingAssembly.Location | Should Be $assemblyLocation
$module.NestedModules.ImplementingAssembly.Location | Should -Be $assemblyLocation
}
finally
{
Expand Down Expand Up @@ -193,10 +193,10 @@ Describe "Import-Module should be case insensitive" -Tags 'CI' {
Set-Content -Path "$modulesPath/$modulePath/TESTMODULE.psm1" -Value "function mytest { 'hello' }"
Import-Module testMODULE
$m = Get-Module TESTmodule
$m | Should BeOfType "System.Management.Automation.PSModuleInfo"
$m.Name | Should BeIn "TESTMODULE"
mytest | Should BeExactly "hello"
$m | Should -BeOfType "System.Management.Automation.PSModuleInfo"
$m.Name | Should -BeIn "TESTMODULE"
mytest | Should -BeExactly "hello"
Remove-Module TestModule
Get-Module tESTmODULE | Should BeNullOrEmpty
Get-Module tESTmODULE | Should -BeNullOrEmpty
}
}
64 changes: 32 additions & 32 deletions test/powershell/Modules/Microsoft.PowerShell.Core/Job.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
Get-Job | Remove-Job -Force
}
It "Start-Job produces a job object" {
$j | Should BeOfType "System.Management.Automation.Job"
$j.Name | Should Be "My Job"
$j | Should -BeOfType "System.Management.Automation.Job"
$j.Name | Should -BeExactly "My Job"
}
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" {
Start-Job -ScriptBlock { 2 * 2 }
$jobs = Get-Job
$jobs.Count | Should Be 2
$jobs.Count | Should -Be 2
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" {
Remove-Job $j -Force
{ Get-Job $j -ErrorAction Stop } | ShouldBeErrorId "JobWithSpecifiedNameNotFound,Microsoft.PowerShell.Commands.GetJobCommand"
}
It "Receive-Job can retrieve job results" {
Wait-Job -Timeout 60 -id $j.id | Should Not BeNullOrEmpty
receive-job -id $j.id | Should be 2
Wait-Job -Timeout 60 -id $j.id | Should -Not -BeNullOrEmpty
receive-job -id $j.id | Should -Be 2
}
}
Context "Jobs with arguments" {
It "Start-Job accepts arguments" {
$sb = { Write-Output $args[1]; Write-Output $args[0] }
$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 -Join "," | Should Be "42,$TestDrive"
$r -Join "," | Should -Be "42,$TestDrive"
}
}
Context "jobs which take time" {
Expand All @@ -51,28 +51,28 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
}
It "Wait-Job will wait for a job" {
$result = Wait-Job $j
$result | Should Be $j
$j.State | Should Be "Completed"
$result | Should -Be $j
$j.State | Should -BeExactly "Completed"
}
It "Wait-Job will timeout waiting for a job" {
$result = Wait-Job -Timeout 2 $j
$result | Should Be $null
$result | Should -BeNullOrEmpty
}
It "Stop-Job will stop a job" {
Stop-Job -Id $j.Id
$j.State | Should Be "Stopped"
$j.State | Should -BeExactly "Stopped"
}
It "Remove-Job will not remove a running job" {
$id = $j.Id
Remove-Job $j -ErrorAction SilentlyContinue
$job = Get-Job -Id $id
$job | Should Be $j
$job | Should -Be $j
}
It "Remove-Job -Force will remove a running job" {
$id = $j.Id
Remove-Job $j -Force
$job = Get-Job -Id $id -ErrorAction SilentlyContinue
$job | Should Be $null
$job | Should -BeNullOrEmpty
}
}
Context "Retrieving partial output from jobs" {
Expand Down Expand Up @@ -130,13 +130,13 @@ Describe "Job Cmdlet Tests" -Tag "CI" {
It "Receive-Job will retrieve partial output" {
$result1 = 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" {
$result1 = GetResults $j 5 $true
$result2 = GetResults $j ($result1.Count + 5) $false
Compare-Object -SyncWindow 0 -PassThru $result1 $result2[0..($result1.Count-1)] | Should Be $null
$result2[$result1.Count - 1] + 1 | Should Be $result2[$result1.Count]
Compare-Object -SyncWindow 0 -PassThru $result1 $result2[0..($result1.Count-1)] | Should -BeNullOrEmpty
$result2[$result1.Count - 1] + 1 | Should -Be $result2[$result1.Count]
}
}
}
Expand All @@ -158,13 +158,13 @@ Describe "Debug-job test" -tag "Feature" {
It "Debug-Job will break into debugger" -pending {
$ps.AddScript('$job = start-job { 1..300 | ForEach-Object { sleep 1 } }').Invoke()
$ps.Commands.Clear()
$ps.Runspace.Debugger.GetCallStack() | Should BeNullOrEmpty
$ps.Runspace.Debugger.GetCallStack() | Should -BeNullOrEmpty
Start-Sleep 3
$asyncResult = $ps.AddScript('debug-job $job').BeginInvoke()
$ps.commands.clear()
Start-Sleep 2
$result = $ps.runspace.Debugger.GetCallStack()
$result.Command | Should be "<ScriptBlock>"
$result.Command | Should -BeExactly "<ScriptBlock>"
}
}

Expand All @@ -175,7 +175,7 @@ Describe "Ampersand background test" -tag "CI","Slow" {
}
It "Background with & produces a job object" {
$j = Write-Output Hi &
$j | Should BeOfType System.Management.Automation.Job
$j | Should -BeOfType System.Management.Automation.Job
}
}
Context "Variable tests" {
Expand All @@ -185,38 +185,38 @@ Describe "Ampersand background test" -tag "CI","Slow" {
It "doesn't cause error when variable is missing" {
Remove-Item variable:name -ErrorAction Ignore
$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" {
$n1 = "Bob"
$n2 = "Mary"
${n 3} = "Bill"
$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' {
$j = Write-Output $pid &
$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' {
$j = Write-Output $global:pid &
$cpid = Receive-Job -Wait $j
$pid | Should Not BeExactly $cpid
$pid | Should -Not -BeExactly $cpid
}
It "starts in the current directory" {
$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" {
$j = Write-Output hello > $TESTDRIVE/hello.txt &
Receive-Job -Wait $j | Should Be $null
Get-Content $TESTDRIVE/hello.txt | Should BeExactly "hello"
Receive-Job -Wait $j | Should -BeNullOrEmpty
Get-Content $TESTDRIVE/hello.txt | Should -BeExactly "hello"
}
It "Test that error redirection is done in the background job" {
$j = Write-Error MyError 2> $TESTDRIVE/myerror.txt &
Receive-Job -Wait $j | Should Be $null
Get-Content -Raw $TESTDRIVE/myerror.txt | Should Match "MyError"
Receive-Job -Wait $j | Should -BeNullOrEmpty
Get-Content -Raw $TESTDRIVE/myerror.txt | Should -Match "MyError"
}
}
Context "Backgrounding expressions" {
Expand All @@ -225,11 +225,11 @@ Describe "Ampersand background test" -tag "CI","Slow" {
}
It "handles backgrounding expressions" {
$j = 2+3 &
Receive-Job $j -Wait | Should Be 5
Receive-Job $j -Wait | Should -Be 5
}
It "handles backgrounding mixed expressions" {
$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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Describe "Out-Default Tests" -tag CI {
`$null = Stop-Transcript
"@

& $powershell -noprofile -command $script | Should BeExactly 'bye'
"TestDrive:\transcript.txt" | Should FileContentMatch 'hello'
& $powershell -noprofile -command $script | Should -BeExactly 'bye'
"TestDrive:\transcript.txt" | Should -FileContentMatch 'hello'
}

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" {
& $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" {
Expand All @@ -37,6 +37,6 @@ Describe "Out-Default Tests" -tag CI {
[GC]::WaitForPendingFinalizers();
'hello'
"@
& $powershell -noprofile -command $script | Should BeExactly 'hello'
& $powershell -noprofile -command $script | Should -BeExactly 'hello'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Describe "Out-Host Tests" -tag CI {
$stringToWrite = "thing to write"
$stringExpected = "::$($stringToWrite):NewLine"
$result = $ps.AddScript("Out-Host -inputobject '$stringToWrite'").Invoke()
$th.UI.Streams.ConsoleOutput.Count | should be 1
$th.UI.Streams.ConsoleOutput[0] | should be $stringExpected
$th.UI.Streams.ConsoleOutput.Count | Should -Be 1
$th.UI.Streams.ConsoleOutput[0] | Should -BeExactly $stringExpected
}
}
Loading