mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add migrated files
This commit is contained in:
committed by
James Truher
parent
721ad34c62
commit
7305b82b73
@@ -0,0 +1,64 @@
|
||||
Describe "History cmdlet test cases" -tags 'DRT' {
|
||||
|
||||
It "Tests Invoke-History on a cmdlet that generates output on all streams" {
|
||||
$streamSpammer = '
|
||||
function StreamSpammer
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
Write-Debug "Debug"
|
||||
Write-Error "Error"
|
||||
Write-Information "Information"
|
||||
Write-Progress "Progress"
|
||||
Write-Verbose "Verbose"
|
||||
Write-Warning "Warning"
|
||||
"Output"
|
||||
}
|
||||
|
||||
$informationPreference = "Continue"
|
||||
$debugPreference = "Continue"
|
||||
$verbosePreference = "Continue"
|
||||
'
|
||||
|
||||
$invocationSettings = New-Object System.Management.Automation.PSInvocationSettings
|
||||
$invocationSettings.AddToHistory = $true
|
||||
$ps = [PowerShell]::Create()
|
||||
$null = $ps.AddScript($streamSpammer).Invoke()
|
||||
$ps.Commands.Clear()
|
||||
$null = $ps.AddScript("StreamSpammer");
|
||||
$null = $ps.Invoke($null, $invocationSettings)
|
||||
$ps.Commands.Clear()
|
||||
$null = $ps.AddScript("Invoke-History -id 1")
|
||||
$result = $ps.Invoke($null, $invocationSettings)
|
||||
$outputCount = $(
|
||||
$ps.Streams.Error;
|
||||
$ps.Streams.Progress;
|
||||
$ps.Streams.Verbose;
|
||||
$ps.Streams.Debug;
|
||||
$ps.Streams.Warning;
|
||||
$ps.Streams.Information).Count
|
||||
$ps.Dispose()
|
||||
|
||||
## Twice per stream - once for the original invocatgion, and once for the re-invocation
|
||||
$outputCount | Should be 12
|
||||
}
|
||||
|
||||
It "Tests Invoke-History on a private command" {
|
||||
|
||||
$invocationSettings = New-Object System.Management.Automation.PSInvocationSettings
|
||||
$invocationSettings.AddToHistory = $true
|
||||
$ps = [PowerShell]::Create()
|
||||
$null = $ps.AddScript("(Get-Command Get-Process).Visibility = 'Private'").Invoke()
|
||||
$ps.Commands.Clear()
|
||||
$null = $ps.AddScript("Get-Process -id $pid")
|
||||
$null = $ps.Invoke($null, $invocationSettings)
|
||||
$ps.Commands.Clear()
|
||||
$null = $ps.AddScript("Invoke-History -id 1")
|
||||
$result = $ps.Invoke($null, $invocationSettings)
|
||||
$errorResult = $ps.Streams.Error[0].FullyQualifiedErrorId
|
||||
$ps.Dispose()
|
||||
|
||||
$errorResult | Should be CommandNotFoundException
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
##
|
||||
## Copyright (c) Microsoft Corporation, 2015
|
||||
##
|
||||
|
||||
Describe "Tests Get-Command with relative paths and wildcards" {
|
||||
|
||||
BeforeAll {
|
||||
# Create temporary EXE command files
|
||||
$null = New-Item -ItemType File -Path (Join-Path $env:Temp WildCardCommandA.exe) -ErrorAction Ignore
|
||||
$null = New-Item -ItemType File -Path (Join-Path $env:Temp WildCardCommand[B].exe) -ErrorAction Ignore
|
||||
}
|
||||
|
||||
It "Test wildcard with drive relative directory path" {
|
||||
$pathName = Join-Path $env:Temp "WildCardCommandA*"
|
||||
$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" {
|
||||
pushd $env:Temp
|
||||
$result = Get-Command -Name .\WildCardCommandA*
|
||||
popd
|
||||
$result | Should Not Be $null
|
||||
$result | Should Be WildCardCommandA.exe
|
||||
}
|
||||
|
||||
It "Test with PowerShell wildcard and reative path" {
|
||||
pushd $env:Temp
|
||||
|
||||
# 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
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Remove temporary files
|
||||
Remove-Item -Path (Join-Path $env:Temp WildCardCommand*) -Force -ErrorAction Ignore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
Describe "Job cmdlets" -Tags 'innerloop', 'DRT' {
|
||||
Context "Start-Job" {
|
||||
It "should be able to load by definitionName and type" {
|
||||
$jobname = "StartJobShouldBeAbleLoadByDefinitionNameAndType"
|
||||
try
|
||||
{
|
||||
$scheduledjob = Get-ScheduledJob -Name $jobname -ErrorAction SilentlyContinue
|
||||
|
||||
if (!$scheduledjob)
|
||||
{
|
||||
$scheduledjob = Register-ScheduledJob -Name $jobname -ScriptBlock {echo $args[0]} -ArgumentList ($jobname)
|
||||
}
|
||||
|
||||
$job = Start-Job -DefinitionName $jobname -Type "*ScheduledJob*"
|
||||
$actual = $job | Wait-Job | Receive-Job
|
||||
$actual | Should Be $jobname
|
||||
}
|
||||
finally
|
||||
{
|
||||
Remove-Job -Name $jobname -Force -ErrorAction SilentlyContinue
|
||||
Unregister-ScheduledJob -Name $jobname -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
It "no recurse should not return result from child jobs" {
|
||||
$message = "StartJobNoRecurseShouldNotReturnTheResultsFromAnyChildJobs"
|
||||
try
|
||||
{
|
||||
$job = Start-Job {echo $args[0]} -ArgumentList ($message)
|
||||
$result = $job | Wait-Job | Receive-Job -NoRecurse
|
||||
$result | Should BeNullOrEmpty
|
||||
|
||||
$result = $job.ChildJobs | Receive-Job
|
||||
$result | Should Be $message
|
||||
}
|
||||
finally
|
||||
{
|
||||
$job | Remove-Job -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user