From 0a18a46281ec85672c172f0f0907679d347f9af3 Mon Sep 17 00:00:00 2001 From: James Truher Date: Mon, 25 Jul 2016 12:19:16 -0700 Subject: [PATCH] Update json tests to be more cross-plat and handle multiple invocations only create the enumtest type if it doesn't exist don't try to compare line endings on json tests which contain arrays, formatting of the output need not be validated --- .../Pester.Commands.Cmdlets.Json.Tests.ps1 | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 index 74c1c9312..6fea81ea0 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Pester.Commands.Cmdlets.Json.Tests.ps1 @@ -69,19 +69,25 @@ Describe "Json Tests" -Tags "Feature" { It "Convertto-Json should handle Enum based on Int64" { # Test follow-up for bug Win8: 378368 Convertto-Json problems with Enum based on Int64. - enum TestEnum : ulong { One = 1, Two = 2 } - enum TestEnum1 : long { One = 1, Two = 2 } - enum TestEnum2 : int { One = 1, Two = 2 } + if ( ("JsonEnumTest" -as "Type") -eq $null ) { + $enum1 = "TestEnum" + (get-random) + $enum2 = "TestEnum" + (get-random) + $enum3 = "TestEnum" + (get-random) - class Test { - [TestEnum] $TestEnum = [TestEnum]::One - [TestEnum1] $TestEnum1 = [TestEnum1]::Two - [TestEnum2] $TestEnum2 = [TestEnum2]::One + $jsontype = add-type -pass -TypeDef " + public enum $enum1 : ulong { One = 1, Two = 2 }; + public enum $enum2 : long { One = 1, Two = 2 }; + public enum $enum3 : int { One = 1, Two = 2 }; + public class JsonEnumTest { + public $enum1 TestEnum1 = ${enum1}.One; + public $enum2 TestEnum2 = ${enum2}.Two; + public $enum3 TestEnum3 = ${enum3}.One; + }" } - $op = [Test]::New() | convertto-json | convertfrom-json - $op.TestEnum | Should Be "One" - $op.TestEnum1 | Should Be "Two" - $op.TestEnum2 | Should Be 1 + $op = [JsonEnumTest]::New() | convertto-json | convertfrom-json + $op.TestEnum1 | Should Be "One" + $op.TestEnum2 | Should Be "Two" + $op.TestEnum3 | Should Be 1 } It "Test followup for Windows 8 bug 121627" { @@ -1321,7 +1327,9 @@ Describe "Validate Json serialization" -Tags "CI" { $a = 1..5 $b = 6..10 - $actual = [ordered]@{'a'=$a;'b'=$b} | ConvertTo-Json + # remove whitespace (and newline/cr) which reduces the complexity of a + # cross-plat test + $actual = ([ordered]@{'a'=$a;'b'=$b} | ConvertTo-Json) -replace "\s" $expected = @' { "a": [ @@ -1340,7 +1348,8 @@ Describe "Validate Json serialization" -Tags "CI" { ] } '@ - $actual | Should Be $expected + $expectedNoWhiteSpace = $expected -replace "\s" + $actual | Should Be $expectedNoWhiteSpace } } }