From 616c15556f44bd20d01303d92225c103aef805e8 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Fri, 11 Nov 2016 11:53:40 -0800 Subject: [PATCH] Re-shuffle minishell tests --- test/powershell/Host/ConsoleHost.Tests.ps1 | 56 ++++++++++++++++--- .../NativeCommandProcessor.Tests.ps1 | 21 +++++++ .../NativeExecution/NativeMinishell.Tests.ps1 | 50 ----------------- 3 files changed, 68 insertions(+), 59 deletions(-) delete mode 100644 test/powershell/Language/Scripting/NativeExecution/NativeMinishell.Tests.ps1 diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index 1ab7fed1da..fba8a3b61b 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -1,5 +1,52 @@ using namespace System.Diagnostics +# Minishell (Singleshell) is a powershell concept. +# Its primary use-case is when somebody executes a scriptblock in the new powershell process. +# The objects are automatically marshelled to the child process and +# back to the parent session, so users can avoid custom +# serialization to pass objects between two processes. + +Describe 'minishell for native executables' -Tag 'CI' { + + BeforeAll { + $powershell = Join-Path -Path $PsHome -ChildPath "powershell" + } + + Context 'Streams from minishell' { + + It 'gets a hashtable object from minishell' { + $output = & $powershell -noprofile { @{'a' = 'b'} } + ($output | measure).Count | Should Be 1 + ($output.GetType().Name) | Should Be 'Hashtable' + $output['a'] | Should Be 'b' + } + + It 'gets the error stream from minishell' { + $output = & $powershell -noprofile { Write-Error 'foo' } 2>&1 + ($output | measure).Count | Should Be 1 + ($output.GetType().Name) | Should Be 'ErrorRecord' + $output.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException' + } + + It 'gets the information stream from minishell' { + $output = & $powershell -noprofile { Write-Information 'foo' } 6>&1 + ($output.GetType().Name) | Should Be 'InformationRecord' + $output | Should Be 'foo' + } + } + + Context 'Streams to minishell' { + It "passes input into minishell" { + $a = 1,2,3 + $val = $a | & $powershell -noprofile -command { $input } + $val.Count | Should Be 3 + $val[0] | Should Be 1 + $val[1] | Should Be 2 + $val[2] | Should Be 3 + } + } +} + Describe "ConsoleHost unit tests" -tags "Feature" { BeforeAll { @@ -53,15 +100,6 @@ Describe "ConsoleHost unit tests" -tags "Feature" { } } - It "Verify Simple Interop Scenario Child Single Shell" { - $a = 1,2,3 - $val = $a | & $powershell -noprofile -command { $input } - $val.Count | Should Be 3 - $val[0] | Should Be 1 - $val[1] | Should Be 2 - $val[2] | Should Be 3 - } - It "Verify Validate Dollar Error Populated should throw exception" { $origEA = $ErrorActionPreference $ErrorActionPreference = "Stop" diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 index 7a34facb85..d87bdc99a5 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeCommandProcessor.Tests.ps1 @@ -1,3 +1,24 @@ +Describe 'native commands lifecycle' -tags 'CI' { + + BeforeAll { + $powershell = Join-Path -Path $PsHome -ChildPath "powershell" + } + + It "native | ps | native doesn't block" { + $first = $true + & $powershell -command '1..5 | % {Start-Sleep -mill 100; $_}' | %{$_} | & $powershell -command '$input' | % { + if ($first) + { + $first = $false + $firstTime = [datetime]::Now + } + $lastTime = [datetime]::Now + } + + $lastTime - $firstTime | Should BeGreaterThan ([timespan]::new(0, 0, 0, 0, 100)) # 100 milliseconds + } +} + Describe "Native Command Processor" -tags "Feature" { BeforeAll { diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeMinishell.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeMinishell.Tests.ps1 deleted file mode 100644 index db00856537..0000000000 --- a/test/powershell/Language/Scripting/NativeExecution/NativeMinishell.Tests.ps1 +++ /dev/null @@ -1,50 +0,0 @@ -# Minishell is a powershell concept. -# Its primare use-case is when somebody executes a scriptblock in the new powershell process. -# The objects are automatically marshelled back to the parent session, so users can avoid custom -# serialization to pass objects between two processes. - -Describe 'minishell for native executables' -Tag 'CI' { - - BeforeAll { - $powershell = Join-Path -Path $PsHome -ChildPath "powershell" - } - - Context 'Streams' { - - It 'gets a hashtable object from minishell' { - $output = & $powershell { @{'a' = 'b'} } - ($output | measure).Count | Should Be 1 - ($output.GetType().Name) | Should Be 'Hashtable' - $output['a'] | Should Be 'b' - } - - It 'gets the error stream from minishell' { - $output = & $powershell { Write-Error 'foo' } 2>&1 - ($output | measure).Count | Should Be 1 - ($output.GetType().Name) | Should Be 'ErrorRecord' - $output.FullyQualifiedErrorId | Should Be 'Microsoft.PowerShell.Commands.WriteErrorException' - } - - It 'gets the information stream from minishell' { - $output = & $powershell { Write-Information 'foo' } 6>&1 - ($output.GetType().Name) | Should Be 'InformationRecord' - $output | Should Be 'foo' - } - } - - Context 'native commands lifecycle' { - It "native | ps | native doesn't block" { - $first = $true - & $powershell -command '1..5 | % {Start-Sleep -mill 100; $_}' | %{$_} | & $powershell -command '$input' | % { - if ($first) - { - $first = $false - $firstTime = [datetime]::Now - } - $lastTime = [datetime]::Now - } - - $lastTime - $firstTime | Should BeGreaterThan ([timespan]::new(0, 0, 0, 0, 100)) # 100 milliseconds - } - } -}