forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeStreams.Tests.ps1
More file actions
53 lines (43 loc) · 2.19 KB
/
Copy pathNativeStreams.Tests.ps1
File metadata and controls
53 lines (43 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Describe "Native streams behavior with PowerShell" -Tags 'CI' {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
Context "Error stream" {
# we are using powershell itself as an example of a native program.
# we can create a behavior we want on the fly and test complex scenarios.
$error.Clear()
$command = [string]::Join('', @(
'[Console]::Error.Write(\"foo`n`nbar`n`nbaz\"); ',
'[Console]::Error.Write(\"middle\"); ',
'[Console]::Error.Write(\"foo`n`nbar`n`nbaz\")'
))
$out = & $powershell -noprofile -command $command 2>&1
# this check should be the first one, because $error is a global shared variable
It 'should not add records to $error variable' {
# we are keeping existing Windows PS v5.1 behavior for $error variable
$error.Count | Should Be 9
}
It 'uses ErrorRecord object to return stderr output' {
($out | measure).Count | Should BeGreaterThan 1
$out[0] | Should BeOfType 'System.Management.Automation.ErrorRecord'
$out[0].FullyQualifiedErrorId | Should Be 'NativeCommandError'
$out | Select-Object -Skip 1 | % {
$_ | Should BeOfType 'System.Management.Automation.ErrorRecord'
$_.FullyQualifiedErrorId | Should Be 'NativeCommandErrorMessage'
}
}
It 'uses correct exception messages for error stream' {
($out | measure).Count | Should Be 9
$out[0].Exception.Message | Should Be 'foo'
$out[1].Exception.Message | Should Be ''
$out[2].Exception.Message | Should Be 'bar'
$out[3].Exception.Message | Should Be ''
$out[4].Exception.Message | Should Be 'bazmiddlefoo'
$out[5].Exception.Message | Should Be ''
$out[6].Exception.Message | Should Be 'bar'
$out[7].Exception.Message | Should Be ''
$out[8].Exception.Message | Should Be 'baz'
}
It 'preserves error stream as is with Out-String' {
($out | Out-String).Replace("`r", '') | Should Be "foo`n`nbar`n`nbazmiddlefoo`n`nbar`n`nbaz`n"
}
}
}