From 96ff914ee1792f430d10e790f876229959d6fd95 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Thu, 1 Sep 2016 14:37:21 -0700 Subject: [PATCH 01/14] Added tests for hashtabletoPSCustomObjectConversion, OutErrorVairable tests. --- ...htableToPSCustomObjectConversion.Tests.ps1 | Bin 0 -> 19744 bytes .../Scripting/OutErrorVariable.Tests.ps1 | 390 ++++++++++++++++++ 2 files changed, 390 insertions(+) create mode 100644 test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 create mode 100644 test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..c2fac792c4fff3a1a094441911ae5724a0d2803d GIT binary patch literal 19744 zcmeHPZExE)5a!no*nbc*15UTbXcMHsRs?A0b!&mO+1h>!g3Yn>w#81CI8B1Ce|_8Y z@O&XDQZj4j&7C1Qk|>h8J09O6{y3bjWz?c**53+TbQPKjq5YCU&s6Y zz;)M_cTL~)%mMCM>%{D#-6`&Sxa*)!7f+7tvu)Jm)dimH;Th`=ao)163rk~R8h9() zAK3Qf;TO<;h?e9_T6b`@i&}k@k;W!!2?t7j`AqK0Wgk$|02LxbQuZCFDa;yvlp=XO z40t_4?XYACbd{;|Irxaa{>JZZAeRApp|pl5W$Uv*@=9ll=9jiz6Lgc(P}+l03B>Q0C#`OHz39ORhrG-AHm&si}SNK~Blf z0Q?rVl%suYC3A+cC;tVgKC#a@o|I%4Eq3tZ{N@~@Hc}!>C^<*DNRxVBB(#tHlLp!V z>4B1EKPNc$K?&bUnz|_Gj1(Gm7QV;*ftBP*<-GExr;_FyFOvGgd6sISEjb5iGmfpT zkoor%R;jLywk@BJ&<{DG{VVW081c;+*sS=r9?LvR<0#@X z@uaVyYaFv`%3(K{-vJ^#P2->rymP$BG!qc+D&+!50=+$YnPvZjx*e^nPtq%babfkSOM!& z9UnRiMfyU1Q?Xwd=d#VTkzh!HdP+A}%5O~B%oG)B>!ynwtMsWESi?}a#S)gS$aU+t zubtFxYH3-wX^B*~IrGyQ6xvQk+XZw?qf5qjw9C|ci6&J`X>BD|rR|e(^XIjbhI$A& z%N)s_6?OVg&y>=DycrPF8fxVA&xurA8`3bFvqHx^mT&_$P*Ci{gs1%q&)Qb=y71$o z%hXk7N9fh*U1|N(nF|@Ob!($jZ$5_?D`(*7|L6}jJE%Di+O{2(JIqlTlzk=r7zqvWJi=_FX7Y*G z>(Jiq;k|H7d^`=5Ws{gbnRRrwv({WqB z#LbbLN0s5bXVY`aY@f<1Zl@z`Cu~nFP*}+WQuR(OGi9Ur| zCgHUjNqxp*T*T&PUrc3a z->*M98%M!xdKk3?F?aLWOl70zn~Y-Sv6)JJlC#AmQ+_EN=hz-`_Qj>r>NfX$JgTHBk{XD&j{0Mm@#_;nUCMwaJkobIuiAp>79O|-a>}>8ZQJ$}Nr-{C$ zI>%IH5d{0kJ4m$0@;RO{=`574=gdxY&_Z>SgCvqim=-~-w7<2Zf%F0Y`L|c`Cx~rICIT%MB-*M->Y)(}#p=C_Z z>E*eX$2{~8f4=$UIoG)opL_WnY5H|S$tg!-CztcZhTDcPu(ip9@M+e!_F?f%N(3 zhh2PL9a>R-zrqev<{r-QSN6Yije@&OmyvyWY`(>n-^1-A8=_MAuANyHQcBdqz24#8 z2ksl_fIC{3UDRT(DYZf)D~_@lN-K z;@p@2njv35@vE#CnBCUK5Mm(N1 zldtl{eWg|@^S?}t`{UO!WvOsAukI`2ru|}`Yj%Er4s-gYiX)$4XRLlv#~rn2urG?F z_#a#3OK^V==)2PQ{X}Br{~qMl$M{ZXyBqKy+~cF;Tenku6ScU9n)^PLB1aD`aT8w> zUtB)ZFCyc&$^YPq>E3`H=Ud`&(iPCKe_wu1s%j_b8@Ug~?YnidCAN3iRS~grb@$~Q zq5waW8%td^OUJrO`to)6sg;@N3wQsDe&n>N9=8=pTgJ!fLM~OR6FN4zlxe$aU8<9z M(yO{8)PFSp0m?sS^#A|> literal 0 HcmV?d00001 diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 new file mode 100644 index 00000000000..f2277992661 --- /dev/null +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -0,0 +1,390 @@ +function Validate-Result { + param($out, $outStr, $count, $v) + + It "$outStr.count" { $out.count | Should Be $count } + for($i=0; $i -lt $count; $i++) + { + It "$outStr[$i]" { $out[$i] | Should Be $v[$i] } + } +} + +Describe "Tests OutVariable only" -Tags "CI" { + BeforeAll { + + function get-foo1 + { + [CmdletBinding()] + param() + + "foo" + } + + function get-foo2 + { + [CmdletBinding()] + param() + + $pscmdlet.writeobject("foo") + } + + function get-bar + { + [CmdletBinding()] + param() + + "bar" + get-foo1 -outVariable global:a + } + } + + Context 'Updating OutVariable Case 1: pipe string' { + + get-foo1 -outVariable a > $null + + $a.count | Should Be 1 + $a[0] | Should Be "foo" + } + + + Context 'Updating OutVariable Case 2: $pscmdlet.writeobject' { + + get-foo2 -outVariable a > $null + + $a.count | Should Be 1 + $a[0] | Should Be "foo" + } + + + Context 'Appending OutVariable Case 1: pipe string' { + + $a = 'a','b' + get-foo1 -outVariable +a > $null + + Validate-Result $a '$a' 3 @("a", "b", "foo") + } + + + Context 'Appending OutVariable Case 2: $pscmdlet.writeobject' { + + $a = 'a','b' + get-foo2 -outVariable +a > $null + + Validate-Result $a '$a' 3 @("a", "b", "foo") + } + + Context 'Nested OutVariable' { + + get-bar -outVariable b > $null + + Validate-Result $global:a '$global:foo' 1 @("foo") + + Validate-Result $b '$b' 2 @("bar", "foo") + } +} + +Describe "Test ErrorVariable only" -Tags "CI" { + BeforeAll { + function get-foo1 + { + [CmdletBinding()] + param() + + write-error "foo" + } + + function get-foo2 + { + [CmdletBinding()] + param() + + $pscmdlet.WriteError($global:foo[0]) + } + + function get-bar + { + [CmdletBinding()] + param() + + write-error "bar" + get-foo1 -errorVariable global:a + } + } + Context 'Updating ErrorVariable Case 1: write-error' { + get-foo1 -errorVariable a 2> $null + + Validate-Result $a '$a' 1 @("foo") + } + + Context 'Updating ErrorVariable Case 2: $pscmdlet.WriteError' { + + write-error "foo" -errorVariable global:foo 2> $null + get-foo2 -errorVariable a 2> $null + + Validate-Result $global:foo '$global:foo' 1 @("foo") + } + + Context 'Appending ErrorVariable Case 1' { + + $a = 'a','b' + get-foo1 -errorVariable +a 2> $null + + Validate-Result $a '$a' 3 @("a", "b", "foo") + } + + Context 'Appending ErrorVariable Case 1' { + + write-error "foo" -errorVariable global:foo 2> $null + $a = 'a','b' + get-foo2 -errorVariable +a 2> $null + + Validate-Result $a '$a' 3 @("a", "b", "foo") + } + + Context 'Nested ErrorVariable' { + + get-bar -errorVariable b 2> $null + + It '$global:a.count' { $global:a.count | Should Be 1 } + It '$global:a[0]' {$global:a[0].ToString() | Should Be "foo" } + + It '$b.count' { $b.count | Should Be 2 } + It '$b[0]' { $b[0].ToString() -eq "bar" } + It '$b[1]' { $b[1].ToString() -eq "foo" } + } + + Context 'Nested ErrorVariable with redirection' { + + get-bar -errorVariable b 2>&1 > $null + + Validate-Result $global:a '$global:a' 1 @("foo") + Validate-Result $b '$b' 2 @("bar", "foo") + } + +} + +Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { + BeforeAll { + + function get-foo + { + [CmdletBinding()] + param() + + write-output "foo-output" + write-error "foo-error" + } + + function get-foo1 + { + [CmdletBinding()] + param() + + write-error "foo" + } + + function get-foo2 + { + [CmdletBinding()] + param() + + $pscmdlet.WriteError($global:foo[0]) + } + + function get-bar + { + [CmdletBinding()] + param() + + write-error "bar" + get-foo1 -errorVariable global:a + } + + function get-foo3 + { + [CmdletBinding()] + param() + + "foo-output-0" + write-output "foo-output-1" + write-error "foo-error" + } + + function get-bar2 + { + [CmdletBinding()] + param() + + "bar-output-0" + write-output "bar-output-1" + write-error "bar-error" + get-foo3 -OutVariable global:foo_out -errorVariable global:foo_err + } + } + + Context 'Update OutVariable and ErrorVariable' { + + get-foo3 -OutVariable out -errorVariable err 2> $null > $null + + Validate-Result $out '$out' 2 @("foo-output-0", "foo-output-1") + Validate-Result $err '$err' 1 @("foo-error") + } + + Context 'Update OutVariable and ErrorVariable' { + + get-bar2 -OutVariable global:bar_out -errorVariable global:bar_err 2> $null > $null + + Validate-Result $foo_out '$foo_out' 2 @("foo-output-0", "foo-output-1") + Validate-Result $foo_err '$foo_err' 1 @("foo-error") + + Validate-Result $bar_out '$bar_out' 4 @("bar-output-0", "bar-output-1", "foo-output-0", "foo-output-1") + Validate-Result $bar_err '$bar_err' 2 @("bar-error", "foo-error") + } + + Context 'Verify that exceptions are added to the ErrorVariable' { + + function get-foo4 + { + [CmdletBinding()] + param() + + write-error "foo-error" + + try + { + throw "foo-exception" + } + catch + {} + } + + get-foo4 -errorVariable err 2> $null + + Validate-Result $err '$err' 2 @("foo-error", "foo-exception") + } + + Context 'Error variable in multi-command pipeline' { + + + + function get-foo5 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $foo) + + process + { + write-output $foo + write-error $foo + } + } + + (get-foo5 "foo-message" -ev foo_err1 -ov foo_out1 | get-foo5 -ev foo_err2 -ov foo_out2 | get-foo5 -ev foo_err3 -ov foo_out3) 2>&1 > $null + + Validate-Result $foo_out1 '$foo_out1' 1 @("foo-message") + Validate-Result $foo_out2 '$foo_out2' 1 @("foo-message") + Validate-Result $foo_out3 '$foo_out3' 1 @("foo-message") + Validate-Result $foo_err1 '$foo_err1' 1 @("foo-message") + Validate-Result $foo_err2 '$foo_err2' 1 @("foo-message") + Validate-Result $foo_err3 '$foo_err3' 1 @("foo-message") + } + + Context 'Error variable in multi-command pipeline (with native cmdlet)' { + + (get-foo -ev foo_err | get-item -ev get_item_err ) 2>&1 > $null + + Validate-Result $foo_err '$foo_err' 1 @("foo-error") + + It '$get_item_err.count' { $get_item_err.count | Should Be 1 } + It '$get_item_err[0].exception' { $get_item_err[0].exception.GetType() | Should Be 'System.Management.Automation.ItemNotFoundException' } + } + + Context 'Multi-command pipeline with nested commands' { + + function get-bar3 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $i) + + write-error "bar-error" + write-output "bar-output" + get-foo + } + + (get-foo -errorVariable foo_err | get-bar3 -errorVariable bar_err) 2>&1 > $null + + Validate-Result $foo_err '$foo_err' 1 @("foo-error") + + Validate-Result $bar_err '$bar_err' 2 @("bar-error", "foo-error") +} + + Context 'multi-command pipeline with nested commands' { + + function get-foo6 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $i) + + write-error "foo-error" + write-output $i + } + + function get-bar4 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $i) + + write-error "bar-error" + get-foo6 "foo-output" -errorVariable global:foo_err1 | get-foo6 -errorVariable global:foo_err2 + } + + get-bar4 -errorVariable global:bar_err 2>&1 > $null + + Validate-Result $global:foo_err1 '$global:foo_err1' 1 @("foo-error") + Validate-Result $global:foo_err2 '$global:foo_err2' 1 @("foo-error") + + Validate-Result $global:bar_err '$global:bar_err' 2 @("bar-error", "foo-error") + } + + Context 'Nested output variables' { + BeforeAll { + + + function get-foo7 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $output) + + $output + write-error "foo-error" + } + + function get-bar5 + { + [CmdletBinding()] + param() + + "bar-output" + write-error "bar-error" + get-foo7 "foo-output" -ev global:foo_err1 -ov global:foo_out1 | get-foo7 -ev global:foo_err2 -ov global:foo_out2 + get-foo7 "foo-output" -ev global:foo_err3 -ov global:foo_out3 | get-foo7 -ev global:foo_err4 -ov global:foo_out4 + } + } + + get-bar5 -ev global:bar_err -ov global:bar_out 2>&1 > $null + + Validate-Result $global:foo_out1 '$global:foo_out1' 1 @("foo-output") + Validate-Result $global:foo_err1 '$global:foo_err1' 1 @("foo-error") + + Validate-Result $global:foo_out2 '$global:foo_out2' 1 @("foo-output") + Validate-Result $global:foo_err2 '$global:foo_err2' 1 @("foo-error") + + Validate-Result $global:foo_out3 '$global:foo_out3' 1 @("foo-output") + Validate-Result $global:foo_err3 '$global:foo_err3' 1 @("foo-error") + + Validate-Result $global:foo_out4 '$global:foo_out4' 1 @("foo-output") + Validate-Result $global:foo_err4 '$global:foo_err4' 1 @("foo-error") + + Validate-Result $global:bar_out '$global:bar_out' 3 @("bar-output", "foo-output", "foo-output") + Validate-Result $global:bar_err '$global:bar_err' 3 @("bar-error", "foo-error", "foo-error") + } +} \ No newline at end of file From 31f22c6bf2682fe0e14175875e43c09e3fd29543 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Thu, 1 Sep 2016 15:29:50 -0700 Subject: [PATCH 02/14] Update the title of hashtable to PSCustomObject conversion. --- test/csharp/csharp.nuget.props | 10 ++++++++++ ...htableToPSCustomObjectConversion.Tests.ps1 | Bin 19744 -> 19808 bytes 2 files changed, 10 insertions(+) create mode 100644 test/csharp/csharp.nuget.props diff --git a/test/csharp/csharp.nuget.props b/test/csharp/csharp.nuget.props new file mode 100644 index 00000000000..4492ed20c65 --- /dev/null +++ b/test/csharp/csharp.nuget.props @@ -0,0 +1,10 @@ + + + + C:\git\part4\Packages + + + + + + \ No newline at end of file diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 index c2fac792c4fff3a1a094441911ae5724a0d2803d..6cff1a7929604a54eef0fcd2bc4d5d19f18a0534 100644 GIT binary patch delta 38 scmZ25i}ArM#tCAAAq=Su#SA4ttiX`Qkk3#wxnJIT@+Ll!jb^WW0N~*Z=l}o! delta 44 ucmaDbi*dm$#tCBb?hL66c|csmkjaqDP|TnJ#H9=cK$s5{E7@53+6Mp Date: Fri, 2 Sep 2016 18:43:49 -0700 Subject: [PATCH 03/14] Update based on PR feedback --- ...htableToPSCustomObjectConversion.Tests.ps1 | Bin 19808 -> 9695 bytes .../Scripting/OutErrorVariable.Tests.ps1 | 292 +++++++++--------- 2 files changed, 147 insertions(+), 145 deletions(-) diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 index 6cff1a7929604a54eef0fcd2bc4d5d19f18a0534..504a1ece0d03c5c6d90678ab46c5a9b1e1b17a7c 100644 GIT binary patch literal 9695 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 ONrpXK0Z$@~WawQ|e= diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index f2277992661..2b314852008 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -1,14 +1,4 @@ -function Validate-Result { - param($out, $outStr, $count, $v) - - It "$outStr.count" { $out.count | Should Be $count } - for($i=0; $i -lt $count; $i++) - { - It "$outStr[$i]" { $out[$i] | Should Be $v[$i] } - } -} - -Describe "Tests OutVariable only" -Tags "CI" { +Describe "Tests OutVariable only" -Tags "CI" { BeforeAll { function get-foo1 @@ -35,50 +25,59 @@ Describe "Tests OutVariable only" -Tags "CI" { "bar" get-foo1 -outVariable global:a } - } - - Context 'Updating OutVariable Case 1: pipe string' { - - get-foo1 -outVariable a > $null - - $a.count | Should Be 1 - $a[0] | Should Be "foo" - } - + } - Context 'Updating OutVariable Case 2: $pscmdlet.writeobject' { + $testdata = @( + @{ Name = 'Updating OutVariable Case 1: pipe string'; + Command = "get-foo1"; + OutVariable = 'a'; + Expected = 'foo' + }, + @{ Name = 'Updating OutVariable Case 2: $pscmdlet.writeobject'; + Command = "get-foo2"; + OutVariable = 'a'; + Expected = 'foo' + } ) + + - get-foo2 -outVariable a > $null + It '' -TestCases $testdata { + param ( $Name, $Command, $OutVariable, $Expected ) - $a.count | Should Be 1 - $a[0] | Should Be "foo" + & $Command -OutVariable $OutVariable > $null + $a = Get-Variable -ValueOnly $OutVariable + $a | Should Be $Expected } - - Context 'Appending OutVariable Case 1: pipe string' { - - $a = 'a','b' - get-foo1 -outVariable +a > $null - - Validate-Result $a '$a' 3 @("a", "b", "foo") + $testdata1 = @( + @{ Name = 'Appending OutVariable Case 1: pipe string'; + Command = "get-foo1"; + OutVariable = 'a'; + PreSet = 'a','b'; + Expected = @("a", "b", "foo") + }, + @{ Name = 'Appending OutVariable Case 2: $pscmdlet.writeobject'; + Command = "get-foo2"; + OutVariable = 'a'; + PreSet = 'a','b'; + Expected = @("a", "b", "foo") + } + ) + + It '' -TestCases $testdata { + param ( $Name, $Command, $OutVariable, $PreSet, $Expected ) + + Set-Variable -Name $OutVariable -Value $PreSet + & $Command -OutVariable +$OutVariable > $null + $a = Get-Variable -ValueOnly $OutVariable + $a | Should Be $Expected } - - Context 'Appending OutVariable Case 2: $pscmdlet.writeobject' { - - $a = 'a','b' - get-foo2 -outVariable +a > $null - - Validate-Result $a '$a' 3 @("a", "b", "foo") - } - - Context 'Nested OutVariable' { + It 'Nested OutVariable' { get-bar -outVariable b > $null - - Validate-Result $global:a '$global:foo' 1 @("foo") - - Validate-Result $b '$b' 2 @("bar", "foo") + Validate-Result $global:a 'foo' + Validate-Result $b @("bar", "foo") } } @@ -109,55 +108,67 @@ Describe "Test ErrorVariable only" -Tags "CI" { get-foo1 -errorVariable global:a } } - Context 'Updating ErrorVariable Case 1: write-error' { - get-foo1 -errorVariable a 2> $null - - Validate-Result $a '$a' 1 @("foo") - } - - Context 'Updating ErrorVariable Case 2: $pscmdlet.WriteError' { - - write-error "foo" -errorVariable global:foo 2> $null - get-foo2 -errorVariable a 2> $null - - Validate-Result $global:foo '$global:foo' 1 @("foo") - } - - Context 'Appending ErrorVariable Case 1' { - - $a = 'a','b' - get-foo1 -errorVariable +a 2> $null - Validate-Result $a '$a' 3 @("a", "b", "foo") + + $testdata2 = @( + @{ Name = 'Updating ErrorVariable Case 1: write-error'; + Command = "get-foo1"; + ErrorVariable = 'a'; + Expected = 'foo' + }, + @{ Name = 'Updating ErrorVariable Case 2: $pscmdlet.WriteError'; + Command = "get-foo1"; + ErrorVariable = 'a'; + Expected = 'foo' + } + ) + + It '' -TestCases $testdata2 { + param ( $Name, $Command, $ErrorVariable, $Expected ) + + & $Command -ErrorVariable $ErrorVariable 2> $null + $a = Get-Variable -ValueOnly $ErrorVariable + $a | should be $Expected } - Context 'Appending ErrorVariable Case 1' { - - write-error "foo" -errorVariable global:foo 2> $null - $a = 'a','b' - get-foo2 -errorVariable +a 2> $null - - Validate-Result $a '$a' 3 @("a", "b", "foo") - } + $testdata3 = @( + @{ Name = 'Appending ErrorVariable Case 1: pipe string'; + Command = "get-foo1"; + ErrorVariable = 'a'; + PreSet = 'a','b'; + Expected = @("a", "b", "foo") + }, + @{ Name = 'Appending ErrorVariable Case 2: $pscmdlet.writeobject'; + Command = "get-foo2"; + ErrorVariable = 'a'; + PreSet = 'a','b'; + Expected = @("a", "b", "foo") + } + ) + + It '' -TestCases $testdata3 { + param ( $Name, $Command, $ErrorVariable, $PreSet, $Expected ) + + Set-Variable -Name $ErrorVariable -Value $PreSet + & $Command -ErrorVariable +$ErrorVariable 2> $null + $a = Get-Variable -ValueOnly $ErrorVariable + $a | should be $Expected + } - Context 'Nested ErrorVariable' { + It 'Nested ErrorVariable' { get-bar -errorVariable b 2> $null - It '$global:a.count' { $global:a.count | Should Be 1 } - It '$global:a[0]' {$global:a[0].ToString() | Should Be "foo" } - - It '$b.count' { $b.count | Should Be 2 } - It '$b[0]' { $b[0].ToString() -eq "bar" } - It '$b[1]' { $b[1].ToString() -eq "foo" } + $global:a | Should be 'foo' + $b | Should be @("bar","foo") } Context 'Nested ErrorVariable with redirection' { get-bar -errorVariable b 2>&1 > $null - Validate-Result $global:a '$global:a' 1 @("foo") - Validate-Result $b '$b' 2 @("bar", "foo") + $global:a | Should be 'foo' + $b | Should be @("bar", "foo") } } @@ -221,27 +232,26 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { } } - Context 'Update OutVariable and ErrorVariable' { + It 'Update OutVariable and ErrorVariable' { get-foo3 -OutVariable out -errorVariable err 2> $null > $null - Validate-Result $out '$out' 2 @("foo-output-0", "foo-output-1") - Validate-Result $err '$err' 1 @("foo-error") + $out | Should be @("foo-output-0", "foo-output-1") + $err | Should be "foo-error" } - Context 'Update OutVariable and ErrorVariable' { + It 'Update OutVariable and ErrorVariable' { get-bar2 -OutVariable global:bar_out -errorVariable global:bar_err 2> $null > $null - Validate-Result $foo_out '$foo_out' 2 @("foo-output-0", "foo-output-1") - Validate-Result $foo_err '$foo_err' 1 @("foo-error") + $foo_out | Should be @("foo-output-0", "foo-output-1") + $foo_err | Should be 'foo-error' - Validate-Result $bar_out '$bar_out' 4 @("bar-output-0", "bar-output-1", "foo-output-0", "foo-output-1") - Validate-Result $bar_err '$bar_err' 2 @("bar-error", "foo-error") + $bar_out | Should be @("bar-output-0", "bar-output-1", "foo-output-0", "foo-output-1") + $bar_err | Should be @("bar-error", "foo-error") } - Context 'Verify that exceptions are added to the ErrorVariable' { - + It 'Verify that exceptions are added to the ErrorVariable' { function get-foo4 { [CmdletBinding()] @@ -259,13 +269,10 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { get-foo4 -errorVariable err 2> $null - Validate-Result $err '$err' 2 @("foo-error", "foo-exception") + $err | Should be @("foo-error", "foo-exception") } - Context 'Error variable in multi-command pipeline' { - - - + It 'Error variable in multi-command pipeline' { function get-foo5 { [CmdletBinding()] @@ -280,44 +287,43 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { (get-foo5 "foo-message" -ev foo_err1 -ov foo_out1 | get-foo5 -ev foo_err2 -ov foo_out2 | get-foo5 -ev foo_err3 -ov foo_out3) 2>&1 > $null - Validate-Result $foo_out1 '$foo_out1' 1 @("foo-message") - Validate-Result $foo_out2 '$foo_out2' 1 @("foo-message") - Validate-Result $foo_out3 '$foo_out3' 1 @("foo-message") - Validate-Result $foo_err1 '$foo_err1' 1 @("foo-message") - Validate-Result $foo_err2 '$foo_err2' 1 @("foo-message") - Validate-Result $foo_err3 '$foo_err3' 1 @("foo-message") + $foo_out1 | Should be "foo-message" + $foo_out2 | Should be "foo-message" + $foo_out3 | Should be "foo-message" + $foo_err1 | Should be "foo-message" + $foo_err2 | Should be "foo-message" + $foo_err3 | Should be "foo-message" } Context 'Error variable in multi-command pipeline (with native cmdlet)' { (get-foo -ev foo_err | get-item -ev get_item_err ) 2>&1 > $null - Validate-Result $foo_err '$foo_err' 1 @("foo-error") + Validate-Result $foo_err @("foo-error") It '$get_item_err.count' { $get_item_err.count | Should Be 1 } It '$get_item_err[0].exception' { $get_item_err[0].exception.GetType() | Should Be 'System.Management.Automation.ItemNotFoundException' } } - Context 'Multi-command pipeline with nested commands' { + It 'Multi-command pipeline with nested commands' { function get-bar3 { [CmdletBinding()] param([Parameter(ValueFromPipeline = $true)][string] $i) - write-error "bar-error" - write-output "bar-output" + write-error 'bar-error' + write-output 'bar-output' get-foo } (get-foo -errorVariable foo_err | get-bar3 -errorVariable bar_err) 2>&1 > $null - Validate-Result $foo_err '$foo_err' 1 @("foo-error") - - Validate-Result $bar_err '$bar_err' 2 @("bar-error", "foo-error") + $foo_err | Should be 'foo-error' + $bar_err | Should be @("bar-error", "foo-error") } - Context 'multi-command pipeline with nested commands' { + It 'multi-command pipeline with nested commands' { function get-foo6 { @@ -339,52 +345,48 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { get-bar4 -errorVariable global:bar_err 2>&1 > $null - Validate-Result $global:foo_err1 '$global:foo_err1' 1 @("foo-error") - Validate-Result $global:foo_err2 '$global:foo_err2' 1 @("foo-error") - - Validate-Result $global:bar_err '$global:bar_err' 2 @("bar-error", "foo-error") + $global:foo_err1 | Should be "foo-error" + $global:foo_err2 | Should be "foo-error" + $global:bar_err | Should be @("bar-error", "foo-error") } - Context 'Nested output variables' { - BeforeAll { - - - function get-foo7 - { - [CmdletBinding()] - param([Parameter(ValueFromPipeline = $true)][string] $output) + It 'Nested output variables' { + function get-foo7 + { + [CmdletBinding()] + param([Parameter(ValueFromPipeline = $true)][string] $output) - $output - write-error "foo-error" - } + $output + write-error "foo-error" + } - function get-bar5 - { - [CmdletBinding()] - param() + function get-bar5 + { + [CmdletBinding()] + param() - "bar-output" - write-error "bar-error" - get-foo7 "foo-output" -ev global:foo_err1 -ov global:foo_out1 | get-foo7 -ev global:foo_err2 -ov global:foo_out2 - get-foo7 "foo-output" -ev global:foo_err3 -ov global:foo_out3 | get-foo7 -ev global:foo_err4 -ov global:foo_out4 - } + "bar-output" + write-error "bar-error" + get-foo7 "foo-output" -ev global:foo_err1 -ov global:foo_out1 | get-foo7 -ev global:foo_err2 -ov global:foo_out2 + get-foo7 "foo-output" -ev global:foo_err3 -ov global:foo_out3 | get-foo7 -ev global:foo_err4 -ov global:foo_out4 } + get-bar5 -ev global:bar_err -ov global:bar_out 2>&1 > $null - Validate-Result $global:foo_out1 '$global:foo_out1' 1 @("foo-output") - Validate-Result $global:foo_err1 '$global:foo_err1' 1 @("foo-error") + $global:foo_out1 | Should be "foo-output" + $global:foo_err1 | Should be "foo-error" - Validate-Result $global:foo_out2 '$global:foo_out2' 1 @("foo-output") - Validate-Result $global:foo_err2 '$global:foo_err2' 1 @("foo-error") + $global:foo_out2 | Should be "foo-output" + $global:foo_err2 | Should be "foo-error" - Validate-Result $global:foo_out3 '$global:foo_out3' 1 @("foo-output") - Validate-Result $global:foo_err3 '$global:foo_err3' 1 @("foo-error") + $global:foo_out3 | Should be "foo-output" + $global:foo_err3 | Should be "foo-error" - Validate-Result $global:foo_out4 '$global:foo_out4' 1 @("foo-output") - Validate-Result $global:foo_err4 '$global:foo_err4' 1 @("foo-error") + $global:foo_out4 | Should be "foo-output" + $global:foo_err4 | Should be "foo-error" - Validate-Result $global:bar_out '$global:bar_out' 3 @("bar-output", "foo-output", "foo-output") - Validate-Result $global:bar_err '$global:bar_err' 3 @("bar-error", "foo-error", "foo-error") + $global:bar_out | Should be @("bar-output", "foo-output", "foo-output") + $global:bar_err | Should be @("bar-error", "foo-error", "foo-error") } } \ No newline at end of file From 0d8f3f97fb6642fa4646f34d4c9e1213102e3ef5 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Sun, 4 Sep 2016 16:52:10 -0700 Subject: [PATCH 04/14] updated more cases using testcase --- ...htableToPSCustomObjectConversion.Tests.ps1 | 18 +++--- .../Scripting/OutErrorVariable.Tests.ps1 | 64 ++++++++----------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 index 504a1ece0d0..f5213b4f8e5 100644 --- a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 +++ b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 @@ -4,8 +4,8 @@ { $script:a = new-object psobject -property $null } | Should not throw - It '$a should not be $null' { $a | Should Not Be $null } - It '$a type' { $a | should BeOfType "System.Management.automation.psobject" } + It '$a should not be $null' { $script:a | Should Not Be $null } + It '$a type' { $script:a | should BeOfType "System.Management.automation.psobject" } } It 'New-Object cmdlet should throw terminating errors when user specifies a non-existent property or tries to assign incompatible values' { @@ -42,20 +42,20 @@ Context 'Hashtable conversion to PSCustomObject succeeds (Insertion Order is not retained)' { { $script:x = [pscustomobject][hashtable]@{one=1;two=2}} | Should Not Throw It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $x | should BeOfType "System.Management.automation.psobject" } + It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } } Context 'Hashtable conversion to PSCustomObject retains insertion order of hashtable keys when passed a hashliteral' { - { $x = [pscustomobject]@{one=1;two=2} } | Should Not Throw + { $script:x = [pscustomobject]@{one=1;two=2} } | Should Not Throw It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $x | should BeOfType "System.Management.automation.psobject" } + It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } $p = 0 # Checks if the first property is One - $x.psobject.Properties | foreach-object ` + $script:x.psobject.Properties | foreach-object ` { if ($p -eq 0) { @@ -74,7 +74,7 @@ } | Should not throw It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $x | should BeOfType "System.Management.automation.psobject" } + It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } } @@ -96,11 +96,11 @@ { $script:x = [pscustomobject][ordered]@{one=1;two=2} } | Should Not Throw It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $x | should BeOfType "System.Management.automation.psobject" } + It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } $p = 0 # Checks if the first property is One - $x.psobject.Properties | foreach-object ` + $script:x.psobject.Properties | foreach-object ` { if ($p -eq 0) { diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 2b314852008..55743e2e76d 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -37,19 +37,7 @@ Command = "get-foo2"; OutVariable = 'a'; Expected = 'foo' - } ) - - - - It '' -TestCases $testdata { - param ( $Name, $Command, $OutVariable, $Expected ) - - & $Command -OutVariable $OutVariable > $null - $a = Get-Variable -ValueOnly $OutVariable - $a | Should Be $Expected - } - - $testdata1 = @( + }, @{ Name = 'Appending OutVariable Case 1: pipe string'; Command = "get-foo1"; OutVariable = 'a'; @@ -66,9 +54,15 @@ It '' -TestCases $testdata { param ( $Name, $Command, $OutVariable, $PreSet, $Expected ) - - Set-Variable -Name $OutVariable -Value $PreSet - & $Command -OutVariable +$OutVariable > $null + if($PreSet -ne $null) + { + Set-Variable -Name $OutVariable -Value $PreSet + & $Command -OutVariable +$OutVariable > $null + } + else + { + & $Command -OutVariable $OutVariable > $null + } $a = Get-Variable -ValueOnly $OutVariable $a | Should Be $Expected } @@ -76,8 +70,8 @@ It 'Nested OutVariable' { get-bar -outVariable b > $null - Validate-Result $global:a 'foo' - Validate-Result $b @("bar", "foo") + $global:a | Should Be 'foo' + $b | Should Be @("bar", "foo") } } @@ -110,7 +104,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { } - $testdata2 = @( + $testdata1 = @( @{ Name = 'Updating ErrorVariable Case 1: write-error'; Command = "get-foo1"; ErrorVariable = 'a'; @@ -120,18 +114,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { Command = "get-foo1"; ErrorVariable = 'a'; Expected = 'foo' - } - ) - - It '' -TestCases $testdata2 { - param ( $Name, $Command, $ErrorVariable, $Expected ) - - & $Command -ErrorVariable $ErrorVariable 2> $null - $a = Get-Variable -ValueOnly $ErrorVariable - $a | should be $Expected - } - - $testdata3 = @( + }, @{ Name = 'Appending ErrorVariable Case 1: pipe string'; Command = "get-foo1"; ErrorVariable = 'a'; @@ -146,12 +129,19 @@ Describe "Test ErrorVariable only" -Tags "CI" { } ) - It '' -TestCases $testdata3 { + It '' -TestCases $testdata1 { param ( $Name, $Command, $ErrorVariable, $PreSet, $Expected ) - - Set-Variable -Name $ErrorVariable -Value $PreSet - & $Command -ErrorVariable +$ErrorVariable 2> $null - $a = Get-Variable -ValueOnly $ErrorVariable + if($PreSet -ne $null) + { + Set-Variable -Name $ErrorVariable -Value $PreSet + & $Command -ErrorVariable +$ErrorVariable 2> $null + } + else + { + & $Command -ErrorVariable $ErrorVariable 2> $null + } + $a = (Get-Variable -ValueOnly $ErrorVariable) | % {$_.ToString()} + $a | should be $Expected } @@ -299,7 +289,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { (get-foo -ev foo_err | get-item -ev get_item_err ) 2>&1 > $null - Validate-Result $foo_err @("foo-error") + $foo_err | Should Be "foo-error" It '$get_item_err.count' { $get_item_err.count | Should Be 1 } It '$get_item_err[0].exception' { $get_item_err[0].exception.GetType() | Should Be 'System.Management.Automation.ItemNotFoundException' } From 17a518bbbd559b177fcc82f9be6bc14bae537d04 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Sun, 4 Sep 2016 21:23:50 -0700 Subject: [PATCH 05/14] update the format of the array --- .../Language/Scripting/OutErrorVariable.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 55743e2e76d..6768ad96d37 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -52,7 +52,7 @@ } ) - It '' -TestCases $testdata { + It 'Test: ' -TestCases $testdata { param ( $Name, $Command, $OutVariable, $PreSet, $Expected ) if($PreSet -ne $null) { @@ -118,13 +118,13 @@ Describe "Test ErrorVariable only" -Tags "CI" { @{ Name = 'Appending ErrorVariable Case 1: pipe string'; Command = "get-foo1"; ErrorVariable = 'a'; - PreSet = 'a','b'; + PreSet = @('a','b'); Expected = @("a", "b", "foo") }, @{ Name = 'Appending ErrorVariable Case 2: $pscmdlet.writeobject'; Command = "get-foo2"; ErrorVariable = 'a'; - PreSet = 'a','b'; + PreSet = @('a','b'); Expected = @("a", "b", "foo") } ) From 58486a7397f419eadffbf62348e90cf70a671972 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Sun, 4 Sep 2016 21:37:27 -0700 Subject: [PATCH 06/14] Update to investigate an failure only happy in CI system --- .../Language/Scripting/OutErrorVariable.Tests.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 6768ad96d37..c88c891a301 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -133,15 +133,18 @@ Describe "Test ErrorVariable only" -Tags "CI" { param ( $Name, $Command, $ErrorVariable, $PreSet, $Expected ) if($PreSet -ne $null) { + '$PreSet' + $PreSet | Out-String + '$Command' + $Command | Out-String Set-Variable -Name $ErrorVariable -Value $PreSet & $Command -ErrorVariable +$ErrorVariable 2> $null + $a = (Get-Variable -ValueOnly $ErrorVariable) | % {$_.ToString()} } else { & $Command -ErrorVariable $ErrorVariable 2> $null + $a = Get-Variable -ValueOnly $ErrorVariable } - $a = (Get-Variable -ValueOnly $ErrorVariable) | % {$_.ToString()} - + $a | should be $Expected } @@ -153,7 +156,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { $b | Should be @("bar","foo") } - Context 'Nested ErrorVariable with redirection' { + It 'Nested ErrorVariable with redirection' { get-bar -errorVariable b 2>&1 > $null @@ -311,7 +314,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { $foo_err | Should be 'foo-error' $bar_err | Should be @("bar-error", "foo-error") -} + } It 'multi-command pipeline with nested commands' { From daf1bf76cb17dc73a00e10117ef7ec265839f8f3 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Mon, 5 Sep 2016 18:17:45 -0700 Subject: [PATCH 07/14] update one test in OutErrorVariable --- .../Scripting/OutErrorVariable.Tests.ps1 | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index c88c891a301..f1f65152df7 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -101,6 +101,8 @@ Describe "Test ErrorVariable only" -Tags "CI" { write-error "bar" get-foo1 -errorVariable global:a } + + } @@ -120,12 +122,6 @@ Describe "Test ErrorVariable only" -Tags "CI" { ErrorVariable = 'a'; PreSet = @('a','b'); Expected = @("a", "b", "foo") - }, - @{ Name = 'Appending ErrorVariable Case 2: $pscmdlet.writeobject'; - Command = "get-foo2"; - ErrorVariable = 'a'; - PreSet = @('a','b'); - Expected = @("a", "b", "foo") } ) @@ -136,17 +132,27 @@ Describe "Test ErrorVariable only" -Tags "CI" { '$PreSet' + $PreSet | Out-String '$Command' + $Command | Out-String Set-Variable -Name $ErrorVariable -Value $PreSet - & $Command -ErrorVariable +$ErrorVariable 2> $null - $a = (Get-Variable -ValueOnly $ErrorVariable) | % {$_.ToString()} + & $Command -ErrorVariable +$ErrorVariable 2> $null } else { & $Command -ErrorVariable $ErrorVariable 2> $null - $a = Get-Variable -ValueOnly $ErrorVariable + } - + $a = (Get-Variable -ValueOnly $ErrorVariable) | % {$_.ToString()} $a | should be $Expected - } + } + + It 'Appending ErrorVariable Case 2: $pscmdlet.writeobject' { + write-error "foo" -errorVariable global:foo 2> $null + $a = 'a','b' + + get-foo2 -errorVariable +a 2> $null + + $a.count | Should Be 3 + $a| % {$_.ToString()} | Should Be @('a', 'b', 'foo') + + } It 'Nested ErrorVariable' { From 38957793c9fe0167303448519119227eea4c3ef7 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Tue, 6 Sep 2016 10:13:06 -0700 Subject: [PATCH 08/14] update a test title --- test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index f1f65152df7..015a395f209 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -143,7 +143,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { $a | should be $Expected } - It 'Appending ErrorVariable Case 2: $pscmdlet.writeobject' { + It 'Appending ErrorVariable Case 2: $pscmdlet.writeerror' { write-error "foo" -errorVariable global:foo 2> $null $a = 'a','b' From 71feca879cf05dbd839d4fd2f0b0435f45ab4865 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Tue, 6 Sep 2016 10:35:56 -0700 Subject: [PATCH 09/14] Fixed tests which has impact on other tests --- .../Scripting/OutErrorVariable.Tests.ps1 | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 015a395f209..98e89dfeecb 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -23,9 +23,9 @@ param() "bar" - get-foo1 -outVariable global:a + get-foo1 -outVariable script:a } - } + } $testdata = @( @{ Name = 'Updating OutVariable Case 1: pipe string'; @@ -70,7 +70,7 @@ It 'Nested OutVariable' { get-bar -outVariable b > $null - $global:a | Should Be 'foo' + $script:a | Should Be 'foo' $b | Should Be @("bar", "foo") } } @@ -90,7 +90,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { [CmdletBinding()] param() - $pscmdlet.WriteError($global:foo[0]) + $pscmdlet.WriteError($script:foo[0]) } function get-bar @@ -99,13 +99,10 @@ Describe "Test ErrorVariable only" -Tags "CI" { param() write-error "bar" - get-foo1 -errorVariable global:a + get-foo1 -errorVariable script:a } - - } - - + $testdata1 = @( @{ Name = 'Updating ErrorVariable Case 1: write-error'; Command = "get-foo1"; @@ -144,21 +141,21 @@ Describe "Test ErrorVariable only" -Tags "CI" { } It 'Appending ErrorVariable Case 2: $pscmdlet.writeerror' { - write-error "foo" -errorVariable global:foo 2> $null + write-error "foo" -errorVariable script:foo 2> $null $a = 'a','b' get-foo2 -errorVariable +a 2> $null $a.count | Should Be 3 $a| % {$_.ToString()} | Should Be @('a', 'b', 'foo') - + Remove-Variable -Name foo -Scope global -ErrorAction SilentlyContinue } It 'Nested ErrorVariable' { get-bar -errorVariable b 2> $null - $global:a | Should be 'foo' + $script:a | Should be 'foo' $b | Should be @("bar","foo") } @@ -166,7 +163,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { get-bar -errorVariable b 2>&1 > $null - $global:a | Should be 'foo' + $script:a | Should be 'foo' $b | Should be @("bar", "foo") } @@ -197,7 +194,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { [CmdletBinding()] param() - $pscmdlet.WriteError($global:foo[0]) + $pscmdlet.WriteError($script:foo[0]) } function get-bar @@ -206,7 +203,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { param() write-error "bar" - get-foo1 -errorVariable global:a + get-foo1 -errorVariable script:a } function get-foo3 @@ -227,7 +224,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { "bar-output-0" write-output "bar-output-1" write-error "bar-error" - get-foo3 -OutVariable global:foo_out -errorVariable global:foo_err + get-foo3 -OutVariable script:foo_out -errorVariable script:foo_err } } @@ -241,7 +238,7 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { It 'Update OutVariable and ErrorVariable' { - get-bar2 -OutVariable global:bar_out -errorVariable global:bar_err 2> $null > $null + get-bar2 -OutVariable script:bar_out -errorVariable script:bar_err 2> $null > $null $foo_out | Should be @("foo-output-0", "foo-output-1") $foo_err | Should be 'foo-error' @@ -339,14 +336,14 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { param([Parameter(ValueFromPipeline = $true)][string] $i) write-error "bar-error" - get-foo6 "foo-output" -errorVariable global:foo_err1 | get-foo6 -errorVariable global:foo_err2 + get-foo6 "foo-output" -errorVariable script:foo_err1 | get-foo6 -errorVariable script:foo_err2 } - get-bar4 -errorVariable global:bar_err 2>&1 > $null + get-bar4 -errorVariable script:bar_err 2>&1 > $null - $global:foo_err1 | Should be "foo-error" - $global:foo_err2 | Should be "foo-error" - $global:bar_err | Should be @("bar-error", "foo-error") + $script:foo_err1 | Should be "foo-error" + $script:foo_err2 | Should be "foo-error" + $script:bar_err | Should be @("bar-error", "foo-error") } It 'Nested output variables' { @@ -366,26 +363,26 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { "bar-output" write-error "bar-error" - get-foo7 "foo-output" -ev global:foo_err1 -ov global:foo_out1 | get-foo7 -ev global:foo_err2 -ov global:foo_out2 - get-foo7 "foo-output" -ev global:foo_err3 -ov global:foo_out3 | get-foo7 -ev global:foo_err4 -ov global:foo_out4 + get-foo7 "foo-output" -ev script:foo_err1 -ov script:foo_out1 | get-foo7 -ev script:foo_err2 -ov script:foo_out2 + get-foo7 "foo-output" -ev script:foo_err3 -ov script:foo_out3 | get-foo7 -ev script:foo_err4 -ov script:foo_out4 } - get-bar5 -ev global:bar_err -ov global:bar_out 2>&1 > $null + get-bar5 -ev script:bar_err -ov script:bar_out 2>&1 > $null - $global:foo_out1 | Should be "foo-output" - $global:foo_err1 | Should be "foo-error" + $script:foo_out1 | Should be "foo-output" + $script:foo_err1 | Should be "foo-error" - $global:foo_out2 | Should be "foo-output" - $global:foo_err2 | Should be "foo-error" + $script:foo_out2 | Should be "foo-output" + $script:foo_err2 | Should be "foo-error" - $global:foo_out3 | Should be "foo-output" - $global:foo_err3 | Should be "foo-error" + $script:foo_out3 | Should be "foo-output" + $script:foo_err3 | Should be "foo-error" - $global:foo_out4 | Should be "foo-output" - $global:foo_err4 | Should be "foo-error" + $script:foo_out4 | Should be "foo-output" + $script:foo_err4 | Should be "foo-error" - $global:bar_out | Should be @("bar-output", "foo-output", "foo-output") - $global:bar_err | Should be @("bar-error", "foo-error", "foo-error") + $script:bar_out | Should be @("bar-output", "foo-output", "foo-output") + $script:bar_err | Should be @("bar-error", "foo-error", "foo-error") } } \ No newline at end of file From ea5cb258f0c36f7c06468e4e2459dbf60b0b7cd9 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Tue, 6 Sep 2016 10:37:19 -0700 Subject: [PATCH 10/14] remove line to clean up the global variable since it has been changed o scipt scope. --- test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 98e89dfeecb..48ede535e60 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -147,8 +147,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { get-foo2 -errorVariable +a 2> $null $a.count | Should Be 3 - $a| % {$_.ToString()} | Should Be @('a', 'b', 'foo') - Remove-Variable -Name foo -Scope global -ErrorAction SilentlyContinue + $a| % {$_.ToString()} | Should Be @('a', 'b', 'foo') } It 'Nested ErrorVariable' { From 650c73a4bbd7eee84573e516cd075dcc74d43124 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Tue, 6 Sep 2016 10:39:58 -0700 Subject: [PATCH 11/14] Removed two lines for debugging purpuse --- test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 48ede535e60..5bf4ef78462 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -125,9 +125,7 @@ Describe "Test ErrorVariable only" -Tags "CI" { It '' -TestCases $testdata1 { param ( $Name, $Command, $ErrorVariable, $PreSet, $Expected ) if($PreSet -ne $null) - { - '$PreSet' + $PreSet | Out-String - '$Command' + $Command | Out-String + { Set-Variable -Name $ErrorVariable -Value $PreSet & $Command -ErrorVariable +$ErrorVariable 2> $null } From ae43daeb3aba0cfc905b1a12d92b4f5ee605c58c Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Sun, 11 Sep 2016 18:23:09 -0700 Subject: [PATCH 12/14] Updated based on Jim's feedback. --- ...htableToPSCustomObjectConversion.Tests.ps1 | 294 ++++++------------ 1 file changed, 89 insertions(+), 205 deletions(-) diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 index f5213b4f8e5..0709f899759 100644 --- a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 +++ b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 @@ -1,237 +1,121 @@ Describe "Tests for hashtable to PSCustomObject conversion" -Tags "CI" { - - Context 'New-Object cmdlet should accept empty hashtable or $null as Property argument' { - - { $script:a = new-object psobject -property $null } | Should not throw - - It '$a should not be $null' { $script:a | Should Not Be $null } - It '$a type' { $script:a | should BeOfType "System.Management.automation.psobject" } + BeforeAll { + class SampleClass5 { + [int]$a + [int]$b + SampleClass5([int]$x) { $this.a = $x } + SampleClass5([hashtable]$h) { $this.a = 100; $this.b = 100 } + } } - It 'New-Object cmdlet should throw terminating errors when user specifies a non-existent property or tries to assign incompatible values' { - - try - { - $source = @" - public class SampleClass6 - { - public SampleClass6(int x) - { - a = x; - } - - public SampleClass6() - { - } - - public int a; - public int b; - } -"@ - add-type -typedefinition $source - New-Object -TypeName SampleClass6 -Property @{aa=10;b=5} - Throw "Exception expected, execution should not have reached here" + $testdata = @( + @{ Name = 'New-Object cmdlet should accept empty hashtable or $null as Property argument'; + Cmd = "new-object psobject -property `$null"; + ExpectedType = 'System.Management.automation.psobject' + }, + @{ Name = 'Hashtable conversion to PSCustomObject succeeds (Insertion Order is not retained)'; + Cmd = "[pscustomobject][hashtable]`@{one=1;two=2}"; + ExpectedType = 'System.Management.automation.psobject' + }, + @{ Name = 'Hashtable(Stored in a variable) conversion to PSCustomObject succeeds (Insertion Order is not retained)'; + Cmd = "`$ht = @{one=1;two=2};[pscustomobject]`$ht"; + ExpectedType = 'System.Management.automation.psobject' } - catch { - $_.Exception | Should BeOfType "InvalidOperationException" - $_.Exception.Message | Should Match "aa" - $_.FullyQualifiedErrorId | should be "InvalidOperationException,Microsoft.PowerShell.Commands.NewObjectCommand" - } - } + ) - Context 'Hashtable conversion to PSCustomObject succeeds (Insertion Order is not retained)' { - { $script:x = [pscustomobject][hashtable]@{one=1;two=2}} | Should Not Throw - It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } - } - + It 'Type Validation: ' -TestCases:$testdata { + param ($Name, $Cmd, $ExpectedType) + Invoke-expression $Cmd -OutVariable a + $a = Get-Variable -Name a -ValueOnly + $a | should BeOfType $ExpectedType + } - Context 'Hashtable conversion to PSCustomObject retains insertion order of hashtable keys when passed a hashliteral' { - - { $script:x = [pscustomobject]@{one=1;two=2} } | Should Not Throw - - It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } + It 'Hashtable conversion to PSCustomObject retains insertion order of hashtable keys when passed a hashliteral' { + + $x = [pscustomobject]@{one=1;two=2} + $x | should BeOfType "System.Management.automation.psobject" $p = 0 # Checks if the first property is One - $script:x.psobject.Properties | foreach-object ` + $x.psobject.Properties | foreach-object ` { if ($p -eq 0) { $p++; - It '$_.Name' { $_.Name | Should Be 'one' } + $_.Name | Should Be 'one' } } - } - - - Context 'Hashtable(Stored in a variable) conversion to PSCustomObject succeeds (Insertion Order is not retained)' { - - { - $ht = @{one=1;two=2} - $script:x = [pscustomobject]$ht - } | Should not throw + } - It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } - } - - - It 'Conversion from PSCustomObject to hashtable should fail' { - - try - { - $x = [hashtable][pscustomobject]@{one=1;two=2} - Throw "Exception expected, execution should not have reached here" - } - catch - { - $_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should Be 'InvalidCastConstructorException' - } - } - - - Context 'Conversion of Ordered hashtable to PSCustomObject should succeed' { + It 'Conversion of Ordered hashtable to PSCustomObject should succeed' { - { $script:x = [pscustomobject][ordered]@{one=1;two=2} } | Should Not Throw - It '$x is not $null' { $script:x | Should Not Be $null } - It '$x type' { $script:x | should BeOfType "System.Management.automation.psobject" } + $x = [pscustomobject][ordered]@{one=1;two=2} + $x | should BeOfType "System.Management.automation.psobject" $p = 0 # Checks if the first property is One - $script:x.psobject.Properties | foreach-object ` + $x.psobject.Properties | foreach-object ` { if ($p -eq 0) { $p++; - It 'Name' { $_.Name | Should Be 'one' } + $_.Name | Should Be 'one' } } } - - - Context 'Creating an object of an existing type from hashtable should succeed' { - { - $source = @" - public class SampleClass1 - { - public SampleClass1(int x) - { - a = x; - } - - public SampleClass1() - { - } - - public int a; - public int b; - } -"@ - add-type -typedefinition $source - $script:x = [SampleClass1]@{a=10;b=5} - } | Should Not Throw - It '$x is not $null' { $script:x | Should Not Be $null } - It '$x.a' { $script:x.a | Should Be '10' } - } - - It 'Creating an object of an existing type from hashtable should throw error when setting non-existent properties' { - - try - { - $source = @" - public class SampleClass2 - { - public SampleClass2(int x) - { - a = x; - } - - public SampleClass2() - { - } - - public int a; - public int b; - } -"@ - add-type -typedefinition $source - $x = [SampleClass2]@{blah=10;b=5 } - Throw "Exception expected, execution should not have reached here" - } - catch - { - $_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should Be 'ObjectCreationError' + $testdata1 = @( + @{ Name = 'Creating an object of an existing type from hashtable should throw error when setting non-existent properties'; + Cmd = "[System.MAnagement.Automation.Host.Coordinates]`@{blah=10;Y=5 }"; + ErrorID = 'ObjectCreationError'; + InnerException = $true + }, + @{ Name = 'Creating an object of an existing type from hashtable should throw error when setting incompatible values for properties'; + Cmd = "[System.MAnagement.Automation.Host.Coordinates]`@{X='foo';Y=5}"; + ErrorID = 'ObjectCreationError'; + InnerException = $true + }, + @{ Name = 'Conversion from PSCustomObject to hashtable should fail'; + Cmd = "[hashtable][pscustomobject]`@{one=1;two=2}"; + ErrorID ='InvalidCastConstructorException'; + InnerException = $true + }, + @{ + Name = 'New-Object cmdlet should throw terminating errors when user specifies a non-existent property or tries to assign incompatible values'; + Cmd = "New-Object -TypeName System.MAnagement.Automation.Host.Coordinates -Property `@{xx=10;y=5}"; + ErrorID ='InvalidOperationException,Microsoft.PowerShell.Commands.NewObjectCommand' + } + ) + + It '' -TestCases:$testData1 { + param ($Name, $Cmd, $ErrorID, $InnerException) + try + { + Invoke-Expression $Cmd + Throw "Exception expected, execution should not have reached here" + } catch { + + if($InnerException) + { + $_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should Be $ErrorID + } + else { + $_.FullyQualifiedErrorId | Should Be $ErrorID + } } - } - - - It 'Creating an object of an existing type from hashtable should throw error when setting incompatible values for properties' { + } - try - { - $source = @" - public class SampleClass3 - { - public SampleClass3(int x) - { - a = x; - } - - public SampleClass3() - { - } - - public int a; - public int b; - } -"@ - add-type -typedefinition $source - $x = [SampleClass3]@{a="foo";b=5} - Throw "Exception expected, execution should not have reached here" - } - catch - { - $_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should Be 'ObjectCreationError' - } - } - #known issue 2069 - It 'Creating an object of an existing type from hashtable should call the constructor taking a hashtable if such a constructor exists in the type' -skip:$IsCoreCLR { - { - $source = @" - public class SampleClass5 - { - public SampleClass5(int x) - { - a = x; - } - - public SampleClass5(System.Collections.Hashtable h) - { - a = 100; - b = 200; - } - - public SampleClass5() - { - } - - public int a; - public int b; - } -"@ - add-type -typedefinition $source - $script:x = [SampleClass5]@{a=10;b=5} - - } | Should Not Throw - - $script:x | Should Not Be $null - ($script:x.a) | Should Be '100' + It 'Creating an object of an existing type from hashtable should succeed' { + $result = [System.Management.Automation.Host.Coordinates]@{X=10;Y=33} + $result.X | should be 10 + } + + It 'Creating an object of an existing type from hashtable should call the constructor taking a hashtable if such a constructor exists in the type' { + + $x = [SampleClass5]@{a=10;b=5} + $x.a | Should Be '100' } - It 'Add a new type name to PSTypeNames property' { @@ -239,10 +123,10 @@ $obj.PSTypeNames[0] | Should Be 'Mytype' } - Context 'Add an existing type name to PSTypeNames property' { + It 'Add an existing type name to PSTypeNames property' { $obj = [PSCustomObject] @{pstypename = 'System.Object'} - It '$obj.PSTypeNames.Count' { $obj.PSTypeNames.Count | Should Be 3 } - It '$obj.PSTypeNames[0] type' { $obj.PSTypeNames[0] | Should Be 'System.Object' } + $obj.PSTypeNames.Count | Should Be 3 + $obj.PSTypeNames[0] | Should Be 'System.Object' } } \ No newline at end of file From 4e54e848a347b55db78278facc42a8347dbd9d05 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Mon, 12 Sep 2016 13:40:55 -0700 Subject: [PATCH 13/14] remove file csharp.nuget.props from the PR. It was added by mistake. --- test/csharp/csharp.nuget.props | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 test/csharp/csharp.nuget.props diff --git a/test/csharp/csharp.nuget.props b/test/csharp/csharp.nuget.props deleted file mode 100644 index 4492ed20c65..00000000000 --- a/test/csharp/csharp.nuget.props +++ /dev/null @@ -1,10 +0,0 @@ - - - - C:\git\part4\Packages - - - - - - \ No newline at end of file From 08758ca4d9eeb15a4237c29a91ebaaffc61b84d9 Mon Sep 17 00:00:00 2001 From: Yanbing Wang Date: Mon, 12 Sep 2016 13:46:21 -0700 Subject: [PATCH 14/14] added new lines at the end of the files. --- .../Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 | 3 ++- test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 index 0709f899759..2832fe2fa3b 100644 --- a/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 +++ b/test/powershell/Language/Scripting/HashtableToPSCustomObjectConversion.Tests.ps1 @@ -129,4 +129,5 @@ $obj.PSTypeNames.Count | Should Be 3 $obj.PSTypeNames[0] | Should Be 'System.Object' } -} \ No newline at end of file +} + diff --git a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 index 5bf4ef78462..f85291e8b29 100644 --- a/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 +++ b/test/powershell/Language/Scripting/OutErrorVariable.Tests.ps1 @@ -382,4 +382,5 @@ Describe "Update both OutVariable and ErrorVariable" -Tags "CI" { $script:bar_out | Should be @("bar-output", "foo-output", "foo-output") $script:bar_err | Should be @("bar-error", "foo-error", "foo-error") } -} \ No newline at end of file +} +