Merge pull request #1246 from PowerShell/andschwa/guard-rawui

Guard RawUI when TTY is non-existent
This commit is contained in:
Jason Shirk authored and GitHub committed 2016-07-01 17:20:03 -07:00
commit 9a6655c147
19 files changed
+277 -195

No files matched your search

@@ -21,11 +21,7 @@ Describe "Configuration file locations" {
$expectedReadline = [IO.Path]::Combine($env:HOME, ".local", "share", "powershell", "PSReadLine", "ConsoleHost_history.txt")
}
if ($env:TRAVIS_OS_NAME -eq "osx") {
$ItArgs = @{ pending = $true }
} else {
$ItArgs = @{}
}
$ItArgs = @{}
}
BeforeEach {
@@ -65,8 +61,6 @@ Describe "Configuration file locations" {
# Using It @ItArgs, we automatically skip on Windows for all these tests
if ($IsWindows) {
$ItArgs = @{ skip = $true }
} elseif ($env:TRAVIS_OS_NAME -eq "osx") {
$ItArgs = @{ pending = $true }
} else {
$ItArgs = @{}
}
+133 -61
View File
@@ -1,60 +1,10 @@
using namespace System.Diagnostics
Describe "ConsoleHost unit tests" -Tag 'Slow' {
Describe "ConsoleHost unit tests" {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
Context "CommandLine" {
It "simple -args" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
& $powershell -noprofile { $args[0] } -args "hello world" | Should Be "hello world"
}
It "array -args" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
& $powershell -noprofile { $args[0] } -args 1,(2,3) | Should Be 1
(& $powershell -noprofile { $args[1] } -args 1,(2,3))[1] | Should Be 3
}
foreach ($x in "--help", "-help", "-h", "-?", "--he", "-hel", "--HELP", "-hEl") {
It "Accepts '$x' as a parameter for help" {
& $powershell -noprofile $x | ?{ $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
}
}
It "Should accept a Base64 encoded command" {
$commandString = "Get-Location"
$encodedCommand = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($commandString))
# We don't compare to `Get-Location` directly because object and formatted output comparisons are difficult
$expected = & $powershell -noprofile -command $commandString
$actual = & $powershell -noprofile -EncodedCommand $encodedCommand
$actual | Should Be $expected
}
}
Context "Pipe to/from powershell" {
$p = [PSCustomObject]@{X=10;Y=20}
It "xml input" {
$p | & $powershell -noprofile { $input | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } } | Should Be 30
$p | & $powershell -noprofile -inputFormat xml { $input | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } } | Should Be 30
}
It "text input" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
# Join (multiple lines) and remove whitespace (we don't care about spacing) to verify we converted to string (by generating a table)
$p | & $powershell -noprofile -inputFormat text { -join ($input -replace "\s","") } | Should Be "XY--1020"
}
It "xml output" {
& $powershell -noprofile { [PSCustomObject]@{X=10;Y=20} } | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } | Should Be 30
& $powershell -noprofile -outputFormat xml { [PSCustomObject]@{X=10;Y=20} } | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } | Should Be 30
}
It "text output" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
# Join (multiple lines) and remove whitespace (we don't care about spacing) to verify we converted to string (by generating a table)
-join (& $powershell -noprofile -outputFormat text { [PSCustomObject]@{X=10;Y=20} }) -replace "\s","" | Should Be "XY--1020"
}
}
Context "Redirected standard handles" {
function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn)
{
return [ProcessStartInfo]@{
@@ -84,19 +34,141 @@ Describe "ConsoleHost unit tests" -Tag 'Slow' {
$process.Kill()
}
}
}
It "Simple redirected output" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
Context "CommandLine" {
It "simple -args" {
& $powershell -noprofile { $args[0] } -args "hello world" | Should Be "hello world"
}
It "array -args" {
& $powershell -noprofile { $args[0] } -args 1,(2,3) | Should Be 1
(& $powershell -noprofile { $args[1] } -args 1,(2,3))[1] | Should Be 3
}
foreach ($x in "--help", "-help", "-h", "-?", "--he", "-hel", "--HELP", "-hEl") {
It "Accepts '$x' as a parameter for help" {
& $powershell -noprofile $x | ?{ $_ -match "PowerShell[.exe] -Help | -? | /?" } | Should Not BeNullOrEmpty
}
}
It "Should accept a Base64 encoded command" {
$commandString = "Get-Location"
$encodedCommand = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($commandString))
# We don't compare to `Get-Location` directly because object and formatted output comparisons are difficult
$expected = & $powershell -noprofile -command $commandString
$actual = & $powershell -noprofile -EncodedCommand $encodedCommand
$actual | Should Be $expected
}
}
Context "Pipe to/from powershell" {
$p = [PSCustomObject]@{X=10;Y=20}
It "xml input" {
$p | & $powershell -noprofile { $input | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } } | Should Be 30
$p | & $powershell -noprofile -inputFormat xml { $input | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } } | Should Be 30
}
It "text input" {
# Join (multiple lines) and remove whitespace (we don't care about spacing) to verify we converted to string (by generating a table)
$p | & $powershell -noprofile -inputFormat text { -join ($input -replace "\s","") } | Should Be "XY--1020"
}
It "xml output" {
& $powershell -noprofile { [PSCustomObject]@{X=10;Y=20} } | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } | Should Be 30
& $powershell -noprofile -outputFormat xml { [PSCustomObject]@{X=10;Y=20} } | Foreach-Object {$a = 0} { $a += $_.X + $_.Y } { $a } | Should Be 30
}
It "text output" {
# Join (multiple lines) and remove whitespace (we don't care about spacing) to verify we converted to string (by generating a table)
-join (& $powershell -noprofile -outputFormat text { [PSCustomObject]@{X=10;Y=20} }) -replace "\s","" | Should Be "XY--1020"
}
}
Context "Redirected standard output" {
It "Simple redirected output" {
$si = NewProcessStartInfo "-noprofile 1+1"
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
}
Context "Input redirected but not reading from stdin (not really interactive)" {
# Tests under this context are testing that we do not read from StandardInput
# even though it is redirected - we want to make sure we don't hang.
# So none of these tests should close StandardInput
It "Redirected input w/ implict -Command w/ -NonInteractive" {
$si = NewProcessStartInfo "-NonInteractive -noprofile 1+1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
It "Redirected input w/ implicit -Command w/o -NonInteractive" {
$si = NewProcessStartInfo "-noprofile 1+1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
It "Redirected input w/ explict -Command w/ -NonInteractive" {
$si = NewProcessStartInfo "-NonInteractive -noprofile -Command 1+1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
It "Redirected input w/ explicit -Command w/o -NonInteractive" {
$si = NewProcessStartInfo "-noprofile -Command 1+1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
It "Redirected input w/ -File w/ -NonInteractive" {
'1+1' | Out-File -Encoding Ascii -FilePath TestDrive:test.ps1 -Force
$si = NewProcessStartInfo "-noprofile -NonInteractive -File $testDrive\test.ps1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
It "Redirected input w/ -File w/o -NonInteractive" {
'1+1' | Out-File -Encoding Ascii -FilePath TestDrive:test.ps1 -Force
$si = NewProcessStartInfo "-noprofile -File $testDrive\test.ps1" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardOutput.ReadToEnd() | Should Be 2
EnsureChildHasExited $process
}
}
Context "Redirected standard input for 'interactive' use" {
$nl = [Environment]::Newline
# Redirected input is broken on Windows in .NET Core
It "Redirected input" -Pending:$IsWindows {
$si = NewProcessStartInfo "-noprofile ""`$function:prompt = { 'PS> ' }""" -RedirectStdIn
# All of the following tests replace the prompt (either via an initial command or interactively)
# so that we can read StandardOutput and realiably know exactly what the prompt is.
It "Interactive redirected input" {
$si = NewProcessStartInfo "-noprofile -nologo" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardInput.Write("`$function:prompt = { 'PS> ' }`n")
$null = $process.StandardOutput.ReadLine()
$process.StandardInput.Write("1+1`n")
$process.StandardOutput.ReadLine() | Should Be "PS> 1+1"
$process.StandardOutput.ReadLine() | Should Be "2"
$process.StandardInput.Write("1+2`n")
$process.StandardOutput.ReadLine() | Should Be "PS> 1+2"
$process.StandardOutput.ReadLine() | Should Be "3"
$process.StandardInput.Close()
$process.StandardOutput.ReadToEnd() | Should Be "PS> "
EnsureChildHasExited $process
}
It "Interactive redirected input w/ initial command" {
$si = NewProcessStartInfo "-noprofile -noexit ""`$function:prompt = { 'PS> ' }""" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardInput.Write("1+1`n")
$process.StandardOutput.ReadLine() | Should Be "PS> 1+1"
@@ -109,7 +181,7 @@ Describe "ConsoleHost unit tests" -Tag 'Slow' {
EnsureChildHasExited $process
}
It "Redirected input explicit prompting" -Pending:$IsCore {
It "Redirected input explicit prompting (-File -)" {
$si = NewProcessStartInfo "-noprofile -File -" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardInput.Write("`$function:prompt = { 'PS> ' }`n")
@@ -122,7 +194,7 @@ Describe "ConsoleHost unit tests" -Tag 'Slow' {
EnsureChildHasExited $process
}
It "Redirected input no prompting" -Pending:$IsCore {
It "Redirected input no prompting (-Command -)" {
$si = NewProcessStartInfo "-noprofile -" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardInput.Write("1+1`n")
@@ -131,8 +203,8 @@ Describe "ConsoleHost unit tests" -Tag 'Slow' {
EnsureChildHasExited $process
}
It "Redirected input w/ nested prompt" -Pending:$IsCore {
$si = NewProcessStartInfo "-noprofile ""`$function:prompt = { 'PS' + ('>'*(`$nestedPromptLevel+1)) + ' ' }""" -RedirectStdIn
It "Redirected input w/ nested prompt" {
$si = NewProcessStartInfo "-noprofile -noexit ""`$function:prompt = { 'PS' + ('>'*(`$nestedPromptLevel+1)) + ' ' }""" -RedirectStdIn
$process = RunPowerShell $si
$process.StandardInput.Write("`$host.EnterNestedPrompt()`n")
$process.StandardOutput.ReadLine() | Should Be "PS> `$host.EnterNestedPrompt()"
@@ -58,7 +58,7 @@ Describe "Format-Custom DRT basic functionality" -Tags DRT{
}
"@
It "Format-Custom with subobject should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Custom with subobject should work" {
$expectResult1 = "this is the name"
$expectResult2 = "this is the name of the sub object"
$testObject = @{}
@@ -74,7 +74,7 @@ Describe "Format-Custom DRT basic functionality" -Tags DRT{
$result | Should Match "two"
}
It "Format-Custom with Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Custom with Tree Object should work" {
$expectedResult=@"
class MyContainer1
{
@@ -203,7 +203,7 @@ class MyContainer1
$result | Should Be $expectedResult
}
It "Format-Custom with Empty Data Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Custom with Empty Data Tree Object should work" {
$expectedResult=@"
class MyContainer1
{
@@ -225,7 +225,7 @@ class MyContainer1
$result | Should Be $expectedResult
}
It "Format-Custom with Back Pointers Tree Object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Custom with Back Pointers Tree Object should work" {
$expectedResult=@"
class MyContainer1
{
@@ -268,7 +268,7 @@ class MyContainer1
$result | Should Be $expectedResult
}
It "Format-Custom with Leaf Only Data should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Custom with Leaf Only Data should work" {
$expectedResult=@"
class MyLeaf1
{
@@ -20,7 +20,7 @@ Describe "Format-List" {
$actual | Should Be $expected
}
It "Should produce the expected output" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should produce the expected output" {
$expected = "${nl}${nl}testName : testValue${nl}${nl}${nl}${nl}"
$in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
@@ -68,7 +68,7 @@ Describe "Format-List" {
}
Describe "Format-List DRT basic functionality" -Tags DRT{
It "Format-List with array should work"-Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-List with array should work" {
$al = (0..255)
$info = @{}
$info.array = $al
@@ -106,7 +106,7 @@ Describe "Format-List DRT basic functionality" -Tags DRT{
$result.Trim() | Should BeNullOrEmpty
}
It "Format-List with complex object for End-To-End should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-List with complex object for End-To-End should work" {
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}"
$eto = [MyDayOfWeek]::New()
$info = @{}
@@ -125,7 +125,7 @@ Describe "Format-List DRT basic functionality" -Tags DRT{
$result | Should Match "Value : {1, 2, 3, 4}"
}
It "Format-List with multiple same class object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){
It "Format-List with multiple same class object should work"{
Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}"
$testobjects = [TestClass]::New('name1',1),[TestClass]::New('name2',2),[TestClass]::New('name3',3)
$result = $testobjects|Format-List|Out-String
@@ -137,7 +137,7 @@ Describe "Format-List DRT basic functionality" -Tags DRT{
$result | Should Match "Length : 3"
}
It "Format-List with multiple different class object should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){
It "Format-List with multiple different class object should work"{
Add-Type -TypeDefinition "public class TestClass{public TestClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;}"
Add-Type -TypeDefinition "public class TestClass2{public TestClass2(string name,string value,int length){Name = name;Value = value; Length = length;}public string Name;public string Value;public int Length;}"
$testobjects = [TestClass]::New('name1',1),[TestClass2]::New('name2',"value2",2),[TestClass]::New('name3',3)
@@ -43,7 +43,7 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
}
}
It "Format-Table with array should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with array should work" {
$al = (0..255)
$info = @{}
$info.array = $al
@@ -51,7 +51,7 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$result | Should Match "array\s+{0, 1, 2, 3...}"
}
It "Format-Table with Negative Count should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with Negative Count should work" {
$FormatEnumerationLimit = -1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
@@ -66,21 +66,21 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$resultStr | Should Match "test\s+{...}"
}
It "Format-Table with Less Count should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with Less Count should work" {
$FormatEnumerationLimit = 1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1...}"
}
It "Format-Table with More Count should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with More Count should work" {
$FormatEnumerationLimit = 10
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should Match "test\s+{1, 2}"
}
It "Format-Table with Equal Count should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with Equal Count should work" {
$FormatEnumerationLimit = 2
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
@@ -104,14 +104,14 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$resultStr | Should Match "test\s+{1, 2}"
}
It "Format-Table with new line should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with new line should work" {
$info = @{}
$info.name = "1\n2"
$result = $info|Format-Table|Out-String
$result | Should Match "name\s+1.+2"
}
It "Format-Table with ExposeBug920454 should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with ExposeBug920454 should work" {
$IP1 = [System.Net.IPAddress]::Parse("1.1.1.1")
$IP2 = [System.Net.IPAddress]::Parse("4fde:0000:0000:0002:0022:f376:255.59.171.63")
$IPs = New-Object System.Collections.ArrayList
@@ -123,7 +123,7 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$result | Should Match "test\s+{1.1.1.1, 4fde::2:22:f376:ff3b:ab3f}"
}
It "Format-Table with Autosize should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with Autosize should work" {
$IP1 = [PSCustomObject]@{'name'='Bob';'size'=1234;'booleanValue'=$true;}
$IP2 = [PSCustomObject]@{'name'='Jim';'size'=5678;'booleanValue'=$false;}
$IPs = New-Object System.Collections.ArrayList
@@ -176,7 +176,7 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$result | Should BeNullOrEmpty
}
It "Format-Table with complex object for End-To-End should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with complex object for End-To-End should work" {
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}"
$eto = New-Object MyDayOfWeek
$info = @{}
@@ -191,7 +191,7 @@ Describe "Format-Table DRT Unit Tests" -Tags DRT{
$result | Should Match "enumerableTestObject\s+Sun"
}
It "Format-Table with Expand Enumerable should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Table with Expand Enumerable should work" {
$obj1 = "x 0","y 0"
$obj2 = "x 1","y 1"
$objs = New-Object System.Collections.ArrayList
@@ -40,7 +40,7 @@ Describe "Format-Wide" {
}
Describe "Format-Wide DRT basic functionality" -Tags DRT{
It "Format-Wide with array should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Wide with array should work" {
$al = (0..255)
$info = @{}
$info.array = $al
@@ -80,7 +80,7 @@ Describe "Format-Wide DRT basic functionality" -Tags DRT{
$result | Should Match "Line2"
}
It "Format-Wide with complex object for End-To-End should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Format-Wide with complex object for End-To-End should work" {
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}"
$eto = New-Object MyDayOfWeek
$info = @{}
@@ -95,7 +95,7 @@ Describe "Format-Wide DRT basic functionality" -Tags DRT{
$result | Should Match "enumerableTestObject"
}
It "Format-Wide with multiple same class object with grouping should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx"){
It "Format-Wide with multiple same class object with grouping should work"{
Add-Type -TypeDefinition "public class TestGroupingClass{public TestGroupingClass(string name,int length){Name = name;Length = length;}public string Name;public int Length;public string GroupingKey;}"
$testobject1 = [TestGroupingClass]::New('name1',1)
$testobject1.GroupingKey = "foo"
@@ -12,7 +12,7 @@ Describe "Get-Date DRT Unit Tests" -Tags DRT {
$result.Millisecond | Should be 200
}
It "using -displayhint produces the correct output" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "using -displayhint produces the correct output" {
$d = Get-date -Date:"Jan 1, 2020" -DisplayHint Date | Out-String
$d.Trim() | Should be "Wednesday, January 1, 2020"
}
@@ -52,7 +52,7 @@ Describe "Out-File" {
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
}
It "Should not overwrite when the noclobber switch is used" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should not overwrite when the noclobber switch is used" {
Out-File -FilePath $testfile -InputObject $inObject
@@ -67,7 +67,7 @@ Describe "Out-File" {
$actual[3] | Should Match "some test text"
}
It "Should Append a new line when the append switch is used" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should Append a new line when the append switch is used" {
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
{ Out-File -FilePath $testfile -InputObject $inObject -Append } | Should Not Throw
@@ -101,7 +101,7 @@ Describe "Out-File" {
}
It "Should allow the cmdlet to overwrite an existing read-only file" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should allow the cmdlet to overwrite an existing read-only file" {
# create a read-only text file
{ Out-File -FilePath $testfile -InputObject $inObject } | Should Not Throw
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true
@@ -1,6 +1,6 @@
Describe "Out-String DRT Unit Tests" -Tags DRT{
It "check display of properties with names containing wildcard characters" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "check display of properties with names containing wildcard characters" {
$results = new-object psobject | add-member -passthru noteproperty 'name with square brackets: [0]' 'myvalue' | out-string
$results.Length | Should BeGreaterThan 1
$results.GetType() | Should Be string
@@ -208,7 +208,7 @@ Describe "Set-Variable" {
$testVar | Should Be $testValue
}
It "Should be able to pipe object properties to output using the PassThru switch" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should be able to pipe object properties to output using the PassThru switch" {
$in = Set-Variable -Name testVar -Value "test" -Description "test description" -PassThru
$output = $in | Format-List -Property Description | Out-String
@@ -1,22 +1,18 @@
Describe "Write-Host DRT Unit Tests" -Tags DRT{
Describe "Write-Host DRT Unit Tests" -Tags DRT {
BeforeAll {
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
}
$testData = @(
@{ Name = 'NoNewline';Command = "Write-Host a,b -Separator ',' -ForegroundColor Yellow -BackgroundColor DarkBlue -NoNewline"; returnValue = "a,b" }
@{ Name = 'Separator';Command = "Write-Host a,b,c -Separator '+'"; returnValue = "a+b+c" }
)
It "write-Host works with '<Name>' switch" -TestCases $testData -Pending:$IsOSX {
param($Command, $returnValue)
If($IsLinux)
{
$content = powershell -noprofile -command $Command
}
If ($IsWindows)
{
$content = powershell.exe -noprofile -command $Command
}
It "write-Host works with '<Name>' switch" -TestCases $testData -Pending:$IsOSX {
param($Command, $returnValue)
$content | Should Be $returnValue
& $powershell -noprofile $Command | Should Be $returnValue
}
}
}
@@ -28,13 +28,13 @@ Describe "Stream writer tests" {
# These tests validate that a stream is actually being written to by redirecting the output of that stream
AfterEach { Remove-Item $targetfile }
It "Should write warnings to the warning stream" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should write warnings to the warning stream" {
Write-Warning "Test Warning" 3>&1 > $targetfile
Get-Content $targetfile | Should Be "Test Warning"
}
It "Should write error messages to the error stream" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should write error messages to the error stream" {
Write-Error "Testing Error" 2>&1 > $targetfile
$result = Get-OutputResults $targetfile
@@ -42,7 +42,7 @@ Describe "Stream writer tests" {
$result -match ": Testing Error" | Should Be $true
}
It "Should write debug messages to the debug stream" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should write debug messages to the debug stream" {
Write-Messages -Debug -EA SilentlyContinue 5>&1 > $targetfile
$result = Get-OutputResults $targetfile
@@ -51,7 +51,7 @@ Describe "Stream writer tests" {
$result -match "Debug Message" | Should Be $true
}
It "Should write messages to the verbose stream" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
It "Should write messages to the verbose stream" {
Write-Messages -Verbose 4>&1 > $targetfile
$result = Get-OutputResults $targetfile