diff --git a/test/powershell/Language/Classes/ProtectedAccess.Tests.ps1 b/test/powershell/Language/Classes/ProtectedAccess.Tests.ps1 index c54964860c..4b37e6a1a4 100644 --- a/test/powershell/Language/Classes/ProtectedAccess.Tests.ps1 +++ b/test/powershell/Language/Classes/ProtectedAccess.Tests.ps1 @@ -141,50 +141,50 @@ class Derived2 : Base {} '@ Describe "Protected Member Access - w/ default ctor" -Tags "CI" { - It "Method Access" { $derived1.TestMethodAccess() | Should Be 42 } - It "Dynamic Method Access" { $derived1.TestDynamicMethodAccess() | Should Be 42 } - It "Field Access" { $derived1.TestFieldAccess() | Should Be 11 } - It "Dynamic Field Access" { $derived1.TestDynamicFieldAccess() | Should Be 12 } - It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should Be 1111 } - It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should Be 2111 } - It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should Be 3111 } - It "Dynamic Property Access" { $derived1.TestDynamicPropertyAccess() | Should Be 1112 } + It "Method Access" { $derived1.TestMethodAccess() | Should -Be 42 } + It "Dynamic Method Access" { $derived1.TestDynamicMethodAccess() | Should -Be 42 } + It "Field Access" { $derived1.TestFieldAccess() | Should -Be 11 } + It "Dynamic Field Access" { $derived1.TestDynamicFieldAccess() | Should -Be 12 } + It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should -Be 1111 } + It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should -Be 2111 } + It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should -Be 3111 } + It "Dynamic Property Access" { $derived1.TestDynamicPropertyAccess() | Should -Be 1112 } - It "Method Access - overloaded 1a" { $derived1.TestOverloadedMethodAccess1a() | Should Be 84 } - It "Method Access - overloaded 1b" { $derived1.TestOverloadedMethodAccess1b() | Should Be 11 } - It "Method Access - overloaded 2a" { $derived1.TestOverloadedMethodAccess2a() | Should Be 84 } - It "Method Access - overloaded 2b" { $derived1.TestOverloadedMethodAccess2b() | Should Be 11 } - It "Method Access - overloaded 3a" { $derived1.TestOverloadedMethodAccess3a() | Should Be 84 } - It "Method Access - overloaded 3b" { $derived1.TestOverloadedMethodAccess3b() | Should Be 11 } - It "Implicit ctor calls protected ctor" { $derived3.OverloadedMethod2(42) | Should Be 84 } + It "Method Access - overloaded 1a" { $derived1.TestOverloadedMethodAccess1a() | Should -Be 84 } + It "Method Access - overloaded 1b" { $derived1.TestOverloadedMethodAccess1b() | Should -Be 11 } + It "Method Access - overloaded 2a" { $derived1.TestOverloadedMethodAccess2a() | Should -Be 84 } + It "Method Access - overloaded 2b" { $derived1.TestOverloadedMethodAccess2b() | Should -Be 11 } + It "Method Access - overloaded 3a" { $derived1.TestOverloadedMethodAccess3a() | Should -Be 84 } + It "Method Access - overloaded 3b" { $derived1.TestOverloadedMethodAccess3b() | Should -Be 11 } + It "Implicit ctor calls protected ctor" { $derived3.OverloadedMethod2(42) | Should -Be 84 } } Describe "Protected Member Access - w/ non-default ctor" -Tags "CI" { - It "Method Access" { $derived2.TestMethodAccess() | Should Be 52 } - It "Dynamic Method Access" { $derived2.TestDynamicMethodAccess() | Should Be 52 } - It "Field Access" { $derived2.TestFieldAccess() | Should Be 11 } - It "Dynamic Field Access" { $derived2.TestDynamicFieldAccess() | Should Be 12 } - It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should Be 1111 } - It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should Be 2111 } - It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should Be 3111 } - It "Dynamic Property Access" { $derived2.TestDynamicPropertyAccess() | Should Be 1112 } + It "Method Access" { $derived2.TestMethodAccess() | Should -Be 52 } + It "Dynamic Method Access" { $derived2.TestDynamicMethodAccess() | Should -Be 52 } + It "Field Access" { $derived2.TestFieldAccess() | Should -Be 11 } + It "Dynamic Field Access" { $derived2.TestDynamicFieldAccess() | Should -Be 12 } + It "Property Access - protected get/protected set" { $derived1.TestPropertyAccess() | Should -Be 1111 } + It "Property Access - public get/protected set " { $derived1.TestPropertyAccess1() | Should -Be 2111 } + It "Property Access - protected get/public set" { $derived1.TestPropertyAccess2() | Should -Be 3111 } + It "Dynamic Property Access" { $derived2.TestDynamicPropertyAccess() | Should -Be 1112 } - It "Method Access - overloaded 1a" { $derived2.TestOverloadedMethodAccess1a() | Should Be 94 } - It "Method Access - overloaded 1b" { $derived2.TestOverloadedMethodAccess1b() | Should Be 21 } - It "Method Access - overloaded 2a" { $derived2.TestOverloadedMethodAccess2a() | Should Be 94 } - It "Method Access - overloaded 2b" { $derived2.TestOverloadedMethodAccess2b() | Should Be 21 } - It "Method Access - overloaded 3a" { $derived2.TestOverloadedMethodAccess3a() | Should Be 94 } - It "Method Access - overloaded 3b" { $derived2.TestOverloadedMethodAccess3b() | Should Be 21 } + It "Method Access - overloaded 1a" { $derived2.TestOverloadedMethodAccess1a() | Should -Be 94 } + It "Method Access - overloaded 1b" { $derived2.TestOverloadedMethodAccess1b() | Should -Be 21 } + It "Method Access - overloaded 2a" { $derived2.TestOverloadedMethodAccess2a() | Should -Be 94 } + It "Method Access - overloaded 2b" { $derived2.TestOverloadedMethodAccess2b() | Should -Be 21 } + It "Method Access - overloaded 3a" { $derived2.TestOverloadedMethodAccess3a() | Should -Be 94 } + It "Method Access - overloaded 3b" { $derived2.TestOverloadedMethodAccess3b() | Should -Be 21 } } Describe "Protected Member Access - members not visible outside class" -Tags "CI" { Set-StrictMode -v 3 - It "Invalid protected field Get Access" { { $derived1.Field } | Should Throw } - It "Invalid protected property Get Access" { { $derived1.Property } | Should Throw } - It "Invalid protected field Set Access" { { $derived1.Field = 1 } | Should Throw } - It "Invalid protected property Set Access" { { $derived1.Property = 1 } | Should Throw } + It "Invalid protected field Get Access" { { $derived1.Field } | Should -Throw -ErrorId "PropertyNotFoundStrict" } + It "Invalid protected property Get Access" { { $derived1.Property } | Should -Throw -ErrorId "PropertyNotFoundStrict" } + It "Invalid protected field Set Access" { { $derived1.Field = 1 } | Should -Throw -ErrorId "PropertyAssignmentException"} + It "Invalid protected property Set Access" { { $derived1.Property = 1 } | Should -Throw -ErrorId "PropertyAssignmentException" } - It "Invalid protected constructor Access" { { [Base]::new() } | Should Throw } - It "Invalid protected method Access" { { $derived1.Method() } | Should Throw } + It "Invalid protected constructor Access" { { [Base]::new() } | Should -Throw -ErrorId "MethodCountCouldNotFindBest" } + It "Invalid protected method Access" { { $derived1.Method() } | Should -Throw -ErrorId "MethodNotFound" } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 index 9813455286..b659f8de2d 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 @@ -56,15 +56,7 @@ namespace Dummy [C1]::new().Ensure = "Present" It 'Error when ValidateSet should be ExceptionWhenSetting' { - try - { - [C1]::new().Ensure = "foo" - throw "Exception expected" - } - catch - { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { [C1]::new().Ensure = "foo" } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -73,13 +65,7 @@ namespace Dummy # This call should not throw exception [C1]::Ensure = "Present" It 'Error when ValidateSet should be ExceptionWhenSetting'{ - try { - [C1]::Ensure = "foo" - throw "Exception expected" - } - catch { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { [C1]::Ensure = "foo" } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -89,13 +75,7 @@ namespace Dummy [C1]::new().f = 10 [C1]::new().f = 1 It 'Error when ValidateSet should be ExceptionWhenSetting'{ - try { - [C1]::new().f = 20 - throw "Exception expected" - } - catch { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { [C1]::new().f = 20 } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -104,13 +84,7 @@ namespace Dummy # This call should not throw exception [C1]::f = 5 It 'Error when ValidateSet should be ExceptionWhenSetting'{ - try { - [C1]::f = 20 - throw "Exception expected" - } - catch { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { [C1]::f = 20 } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -120,13 +94,7 @@ namespace Dummy [C1]::o = "abc" [C1]::o = 5 It 'Error when ValidateSet should be ExceptionWhenSetting'{ - try { - [C1]::o = 1 - throw "Exception expected" - } - catch { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { [C1]::o = 1 } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -142,11 +110,11 @@ namespace Dummy It 'Implicitly Transform to 100' { $c.arg = 100 - $c.arg | should be 100 + $c.arg | Should -Be 100 } It 'Implicitly Transform to foo' { $c.arg = "foo" - $c.arg | should be "foofoo" + $c.arg | Should -BeExactly "foofoo" } } @@ -154,7 +122,7 @@ namespace Dummy $c = [scriptblock]::Create('class C1 { [Dummy.DoubleStringTransformation()][string]$arg }; [C1]::new()').Invoke()[0] It 'set to foo' { $c.arg = "foo" - $c.arg | should be "foofoo" + $c.arg | Should -BeExactly "foofoo" } } @@ -162,16 +130,10 @@ namespace Dummy $c = [scriptblock]::Create('class C1 { [Dummy.DoubleInt()][int]$arg }; [C1]::new()').Invoke()[0] It 'arg should be 200' { $c.arg = 100 - $c.arg | should be 200 + $c.arg | Should -Be 200 } It 'Set to string should fail with ExceptionWhenSetting' { - try { - $c.arg = "abc" - throw "Exception expected" - } - catch { - $_.FullyQualifiedErrorId | Should be 'ExceptionWhenSetting' - } + { $c.arg = "abc" } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -179,7 +141,7 @@ namespace Dummy $c = [scriptblock]::Create('class C1 { [Nullable[int]][Dummy.DoubleStringTransformation()]$arg }; [C1]::new()').Invoke()[0] It 'arg should be 100' { $c.arg = 100 - $c.arg | should be 100 + $c.arg | Should -Be 100 } } @@ -187,12 +149,12 @@ namespace Dummy $c = [scriptblock]::Create('class C1 { [Dummy.DoubleStringTransformation()][Dummy.AppendStringTransformation()]$arg }; [C1]::new()').Invoke()[0] It 'arg should be 100' { $c.arg = 100 - $c.arg | should be 100 + $c.arg | Should -Be 100 } It 'arg should be foo___foo___g' { $c.arg = "foo" - $c.arg | should be "foo___foo___" + $c.arg | Should -BeExactly "foo___foo___" } } } @@ -211,7 +173,7 @@ Describe 'Type resolution with attributes' -Tag "CI" { [void] OnEvent([string]$Message) {} } - [MyEventSource]::new() | Should Not Be $null + [MyEventSource]::new() | Should -Not -BeNullOrEmpty } } @@ -302,14 +264,14 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" { } It 'Dynamically generated set works in C# with default (immediate) cache expire' { - Get-TestValidateSet4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1" + Get-TestValidateSet4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1" } It 'Empty dynamically generated set throws in C#' { $exc = { Get-TestValidateSet5 -Param1 "TestString1" -ErrorAction Stop } | ShouldBeErrorId "ParameterArgumentValidationError,Test.Language.TestValidateSetCommand5" - $exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should BeExactly "ValidateSetGeneratedValidValuesListIsNull" + $exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ValidateSetGeneratedValidValuesListIsNull" } } @@ -390,7 +352,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" { } It 'Dynamically generated set works in PowerShell script with default (immediate) cache expire' { - Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1" + Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1" } It 'Get the appropriate error message' { @@ -401,7 +363,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" { $exc = { Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction Stop } | ShouldBeErrorId "ParameterArgumentValidationError,Get-TestValidateSetPS5" - $exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should BeExactly "ValidateSetGeneratedValidValuesListIsNull" + $exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ValidateSetGeneratedValidValuesListIsNull" } It 'Unimplemented valid values generator type throws in PowerShell script' { @@ -437,7 +399,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" { try { Import-Module -Name $moduleFile -Force - Test-ValidateSet 'Hello' | Should Be 'Hello' + Test-ValidateSet 'Hello' | Should -BeExactly 'Hello' } finally { Remove-Module -Name $moduleFile -Force } @@ -502,14 +464,14 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" { } It 'Can implement CachedValidValuesGeneratorBase in PowerShell' { - Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1" + Get-TestValidateSetPS4 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1" } It 'Can implement CachedValidValuesGeneratorBase with cache expiration in PowerShell' { - Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1" - Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should BeExactly "TestString1" + Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1" + Get-TestValidateSetPS5 -Param1 "TestString1" -ErrorAction SilentlyContinue | Should -BeExactly "TestString1" Start-Sleep 3 - Get-TestValidateSetPS5 -Param1 "TestString2" -ErrorAction SilentlyContinue | Should BeExactly "TestString2" + Get-TestValidateSetPS5 -Param1 "TestString2" -ErrorAction SilentlyContinue | Should -BeExactly "TestString2" } } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 index 02e52384ff..1d017ce11a 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.BasicParsing.Tests.ps1 @@ -109,13 +109,13 @@ Describe 'Positive Parse Properties Tests' -Tags "CI" { # Method with return type of self class C9 { [C9] f() { return [C9]::new() } } $c9 = [C9]::new().f() - It "Expected a C9 returned" { $c9.GetType().Name | should be C9 } + It "Expected a C9 returned" { $c9.GetType().Name | Should -Be C9 } class C9a { [C9a[]] f() { return [C9a]::new() } } $c9a = [C9a]::new().f() - It "Expected a C9a[] returned" { $c9a.GetType().Name | should be C9a[] } + It "Expected a C9a[] returned" { $c9a.GetType().Name | Should -Be C9a[] } class C9b { [System.Collections.Generic.List[C9b]] f() { return [C9b]::new() } } $c9b = [C9b]::new().f() - It "Expected a System.Collections.Generic.List[C9b] returned" { $c9b -is [System.Collections.Generic.List[C9b]] | should be $true } + It "Expected a System.Collections.Generic.List[C9b] returned" { $c9b -is [System.Collections.Generic.List[C9b]] | Should -BeTrue } } It 'Positive ParseProperty Attributes Test' { @@ -216,7 +216,7 @@ Describe 'Positive Parse Properties Tests' -Tags "CI" { { $LASTEXITCODE $lastexitcode - '111' -match '1' + '111' -Match '1' $Matches $mAtches $Error[0] @@ -242,7 +242,7 @@ Describe 'Positive Parse Properties Tests' -Tags "CI" { $this.h = [ordered] @{} } } - [A]::new().h.GetType().Name | Should Be 'OrderedDictionary' + [A]::new().h.GetType().Name | Should -BeExactly 'OrderedDictionary' } } @@ -365,31 +365,31 @@ Describe 'Negative ClassAttributes Tests' -Tags "CI" { [System.Management.Automation.Cmdlet("Get", "Thing")]class C{} $t = [C].GetCustomAttributes($false) - It "Should have one attribute (class C)" {$t.Count | should be 1} - It "Should have instance of CmdletAttribute (class C)" {$t[0].GetType().FullName | should be System.Management.Automation.CmdletAttribute } + It "Should have one attribute (class C)" {$t.Count | Should -Be 1} + It "Should have instance of CmdletAttribute (class C)" {$t[0] | Should -BeOfType System.Management.Automation.CmdletAttribute } [System.Management.Automation.CmdletAttribute]$c = $t[0] - It "Verb should be Get (class C)" {$c.VerbName | should be 'Get'} - It "Noun should be Thing (class C)" {$c.NounName | should be 'Thing'} + It "Verb should be Get (class C)" {$c.VerbName | Should -BeExactly 'Get'} + It "Noun should be Thing (class C)" {$c.NounName | Should -BeExactly 'Thing'} [System.Management.Automation.Cmdlet("Get", "Thing", SupportsShouldProcess = $true, SupportsPaging = $true)]class C2{} $t = [C2].GetCustomAttributes($false) - It "Should have one attribute (class C2)" { $t.Count | should be 1 } - It "Should have instance of CmdletAttribute (class C2)" { $t[0].GetType().FullName | should be System.Management.Automation.CmdletAttribute } + It "Should have one attribute (class C2)" { $t.Count | should -Be 1 } + It "Should have instance of CmdletAttribute (class C2)" { $t[0] | Should -BeOfType System.Management.Automation.CmdletAttribute } [System.Management.Automation.CmdletAttribute]$c = $t[0] - It "Verb should be Get (class C2)" {$c.VerbName | should be 'Get'} - It "Noun should be Thing (class C2)" {$c.NounName | should be 'Thing'} + It "Verb should be Get (class C2)" {$c.VerbName | Should -BeExactly 'Get'} + It "Noun should be Thing (class C2)" {$c.NounName | Should -BeExactly 'Thing'} - It "SupportsShouldProcess should be $true" { $c.ConfirmImpact | should be $true } - It "SupportsPaging should be `$true" { $c.SupportsPaging | should be $true } + It "SupportsShouldProcess should be $true" { $c.ConfirmImpact | Should -BeTrue } + It "SupportsPaging should be `$true" { $c.SupportsPaging | Should -BeTrue } Context "Support ConfirmImpact as an attribute" { - It "ConfirmImpact should be high" -pending { + It "ConfirmImpact should be high" { [System.Management.Automation.Cmdlet("Get", "Thing", ConfirmImpact = 'High', SupportsPaging = $true)]class C3{} $t = [C3].GetCustomAttributes($false) - It "Should have one attribute" { $t.Count | should be 1 } - It "Should have instance of CmdletAttribute" { $t[0].GetType().FullName | should be System.Management.Automation.CmdletAttribute } + $t.Count | Should -Be 1 + $t[0] | Should -BeOfType System.Management.Automation.CmdletAttribute [System.Management.Automation.CmdletAttribute]$c = $t[0] - $c.ConfirmImpact | should be 'High' + $c.ConfirmImpact | Should -BeExactly 'High' } } @@ -399,19 +399,19 @@ Describe 'Property Attributes Test' -Tags "CI" { class C { [ValidateSet('a', 'b')]$p; } $t = [C].GetProperty('p').GetCustomAttributes($false) - It "Should have one attribute" { $t.Count | should be 1 } + It "Should have one attribute" { $t.Count | Should -Be 1 } [ValidateSet]$v = $t[0] - It "Should have 2 valid values" { $v.ValidValues.Count | should be 2 } - It "first value should be a" { $v.ValidValues[0] | should be 'a' } - It "second value should be b" { $v.ValidValues[1] | should be 'b' } + It "Should have 2 valid values" { $v.ValidValues.Count | Should -Be 2 } + It "first value should be a" { $v.ValidValues[0] | Should -Be 'a' } + It "second value should be b" { $v.ValidValues[1] | Should -Be 'b' } } Describe 'Method Attributes Test' -Tags "CI" { class C { [Obsolete("aaa")][int]f() { return 1 } } $t = [C].GetMethod('f').GetCustomAttributes($false) - It "Should have one attribute" {$t.Count | should be 1 } - It "Attribute type should be ObsoleteAttribute" { $t[0].GetType().FullName | should be System.ObsoleteAttribute } + It "Should have one attribute" {$t.Count | Should -Be 1 } + It "Attribute type should be ObsoleteAttribute" { $t[0].GetType().FullName | Should -Be System.ObsoleteAttribute } } Describe 'Positive SelfClass Type As Parameter Test' -Tags "CI" { @@ -432,8 +432,8 @@ Describe 'Positive SelfClass Type As Parameter Test' -Tags "CI" { $point2 = [Point]::new(1,2) $point.Add($point2) - $point.x | should be 101 - $point.y | should be 202 + $point.x | Should -Be 101 + $point.y | Should -Be 202 } It "[Point]::Add works construction via new-object" { @@ -441,8 +441,8 @@ Describe 'Positive SelfClass Type As Parameter Test' -Tags "CI" { $point2 = New-Object Point 1,2 $point.Add($point2) - $point.x | should be 101 - $point.y | should be 202 + $point.x | Should -Be 101 + $point.y | Should -Be 202 } } @@ -460,7 +460,7 @@ Describe 'PositiveReturnSelfClassTypeFromMemberFunction Test' -Tags "CI" { } $f = [ReturnObjectFromMemberFunctionTest]::new() $z = $f.CreateInstance() # Line 13 - It "CreateInstance works" { $z.SayHello() | should be 'Hello1' } + It "CreateInstance works" { $z.SayHello() | Should -BeExactly 'Hello1' } } Describe 'TestMultipleArguments Test' -Tags "CI" { @@ -511,8 +511,8 @@ $ctorAssignments `$inst = [Foo]::new($methodArguments) `$sum = $addUpProperties - It "ExpectedTotal: Sum should be $expectedTotal" { `$sum | should be $expectedTotal } - It "ExpectedTotal: Invocation should return $expectedTotal" { `$inst.DoSomething($methodArguments) | should be $expectedTotal } + It "ExpectedTotal: Sum should be $expectedTotal" { `$sum | Should -Be $expectedTotal } + It "ExpectedTotal: Invocation should return $expectedTotal" { `$inst.DoSomething($methodArguments) | Should -Be $expectedTotal } "@ Invoke-Expression $class @@ -542,7 +542,7 @@ Describe 'Check PS Class Assembly Test' -Tags "CI" { $assem = [C1].Assembly $attrs = @($assem.GetCustomAttributes($true)) $expectedAttr = @($attrs | Where-Object { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute] }) - It "Expected a DynamicClassImplementationAssembly attribute" { $expectedAttr.Length | should be 1} + It "Expected a DynamicClassImplementationAssembly attribute" { $expectedAttr.Length | Should -Be 1} } Describe 'ScriptScopeAccessFromClassMethod' -Tags "CI" { @@ -550,7 +550,7 @@ Describe 'ScriptScopeAccessFromClassMethod' -Tags "CI" { try { $c = Get-MSFT_778492 - It "Method should have found variable in module scope" { $c.F() | should be 'MSFT_778492 script scope'} + It "Method should have found variable in module scope" { $c.F() | Should -BeExactly 'MSFT_778492 script scope'} } finally { @@ -569,32 +569,32 @@ Describe 'Hidden Members Test ' -Tags "CI" { # Create an instance $instance = [C1]@{ visibleX = 10; visibleY = 12; hiddenZ = 42 } - It "Access hidden property should still work" { $instance.hiddenZ | should be 42 } + It "Access hidden property should still work" { $instance.hiddenZ | Should -Be 42 } # Formatting should not include hidden members by default $tableOutput = $instance | Format-Table -HideTableHeaders -AutoSize | Out-String - It "Table formatting should not have included hidden member hiddenZ - should contain 10" { $tableOutput.Contains(10) | should be $true} - It "Table formatting should not have included hidden member hiddenZ- should contain 12" { $tableOutput.Contains(12) | should be $true} - It "Table formatting should not have included hidden member hiddenZ - should not contain 42" { $tableOutput.Contains(42) | should be $false} + It "Table formatting should not have included hidden member hiddenZ - should contain 10" { $tableOutput.Contains(10) | Should -BeTrue} + It "Table formatting should not have included hidden member hiddenZ- should contain 12" { $tableOutput.Contains(12) | Should -BeTrue} + It "Table formatting should not have included hidden member hiddenZ - should not contain 42" { $tableOutput.Contains(42) | Should -BeFalse} # Get-Member should not include hidden members by default $member = $instance | Get-Member hiddenZ - it "Get-Member should not find hidden member w/o -Force" { $member | should be $null } + it "Get-Member should not find hidden member w/o -Force" { $member | Should -BeNullOrEmpty } # Get-Member should include hidden members with -Force $member = $instance | Get-Member hiddenZ -Force - It "Get-Member should find hidden member w/ -Force" { $member | should not be $null } + It "Get-Member should find hidden member w/ -Force" { $member | Should -Not -BeNullOrEmpty } # Tab completion should not return a hidden member $line = 'class C2 { hidden [int]$hiddenZ } [C2]::new().h' $completions = [System.Management.Automation.CommandCompletion]::CompleteInput($line, $line.Length, $null) - It "Tab completion should not return a hidden member" { $completions.CompletionMatches.Count | should be 0 } + It "Tab completion should not return a hidden member" { $completions.CompletionMatches.Count | Should -Be 0 } } Describe 'BaseMethodCall Test ' -Tags "CI" { - It "Derived class method call" {"abc".ToString() | should be "abc" } + It "Derived class method call" {"abc".ToString() | Should -BeExactly "abc" } # call [object] ToString() method as a base class method. - It "Base class method call" {([object]"abc").ToString() | should be "System.String" } + It "Base class method call" {([object]"abc").ToString() | Should -BeExactly "System.String" } } Describe 'Scoped Types Test' -Tags "CI" { @@ -614,14 +614,14 @@ Describe 'Scoped Types Test' -Tags "CI" { return (new-object C1).GetContext() } - It "New-Object at test scope" { (new-object C1).GetContext() | should be "Test scope" } - It "[C1]::new() at test scope" { [C1]::new().GetContext() | should be "Test scope" } + It "New-Object at test scope" { (new-object C1).GetContext() | Should -BeExactly "Test scope" } + It "[C1]::new() at test scope" { [C1]::new().GetContext() | Should -BeExactly "Test scope" } - It "[C1]::new() in nested scope" { (f1) | should be "f1 scope" } - It "'new-object C1' in nested scope" { (f2) | should be "f2 scope" } + It "[C1]::new() in nested scope" { (f1) | Should -BeExactly "f1 scope" } + It "'new-object C1' in nested scope" { (f2) | Should -BeExactly "f2 scope" } - It "[C1]::new() in nested scope (in pipeline)" { (1 | f1 | f2 | f1) | should be "f1 scope" } - It "'new-object C1' in nested scope (in pipeline)" { (1 | f2 | f1 | f2) | should be "f2 scope" } + It "[C1]::new() in nested scope (in pipeline)" { (1 | f1 | f2 | f1) | Should -BeExactly "f1 scope" } + It "'new-object C1' in nested scope (in pipeline)" { (1 | f2 | f1 | f2) | Should -BeExactly "f2 scope" } } Describe 'ParameterOfClassTypeInModule Test' -Tags "CI" { @@ -633,7 +633,7 @@ function test-it([EE]$ee){$ee} '@) $mod = New-Module $sb -Name MSFT_2081529 | Import-Module $result = test-it -ee one - It "Parameter of class/enum type defined in module should work" { $result | should be 1 } + It "Parameter of class/enum type defined in module should work" { $result | Should -Be 1 } } finally { @@ -647,7 +647,7 @@ Describe 'Type building' -Tags "CI" { 1..10 | ForEach-Object { class C {} if ($a) { - $a -eq [C] | Should Be $true + $a -eq [C] | Should -BeTrue } $a = [C] } @@ -657,8 +657,8 @@ Describe 'Type building' -Tags "CI" { $sb = [scriptblock]::Create('class A {static [int] $a }; [A]::new()') 1..2 | ForEach-Object { $a = $sb.Invoke()[0] - ++$a::a | Should Be 1 - ++$a::a | Should Be 2 + ++$a::a | Should -Be 1 + ++$a::a | Should -Be 2 } } @@ -667,7 +667,7 @@ Describe 'Type building' -Tags "CI" { $a = [C].Assembly.GetCustomAttributes($false).Where{ $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute]} - $a.ScriptFile | Should BeExactly $PSCommandPath + $a.ScriptFile | Should -BeExactly $PSCommandPath } } @@ -693,17 +693,17 @@ class Derived : Base $iss.Commands.Add($ssfe) $ps = [powershell]::Create($iss) - $ps.AddCommand("foo").Invoke() | Should be 200 - $ps.Streams.Error | Should Be $null + $ps.AddCommand("foo").Invoke() | Should -Be 200 + $ps.Streams.Error | Should -BeNullOrEmpty $ps1 = [powershell]::Create($iss) - $ps1.AddCommand("foo").Invoke() | Should be 200 - $ps1.Streams.Error | Should Be $null + $ps1.AddCommand("foo").Invoke() | Should -Be 200 + $ps1.Streams.Error | Should -BeNullOrEmpty $ps.Commands.Clear() $ps.Streams.Error.Clear() - $ps.AddScript(". foo").Invoke() | Should be 200 - $ps.Streams.Error | Should Be $null + $ps.AddScript(". foo").Invoke() | Should -Be 200 + $ps.Streams.Error | Should -BeNullOrEmpty } } @@ -724,11 +724,11 @@ class B '@).Invoke()[0] It 'can do type lookup by name' { - $b.getA1() | Should Be 'A' + $b.getA1() | Should -BeExactly 'A' } It 'can do type lookup by [type]' { - $b.getA2() | Should Be 'A' + $b.getA2() | Should -BeExactly 'A' } } } @@ -745,7 +745,7 @@ namespace Foo } '@ - It 'doesn''t allow protected methods access outside of inheritance chain' -pending { + It 'doesn''t allow protected methods access outside of inheritance chain' { $a = [scriptblock]::Create(@' class A { @@ -764,20 +764,8 @@ class A '@).Invoke() $bar = [Foo.Bar]::new() - $throwCount = 0 - try { - $a.SetX($bar, 42) - } catch { - $_.FullyQualifiedErrorId | Should Be PropertyAssignmentException - $throwCount++ - } - try { - $a.GetX($bar) - } catch { - $_.FullyQualifiedErrorId | Should Be PropertyNotFoundStrict - $throwCount++ - } - $throwCount | Should Be 2 + { $a.SetX($bar, 42) } | Should -Throw -ErrorId 'PropertyAssignmentException' + { $a.GetX($bar) } | Should -Throw -ErrorId 'PropertyNotFoundStrict' } It 'can call protected methods sequentially from two different contexts' { @@ -802,17 +790,17 @@ return [A]::new() $ps = [powershell]::Create($iss) $a = $ps.AddCommand("foo").Invoke()[0] - $ps.Streams.Error | Should Be $null + $ps.Streams.Error | Should -BeNullOrEmpty $ps1 = [powershell]::Create($iss) $a1 = $ps1.AddCommand("foo").Invoke()[0] - $ps1.Streams.Error | Should Be $null + $ps1.Streams.Error | Should -BeNullOrEmpty $a.SetX(101) $a1.SetX(103) - $a.GetX() | Should Be 101 - $a1.GetX() | Should Be 103 + $a.GetX() | Should -Be 101 + $a1.GetX() | Should -Be 103 } } @@ -829,6 +817,6 @@ Describe 'variable analysis' -Tags "CI" { } } - [B]::getA().getFoo() | Should Be 'foo' + [B]::getA().getFoo() | Should -BeExactly 'foo' } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.Break.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Break.Tests.ps1 index e4fc11e4f5..ead2ed5ee2 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Break.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Break.Tests.ps1 @@ -21,8 +21,8 @@ class A } } '@ - $errors.Count | Should be 1 - $errors[0].ErrorId | Should be 'LabelNotFound' + $errors.Count | Should -Be 1 + $errors[0].ErrorId | Should -BeExactly 'LabelNotFound' } It 'reports parse error for break outside of loop' { @@ -36,8 +36,8 @@ class A } } '@ - $errors.Count | Should be 1 - $errors[0].ErrorId | Should be 'LabelNotFound' + $errors.Count | Should -Be 1 + $errors[0].ErrorId | Should -BeExactly 'LabelNotFound' } It 'work fine, when break is legit' { @@ -51,7 +51,7 @@ class A return $i } } - [C]::foo() | Should be 101 + [C]::foo() | Should -Be 101 } } @@ -67,8 +67,8 @@ class A } } '@ - $errors.Count | Should be 1 - $errors[0].ErrorId | Should be 'LabelNotFound' + $errors.Count | Should -Be 1 + $errors[0].ErrorId | Should -BeExactly 'LabelNotFound' } } @@ -90,10 +90,10 @@ class A $canary = $false try { - [C]::getInt() | Should Be 123 + [C]::getInt() | Should -Be 123 $canary = $true } finally { - $canary | Should be $true + $canary | Should -BeTrue } } @@ -121,10 +121,10 @@ class A $canary = $false try { - [C]::getInt() | Should Be (123 + 4*4) + [C]::getInt() | Should -Be (123 + 4*4) $canary = $true } finally { - $canary | Should be $true + $canary | Should -BeTrue } } } @@ -140,7 +140,7 @@ function foo() return 1 } '@ - $errors.Count | Should be 0 + $errors.Count | Should -Be 0 } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.Exceptions.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Exceptions.Tests.ps1 index ccb6b5c17f..f38d2fda1c 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Exceptions.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Exceptions.Tests.ps1 @@ -42,7 +42,7 @@ class C } catch {} - $canaryHashtable['canary'] | Should Be 42 + $canaryHashtable['canary'] | Should -Be 42 } It 'does not execute statements after static method with exception' { @@ -71,7 +71,7 @@ class C } catch {} - $canaryHashtable['canary'] | Should Be 43 + $canaryHashtable['canary'] | Should -Be 43 } It 'does not execute statements after instance method with exception and deep stack' { @@ -127,7 +127,7 @@ class C } catch {} - $canaryHashtable['canary'] | Should Be 11111 + $canaryHashtable['canary'] | Should -Be 11111 } } @@ -185,7 +185,7 @@ function ImThrow() } catch {} - $canaryHashtable['canaryM'] | Should Be 45 + $canaryHashtable['canaryM'] | Should -Be 45 } It 'does not execute statements after function with exception called from static method' { @@ -198,7 +198,7 @@ function ImThrow() } catch {} - $canaryHashtable['canaryS'] | Should Be 46 + $canaryHashtable['canaryS'] | Should -Be 46 } } @@ -220,7 +220,7 @@ $canaryHashtable['canary'] += 100 } catch {} - $canaryHashtable['canary'] | Should Be 111 + $canaryHashtable['canary'] | Should -Be 111 } } } @@ -239,7 +239,7 @@ Describe "Exception error position" -Tags "CI" { [MSFT_3090412]::f1() throw "f1 should have thrown" } catch { - $_.InvocationInfo.Line | Should Match ([regex]::Escape('[MSFT_3090412]::bar = 42')) + $_.InvocationInfo.Line | Should -Match ([regex]::Escape('[MSFT_3090412]::bar = 42')) } } @@ -248,7 +248,7 @@ Describe "Exception error position" -Tags "CI" { [MSFT_3090412]::f2() throw "f2 should have thrown" } catch { - $_.InvocationInfo.Line | Should Match ([regex]::Escape('throw "an error in f2"')) + $_.InvocationInfo.Line | Should -Match ([regex]::Escape('throw "an error in f2"')) } } @@ -257,7 +257,7 @@ Describe "Exception error position" -Tags "CI" { [MSFT_3090412]::f3() throw "f3 should have thrown" } catch { - $_.InvocationInfo.Line | Should Match ([regex]::Escape('"".Substring(0, 10)')) + $_.InvocationInfo.Line | Should -Match ([regex]::Escape('"".Substring(0, 10)')) } } @@ -266,7 +266,7 @@ Describe "Exception error position" -Tags "CI" { [MSFT_3090412]::f4() throw "f4 should have thrown" } catch { - $_.InvocationInfo.Line | Should Match ([regex]::Escape('dir nosuchfile -ea Stop')) + $_.InvocationInfo.Line | Should -Match ([regex]::Escape('dir nosuchfile -ea Stop')) } } } @@ -302,8 +302,8 @@ Describe "Exception from initializer" -Tags "CI" { catch { $e = $_ - $e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger - $e.InvocationInfo.Line | Should Match 'a = "zz"' + $e.FullyQualifiedErrorId | Should -BeExactly 'InvalidCastFromStringToInteger' + $e.InvocationInfo.Line | Should -Match 'a = "zz"' } } @@ -315,8 +315,8 @@ Describe "Exception from initializer" -Tags "CI" { catch { $e = $_ - $e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger - $e.InvocationInfo.Line | Should Match 'a = "zz"' + $e.FullyQualifiedErrorId | Should -BeExactly 'InvalidCastFromStringToInteger' + $e.InvocationInfo.Line | Should -Match 'a = "zz"' } } @@ -327,10 +327,10 @@ Describe "Exception from initializer" -Tags "CI" { } catch { - $_.Exception | Should BeOfType System.TypeInitializationException + $_.Exception | Should -BeOfType System.TypeInitializationException $e = $_.Exception.InnerException.InnerException.ErrorRecord - $e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger - $e.InvocationInfo.Line | Should Match 'a = "zz"' + $e.FullyQualifiedErrorId | Should -BeExactly 'InvalidCastFromStringToInteger' + $e.InvocationInfo.Line | Should -Match 'a = "zz"' } } @@ -341,10 +341,10 @@ Describe "Exception from initializer" -Tags "CI" { } catch { - $_.Exception | Should BeOfType System.TypeInitializationException + $_.Exception | Should -BeOfType System.TypeInitializationException $e = $_.Exception.InnerException.InnerException.ErrorRecord - $e.FullyQualifiedErrorId | Should Be InvalidCastFromStringToInteger - $e.InvocationInfo.Line | Should Match 'a = "zz"' + $e.FullyQualifiedErrorId | Should -BeExactly 'InvalidCastFromStringToInteger' + $e.InvocationInfo.Line | Should -Match 'a = "zz"' } } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.MiscOps.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.MiscOps.Tests.ps1 index 9cd054ea1b..0b7be62ebe 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.MiscOps.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.MiscOps.Tests.ps1 @@ -15,10 +15,10 @@ Describe 'Misc Test' -Tags "CI" { } } It 'Invoke Where' { - [C1]::new().Foo() | should be "1;2;3" + [C1]::new().Foo() | Should -Be "1;2;3" } It 'Pipe to where' { - [C1]::new().Bar() | should be "1;2;3" + [C1]::new().Bar() | Should -Be "1;2;3" } } @@ -39,10 +39,10 @@ Describe 'Misc Test' -Tags "CI" { } } It 'Invoke Foreach' { - [C1]::new().Foo() | should be "1;2;3;" + [C1]::new().Foo() | Should -Be "1;2;3;" } It 'Pipe to Foreach' { - [C1]::new().Bar() | should be "1;2;3;" + [C1]::new().Bar() | Should -Be "1;2;3;" } } @@ -78,7 +78,7 @@ Describe 'Misc Test' -Tags "CI" { function InstantiateInNewRunspace([Type]$type) { try { $result = $powershell.AddCommand("New-UnboundInstance").AddParameter("type", $type).Invoke() - $result.Count | Should Be 1 > $null + $result.Count | Should -Be 1 return $result[0] } finally { $powershell.Commands.Clear() @@ -88,7 +88,7 @@ Describe 'Misc Test' -Tags "CI" { function RunFooInNewRunspace($instance) { try { $result = $powershell.AddCommand("Run-Foo").AddParameter("C1Instance", $instance).Invoke() - $result.Count | Should Be 1 > $null + $result.Count | Should -Be 1 return $result[0] } finally { $powershell.Commands.Clear() @@ -104,16 +104,16 @@ Describe 'Misc Test' -Tags "CI" { $instance = [C1]::new() ## For a bound class instance, the execution of an instance method is ## done in the Runspace/SessionState the instance is bound to. - $instance.Foo() | Should Be $ExpectedTextFromBoundInstance - RunFooInNewRunspace $instance | Should Be $ExpectedTextFromBoundInstance + $instance.Foo() | Should -BeExactly $ExpectedTextFromBoundInstance + RunFooInNewRunspace $instance | Should -BeExactly $ExpectedTextFromBoundInstance } It "Create instance that is NOT bound to a SessionState" { $instance = InstantiateInNewRunspace ([C1]) ## For an unbound class instance, the execution of an instance method is done in ## the Runspace/SessionState where the call to the instance method is made. - $instance.Foo() | Should Be $ExpectedTextFromBoundInstance - RunFooInNewRunspace $instance | Should Be $ExpectedTextFromUnboundInstance + $instance.Foo() | Should -BeExactly $ExpectedTextFromBoundInstance + RunFooInNewRunspace $instance | Should -BeExactly $ExpectedTextFromUnboundInstance } } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 index d28c898aa5..0bd882013b 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 @@ -3,7 +3,7 @@ Describe 'PSModuleInfo.GetExportedTypeDefinitions()' -Tags "CI" { It "doesn't throw for any module" { $discard = Get-Module -ListAvailable | ForEach-Object { $_.GetExportedTypeDefinitions() } - $true | Should Be $true # we only verify that we didn't throw. This line contains a dummy Should to make pester happy. + $true | Should -BeTrue # we only verify that we didn't throw. This line contains a dummy Should to make pester happy. } } @@ -26,7 +26,7 @@ Describe 'use of a module from two runspaces' -Tags "CI" { } New-ModuleManifest @manifestParams - if ($env:PSModulePath -notlike "*$TestModulePath*") { + if ($env:PSModulePath -NotLike "*$TestModulePath*") { $env:PSModulePath += "$([System.IO.Path]::PathSeparator)$TestModulePath" } } @@ -62,10 +62,10 @@ Import-Module Random } } - $res.Count | Should Be 4 - $res[0] | Should Not Be $res[1] - $res[0] | Should Be $res[2] - $res[1] | Should Be $res[3] + $res.Count | Should -Be 4 + $res[0] | Should -Not -Be $res[1] + $res[0] | Should -Be $res[2] + $res[1] | Should -Be $res[3] } } finally { @@ -93,23 +93,23 @@ function Get-PassedArgsNoRoot { $passedArgs } It "Class execution reflects changes in module reloading with '-Force'" { Import-Module TestDrive:\TestModule.psm1 -ArgumentList $Arg_Hello - Get-PassedArgsRoot | Should Be $Arg_Hello - Get-PassedArgsNoRoot | Should Be $Arg_Hello + Get-PassedArgsRoot | Should -BeExactly $Arg_Hello + Get-PassedArgsNoRoot | Should -BeExactly $Arg_Hello Import-Module TestDrive:\TestModule.psm1 -ArgumentList $Arg_World -Force - Get-PassedArgsRoot | Should Be $Arg_World - Get-PassedArgsNoRoot | Should Be $Arg_World + Get-PassedArgsRoot | Should -BeExactly $Arg_World + Get-PassedArgsNoRoot | Should -BeExactly $Arg_World } It "Class execution reflects changes in module reloading with 'Remove-Module' and 'Import-Module'" { Import-Module TestDrive:\TestModule.psm1 -ArgumentList $Arg_Hello - Get-PassedArgsRoot | Should Be $Arg_Hello - Get-PassedArgsNoRoot | Should Be $Arg_Hello + Get-PassedArgsRoot | Should -BeExactly $Arg_Hello + Get-PassedArgsNoRoot | Should -BeExactly $Arg_Hello Remove-Module TestModule Import-Module TestDrive:\TestModule.psm1 -ArgumentList $Arg_World - Get-PassedArgsRoot | Should Be $Arg_World - Get-PassedArgsNoRoot | Should Be $Arg_World + Get-PassedArgsRoot | Should -BeExactly $Arg_World + Get-PassedArgsNoRoot | Should -BeExactly $Arg_World } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 index 7d88e5ccb7..85c78a7494 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.RunPath.Tests.ps1 @@ -17,6 +17,6 @@ class MyClass { static [string]$MyProperty = 'Some value' } [MyClass]::MyProperty '@ | Out-File -FilePath $FilePath - ( . $FilePath ) | Should Match 'Some value' + ( . $FilePath ) | Should -Match 'Some value' } } diff --git a/test/powershell/Language/Classes/Scripting.Classes.StaticMethod.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.StaticMethod.Tests.ps1 index 69619df096..687877c06a 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.StaticMethod.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.StaticMethod.Tests.ps1 @@ -13,7 +13,7 @@ Describe "Additional static method tests" -Tags "CI" { static Foo() { [Foo]::Name = Get-Name } } - [Foo]::Name | Should Be "Yes" + [Foo]::Name | Should -Be "Yes" } It "test basic static method" { @@ -21,7 +21,7 @@ Describe "Additional static method tests" -Tags "CI" { static [string] GetName() { return (Get-Name) } } - [Foo]::GetName() | Should Be "Yes" + [Foo]::GetName() | Should -Be "Yes" } } @@ -84,22 +84,22 @@ class Foo ## The static constructor is triggered by accessing '[Foo]::Name' which happens in the current Runspace. ## The class 'Foo' has been defined in the current Runspace, so it uses the current Runspace to run the ## static constructor. - [Foo]::Name | Should Be "Default Runspace - Name" + [Foo]::Name | Should -BeExactly "Default Runspace - Name" ## Static constructor runs only once, so accessing the Name property in the PS1 Runspace will just return ## the existing value. - RunScriptInPS -PowerShell $ps1 -Script "[Foo]::Name" | Should Be "Default Runspace - Name" + RunScriptInPS -PowerShell $ps1 -Script "[Foo]::Name" | Should -BeExactly "Default Runspace - Name" } It "Static method use the Runspace where the call happens if the class has been defined in that Runspace" { ## We call the static method in the current Runspace. The class 'Foo' has been defined ## in the current Runspace, so it will use it to run the method. - [Foo]::GetName() | Should Be "Default Runspace - AnotherName" + [Foo]::GetName() | Should -BeExactly "Default Runspace - AnotherName" ## We call the static method in PS1 Runspace. The class 'Foo' has been defined in the ## PS1 Runspace, so it will use it to run the method. - RunScriptInPS -PowerShell $ps1 -Script "[Foo]::GetName()" | Should Be 'PS1 Runspace - AnotherName' + RunScriptInPS -PowerShell $ps1 -Script "[Foo]::GetName()" | Should -BeExactly 'PS1 Runspace - AnotherName' } It "Static method use the default SessionState if it's called in a Runspace where the class is not defined" { @@ -116,7 +116,7 @@ class Foo ## is always the one where the class was defined most recently. In this case, the class ## was lastly defined in PS1 Runspace, os the method will be invoked in PS1 Runspace. $result = $ps2.AddCommand("Call-GetName").AddParameter("type", [Foo]).Invoke() - $result | Should Be 'PS1 Runspace - AnotherName' + $result | Should -BeExactly 'PS1 Runspace - AnotherName' } } } diff --git a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 index b62f45311c..70089cb5f8 100644 --- a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 @@ -57,40 +57,40 @@ Describe 'NestedModules' -Tags "CI" { It 'Get-Module is able to find types' { $module = Get-Module NoRoot -ListAvailable - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 $module = Get-Module WithRoot -ListAvailable - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 $module = Get-Module ABC -ListAvailable - $module.GetExportedTypeDefinitions().Count | Should Be 3 + $module.GetExportedTypeDefinitions().Count | Should -Be 3 } It 'Import-Module pick the right type' { $module = Import-Module ABC -PassThru - $module.GetExportedTypeDefinitions().Count | Should Be 3 + $module.GetExportedTypeDefinitions().Count | Should -Be 3 $module = Import-Module ABC -PassThru -Force - $module.GetExportedTypeDefinitions().Count | Should Be 3 + $module.GetExportedTypeDefinitions().Count | Should -Be 3 $module = Import-Module NoRoot -PassThru - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 $module = Import-Module NoRoot -PassThru -Force - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 [scriptblock]::Create(@' using module NoRoot [A]::new().foo() '@ -).Invoke() | Should Be A2 +).Invoke() | Should -Be A2 $module = Import-Module WithRoot -PassThru - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 $module = Import-Module WithRoot -PassThru -Force - $module.GetExportedTypeDefinitions().Count | Should Be 1 + $module.GetExportedTypeDefinitions().Count | Should -Be 1 [scriptblock]::Create(@' using module WithRoot [A]::new().foo() '@ -).Invoke() | Should Be A0 +).Invoke() | Should -Be A0 } Context 'execute type creation in the module context' { @@ -104,17 +104,17 @@ using module WithRoot # Currently, types are resolved in compile-time to the 'local' versions # So at runtime we don't call the module versions. It 'Can execute type creation in the module context with new()' -pending { - & (Get-Module ABC) { [C]::new().foo() } | Should Be C - & (Get-Module NoRoot) { [A]::new().foo() } | Should Be A2 - & (Get-Module WithRoot) { [A]::new().foo() } | Should Be A0 - & (Get-Module ABC) { [A]::new().foo() } | Should Be A + & (Get-Module ABC) { [C]::new().foo() } | Should -Be C + & (Get-Module NoRoot) { [A]::new().foo() } | Should -Be A2 + & (Get-Module WithRoot) { [A]::new().foo() } | Should -Be A0 + & (Get-Module ABC) { [A]::new().foo() } | Should -Be A } It 'Can execute type creation in the module context with New-Object' { - & (Get-Module ABC) { (New-Object C).foo() } | Should Be C - & (Get-Module NoRoot) { (New-Object A).foo() } | Should Be A2 - & (Get-Module WithRoot) { (New-Object A).foo() } | Should Be A0 - & (Get-Module ABC) { (New-Object A).foo() } | Should Be A + & (Get-Module ABC) { (New-Object C).foo() } | Should -Be C + & (Get-Module NoRoot) { (New-Object A).foo() } | Should -Be A2 + & (Get-Module WithRoot) { (New-Object A).foo() } | Should -Be A0 + & (Get-Module ABC) { (New-Object A).foo() } | Should -Be A } } diff --git a/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1 index e2dfc8d928..0295b53502 100644 --- a/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.inheritance.tests.ps1 @@ -8,8 +8,8 @@ Describe 'Classes inheritance syntax' -Tags "CI" { class C2a : C1 {} class C2b:C1 {} - [C2a]::new().GetType().BaseType.Name | Should Be "C1" - [C2b].BaseType.Name | Should Be "C1" + [C2a]::new().GetType().BaseType.Name | Should -Be "C1" + [C2b].BaseType.Name | Should -Be "C1" } It 'inheritance from abstract base class with no abstract methods and protected ctor' { @@ -43,13 +43,13 @@ Describe 'Classes inheritance syntax' -Tags "CI" { } } - [C2a].GetInterface("System.IDisposable") | Should Not Be $null - [C2b].GetInterface("System.IDisposable") | Should Not Be $null + [C2a].GetInterface("System.IDisposable") | Should -Not -BeNullOrEmpty + [C2b].GetInterface("System.IDisposable") | Should -Not -BeNullOrEmpty } It 'can subclass .NET type' { class MyIntList : system.collections.generic.list[int] {} - [MyIntList]::new().GetType().BaseType.FullName.StartsWith('System.Collections.Generic.List') | Should Be $true + [MyIntList]::new().GetType().BaseType.FullName.StartsWith('System.Collections.Generic.List') | Should -BeTrue } It 'can implement .NET interface' { @@ -60,19 +60,14 @@ Describe 'Classes inheritance syntax' -Tags "CI" { return 0; } } - [MyComparable].GetInterface("System.IComparable") | Should Not Be $null + [MyComparable].GetInterface("System.IComparable") | Should -Not -BeNullOrEmpty } It 'allows use of defined later type as a property type' { class A { static [B]$b } class B : A {} [A]::b = [B]::new() - try { - [A]::b = "bla" - throw "No Exception!" - } catch { - $_.Exception | Should BeOfType 'System.Management.Automation.SetValueInvocationException' - } + { [A]::b = "bla" } | Should -Throw -ErrorId 'ExceptionWhenSetting' } } @@ -123,7 +118,7 @@ Describe 'Classes methods with inheritance' -Tags "CI" { [int]foo() {return 100500} } class baz : bar {} - [baz]::new().foo() | Should Be 100500 + [baz]::new().foo() | Should -Be 100500 } It 'can call static method on base class' { @@ -132,7 +127,7 @@ Describe 'Classes methods with inheritance' -Tags "CI" { static [int]foo() {return 100500} } class baz : bar {} - [baz]::foo() | Should Be 100500 + [baz]::foo() | Should -Be 100500 } It 'can access static and instance base class property' { @@ -151,8 +146,8 @@ Describe 'Classes methods with inheritance' -Tags "CI" { } $b = [B]::new() $b.foo() - [A]::si | Should Be 1001 - ($b.i) | Should Be 1003 + [A]::si | Should -Be 1001 + ($b.i) | Should -Be 1003 } It 'works with .NET types' { @@ -160,9 +155,9 @@ Describe 'Classes methods with inheritance' -Tags "CI" { $intList = [MyIntList]::new() $intList.Add(100501) $intList.Add(100502) - $intList.Count | Should Be 2 - $intList[0] | Should Be 100501 - $intList[1] | Should Be 100502 + $intList.Count | Should -Be 2 + $intList[0] | Should -Be 100501 + $intList[1] | Should -Be 100502 } It 'overrides instance method' { @@ -174,7 +169,7 @@ Describe 'Classes methods with inheritance' -Tags "CI" { { [int]foo() {return 200600} } - [baz]::new().foo() | Should Be 200600 + [baz]::new().foo() | Should -Be 200600 } It 'allows base class method call and doesn''t fall into recursion' { @@ -196,7 +191,7 @@ Describe 'Classes methods with inheritance' -Tags "CI" { } $res = [baz]::new().foo() - $res | Should Be 3003 + $res | Should -Be 3003 } It 'case insensitive for base class method calls' { @@ -218,7 +213,7 @@ Describe 'Classes methods with inheritance' -Tags "CI" { } $res = [baz]::new().foo() - $res | Should Be 2002 + $res | Should -Be 2002 } It 'allows any call from the inheritance hierarchy' { @@ -240,11 +235,11 @@ Describe 'Classes methods with inheritance' -Tags "CI" { } $d = [D]::new() - ([A]$d).GetName() | Should Be "A" - ([B]$d).GetName() | Should Be "B" - ([C]$d).GetName() | Should Be "C" - ([D]$d).GetName() | Should Be "D" - $d.GetName() | Should Be "D" + ([A]$d).GetName() | Should -Be "A" + ([B]$d).GetName() | Should -Be "B" + ([C]$d).GetName() | Should -Be "C" + ([D]$d).GetName() | Should -Be "D" + $d.GetName() | Should -Be "D" } It 'can call base method with params' { @@ -257,8 +252,8 @@ Describe 'Classes methods with inheritance' -Tags "CI" { [string]ToStr([int]$a) {return "B" + $a} } $b = [B]::new() - ([A]$b).ToStr(101) | Should Be "A101" - $b.ToStr(100) | Should Be "B100" + ([A]$b).ToStr(101) | Should -Be "A101" + $b.ToStr(100) | Should -Be "B100" } It 'can call base method with many params' { @@ -289,8 +284,8 @@ Describe 'Classes methods with inheritance' -Tags "CI" { # we don't really care about methods results, we only checks that calls doesn't throw # 14 args is a limit - $b.ToStr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) | Should Be 'B' - ([A]$b).ToStr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) | Should Be 'A' + $b.ToStr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) | Should -Be 'B' + ([A]$b).ToStr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) | Should -Be 'A' # 14 args is a limit $b.Noop(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) @@ -311,13 +306,13 @@ Describe 'Classes methods with inheritance' -Tags "CI" { } $b = [B]::new() ([A]$b).SetStr(101) - $script:voidOverrideVar | Should Be "A101" + $script:voidOverrideVar | Should -Be "A101" $b.SetStr(100) - $script:voidOverrideVar | Should Be "B100" + $script:voidOverrideVar | Should -Be "B100" ([A]$b).SetStr() - $script:voidOverrideVar | Should Be "A" + $script:voidOverrideVar | Should -Be "A" $b.SetStr() - $script:voidOverrideVar | Should Be "B" + $script:voidOverrideVar | Should -Be "B" } It 'hides final .NET method' { @@ -332,8 +327,8 @@ Describe 'Classes methods with inheritance' -Tags "CI" { $intList = [MyIntList]::new() $intList.Add(100201) - $intList.Count | Should Be 1 - $intList[0] | Should Be 200402 + $intList.Count | Should -Be 1 + $intList[0] | Should -Be 200402 } } @@ -352,11 +347,11 @@ Describe 'Classes methods with inheritance' -Tags "CI" { # MSFT:1911652 # MSFT:2973835 It 'doesn''t affect static method call on type' -Skip { - ([A]$b)::ToStr(101) | Should Be "A101" + ([A]$b)::ToStr(101) | Should -Be "A101" } It 'overrides static method call on instance' { - $b::ToStr(100) | Should Be "B100" + $b::ToStr(100) | Should -Be "B100" } } } @@ -393,7 +388,7 @@ Describe 'Classes inheritance ctors' -Tags "CI" { } $b = [B]::new(101) - $b.a | Should Be 202 + $b.a | Should -Be 202 } # TODO: can we detect it in the parse time? @@ -411,12 +406,7 @@ Describe 'Classes inheritance ctors' -Tags "CI" { B([int]$a) : base($a * 2, 100) {} } - try { - [B]::new(101) - throw "No Exception!" - } catch { - $_.Exception | Should BeOfType "System.Management.Automation.MethodException" - } + { [B]::new(101) } | Should -Throw -ErrorId "MethodCountCouldNotFindBest" } It 'call default base ctor implicitly' { @@ -439,21 +429,14 @@ Describe 'Classes inheritance ctors' -Tags "CI" { $b = [B]::new() $c = [C]::new() - $b.a | Should Be 1007 - $c.a | Should Be 1007 + $b.a | Should -Be 1007 + $c.a | Should -Be 1007 } It 'doesn''t allow base ctor as an explicit method call' { $o = [object]::new() - try { - # we should not allow direct .ctor call. - $o.{.ctor}() - } catch { - $_.FullyQualifiedErrorId | Should Be MethodNotFound - return - } - # Fail - '' | Should Be "Exception expected" + # we should not allow direct .ctor call. + { $o.{.ctor}() } | Should -Throw -ErrorId "MethodNotFound" } It 'allow use conversion [string -> int] in base ctor call' { @@ -471,7 +454,7 @@ Describe 'Classes inheritance ctors' -Tags "CI" { } $b = [B]::new() - $b.a | Should Be 103 + $b.a | Should -Be 103 } It 'resolves ctor call based on argument type' { @@ -495,8 +478,8 @@ Describe 'Classes inheritance ctors' -Tags "CI" { $b1 = [B]::new("foo") $b2 = [B]::new(1001) - $b1.s | Should Be "foo" - $b2.i | Should Be 1001 + $b1.s | Should -Be "foo" + $b2.i | Should -Be 1001 } } @@ -515,7 +498,7 @@ class Derived : Base [Derived]::new().foo() '@) - $sb.Invoke() | Should Be 200 - $sb.Invoke() | Should Be 200 + $sb.Invoke() | Should -Be 200 + $sb.Invoke() | Should -Be 200 } } diff --git a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 index 57c99f91e8..88b32b8c8e 100644 --- a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 @@ -41,7 +41,7 @@ Describe 'using module' -Tags "CI" { $module = Import-Module Foo -PassThru try { - $module.ImplementingAssembly | Should Not Be $null + $module.ImplementingAssembly | Should -Not -BeNullOrEmpty } finally { $module | Remove-Module } @@ -54,7 +54,7 @@ class Bar : Foo {} [Bar] "@).Invoke() - $barType.BaseType.Name | Should Be 'Foo' + $barType.BaseType.Name | Should -BeExactly 'Foo' } It "can use class from another module in New-Object" { @@ -65,9 +65,9 @@ New-Object FooWithManifest.Foo New-Object Foo.Foo "@).Invoke() - $foo.Count | Should Be 2 - $foo[0].GetModuleName() | Should Be 'FooWithManifest' - $foo[1].GetModuleName() | Should Be 'Foo' + $foo.Count | Should -Be 2 + $foo[0].GetModuleName() | Should -BeExactly 'FooWithManifest' + $foo[1].GetModuleName() | Should -BeExactly 'Foo' } It "can use class from another module by full name as base class and [type]" { @@ -76,7 +76,7 @@ using module Foo class Bar : Foo.Foo {} [Foo.Foo]::new() "@).Invoke() - $fooObject.GetModuleName() | Should Be 'Foo' + $fooObject.GetModuleName() | Should -BeExactly 'Foo' } It "can use modules with classes collision" { @@ -99,11 +99,11 @@ class Bar : Foo {} (New-Object Foo).GetModuleName() # This "@).Invoke() - $fooModuleName.Count | Should Be 4 - $fooModuleName[0] | Should Be 'Foo' - $fooModuleName[1] | Should Be 'FooWithManifest' - $fooModuleName[2] | Should Be 'This' - $fooModuleName[3] | Should Be 'This' + $fooModuleName.Count | Should -Be 4 + $fooModuleName[0] | Should -BeExactly 'Foo' + $fooModuleName[1] | Should -BeExactly 'FooWithManifest' + $fooModuleName[2] | Should -BeExactly 'This' + $fooModuleName[3] | Should -BeExactly 'This' } It "doesn't mess up two consecutive scripts" { @@ -121,8 +121,8 @@ class Bar : Foo {} [Bar]::new().GetModuleName() "@) - $sb1.Invoke() | Should Be 'Foo' - $sb2.Invoke() | Should Be 'This' + $sb1.Invoke() | Should -BeExactly 'Foo' + $sb2.Invoke() | Should -BeExactly 'This' } It "can use modules with classes collision simple" { @@ -141,12 +141,12 @@ class Bar : Foo {} (New-Object Foo).GetModuleName() # This "@).Invoke() - $fooModuleName.Count | Should Be 5 - $fooModuleName[0] | Should Be 'Foo' - $fooModuleName[1] | Should Be 'Foo' - $fooModuleName[2] | Should Be 'This' - $fooModuleName[3] | Should Be 'This' - $fooModuleName[4] | Should Be 'This' + $fooModuleName.Count | Should -Be 5 + $fooModuleName[0] | Should -BeExactly 'Foo' + $fooModuleName[1] | Should -BeExactly 'Foo' + $fooModuleName[2] | Should -BeExactly 'This' + $fooModuleName[3] | Should -BeExactly 'This' + $fooModuleName[4] | Should -BeExactly 'This' } It "can use class from another module as a base class with using module with manifest" { @@ -156,7 +156,7 @@ class Bar : Foo {} [Bar] "@).Invoke() - $barType.BaseType.Name | Should Be 'Foo' + $barType.BaseType.Name | Should -BeExactly 'Foo' } It "can instantiate class from another module" { @@ -165,7 +165,7 @@ using module Foo [Foo]::new() "@).Invoke() - $foo.GetModuleName() | Should Be 'Foo' + $foo.GetModuleName() | Should -BeExactly 'Foo' } It "cannot instantiate class from another module without using statement" { @@ -173,7 +173,7 @@ using module Foo #using module Foo [Foo]::new() "@ - $err.FullyQualifiedErrorId | Should Be TypeNotFound + $err.FullyQualifiedErrorId | Should -BeExactly 'TypeNotFound' } It "can use class from another module in New-Object by short name" { @@ -181,7 +181,7 @@ using module Foo using module FooWithManifest New-Object Foo "@).Invoke() - $foo.GetModuleName() | Should Be 'FooWithManifest' + $foo.GetModuleName() | Should -BeExactly 'FooWithManifest' } It "can use class from this module in New-Object by short name" { @@ -189,7 +189,7 @@ New-Object Foo class Foo {} New-Object Foo "@).Invoke() - $foo | Should Not Be $null + $foo | Should -Not -BeNullOrEmpty } # Pending reason: @@ -199,90 +199,90 @@ New-Object Foo using module @{ ModuleName = 'FooWithManifest'; ModuleVersion = '1.0' } New-Object Foo "@).Invoke() - $foo.GetModuleName() | Should Be 'FooWithManifest' + $foo.GetModuleName() | Should -BeExactly 'FooWithManifest' } Context 'parse time errors' { It "report an error about not found module" { $err = Get-ParseResults "using module ThisModuleDoesntExist" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'ModuleNotFoundDuringParse' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'ModuleNotFoundDuringParse' } It "report an error about misformatted module specification" { $err = Get-ParseResults "using module @{ Foo = 'Foo' }" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'RequiresModuleInvalid' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'RequiresModuleInvalid' } It "report an error about wildcard in the module name" { $err = Get-ParseResults "using module fo*" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'WildCardModuleNameError' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'WildCardModuleNameError' } It "report an error about wildcard in the module path" { $err = Get-ParseResults "using module C:\fo*" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'WildCardModuleNameError' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'WildCardModuleNameError' } It "report an error about wildcard in the module name inside ModuleSpecification hashtable" { $err = Get-ParseResults "using module @{ModuleName = 'Fo*'; RequiredVersion = '1.0'}" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'WildCardModuleNameError' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'WildCardModuleNameError' } # MSFT:5246105 It "report an error when tokenizer encounters comma" { $err = Get-ParseResults "using module ,FooWithManifest" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'MissingUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'MissingUsingItemName' } It "report an error when tokenizer encounters nothing" { $err = Get-ParseResults "using module " - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'MissingUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'MissingUsingItemName' } It "report an error on badly formatted RequiredVersion" { $err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; RequiredVersion = 1. }" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'RequiresModuleInvalid' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'RequiresModuleInvalid' } # MSFT:6897275 It "report an error on incomplete using input" { $err = Get-ParseResults "using module @{ModuleName = 'FooWithManifest'; FooWithManifest = 1." # missing closing bracket - $err.Count | Should Be 2 - $err[0].ErrorId | Should Be 'MissingEndCurlyBrace' - $err[1].ErrorId | Should Be 'RequiresModuleInvalid' + $err.Count | Should -Be 2 + $err[0].ErrorId | Should -BeExactly 'MissingEndCurlyBrace' + $err[1].ErrorId | Should -BeExactly 'RequiresModuleInvalid' } It "report an error when 'using module' terminating by NewLine" { $err = Get-ParseResults "using module" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'MissingUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'MissingUsingItemName' } It "report an error when 'using module' terminating by Semicolon" { $err = Get-ParseResults "using module; $testvar=1" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'MissingUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'MissingUsingItemName' } It "report an error when a value after 'using module' is a unallowed expression" { $err = Get-ParseResults "using module )" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'InvalidValueForUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'InvalidValueForUsingItemName' } It "report an error when a value after 'using module' is not a valid module name" { $err = Get-ParseResults "using module 123" - $err.Count | Should Be 1 - $err[0].ErrorId | Should Be 'InvalidValueForUsingItemName' + $err.Count | Should -Be 1 + $err[0].ErrorId | Should -BeExactly 'InvalidValueForUsingItemName' } } @@ -293,7 +293,7 @@ using module Foo using module FooWithManifest class Bar : Foo {} "@ - $err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference + $err.FullyQualifiedErrorId | Should -Be AmbiguousTypeReference } It "cannot use as [...]" { @@ -302,7 +302,7 @@ using module Foo using module FooWithManifest [Foo] "@ - $err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference + $err.FullyQualifiedErrorId | Should -BeExactly 'AmbiguousTypeReference' } It "cannot use in New-Object" { @@ -311,7 +311,7 @@ using module Foo using module FooWithManifest New-Object Foo "@ - $err.FullyQualifiedErrorId | Should Be 'AmbiguousTypeReference,Microsoft.PowerShell.Commands.NewObjectCommand' + $err.FullyQualifiedErrorId | Should -BeExactly 'AmbiguousTypeReference,Microsoft.PowerShell.Commands.NewObjectCommand' } It "cannot use [type] cast from string" { @@ -320,7 +320,7 @@ using module Foo using module FooWithManifest [type]"Foo" "@ - $err.FullyQualifiedErrorId | Should Be AmbiguousTypeReference + $err.FullyQualifiedErrorId | Should -BeExactly 'AmbiguousTypeReference' } } @@ -335,7 +335,7 @@ using module Foo [Foo]::new().GetModuleName() "@).Invoke() - $moduleName | Should Be 'Foo2' + $moduleName | Should -BeExactly 'Foo2' } } @@ -357,7 +357,7 @@ using module Foo using module FooWithManifest [Foo]::new() "@).Invoke() - $foo.GetModuleName() | Should Be 'Foo230' + $foo.GetModuleName() | Should -BeExactly 'Foo230' } It "uses right version, when RequiredModule=1.0 specified" { @@ -365,7 +365,7 @@ using module FooWithManifest using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '1.0'} [Foo]::new() "@).Invoke() - $foo.GetModuleName() | Should Be 'FooWithManifest' + $foo.GetModuleName() | Should -BeExactly 'FooWithManifest' } It "uses right version, when RequiredModule=2.3.0 specified" { @@ -373,7 +373,7 @@ using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '1.0'} using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '2.3.0'} [Foo]::new() "@).Invoke() - $foo.GetModuleName() | Should Be 'Foo230' + $foo.GetModuleName() | Should -BeExactly 'Foo230' } It "uses right version, when RequiredModule=3.4.5 specified" { @@ -381,7 +381,7 @@ using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '2.3.0'} using module @{ModuleName = 'FooWithManifest'; RequiredVersion = '3.4.5'} [Foo]::new() "@).Invoke() - $foo.GetModuleName() | Should Be 'Foo345' + $foo.GetModuleName() | Should -BeExactly 'Foo345' } } @@ -399,7 +399,7 @@ using module ModuleWithRuntimeError [Foo]::new().GetModuleName() "@ - $err | Should Be 'error' + $err | Should -Be 'error' } } @@ -421,17 +421,17 @@ function foo() $iss.StartupScripts.Add($scriptToProcessPath) $ps = [powershell]::Create($iss) - $ps.AddCommand("foo").Invoke() | Should be Foo - $ps.Streams.Error | Should Be $null + $ps.AddCommand("foo").Invoke() | Should -BeExactly 'Foo' + $ps.Streams.Error | Should -BeNullOrEmpty $ps1 = [powershell]::Create($iss) - $ps1.AddCommand("foo").Invoke() | Should be Foo - $ps1.Streams.Error | Should Be $null + $ps1.AddCommand("foo").Invoke() | Should -BeExactly 'Foo' + $ps1.Streams.Error | Should -BeNullOrEmpty $ps.Commands.Clear() $ps.Streams.Error.Clear() - $ps.AddScript(". foo").Invoke() | Should be Foo - $ps.Streams.Error | Should Be $null + $ps.AddScript(". foo").Invoke() | Should -BeExactly 'Foo' + $ps.Streams.Error | Should -BeNullOrEmpty } } @@ -457,17 +457,17 @@ class Bar : Foo {} } It 'use non-modified PSModulePath' { - $env:PSModulePath | Should Be $originalPSModulePath + $env:PSModulePath | Should -BeExactly $originalPSModulePath } It "can be accessed by relative path" { $barObject = & TestDrive:\FooRelativeConsumer\FooRelativeConsumer.ps1 - $barObject.GetModuleName() | Should Be 'FooForPaths' + $barObject.GetModuleName() | Should -BeExactly 'FooForPaths' } It "cannot be accessed by relative path without .\ from a script" { $err = Get-RuntimeError '& TestDrive:\FooRelativeConsumerErr.ps1' - $err.FullyQualifiedErrorId | Should Be ModuleNotFoundDuringParse + $err.FullyQualifiedErrorId | Should -BeExactly 'ModuleNotFoundDuringParse' } It "can be accessed by absolute path" { @@ -477,9 +477,9 @@ using module $resolvedTestDrivePath\FooForPaths [Foo]::new() "@ $err = Get-ParseResults $s - $err.Count | Should Be 0 + $err.Count | Should -Be 0 $barObject = [scriptblock]::Create($s).Invoke() - $barObject.GetModuleName() | Should Be 'FooForPaths' + $barObject.GetModuleName() | Should -BeExactly 'FooForPaths' } It "can be accessed by absolute path with file extension" { @@ -488,7 +488,7 @@ using module $resolvedTestDrivePath\FooForPaths using module $resolvedTestDrivePath\FooForPaths\FooForPaths.psm1 [Foo]::new() "@).Invoke() - $barObject.GetModuleName() | Should Be 'FooForPaths' + $barObject.GetModuleName() | Should -BeExactly 'FooForPaths' } It "can be accessed by relative path without file" { @@ -497,7 +497,7 @@ using module $resolvedTestDrivePath\FooForPaths\FooForPaths.psm1 using module .\FooForPaths [Foo]::new() "@ - $err.FullyQualifiedErrorId | Should Be ModuleNotFoundDuringParse + $err.FullyQualifiedErrorId | Should -BeExactly 'ModuleNotFoundDuringParse' Push-Location TestDrive:\modules try { @@ -505,7 +505,7 @@ using module .\FooForPaths using module .\FooForPaths [Foo]::new() "@).Invoke() - $barObject.GetModuleName() | Should Be 'FooForPaths' + $barObject.GetModuleName() | Should -BeExactly 'FooForPaths' } finally { Pop-Location } @@ -518,7 +518,7 @@ using module .\FooForPaths using module FooForPaths [Foo]::new() "@ - $err.FullyQualifiedErrorId | Should Be ModuleNotFoundDuringParse + $err.FullyQualifiedErrorId | Should -BeExactly 'ModuleNotFoundDuringParse' } finally { Pop-Location } @@ -543,7 +543,7 @@ class TestClass { [string] GetName() { return "TestClass" } } using module $testFile [TestClass]::new() "@).Invoke() - $result.GetName() | Should Be "TestClass" + $result.GetName() | Should -BeExactly "TestClass" } } } diff --git a/test/powershell/Language/Classes/scripting.enums.tests.ps1 b/test/powershell/Language/Classes/scripting.enums.tests.ps1 index 7e6c3d3af8..02bb420e1e 100644 --- a/test/powershell/Language/Classes/scripting.enums.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.enums.tests.ps1 @@ -10,11 +10,11 @@ Describe 'enums' -Tags "CI" { e2 } - It "has correct value 0" { [E1]::e0 | Should Be ([E1]0) } - It "has correct value 1" { [E1]::e1 | Should Be ([E1]1) } - It "has correct value 2" { [E1]::e2 | Should Be ([E1]2) } - It "cast from string" { [E1]::e1 | Should Be 'e1' } - It "cast to string" { 'e2' | Should Be ([E1]::e2) } + It "has correct value 0" { [E1]::e0 | Should -Be ([E1]0) } + It "has correct value 1" { [E1]::e1 | Should -Be ([E1]1) } + It "has correct value 2" { [E1]::e2 | Should -Be ([E1]2) } + It "cast from string" { [E1]::e1 | Should -Be 'e1' } + It "cast to string" { 'e2' | Should -Be ([E1]::e2) } } Context 'Basic enum with initial value' { @@ -25,11 +25,11 @@ Describe 'enums' -Tags "CI" { e2 } - It "has correct value 0" { [E2]::e0 | Should Be ([E2]0) } - It "has correct value 5" { [E2]::e1 | Should Be ([E2]5) } - It "has correct value 6" { [E2]::e2 | Should Be ([E2]6) } - It "cast from string" { [E2]::e1 | Should Be 'e1' } - It "cast to string" { 'e2' | Should Be ([E2]::e2) } + It "has correct value 0" { [E2]::e0 | Should -Be ([E2]0) } + It "has correct value 5" { [E2]::e1 | Should -Be ([E2]5) } + It "has correct value 6" { [E2]::e2 | Should -Be ([E2]6) } + It "cast from string" { [E2]::e1 | Should -Be 'e1' } + It "cast to string" { 'e2' | Should -Be ([E2]::e2) } } Context 'Basic enum with initial value expression' { @@ -41,12 +41,12 @@ Describe 'enums' -Tags "CI" { e3 = 1 # This shouldn't be an error even though previous member was max int } - It "has correct value 0" { [E3]::e0 | Should Be ([E3]0) } - It "has correct value 5" { [E3]::e1 | Should Be ([E3]5) } - It "has correct value [int]::MaxValue" { [E3]::e2 | Should Be ([E3]([int]::MaxValue)) } - It "has correct value 1" { [E3]::e3 | Should Be ([E3]1) } - It "cast from string" { [E3]::e2 | Should Be 'e2' } - It "cast to string" { 'e3' | Should Be ([E3]::e3) } + It "has correct value 0" { [E3]::e0 | Should -Be ([E3]0) } + It "has correct value 5" { [E3]::e1 | Should -Be ([E3]5) } + It "has correct value [int]::MaxValue" { [E3]::e2 | Should -Be ([E3]([int]::MaxValue)) } + It "has correct value 1" { [E3]::e3 | Should -Be ([E3]1) } + It "cast from string" { [E3]::e2 | Should -Be 'e2' } + It "cast to string" { 'e3' | Should -Be ([E3]::e3) } } Context 'Enum with complicated initial value' { @@ -66,9 +66,9 @@ Describe 'enums' -Tags "CI" { e0 =38 } - It 'E4 has correct value' { [E4]::e0 | Should Be ([E4]42) } - It 'E5 has correct value' { [E5]::e0 | Should Be ([E5]40) } - It 'E6 has correct value' { [E6]::e0 | Should Be ([E6]38) } + It 'E4 has correct value' { [E4]::e0 | Should -Be ([E4]42) } + It 'E5 has correct value' { [E5]::e0 | Should -Be ([E5]40) } + It 'E6 has correct value' { [E6]::e0 | Should -Be ([E6]38) } } } diff --git a/test/powershell/Language/CompletionTestSupport.psm1 b/test/powershell/Language/CompletionTestSupport.psm1 index 71b4acc7b4..3490830c48 100644 --- a/test/powershell/Language/CompletionTestSupport.psm1 +++ b/test/powershell/Language/CompletionTestSupport.psm1 @@ -113,7 +113,7 @@ function Test-Completions { It "Checking for duplicates of: $($expected.CompletionText)" { # We should only find 1 of each expected result - $expected.Found | Should Be $false + $expected.Found | Should -BeFalse } $expected.Found = $true } @@ -123,7 +123,7 @@ function Test-Completions foreach ($expected in $test.ExpectedResults) { It "Checking for presence of expected result: $($expected.CompletionText)" { - $expected.Found | Should Be $true + $expected.Found | Should -BeTrue } } @@ -132,7 +132,7 @@ function Test-Completions foreach ($result in $results.CompletionMatches) { It "Checking for results that should not be found: $notExpected" { - $result.CompletionText -cne $notExpected | Should Be $true + $result.CompletionText | Should -Not -Be $notExpected } } } diff --git a/test/powershell/Language/Interop/DotNet/DotNetAPI.Tests.ps1 b/test/powershell/Language/Interop/DotNet/DotNetAPI.Tests.ps1 index 75a2f426a4..f5e72690ad 100644 --- a/test/powershell/Language/Interop/DotNet/DotNetAPI.Tests.ps1 +++ b/test/powershell/Language/Interop/DotNet/DotNetAPI.Tests.ps1 @@ -5,23 +5,23 @@ Describe "DotNetAPI" -Tags "CI" { $posh_pi = 3.14159265358979 It "Should be able to use static .NET classes and get a constant" { - [System.Math]::E | Should Match $posh_E.ToString() - [System.Math]::PI | Should Match $posh_pi.ToString() + [System.Math]::E | Should -Match $posh_E.ToString() + [System.Math]::PI | Should -Match $posh_pi.ToString() } It "Should be able to invoke a method" { - [System.Environment]::GetEnvironmentVariable("PATH") | Should Be $env:PATH + [System.Environment]::GetEnvironmentVariable("PATH") | Should -Be $env:PATH } It "Should not require 'system' in front of static classes" { - [Environment]::CommandLine | Should Be ([System.Environment]::CommandLine) + [Environment]::CommandLine | Should -Be ([System.Environment]::CommandLine) - [Math]::E | Should Be ([System.Math]::E) + [Math]::E | Should -Be ([System.Math]::E) } It "Should be able to create a new instance of a .Net object" { [System.Guid]$guidVal = [System.Guid]::NewGuid() - $guidVal | Should BeOfType Guid + $guidVal | Should -BeOfType Guid } } diff --git a/test/powershell/Language/Interop/DotNet/DotNetInterop.Tests.ps1 b/test/powershell/Language/Interop/DotNet/DotNetInterop.Tests.ps1 index fb1283287c..63884843a9 100644 --- a/test/powershell/Language/Interop/DotNet/DotNetInterop.Tests.ps1 +++ b/test/powershell/Language/Interop/DotNet/DotNetInterop.Tests.ps1 @@ -2,6 +2,6 @@ # Licensed under the MIT License. Describe ".NET class interoperability" -Tags "CI" { It "Should access types in System.Console" { - [System.Console]::TreatControlCAsInput | Should Be $false + [System.Console]::TreatControlCAsInput | Should -BeFalse } } diff --git a/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 b/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 index 06c78de8c0..92c5264194 100644 --- a/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 +++ b/test/powershell/Language/Operators/ComparisonOperator.Tests.ps1 @@ -21,7 +21,7 @@ Describe "ComparisonOperator" -tag "CI" { @{lhs = 0; operator = "-or"; rhs = 0; result = $false} ) { param($lhs, $operator, $rhs, $result) - Invoke-Expression "$lhs $operator $rhs" | Should Be $result + Invoke-Expression "$lhs $operator $rhs" | Should -Be $result } It "Should be for " -TestCases @( @@ -33,7 +33,7 @@ Describe "ComparisonOperator" -tag "CI" { @{operator = "!"; rhs = "0"; result = $true} ) { param($operator, $rhs, $result) - Invoke-Expression "$operator$rhs" | Should Be $result + Invoke-Expression "$operator$rhs" | Should -Be $result } It "Should be for " -TestCases @( @@ -48,7 +48,7 @@ Describe "ComparisonOperator" -tag "CI" { @{lhs = "'Hello world'"; operator = "-notlike"; rhs = "'Hello*'"; result = $false} ) { param($lhs, $operator, $rhs, $result) - Invoke-Expression "$lhs $operator $rhs" | Should Be $result + Invoke-Expression "$lhs $operator $rhs" | Should -Be $result } It "Should return error if right hand is not a valid type: 'hello' " -TestCases @( @@ -71,7 +71,7 @@ Describe "ComparisonOperator" -tag "CI" { @{lhs = '"hello"'; operator = '-isnot'; rhs = "[int]"} ) { param($lhs, $operator, $rhs) - Invoke-Expression "$lhs $operator $rhs" | Should Be $true + Invoke-Expression "$lhs $operator $rhs" | Should -BeTrue } It "Should fail in comparing type: " -TestCases @( @@ -80,7 +80,7 @@ Describe "ComparisonOperator" -tag "CI" { @{lhs = '"hello"'; operator = '-isnot'; rhs = "[string]"} ) { param($lhs, $operator, $rhs) - Invoke-Expression "$lhs $operator $rhs" | Should Be $false + Invoke-Expression "$lhs $operator $rhs" | Should -BeFalse } } @@ -89,36 +89,36 @@ Describe "Bytewise Operator" -tag "CI" { It "Test -bor on enum with [byte] as underlying type" { $result = [System.Security.AccessControl.AceFlags]::ObjectInherit -bxor ` [System.Security.AccessControl.AceFlags]::ContainerInherit - $result.ToString() | Should Be "ObjectInherit, ContainerInherit" + $result.ToString() | Should -BeExactly "ObjectInherit, ContainerInherit" } It "Test -bor on enum with [int] as underlying type" { $result = [System.Management.Automation.CommandTypes]::Alias -bor ` [System.Management.Automation.CommandTypes]::Application - $result.ToString() | Should Be "Alias, Application" + $result.ToString() | Should -BeExactly "Alias, Application" } It "Test -band on enum with [byte] as underlying type" { $result = [System.Security.AccessControl.AceFlags]::ObjectInherit -band ` [System.Security.AccessControl.AceFlags]::ContainerInherit - $result.ToString() | Should Be "None" + $result.ToString() | Should -BeExactly "None" } It "Test -band on enum with [int] as underlying type" { $result = [System.Management.Automation.CommandTypes]::Alias -band ` [System.Management.Automation.CommandTypes]::All - $result.ToString() | Should Be "Alias" + $result.ToString() | Should -BeExactly "Alias" } It "Test -bxor on enum with [byte] as underlying type" { $result = [System.Security.AccessControl.AceFlags]::ObjectInherit -bxor ` [System.Security.AccessControl.AceFlags]::ContainerInherit - $result.ToString() | Should Be "ObjectInherit, ContainerInherit" + $result.ToString() | Should -BeExactly "ObjectInherit, ContainerInherit" } It "Test -bxor on enum with [int] as underlying type" { $result = [System.Management.Automation.CommandTypes]::Alias -bxor ` [System.Management.Automation.CommandTypes]::Application - $result.ToString() | Should Be "Alias, Application" + $result.ToString() | Should -BeExactly "Alias, Application" } } diff --git a/test/powershell/Language/Operators/RangeOperator.Tests.ps1 b/test/powershell/Language/Operators/RangeOperator.Tests.ps1 index d847422be4..01ca4627e2 100644 --- a/test/powershell/Language/Operators/RangeOperator.Tests.ps1 +++ b/test/powershell/Language/Operators/RangeOperator.Tests.ps1 @@ -4,255 +4,255 @@ Describe "Range Operator" -Tags CI { Context "Range integer operations" { It "Range operator generates arrays of integers" { $Range = 5..8 - $Range.count | Should Be 4 - $Range[0] | Should BeOfType [int] - $Range[1] | Should BeOfType [int] - $Range[2] | Should BeOfType [int] - $Range[3] | Should BeOfType [int] + $Range.count | Should -Be 4 + $Range[0] | Should -BeOfType [int] + $Range[1] | Should -BeOfType [int] + $Range[2] | Should -BeOfType [int] + $Range[3] | Should -BeOfType [int] - $Range[0] | Should Be 5 - $Range[1] | Should Be 6 - $Range[2] | Should Be 7 - $Range[3] | Should Be 8 + $Range[0] | Should -Be 5 + $Range[1] | Should -Be 6 + $Range[2] | Should -Be 7 + $Range[3] | Should -Be 8 } It "Range operator accepts negative integer values" { $Range = -8..-5 - $Range.count | Should Be 4 - $Range[0] | Should Be -8 - $Range[1] | Should Be -7 - $Range[2] | Should Be -6 - $Range[3] | Should Be -5 + $Range.count | Should -Be 4 + $Range[0] | Should -Be -8 + $Range[1] | Should -Be -7 + $Range[2] | Should -Be -6 + $Range[3] | Should -Be -5 } It "Range operator support single-item sequences" { $Range = 0..0 - $Range.count | Should Be 1 - $Range[0] | Should BeOfType [int] - $Range[0] | Should Be 0 + $Range.count | Should -Be 1 + $Range[0] | Should -BeOfType [int] + $Range[0] | Should -Be 0 } It "Range operator works in descending order" { $Range = 4..3 - $Range.count | Should Be 2 - $Range[0] | Should Be 4 - $Range[1] | Should Be 3 + $Range.count | Should -Be 2 + $Range[0] | Should -Be 4 + $Range[1] | Should -Be 3 } It "Range operator works for sequences of both negative and positive numbers" { $Range = -2..2 - $Range.count | Should Be 5 - $Range[0] | Should Be -2 - $Range[1] | Should Be -1 - $Range[2] | Should Be 0 - $Range[3] | Should Be 1 - $Range[4] | Should Be 2 + $Range.count | Should -Be 5 + $Range[0] | Should -Be -2 + $Range[1] | Should -Be -1 + $Range[2] | Should -Be 0 + $Range[3] | Should -Be 1 + $Range[4] | Should -Be 2 } It "Range operator enumerator works" { $Range = -2..2 | ForEach-Object { $_ } - $Range.count | Should Be 5 - $Range[0] | Should Be -2 - $Range[1] | Should Be -1 - $Range[2] | Should Be 0 - $Range[3] | Should Be 1 - $Range[4] | Should Be 2 + $Range.count | Should -Be 5 + $Range[0] | Should -Be -2 + $Range[1] | Should -Be -1 + $Range[2] | Should -Be 0 + $Range[3] | Should -Be 1 + $Range[4] | Should -Be 2 } It "Range operator works with variables" { $var1 = -1 $var2 = 1 $Range = $var1..$var2 - $Range.count | Should Be 3 - $Range[0] | Should Be -1 - $Range[1] | Should Be 0 - $Range[2] | Should Be 1 + $Range.count | Should -Be 3 + $Range[0] | Should -Be -1 + $Range[1] | Should -Be 0 + $Range[2] | Should -Be 1 $Range = [int]$var2..[int]$var1 - $Range.count | Should Be 3 - $Range[0] | Should Be 1 - $Range[1] | Should Be 0 - $Range[2] | Should Be -1 + $Range.count | Should -Be 3 + $Range[0] | Should -Be 1 + $Range[1] | Should -Be 0 + $Range[2] | Should -Be -1 $Range = $var1..$var2 | ForEach-Object { $_ } - $Range.count | Should Be 3 - $Range[0] | Should Be -1 - $Range[1] | Should Be 0 - $Range[2] | Should Be 1 + $Range.count | Should -Be 3 + $Range[0] | Should -Be -1 + $Range[1] | Should -Be 0 + $Range[2] | Should -Be 1 $Range = [int]$var2..[int]$var1 | ForEach-Object { $_ } - $Range.count | Should Be 3 - $Range[0] | Should Be 1 - $Range[1] | Should Be 0 - $Range[2] | Should Be -1 + $Range.count | Should -Be 3 + $Range[0] | Should -Be 1 + $Range[1] | Should -Be 0 + $Range[2] | Should -Be -1 } } Context "Character expansion" { It "Range operator generates an array of [char] from single-character operands" { $CharRange = 'A'..'E' - $CharRange.count | Should Be 5 - $CharRange[0] | Should BeOfType [char] - $CharRange[1] | Should BeOfType [char] - $CharRange[2] | Should BeOfType [char] - $CharRange[3] | Should BeOfType [char] - $CharRange[4] | Should BeOfType [char] + $CharRange.count | Should -Be 5 + $CharRange[0] | Should -BeOfType [char] + $CharRange[1] | Should -BeOfType [char] + $CharRange[2] | Should -BeOfType [char] + $CharRange[3] | Should -BeOfType [char] + $CharRange[4] | Should -BeOfType [char] } It "Range operator enumerator generates an array of [string] from single-character operands" { $CharRange = 'A'..'E' | ForEach-Object { $_ } - $CharRange.count | Should Be 5 - $CharRange[0] | Should BeOfType [char] - $CharRange[1] | Should BeOfType [char] - $CharRange[2] | Should BeOfType [char] - $CharRange[3] | Should BeOfType [char] - $CharRange[4] | Should BeOfType [char] + $CharRange.count | Should -Be 5 + $CharRange[0] | Should -BeOfType [char] + $CharRange[1] | Should -BeOfType [char] + $CharRange[2] | Should -BeOfType [char] + $CharRange[3] | Should -BeOfType [char] + $CharRange[4] | Should -BeOfType [char] } It "Range operator works in ascending and descending order" { $CharRange = 'a'..'c' - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'a') - $CharRange[1] | Should BeExactly ([char]'b') - $CharRange[2] | Should BeExactly ([char]'c') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'a') + $CharRange[1] | Should -BeExactly ([char]'b') + $CharRange[2] | Should -BeExactly ([char]'c') $CharRange = 'C'..'A' - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'C') - $CharRange[1] | Should BeExactly ([char]'B') - $CharRange[2] | Should BeExactly ([char]'A') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'C') + $CharRange[1] | Should -BeExactly ([char]'B') + $CharRange[2] | Should -BeExactly ([char]'A') } It "Range operator works in ascending and descending order with [char] cast" { $CharRange = [char]'a'..[char]'c' - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'a') - $CharRange[1] | Should BeExactly ([char]'b') - $CharRange[2] | Should BeExactly ([char]'c') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'a') + $CharRange[1] | Should -BeExactly ([char]'b') + $CharRange[2] | Should -BeExactly ([char]'c') $CharRange = [char]"a".."c" - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'a') - $CharRange[1] | Should BeExactly ([char]'b') - $CharRange[2] | Should BeExactly ([char]'c') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'a') + $CharRange[1] | Should -BeExactly ([char]'b') + $CharRange[2] | Should -BeExactly ([char]'c') $CharRange = "a"..[char]"c" - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'a') - $CharRange[1] | Should BeExactly ([char]'b') - $CharRange[2] | Should BeExactly ([char]'c') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'a') + $CharRange[1] | Should -BeExactly ([char]'b') + $CharRange[2] | Should -BeExactly ([char]'c') # The same works in reverse order. $CharRange = [char]'C'..[char]'A' - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'C') - $CharRange[1] | Should BeExactly ([char]'B') - $CharRange[2] | Should BeExactly ([char]'A') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'C') + $CharRange[1] | Should -BeExactly ([char]'B') + $CharRange[2] | Should -BeExactly ([char]'A') $CharRange = [char]"C".."A" - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'C') - $CharRange[1] | Should BeExactly ([char]'B') - $CharRange[2] | Should BeExactly ([char]'A') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'C') + $CharRange[1] | Should -BeExactly ([char]'B') + $CharRange[2] | Should -BeExactly ([char]'A') $CharRange = "C"..[char]"A" - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly ([char]'C') - $CharRange[1] | Should BeExactly ([char]'B') - $CharRange[2] | Should BeExactly ([char]'A') + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly ([char]'C') + $CharRange[1] | Should -BeExactly ([char]'B') + $CharRange[2] | Should -BeExactly ([char]'A') } It "Range operator enumerator works in ascending and descending order" { $CharRange = 'a'..'c' | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "a" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "c" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "a" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "c" $CharRange = 'C'..'A' | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "C" - $CharRange[1] | Should BeExactly "B" - $CharRange[2] | Should BeExactly "A" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "C" + $CharRange[1] | Should -BeExactly "B" + $CharRange[2] | Should -BeExactly "A" } It "Range operator enumerator works in ascending and descending order with [char] cast" { $CharRange = [char]'a'..[char]'c' | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "a" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "c" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "a" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "c" $CharRange = [char]'C'..[char]'A' | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "C" - $CharRange[1] | Should BeExactly "B" - $CharRange[2] | Should BeExactly "A" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "C" + $CharRange[1] | Should -BeExactly "B" + $CharRange[2] | Should -BeExactly "A" } It "Range operator works with variables" { $var1 = 'a' $var2 = 'c' $CharRange = $var1..$var2 - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "a" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "c" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "a" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "c" $CharRange = [char]$var2..[char]$var1 - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "c" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "a" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "c" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "a" $CharRange = $var1..$var2 | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "a" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "c" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "a" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "c" $CharRange = [char]$var2..[char]$var1 | ForEach-Object { $_ } - $CharRange.count | Should Be 3 - $CharRange[0] | Should BeExactly "c" - $CharRange[1] | Should BeExactly "b" - $CharRange[2] | Should BeExactly "a" + $CharRange.count | Should -Be 3 + $CharRange[0] | Should -BeExactly "c" + $CharRange[1] | Should -BeExactly "b" + $CharRange[2] | Should -BeExactly "a" } It "Range operator works with 16-bit unicode characters" { $UnicodeRange = "`u{0110}".."`u{0114}" - $UnicodeRange.count | Should Be 5 - $UnicodeRange[0] | Should Be "`u{0110}"[0] - $UnicodeRange[1] | Should Be "`u{0111}"[0] - $UnicodeRange[2] | Should Be "`u{0112}"[0] - $UnicodeRange[3] | Should Be "`u{0113}"[0] - $UnicodeRange[4] | Should Be "`u{0114}"[0] - $UnicodeRange.Where({$_ -is [char]}).count | Should Be 5 + $UnicodeRange.count | Should -Be 5 + $UnicodeRange[0] | Should -Be "`u{0110}"[0] + $UnicodeRange[1] | Should -Be "`u{0111}"[0] + $UnicodeRange[2] | Should -Be "`u{0112}"[0] + $UnicodeRange[3] | Should -Be "`u{0113}"[0] + $UnicodeRange[4] | Should -Be "`u{0114}"[0] + $UnicodeRange.Where({$_ -is [char]}).count | Should -Be 5 } It "Range operator with special ranges" { $SpecRange = "0".."9" - $SpecRange.count | Should Be 10 - $SpecRange.Where({$_ -is [int]}).count | Should Be 10 + $SpecRange.count | Should -Be 10 + $SpecRange.Where({$_ -is [int]}).count | Should -Be 10 $SpecRange = '0'..'9' - $SpecRange.count | Should Be 10 - $SpecRange.Where({$_ -is [int]}).count | Should Be 10 + $SpecRange.count | Should -Be 10 + $SpecRange.Where({$_ -is [int]}).count | Should -Be 10 $SpecRange = [char]'0'..[char]'9' - $SpecRange.count | Should Be 10 - $SpecRange.Where({$_ -is [char]}).count | Should Be 10 + $SpecRange.count | Should -Be 10 + $SpecRange.Where({$_ -is [char]}).count | Should -Be 10 } } Context "Range operator operand types" { It "Range operator works on [decimal]" { $Range = 1.1d..3.9d - $Range.count | Should Be 4 - $Range[0] | Should Be 1 - $Range[1] | Should Be 2 - $Range[2] | Should Be 3 - $Range[3] | Should Be 4 - $Range.Where({$_ -is [int]}).count | Should Be 4 + $Range.count | Should -Be 4 + $Range[0] | Should -Be 1 + $Range[1] | Should -Be 2 + $Range[2] | Should -Be 3 + $Range[3] | Should -Be 4 + $Range.Where({$_ -is [int]}).count | Should -Be 4 } } } diff --git a/test/powershell/Language/Operators/SplitOperator.Tests.ps1 b/test/powershell/Language/Operators/SplitOperator.Tests.ps1 index 907ebf18b7..25514c9a75 100644 --- a/test/powershell/Language/Operators/SplitOperator.Tests.ps1 +++ b/test/powershell/Language/Operators/SplitOperator.Tests.ps1 @@ -4,105 +4,105 @@ Describe "Split Operator" -Tags CI { Context "Binary split operator" { It "Binary split operator can split array of value" { $res = "a b", "c d" -split " " - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } It "Binary split operator can split a string" { $res = "a b c d" -split " " - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } It "Binary split operator can works with max substring limit" { $res = "a b c d" -split " ", 2 - $res.count | Should Be 2 - $res[0] | Should Be "a" - $res[1] | Should Be "b c d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b c d" $res = "a b c d" -split " ", 0 - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" $res = "a b c d" -split " ", -1 - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } It "Binary split operator can works with freeform delimiter" { $res = "a::b::c::d" -split "::" - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } It "Binary split operator can preserve delimiter" { $res = "a1:b1:c1:d" -split "(1:)" - $res.count | Should Be 7 - $res[0] | Should Be "a" - $res[1] | Should Be "1:" - $res[2] | Should Be "b" - $res[3] | Should Be "1:" - $res[4] | Should Be "c" - $res[5] | Should Be "1:" - $res[6] | Should Be "d" + $res.count | Should -Be 7 + $res[0] | Should -Be "a" + $res[1] | Should -Be "1:" + $res[2] | Should -Be "b" + $res[3] | Should -Be "1:" + $res[4] | Should -Be "c" + $res[5] | Should -Be "1:" + $res[6] | Should -Be "d" $res = "a1:b1:c1:d" -split "1(:)" - $res.count | Should Be 7 - $res[0] | Should Be "a" - $res[1] | Should Be ":" - $res[2] | Should Be "b" - $res[3] | Should Be ":" - $res[4] | Should Be "c" - $res[5] | Should Be ":" - $res[6] | Should Be "d" + $res.count | Should -Be 7 + $res[0] | Should -Be "a" + $res[1] | Should -Be ":" + $res[2] | Should -Be "b" + $res[3] | Should -Be ":" + $res[4] | Should -Be "c" + $res[5] | Should -Be ":" + $res[6] | Should -Be "d" } It "Binary split operator can be case-insensitive and case-sensitive" { $res = "abcBd" -split "B" - $res.count | Should Be 3 - $res[0] | Should Be "a" - $res[1] | Should Be "c" - $res[2] | Should Be "d" + $res.count | Should -Be 3 + $res[0] | Should -Be "a" + $res[1] | Should -Be "c" + $res[2] | Should -Be "d" $res = "abcBd" -isplit "B" - $res.count | Should Be 3 - $res[0] | Should Be "a" - $res[1] | Should Be "c" - $res[2] | Should Be "d" + $res.count | Should -Be 3 + $res[0] | Should -Be "a" + $res[1] | Should -Be "c" + $res[2] | Should -Be "d" $res = "abcBd" -csplit "B" - $res.count | Should Be 2 - $res[0] | Should Be "abc" - $res[1] | Should Be "d" + $res.count | Should -Be 2 + $res[0] | Should -Be "abc" + $res[1] | Should -Be "d" $res = "abcBd" -csplit "B", 0 , 'IgnoreCase' - $res.count | Should Be 3 - $res[0] | Should Be "a" - $res[1] | Should Be "c" - $res[2] | Should Be "d" + $res.count | Should -Be 3 + $res[0] | Should -Be "a" + $res[1] | Should -Be "c" + $res[2] | Should -Be "d" } It "Binary split operator can works with script block" { $res = "a::b::c::d" -split {$_ -eq "b" -or $_ -eq "C"} - $res.count | Should Be 3 - $res[0] | Should Be "a::" - $res[1] | Should Be "::" - $res[2] | Should Be "::d" + $res.count | Should -Be 3 + $res[0] | Should -Be "a::" + $res[1] | Should -Be "::" + $res[2] | Should -Be "::d" } } @@ -120,93 +120,93 @@ Describe "Split Operator" -Tags CI { param($testText, $testText2, $newLine) # Multiline isn't default $res = $testText -split '^b' - $res.count | Should Be 1 + $res.count | Should -Be 1 # Singleline isn't default $res = $testText -split 'b.+c' - $res.count | Should Be 1 + $res.count | Should -Be 1 } It "Binary split operator works with Singleline (new line = '')" -TestCases $testCases { param($testText, $testText2, $newLine) $res = $testText -split 'b.+c', 0, 'Singleline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)" - $res[1] | Should Be "$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)" + $res[1] | Should -Be "$($newLine)d78d" $res = $testText2 -split 'b.+c', 0, 'Singleline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)%" - $res[1] | Should Be "$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)%" + $res[1] | Should -Be "$($newLine)d78d" } It "Binary split operator works with Multiline (new line = '')" -TestCases $testCases { param($testText, $testText2, $newLine) $res = $testText -split '^b', 0, 'Multiline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)" - $res[1] | Should Be "34b$($newLine)c56c$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)" + $res[1] | Should -Be "34b$($newLine)c56c$($newLine)d78d" } It "Binary split operator works with Singleline,Multiline (new line = '')" -TestCases $testCases { param($testText, $testText2, $newLine) $res = $testText -split 'b.+c', 0, 'Singleline,Multiline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)" - $res[1] | Should Be "$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)" + $res[1] | Should -Be "$($newLine)d78d" $res = $testText2 -split 'b.+c', 0, 'Singleline,Multiline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)%" - $res[1] | Should Be "$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)%" + $res[1] | Should -Be "$($newLine)d78d" $res = $testText -split '^b.+c', 0, 'Singleline,Multiline' - $res.count | Should Be 2 - $res[0] | Should Be "a12a$($newLine)" - $res[1] | Should Be "$($newLine)d78d" + $res.count | Should -Be 2 + $res[0] | Should -Be "a12a$($newLine)" + $res[1] | Should -Be "$($newLine)d78d" $res = $testText2 -split '^b.+c', 0, 'Singleline,Multiline' - $res.count | Should Be 1 + $res.count | Should -Be 1 } It "Binary split operator works with IgnorePatternWhitespace" { $res = "a: b:c" -split ': ' - $res.count | Should Be 2 - $res[0] | Should Be "a" - $res[1] | Should Be "b:c" + $res.count | Should -Be 2 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b:c" $res = "a: b:c" -split ': ',0,'IgnorePatternWhitespace' - $res.count | Should Be 3 - $res[0] | Should Be "a" - $res[1] | Should Be " b" - $res[2] | Should Be "c" + $res.count | Should -Be 3 + $res[0] | Should -Be "a" + $res[1] | Should -Be " b" + $res[2] | Should -Be "c" } It "Binary split operator works with ExplicitCapture" { $res = "a:b" -split "(:)" - $res.count | Should Be 3 - $res[0] | Should Be "a" - $res[1] | Should Be ":" - $res[2] | Should Be "b" + $res.count | Should -Be 3 + $res[0] | Should -Be "a" + $res[1] | Should -Be ":" + $res[2] | Should -Be "b" $res = "a:b" -split "(:)", 0, 'ExplicitCapture' - $res.count | Should Be 2 - $res[0] | Should Be "a" - $res[1] | Should Be "b" + $res.count | Should -Be 2 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" } It "Binary split operator works with SimpleMatch" { $res = "abc" -split "B", 0, 'SimpleMatch,IgnoreCase' - $res.count | Should Be 2 - $res[0] | Should Be "a" - $res[1] | Should Be "c" + $res.count | Should -Be 2 + $res[0] | Should -Be "a" + $res[1] | Should -Be "c" } It "Binary split operator works with RegexMatch" { $res = "abc" -split "B", 0, 'RegexMatch,Singleline' - $res.count | Should Be 2 - $res[0] | Should Be "a" - $res[1] | Should Be "c" + $res.count | Should -Be 2 + $res[0] | Should -Be "a" + $res[1] | Should -Be "c" } It "Binary split operator doesn't works with RegexMatch,SimpleMatch" { @@ -217,28 +217,28 @@ Describe "Split Operator" -Tags CI { Context "Unary split operator" { It "Unary split operator has higher precedence than a comma" { $res = -split "a b", "c d" - $res.count | Should Be 2 - $res[0][0] | Should Be "a" - $res[0][1] | Should Be "b" - $res[1] | Should Be "c d" + $res.count | Should -Be 2 + $res[0][0] | Should -Be "a" + $res[0][1] | Should -Be "b" + $res[1] | Should -Be "c d" } It "Unary split operator can split array of values" { $res = -split ("a b", "c d") - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } It "Unary split operator can split a string" { $res = -split "a b c d" - $res.count | Should Be 4 - $res[0] | Should Be "a" - $res[1] | Should Be "b" - $res[2] | Should Be "c" - $res[3] | Should Be "d" + $res.count | Should -Be 4 + $res[0] | Should -Be "a" + $res[1] | Should -Be "b" + $res[2] | Should -Be "c" + $res[3] | Should -Be "d" } } } diff --git a/test/powershell/Language/Parser/Ast.Tests.ps1 b/test/powershell/Language/Parser/Ast.Tests.ps1 index ca87e3b500..1f8ee598e0 100644 --- a/test/powershell/Language/Parser/Ast.Tests.ps1 +++ b/test/powershell/Language/Parser/Ast.Tests.ps1 @@ -7,36 +7,23 @@ Describe "The SafeGetValue method on AST returns safe values" -Tags "CI" { $HtAst = { @{ one = 1 } }.ast.Find({$args[0] -is $HashtableAstType}, $true) - $HtAst | Should Not BeNullOrEmpty - $HtAst.SafeGetValue() | Should BeOfType "Hashtable" + $HtAst | Should -Not -BeNullOrEmpty + $HtAst.SafeGetValue() | Should -BeOfType "Hashtable" } It "An Array is returned from a LiteralArrayAst" { $ArrayAstType = [ArrayLiteralAst] $ArrayAst = { @( 1,2,3,4) }.ast.Find({$args[0] -is $ArrayAstType}, $true) - $ArrayAst | Should Not BeNullOrEmpty - ,$ArrayAst.SafeGetValue() | Should BeOfType "Object[]" + $ArrayAst | Should -Not -BeNullOrEmpty + ,$ArrayAst.SafeGetValue() | Should -BeOfType "Object[]" } It "The proper error is returned when a variable is referenced" { $ast = { $a }.Ast.Find({$args[0] -is "VariableExpressionAst"},$true) - try { - $ast.SafeGetValue() | out-null - throw "No Exception!" - } - catch { - $_.FullyQualifiedErrorId | Should be "InvalidOperationException" - $_.ToString() | Should Match '\$a' - } + { $ast.SafeGetValue() } | Should -Throw -ErrorId "InvalidOperationException" } It "A ScriptBlock AST fails with the proper error" { - try { - { 1 }.Ast.SafeGetValue() - throw "No Exception!" - } - catch { - $_.FullyQualifiedErrorId | Should be "InvalidOperationException" - } + { { 1 }.Ast.SafeGetValue() } | Should -Throw -ErrorId "InvalidOperationException" } } diff --git a/test/powershell/Language/Parser/AutomaticVariables.Tests.ps1 b/test/powershell/Language/Parser/AutomaticVariables.Tests.ps1 index 40e4752091..8265178de5 100644 --- a/test/powershell/Language/Parser/AutomaticVariables.Tests.ps1 +++ b/test/powershell/Language/Parser/AutomaticVariables.Tests.ps1 @@ -9,15 +9,15 @@ Describe 'Automatic variable $input' -Tags "CI" { function from_process { [cmdletbinding()]param() process { Write-Output -NoEnumerate $input } } function from_end { [cmdletbinding()]param() end { Write-Output -NoEnumerate $input } } - (from_begin) -is [System.Collections.IEnumerator] | Should Be $true - (from_process) -is [System.Collections.IEnumerator] | Should Be $true - (from_end) -is [System.Collections.IEnumerator] | Should Be $true + (from_begin) -is [System.Collections.IEnumerator] | Should -BeTrue + (from_process) -is [System.Collections.IEnumerator] | Should -BeTrue + (from_end) -is [System.Collections.IEnumerator] | Should -BeTrue } It 'Empty $input really is empty' { - & { @($input).Count } | Should Be 0 - & { [cmdletbinding()]param() begin { @($input).Count } } | Should Be 0 - & { [cmdletbinding()]param() process { @($input).Count } } | Should Be 0 - & { [cmdletbinding()]param() end { @($input).Count } } | Should Be 0 + & { @($input).Count } | Should -Be 0 + & { [cmdletbinding()]param() begin { @($input).Count } } | Should -Be 0 + & { [cmdletbinding()]param() process { @($input).Count } } | Should -Be 0 + & { [cmdletbinding()]param() end { @($input).Count } } | Should -Be 0 } } diff --git a/test/powershell/Language/Parser/BNotOperator.Tests.ps1 b/test/powershell/Language/Parser/BNotOperator.Tests.ps1 index 3dc9be6c14..0b5e4c1bbd 100644 --- a/test/powershell/Language/Parser/BNotOperator.Tests.ps1 +++ b/test/powershell/Language/Parser/BNotOperator.Tests.ps1 @@ -39,26 +39,26 @@ Describe "bnot on enums" -Tags "CI" { Context $enumType.Name { It "max - 1" { $res = -bnot $enumType::MaxMinus1 - $res | Should Be $enumType::MinPlus1 - $res | Should BeOfType $enumType + $res | Should -Be $enumType::MinPlus1 + $res | Should -BeOfType $enumType } It "min + 1" { $res = -bnot $enumType::MinPlus1 - $res | Should Be $enumType::MaxMinus1 - $res | Should BeOfType $enumType + $res | Should -Be $enumType::MaxMinus1 + $res | Should -BeOfType $enumType } It "Max" { $res = -bnot $enumType::Max - $res | Should Be $enumType::Min - $res | Should BeOfType $enumType + $res | Should -Be $enumType::Min + $res | Should -BeOfType $enumType } It "Min" { $res = -bnot $enumType::Min - $res | Should Be $enumType::Max - $res | Should BeOfType $enumType + $res | Should -Be $enumType::Max + $res | Should -BeOfType $enumType } } } @@ -90,52 +90,52 @@ Describe "bnot on integral types" -Tags "CI" { # tests are a little different. It "max - 1" { $res = -bnot $maxMinus1 - $res | Should Be (-bnot [int]$maxMinus1) - $res | Should BeOfType $expectedResultType + $res | Should -Be (-bnot [int]$maxMinus1) + $res | Should -BeOfType $expectedResultType } It "min + 1" { $res = -bnot $minPlus1 - $res | Should Be (-bnot [int]$minPlus1) - $res | Should BeOfType $expectedResultType + $res | Should -Be (-bnot [int]$minPlus1) + $res | Should -BeOfType $expectedResultType } It "max" { $res = -bnot $max - $res | Should Be (-bnot [int]$max) - $res | Should BeOfType $expectedResultType + $res | Should -Be (-bnot [int]$max) + $res | Should -BeOfType $expectedResultType } It "min" { $res = -bnot $min - $res | Should Be (-bnot [int]$min) - $res | Should BeOfType $expectedResultType + $res | Should -Be (-bnot [int]$min) + $res | Should -BeOfType $expectedResultType } return } It "max - 1" { $res = -bnot $maxMinus1 - $res | Should Be $minPlus1 - $res | Should BeOfType $expectedResultType + $res | Should -Be $minPlus1 + $res | Should -BeOfType $expectedResultType } It "min + 1" { $res = -bnot $minPlus1 - $res | Should Be $maxMinus1 - $res | Should BeOfType $expectedResultType + $res | Should -Be $maxMinus1 + $res | Should -BeOfType $expectedResultType } It "max" { $res = -bnot $max - $res | Should Be $min - $res | Should BeOfType $expectedResultType + $res | Should -Be $min + $res | Should -BeOfType $expectedResultType } It "min" { $res = -bnot $min - $res | Should Be $max - $res | Should BeOfType $expectedResultType + $res | Should -Be $max + $res | Should -BeOfType $expectedResultType } } } diff --git a/test/powershell/Language/Parser/Conversions.Tests.ps1 b/test/powershell/Language/Parser/Conversions.Tests.ps1 index 5cade9d22e..fbc0aee7eb 100644 --- a/test/powershell/Language/Parser/Conversions.Tests.ps1 +++ b/test/powershell/Language/Parser/Conversions.Tests.ps1 @@ -6,21 +6,21 @@ Describe 'conversion syntax' -Tags "CI" { It 'converts array of single enum to bool' { # This test relies on the fact that [ConsoleColor]::Black is 0 and all other values are non-zero - [bool]@([ConsoleColor]::Black) | Should Be $false - [bool]@([ConsoleColor]::Yellow) | Should Be $true + [bool]@([ConsoleColor]::Black) | Should -BeFalse + [bool]@([ConsoleColor]::Yellow) | Should -BeTrue } It 'calls virtual method non-virtually' { - ([object]"abc").ToString() | Should Be "System.String" + ([object]"abc").ToString() | Should -Be "System.String" # generate random string to avoid JIT optimization $r = [guid]::NewGuid().Guid - ([object]($r + "a")).Equals(($r + "a")) | Should Be $false + ([object]($r + "a")).Equals(($r + "a")) | Should -BeFalse } It 'calls method on a super-type, when conversion syntax used' { # This test relies on the fact that there are overloads (at least 2) for ToString method. - ([System.Management.Automation.ActionPreference]"Stop").ToString() | Should Be "Stop" + ([System.Management.Automation.ActionPreference]"Stop").ToString() | Should -Be "Stop" } Context "Cast object[] to more narrow generic collection" { @@ -63,15 +63,15 @@ Describe 'conversion syntax' -Tags "CI" { $result = $null . $Command - $result | Should Not BeNullOrEmpty - $result.GetType().Name | Should Be $CollectionType + $result | Should -Not -BeNullOrEmpty + $result.GetType().Name | Should -Be $CollectionType $genericArgs = $result.GetType().GetGenericArguments() - $genericArgs.Length | Should Be 1 - $genericArgs[0].Name | Should Be $ElementType + $genericArgs.Length | Should -Be 1 + $genericArgs[0].Name | Should -Be $ElementType - $result.Count | Should Be $Elements.Length - $result -join ";" | Should Be ($Elements -join ";") + $result.Count | Should -Be $Elements.Length + $result -join ";" | Should -Be ($Elements -join ";") } } } @@ -126,7 +126,7 @@ namespace TestTypeResolution { [TestTypeResolution.TestTypeFoo].Assembly.Location "@ $location = & $powershell -noprofile -command $command - $location | Should Be $cmdletDllPath + $location | Should -Be $cmdletDllPath } } @@ -221,179 +221,179 @@ Describe 'method conversion' -Tags 'CI' { } It 'converts static method as Func does not throw' { - {[Func[int, int]] [M]::Thrice} | Should Not Throw + {[Func[int, int]] [M]::Thrice} | Should -Not -Throw } It 'converts static method as Func is non null' { - ([Func[int, int]] [M]::Thrice) | Should Not BeNullOrEmpty + ([Func[int, int]] [M]::Thrice) | Should -Not -BeNullOrEmpty } It 'calls static method as Func' { $f = [Func[int, int]] [M]::Thrice - [M]::Apply(1, $f) | Should be 3 + [M]::Apply(1, $f) | Should -Be 3 } It 'calls static method as Func' { $f = [Func[int, int16, int]] [M]::Add - [M]::Apply(3, 4, $f) | Should be 7 + [M]::Apply(3, 4, $f) | Should -Be 7 } It 'calls static method as Func no cast' { - [M]::Apply(3, 4, [M]::Add) | Should be 7 + [M]::Apply(3, 4, [M]::Add) | Should -Be 7 } It 'converts instance psmethodinfo to Func' { $m = [M]::new() - {[Func[int, int]] $m.Twice} | Should Not Throw + {[Func[int, int]] $m.Twice} | Should -Not -Throw $f = [Func[int, int16, int]] [M]::Add - $f.Invoke(2, 6) | Should be 8 + $f.Invoke(2, 6) | Should -Be 8 } It "can call all overloads of M::Foo" { [Func[char, char]] $f1 = [M]::Foo - $f1.Invoke(10) | Should BE 10 + $f1.Invoke(10) | Should -Be 10 [Func[char, char, char]] $f2 = [M]::Foo - $f2.Invoke(10, 1) | Should BE 10 + $f2.Invoke(10, 1) | Should -Be 10 [Func[char, char, char, char]] $f3 = [M]::Foo - $f3.Invoke(10, 1, 2) | Should BE 10 + $f3.Invoke(10, 1, 2) | Should -Be 10 [Func[char, char, char, char, char]] $f4 = [M]::Foo - $f4.Invoke(10, 1, 2, 3) | Should BE 10 + $f4.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[char, char, char, char, char, char]] $f5 = [M]::Foo - $f5.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f5.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[char, char, char, char, char, char, char]] $f6 = [M]::Foo - $f6.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f6.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[char, char, char, char, char, char, char, char]] $f7 = [M]::Foo - $f7.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f7.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[char, char, char, char, char, char, char, char, char]] $f8 = [M]::Foo - $f8.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f8.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[int16, int16]] $f9 = [M]::Foo - $f9.Invoke(10) | Should BE 10 + $f9.Invoke(10) | Should -Be 10 [Func[int16, int16, int16]] $f10 = [M]::Foo - $f10.Invoke(10, 1) | Should BE 10 + $f10.Invoke(10, 1) | Should -Be 10 [Func[int16, int16, int16, int16]] $f11 = [M]::Foo - $f11.Invoke(10, 1, 2) | Should BE 10 + $f11.Invoke(10, 1, 2) | Should -Be 10 [Func[int16, int16, int16, int16, int16]] $f12 = [M]::Foo - $f12.Invoke(10, 1, 2, 3) | Should BE 10 + $f12.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[int16, int16, int16, int16, int16, int16]] $f13 = [M]::Foo - $f13.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f13.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[int16, int16, int16, int16, int16, int16, int16]] $f14 = [M]::Foo - $f14.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f14.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[int16, int16, int16, int16, int16, int16, int16, int16]] $f15 = [M]::Foo - $f15.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f15.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[int16, int16, int16, int16, int16, int16, int16, int16, int16]] $f16 = [M]::Foo - $f16.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f16.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[int, int]] $f17 = [M]::Foo - $f17.Invoke(10) | Should BE 10 + $f17.Invoke(10) | Should -Be 10 [Func[int, int, int]] $f18 = [M]::Foo - $f18.Invoke(10, 1) | Should BE 10 + $f18.Invoke(10, 1) | Should -Be 10 [Func[int, int, int, int]] $f19 = [M]::Foo - $f19.Invoke(10, 1, 2) | Should BE 10 + $f19.Invoke(10, 1, 2) | Should -Be 10 [Func[int, int, int, int, int]] $f20 = [M]::Foo - $f20.Invoke(10, 1, 2, 3) | Should BE 10 + $f20.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[int, int, int, int, int, int]] $f21 = [M]::Foo - $f21.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f21.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[int, int, int, int, int, int, int]] $f22 = [M]::Foo - $f22.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f22.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[int, int, int, int, int, int, int, int]] $f23 = [M]::Foo - $f23.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f23.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[int, int, int, int, int, int, int, int, int]] $f24 = [M]::Foo - $f24.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f24.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[UInt32, UInt32]] $f25 = [M]::Foo - $f25.Invoke(10) | Should BE 10 + $f25.Invoke(10) | Should -Be 10 [Func[UInt32, UInt32, UInt32]] $f26 = [M]::Foo - $f26.Invoke(10, 1) | Should BE 10 + $f26.Invoke(10, 1) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32]] $f27 = [M]::Foo - $f27.Invoke(10, 1, 2) | Should BE 10 + $f27.Invoke(10, 1, 2) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32, UInt32]] $f28 = [M]::Foo - $f28.Invoke(10, 1, 2, 3) | Should BE 10 + $f28.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32, UInt32, UInt32]] $f29 = [M]::Foo - $f29.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f29.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32]] $f30 = [M]::Foo - $f30.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f30.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32]] $f31 = [M]::Foo - $f31.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f31.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32]] $f32 = [M]::Foo - $f32.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f32.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[UInt64, UInt64]] $f33 = [M]::Foo - $f33.Invoke(10) | Should BE 10 + $f33.Invoke(10) | Should -Be 10 [Func[UInt64, UInt64, UInt64]] $f34 = [M]::Foo - $f34.Invoke(10, 1) | Should BE 10 + $f34.Invoke(10, 1) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64]] $f35 = [M]::Foo - $f35.Invoke(10, 1, 2) | Should BE 10 + $f35.Invoke(10, 1, 2) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64, UInt64]] $f36 = [M]::Foo - $f36.Invoke(10, 1, 2, 3) | Should BE 10 + $f36.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64, UInt64, UInt64]] $f37 = [M]::Foo - $f37.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f37.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64]] $f38 = [M]::Foo - $f38.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f38.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64]] $f39 = [M]::Foo - $f39.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f39.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64]] $f40 = [M]::Foo - $f40.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f40.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[float, float]] $f41 = [M]::Foo - $f41.Invoke(10) | Should BE 10 + $f41.Invoke(10) | Should -Be 10 [Func[float, float, float]] $f42 = [M]::Foo - $f42.Invoke(10, 1) | Should BE 10 + $f42.Invoke(10, 1) | Should -Be 10 [Func[float, float, float, float]] $f43 = [M]::Foo - $f43.Invoke(10, 1, 2) | Should BE 10 + $f43.Invoke(10, 1, 2) | Should -Be 10 [Func[float, float, float, float, float]] $f44 = [M]::Foo - $f44.Invoke(10, 1, 2, 3) | Should BE 10 + $f44.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[float, float, float, float, float, float]] $f45 = [M]::Foo - $f45.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f45.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[float, float, float, float, float, float, float]] $f46 = [M]::Foo - $f46.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f46.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[float, float, float, float, float, float, float, float]] $f47 = [M]::Foo - $f47.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f47.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[float, float, float, float, float, float, float, float, float]] $f48 = [M]::Foo - $f48.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f48.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[double, double]] $f49 = [M]::Foo - $f49.Invoke(10) | Should BE 10 + $f49.Invoke(10) | Should -Be 10 [Func[double, double, double]] $f50 = [M]::Foo - $f50.Invoke(10, 1) | Should BE 10 + $f50.Invoke(10, 1) | Should -Be 10 [Func[double, double, double, double]] $f51 = [M]::Foo - $f51.Invoke(10, 1, 2) | Should BE 10 + $f51.Invoke(10, 1, 2) | Should -Be 10 [Func[double, double, double, double, double]] $f52 = [M]::Foo - $f52.Invoke(10, 1, 2, 3) | Should BE 10 + $f52.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[double, double, double, double, double, double]] $f53 = [M]::Foo - $f53.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f53.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[double, double, double, double, double, double, double]] $f54 = [M]::Foo - $f54.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f54.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[double, double, double, double, double, double, double, double]] $f55 = [M]::Foo - $f55.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f55.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[double, double, double, double, double, double, double, double, double]] $f56 = [M]::Foo - $f56.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f56.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 [Func[IntPtr, IntPtr]] $f57 = [M]::Foo - $f57.Invoke(10) | Should BE 10 + $f57.Invoke(10) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr]] $f58 = [M]::Foo - $f58.Invoke(10, 1) | Should BE 10 + $f58.Invoke(10, 1) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr]] $f59 = [M]::Foo - $f59.Invoke(10, 1, 2) | Should BE 10 + $f59.Invoke(10, 1, 2) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr, IntPtr]] $f60 = [M]::Foo - $f60.Invoke(10, 1, 2, 3) | Should BE 10 + $f60.Invoke(10, 1, 2, 3) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr]] $f61 = [M]::Foo - $f61.Invoke(10, 1, 2, 3, 4) | Should BE 10 + $f61.Invoke(10, 1, 2, 3, 4) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr]] $f62 = [M]::Foo - $f62.Invoke(10, 1, 2, 3, 4, 5) | Should BE 10 + $f62.Invoke(10, 1, 2, 3, 4, 5) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr]] $f63 = [M]::Foo - $f63.Invoke(10, 1, 2, 3, 4, 5, 6) | Should BE 10 + $f63.Invoke(10, 1, 2, 3, 4, 5, 6) | Should -Be 10 [Func[IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr]] $f64 = [M]::Foo - $f64.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should BE 10 + $f64.Invoke(10, 1, 2, 3, 4, 5, 6, 7) | Should -Be 10 $timespan = [timespan]::FromMinutes(62) [Func[timespan, timespan]] $f65 = [M]::Foo - $f65.Invoke($timeSpan) | Should BE $timeSpan + $f65.Invoke($timeSpan) | Should -Be $timeSpan [Func[timespan, timespan, timespan]] $f66 = [M]::Foo - $f66.Invoke($timeSpan, [Timespan]::Zero) | Should BE $timeSpan + $f66.Invoke($timeSpan, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan]] $f67 = [M]::Foo - $f67.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f67.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan, timespan]] $f68 = [M]::Foo - $f68.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f68.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan, timespan, timespan]] $f69 = [M]::Foo - $f69.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f69.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan, timespan, timespan, timespan]] $f70 = [M]::Foo - $f70.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f70.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan, timespan, timespan, timespan, timespan]] $f71 = [M]::Foo - $f71.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f71.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan [Func[timespan, timespan, timespan, timespan, timespan, timespan, timespan, timespan, timespan]] $f72 = [M]::Foo - $f72.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should BE $timeSpan + $f72.Invoke($timeSpan, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero, [Timespan]::Zero) | Should -Be $timeSpan } } diff --git a/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 b/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 index 1284faaf16..42785fc555 100644 --- a/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 +++ b/test/powershell/Language/Parser/ExtensibleCompletion.Tests.ps1 @@ -107,9 +107,9 @@ function Test-Completions foreach ($expected in $test.ExpectedResults) { $skip = $false - if ( $expected.CompletionText -match "System.Management.Automation.PerformanceData|System.Management.Automation.Security" ) { $skip = $true } + if ( $expected.CompletionText -Match "System.Management.Automation.PerformanceData|System.Management.Automation.Security" ) { $skip = $true } It ($expected.CompletionText) -skip:$skip { - $expected.Found | Should Be $true + $expected.Found | Should -BeTrue } } @@ -118,7 +118,7 @@ function Test-Completions It "Not expected: $notExpected" { foreach ($result in $results.CompletionMatches) { - ($result.CompletionText -ceq $notExpected) | Should Be $False + $result.CompletionText | Should -Not -Be $notExpected } } } @@ -237,7 +237,7 @@ Describe "Test completion of parameters for native commands" -Tags "CI" { @("-dir", "-verbose", "-help", "-version") | Where-Object { - $_ -match "$wordToComplete*" + $_ -Match "$wordToComplete*" } | ForEach-Object { [CompletionResult]::new($_, $_, [CompletionResultType]::ParameterName, $_) @@ -436,9 +436,9 @@ Describe "ArgumentCompletionsAttribute tests" -Tags "CI" { $line = "$cmdletName -Alpha val" $res = TaBexpansion2 -inputScript $line -cursorColumn $line.Length - $res.CompletionMatches.Count | Should Be 3 - $res.CompletionMatches.CompletionText -join " " | Should Be "value1 value2 value3" - { TestArgumentCompletionsAttribute -Alpha unExpectedValue } | Should Not Throw + $res.CompletionMatches.Count | Should -Be 3 + $res.CompletionMatches.CompletionText -join " " | Should -BeExactly "value1 value2 value3" + { TestArgumentCompletionsAttribute -Alpha unExpectedValue } | Should -Not -Throw } It " works in C#" -TestCases $testCasesCSharp { @@ -446,8 +446,8 @@ Describe "ArgumentCompletionsAttribute tests" -Tags "CI" { $line = "$cmdletName -Param1 val" $res = TaBexpansion2 -inputScript $line -cursorColumn $line.Length - $res.CompletionMatches.Count | Should Be 3 - $res.CompletionMatches.CompletionText -join " " | Should Be "value1 value2 value3" - { TestArgumentCompletionsAttribute -Param1 unExpectedValue } | Should Not Throw + $res.CompletionMatches.Count | Should -Be 3 + $res.CompletionMatches.CompletionText -join " " | Should -BeExactly "value1 value2 value3" + { TestArgumentCompletionsAttribute -Param1 unExpectedValue } | Should -Not -Throw } } diff --git a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 index 20f041a3ba..39d9d23eaa 100644 --- a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 +++ b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 @@ -4,17 +4,17 @@ $powershellexe = (get-process -id $PID).mainmodule.filename Describe "Clone array" -Tags "CI" { It "Cast in target expr" { - (([int[]](42)).clone()) | Should Be 42 - (([int[]](1..5)).clone()).Length | Should Be 5 - (([int[]](1..5)).clone()).GetType() | Should Be ([int[]]) + (([int[]](42)).clone()) | Should -Be 42 + (([int[]](1..5)).clone()).Length | Should -Be 5 + (([int[]](1..5)).clone()).GetType() | Should -Be ([int[]]) } It "Cast not in target expr" { $e = [int[]](42) - $e.Clone() | Should Be 42 + $e.Clone() | Should -Be 42 $e = [int[]](1..5) - $e.Clone().Length | Should Be 5 - $e.Clone().GetType() | Should Be ([int[]]) + $e.Clone().Length | Should -Be 5 + $e.Clone().GetType() | Should -Be ([int[]]) } } @@ -24,15 +24,15 @@ Describe "Set fields through PSMemberInfo" -Tags "CI" { "@ It "via cast" { - ([AStruct]@{s = "abc" }).s | Should Be "abc" + ([AStruct]@{s = "abc" }).s | Should -BeExactly "abc" } It "via new-object" { - (new-object AStruct -prop @{s="abc"}).s | Should Be "abc" + (new-object AStruct -prop @{s="abc"}).s | Should -BeExactly "abc" } It "via PSObject" { $x = [AStruct]::new() $x.psobject.properties['s'].Value = 'abc' - $x.s | Should Be "abc" + $x.s | Should -Be "abc" } } @@ -41,12 +41,12 @@ Describe "MSFT:3309783" -Tags "CI" { It "Run in another process" { # For a reliable test, we must run this in a new process because an earlier binding in this process # could mask the bug/fix. - & $powershellexe -noprofile -command "[psobject] | ForEach-Object FullName" | Should Be System.Management.Automation.PSObject + & $powershellexe -noprofile -command "[psobject] | ForEach-Object FullName" | Should -Be System.Management.Automation.PSObject } It "Run in current process" { # For good measure, do the same thing in this process - [psobject] | ForEach-Object FullName | Should Be System.Management.Automation.PSObject + [psobject] | ForEach-Object FullName | Should -Be System.Management.Automation.PSObject } It "Pipe objects derived from PSObject" { @@ -60,8 +60,8 @@ Describe "MSFT:3309783" -Tags "CI" { } } - [MyPsObj]::new("abc").psobject.ToString() | Should Be "MyObj: abc" - [MyPsObj]::new("def") | Out-String | ForEach-Object Trim | Should Be "MyObj: def" + [MyPsObj]::new("abc").psobject.ToString() | Should -Be "MyObj: abc" + [MyPsObj]::new("def") | Out-String | ForEach-Object Trim | Should -Be "MyObj: def" } } @@ -71,14 +71,14 @@ Describe "ScriptBlockAst.GetScriptBlock throws on error" -Tags "CI" { It "with parse error" { $ast = [System.Management.Automation.Language.Parser]::ParseInput('function ', [ref]$null, [ref]$e) - { $ast.GetScriptBlock() } | Should Throw + { $ast.GetScriptBlock() } | Should -Throw -ErrorId "PSInvalidOperationException" } It "with semantic errors" { $ast = [System.Management.Automation.Language.Parser]::ParseInput('function foo{param()begin{}end{[ref][ref]1}dynamicparam{}}', [ref]$null, [ref]$e) - { $ast.GetScriptBlock() } | Should Throw - { $ast.EndBlock.Statements[0].Body.GetScriptBlock() } | Should Throw + { $ast.GetScriptBlock() } | Should -Throw -ErrorId "PSInvalidOperationException" + { $ast.EndBlock.Statements[0].Body.GetScriptBlock() } | Should -Throw -ErrorId "PSInvalidOperationException" } } @@ -97,13 +97,13 @@ Describe "Hashtable key property syntax" -Tags "CI" { It "In current process" { # Run in current process, but something that ran earlier could influence # the result - Invoke-Expression $script | Should Be Hello + Invoke-Expression $script | Should -BeExactly 'Hello' } It "In different process" { # So also run in a fresh process $bytes = [System.Text.Encoding]::Unicode.GetBytes($script) - & $powershellexe -noprofile -encodedCommand ([Convert]::ToBase64String($bytes)) | Should Be Hello + & $powershellexe -noprofile -encodedCommand ([Convert]::ToBase64String($bytes)) | Should -BeExactly 'Hello' } } @@ -114,32 +114,32 @@ Describe "Assign automatic variables" -Tags "CI" { foreach ($auto in $autos) { It "Assign auto w/ invalid type constraint - $auto" { - { & ([ScriptBlock]::Create("[datetime]`$$auto = 1")) } | Should Throw $auto - { . ([ScriptBlock]::Create("[datetime]`$$auto = 1")) } | Should Throw $auto - { & ([ScriptBlock]::Create("[runspace]`$$auto = 1")) } | Should Throw $auto - { . ([ScriptBlock]::Create("[runspace]`$$auto = 1")) } | Should Throw $auto - { & ([ScriptBlock]::Create("[notexist]`$$auto = 1")) } | Should Throw $auto - { . ([ScriptBlock]::Create("[notexist]`$$auto = 1")) } | Should Throw $auto + { & ([ScriptBlock]::Create("[datetime]`$$auto = 1")) } | Should -Throw $auto + { . ([ScriptBlock]::Create("[datetime]`$$auto = 1")) } | Should -Throw $auto + { & ([ScriptBlock]::Create("[runspace]`$$auto = 1")) } | Should -Throw $auto + { . ([ScriptBlock]::Create("[runspace]`$$auto = 1")) } | Should -Throw $auto + { & ([ScriptBlock]::Create("[notexist]`$$auto = 1")) } | Should -Throw $auto + { . ([ScriptBlock]::Create("[notexist]`$$auto = 1")) } | Should -Throw $auto } } foreach ($auto in $autos) { It "Assign auto w/o type constraint - $auto" { - & ([ScriptBlock]::Create("`$$auto = 1; `$$auto")) | Should Be 1 - . ([ScriptBlock]::Create("`$$auto = 1; `$$auto")) | Should Be 1 + & ([ScriptBlock]::Create("`$$auto = 1; `$$auto")) | Should -Be 1 + . ([ScriptBlock]::Create("`$$auto = 1; `$$auto")) | Should -Be 1 } } It "Assign auto w/ correct type constraint" { - & { [object]$_ = 1; $_ } | Should Be 1 - & { [object[]]$args = 1; $args } | Should Be 1 - & { [object]$this = 1; $this } | Should Be 1 - & { [object]$input = 1; $input } | Should Be 1 + & { [object]$_ = 1; $_ } | Should -Be 1 + & { [object[]]$args = 1; $args } | Should -Be 1 + & { [object]$this = 1; $this } | Should -Be 1 + & { [object]$input = 1; $input } | Should -Be 1 # Can't test PSCmdlet or PSBoundParameters, they use an internal type - & { [System.Management.Automation.InvocationInfo]$myInvocation = $myInvocation; $myInvocation.Line } | Should Match Automation.InvocationInfo - & { [string]$PSScriptRoot = 'abc'; $PSScriptRoot } | Should Be abc - & { [string]$PSCommandPath = 'abc'; $PSCommandPath } | Should Be abc + & { [System.Management.Automation.InvocationInfo]$myInvocation = $myInvocation; $myInvocation.Line } | Should -Match Automation.InvocationInfo + & { [string]$PSScriptRoot = 'abc'; $PSScriptRoot } | Should -BeExactly 'abc' + & { [string]$PSCommandPath = 'abc'; $PSCommandPath } | Should -BeExactly 'abc' } } @@ -153,8 +153,8 @@ Describe "Assign readonly/constant variables" -Tags "CI" { It "Assign readonly/constant variables w/o type constraint - ''" -TestCases $testCase { param($sb_wo_conversion) - { & $sb_wo_conversion } | Should Throw - { . $sb_wo_conversion } | Should Throw + { & $sb_wo_conversion } | Should -Throw -ErrorId "VariableNotWritable" + { . $sb_wo_conversion } | Should -Throw -ErrorId "VariableNotWritable" } $testCase = @( @@ -165,8 +165,8 @@ Describe "Assign readonly/constant variables" -Tags "CI" { It "Assign readonly/constant variables w/ type constraint - ''" -TestCases $testCase { param($sb_w_conversion) - { & $sb_w_conversion } | Should Throw - { . $sb_w_conversion } | Should Throw + { & $sb_w_conversion } | Should -Throw -ErrorId "VariableNotWritable" + { . $sb_w_conversion } | Should -Throw -ErrorId "VariableNotWritable" } } @@ -184,8 +184,8 @@ Describe "Attribute error position" -Tags "CI" { } catch { - $_.InvocationInfo.Line | Should Match ValidateNotNull - $_.FullyQualifiedErrorId | Should Be MethodCountCouldNotFindBest + $_.InvocationInfo.Line | Should -Match ValidateNotNull + $_.FullyQualifiedErrorId | Should -Be MethodCountCouldNotFindBest } } } @@ -201,9 +201,9 @@ Describe "Multiple alias attributes" -Tags "CI" { $cc } - foo -aa 1 | Should Be 1 - foo -bb 2 | Should Be 2 - foo -cc 3 | Should Be 3 + foo -aa 1 | Should -Be 1 + foo -bb 2 | Should -Be 2 + foo -cc 3 | Should -Be 3 } } @@ -214,7 +214,7 @@ Describe "Members of System.Type" -Tags "CI" { [System.Collections.IEnumerator] GetEnumerator() { return $null } } - [type] | Get-Member ImplementedInterfaces | Should Be 'System.Collections.Generic.IEnumerable[type] ImplementedInterfaces {get;}' - [MyType].ImplementedInterfaces | Should Be System.Collections.IEnumerable + [type] | Get-Member ImplementedInterfaces | Should -Be 'System.Collections.Generic.IEnumerable[type] ImplementedInterfaces {get;}' + [MyType].ImplementedInterfaces | Should -Be System.Collections.IEnumerable } } diff --git a/test/powershell/Language/Parser/MethodInvocation.Tests.ps1 b/test/powershell/Language/Parser/MethodInvocation.Tests.ps1 index c894460dcc..69a6cdca9c 100644 --- a/test/powershell/Language/Parser/MethodInvocation.Tests.ps1 +++ b/test/powershell/Language/Parser/MethodInvocation.Tests.ps1 @@ -70,14 +70,14 @@ namespace MSFT_716893 } It "Direct invocation" { - $proxy.Operation("a") | Should Be "1 - a" - $proxy.Operation("a", "b") | Should Be "2 - a b" - $proxy.BaseOperation(42) | Should Be "3 - 42" + $proxy.Operation("a") | Should -Be "1 - a" + $proxy.Operation("a", "b") | Should -Be "2 - a b" + $proxy.BaseOperation(42) | Should -Be "3 - 42" } It "Invocation via method constraints" { - ([MSFT_716893.IInterface2]$proxy).Operation("c") | Should Be "1 - c" - ([MSFT_716893.IInterface2]$proxy).Operation("d", "e") | Should Be "2 - d e" - ([MSFT_716893.IInterface1]$proxy).BaseOperation(22) | Should Be "3 - 22" + ([MSFT_716893.IInterface2]$proxy).Operation("c") | Should -Be "1 - c" + ([MSFT_716893.IInterface2]$proxy).Operation("d", "e") | Should -Be "2 - d e" + ([MSFT_716893.IInterface1]$proxy).BaseOperation(22) | Should -Be "3 - 22" } } diff --git a/test/powershell/Language/Parser/ParameterBinding.Tests.ps1 b/test/powershell/Language/Parser/ParameterBinding.Tests.ps1 index 7ae9e3564b..ad4d539d5c 100644 --- a/test/powershell/Language/Parser/ParameterBinding.Tests.ps1 +++ b/test/powershell/Language/Parser/ParameterBinding.Tests.ps1 @@ -70,32 +70,32 @@ Describe 'Argument transformation attribute on optional argument with explicit $ } It "There was no error importing the in-memory module" { - $ErrorImportingModule | Should Be $null + $ErrorImportingModule | Should -BeNullOrEmpty } It "Script function takes object" { - Invoke-ScriptFunctionTakesObject | Should Be 42 + Invoke-ScriptFunctionTakesObject | Should -Be 42 } It "Script function takes uint64" { - Invoke-ScriptFunctionTakesUInt64 | Should Be 42 + Invoke-ScriptFunctionTakesUInt64 | Should -Be 42 } it "csharp cmdlet takes object" { - Invoke-CSharpCmdletTakesObject | Should Be "passed in null" + Invoke-CSharpCmdletTakesObject | Should -Be "passed in null" } it "csharp cmdlet takes uint64" { - Invoke-CSharpCmdletTakesUInt64 | Should Be 0 + Invoke-CSharpCmdletTakesUInt64 | Should -Be 0 } it "script function takes object when parameter is null" { - Invoke-ScriptFunctionTakesObject -Address $null | Should Be 42 + Invoke-ScriptFunctionTakesObject -Address $null | Should -Be 42 } it "script function takes unit64 when parameter is null" { - Invoke-ScriptFunctionTakesUInt64 -Address $null | Should Be 42 + Invoke-ScriptFunctionTakesUInt64 -Address $null | Should -Be 42 } it "script csharp cmdlet takes object when parameter is null" { - Invoke-CSharpCmdletTakesObject -Address $null | Should Be 42 + Invoke-CSharpCmdletTakesObject -Address $null | Should -Be 42 } it "script csharp cmdlet takes uint64 when parameter is null" { - Invoke-CSharpCmdletTakesUInt64 -Address $null | Should Be 42 + Invoke-CSharpCmdletTakesUInt64 -Address $null | Should -Be 42 } } diff --git a/test/powershell/Language/Parser/Parser.Tests.ps1 b/test/powershell/Language/Parser/Parser.Tests.ps1 index 0edc62fda6..3b012dd3b3 100644 --- a/test/powershell/Language/Parser/Parser.Tests.ps1 +++ b/test/powershell/Language/Parser/Parser.Tests.ps1 @@ -90,11 +90,11 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" $shellfile = Join-Path -Path $TestDrive -ChildPath "testfile.cmd" $testfolder1 = Join-Path -Path $TestDrive -ChildPath "dir1" $testfolder2 = Join-Path -Path $testfolder1 -ChildPath "dir2" - if(-not(Test-Path $testfolder1)) + if(-Not(Test-Path $testfolder1)) { New-Item $testfolder1 -Type Directory } - if(-not(Test-Path $testfolder2)) + if(-Not(Test-Path $testfolder2)) { New-Item $testfolder2 -Type Directory } @@ -143,7 +143,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } @@ -153,7 +153,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } @@ -163,15 +163,15 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } It "Throws an CommandNotFoundException exception if using a label in front of an if statement is not allowed. (line 225)"{ $PowerShell.Streams.Error.Clear() ExecuteCommand ":foo if ($x -eq 3) { 1 }" - $PowerShell.HadErrors | should be $true - $PowerShell.Streams.Error.FullyQualifiedErrorId | should be "CommandNotFoundException" + $PowerShell.HadErrors | Should -BeTrue + $PowerShell.Streams.Error.FullyQualifiedErrorId | Should -Be "CommandNotFoundException" } It "Pipe an expression into a value expression. (line 237)" { @@ -180,7 +180,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } try { @@ -188,7 +188,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } try { @@ -196,7 +196,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } @@ -207,7 +207,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } } @@ -218,57 +218,57 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } It "Test that invoke has a higher precedence for a script than for an executable. (line 279)" { "1">$testfile $result = ExecuteCommand ". $testfile" - $result | should be 1 + $result | Should -Be 1 } It "This test will check that a path is correctly interpreted when using '..' and '.' (line 364)" { $result = ExecuteCommand "set-location $TestDrive; get-childitem dir1\.\.\.\..\dir1\.\dir2\..\..\dir1\.\dir2" - $result.Count | should be 2 - $result[0].Name | should be "testdirfile1.txt" - $result[1].Name | should be "testdirfile2.txt" + $result.Count | Should -Be 2 + $result[0].Name | Should -BeExactly "testdirfile1.txt" + $result[1].Name | Should -BeExactly "testdirfile2.txt" } It "This test will check that the parser can handle a mix of forward slashes and back slashes in the path (line 417)" { $result = ExecuteCommand "get-childitem $TestDrive/dir1/./.\.\../dir1/.\dir2\../..\dir1\.\dir2" - $result.Count | should be 2 - $result[0].Name | should be "testdirfile1.txt" - $result[1].Name | should be "testdirfile2.txt" + $result.Count | Should -Be 2 + $result[0].Name | Should -BeExactly "testdirfile1.txt" + $result[1].Name | Should -BeExactly "testdirfile2.txt" } It "This test checks that the asterisk globs as expected. (line 545)" { $result = ExecuteCommand "get-childitem $TestDrive/dir1\dir2\*.txt" - $result.Count | should be 2 - $result[0].Name | should be "testdirfile1.txt" - $result[1].Name | should be "testdirfile2.txt" + $result.Count | Should -Be 2 + $result[0].Name | Should -BeExactly "testdirfile1.txt" + $result[1].Name | Should -BeExactly "testdirfile2.txt" } It "This test checks that we can use a range for globbing: [1-2] (line 557)" { $result = ExecuteCommand "get-childitem $TestDrive/dir1\dir2\testdirfile[1-2].txt" - $result.Count | should be 2 - $result[0].Name | should be "testdirfile1.txt" - $result[1].Name | should be "testdirfile2.txt" + $result.Count | Should -Be 2 + $result[0].Name | Should -BeExactly "testdirfile1.txt" + $result[1].Name | Should -BeExactly "testdirfile2.txt" } It "This test will check that escaping the $ sigil inside single quotes simply returns the $ character. (line 583)" { $result = ExecuteCommand "'`$'" - $result | should be "`$" + $result | Should -BeExactly "`$" } It "Test that escaping a space just returns that space. (line 593)" { $result = ExecuteCommand '"foo` bar"' - $result | should be "foo bar" + $result | Should -BeExactly "foo bar" } It "Test that escaping the character 'e' returns the ESC character (0x1b)." { $result = ExecuteCommand '"`e"' - $result | should be ([char]0x1b) + $result | Should -BeExactly ([char]0x1b) } Context "Test Unicode escape sequences." { @@ -276,38 +276,38 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" # PowerShell without a BOM, the file is incorrectly interpreted as ASCII. It 'Test that the bracketed Unicode escape sequence `u{0} returns minimum char.' { $result = ExecuteCommand '"`u{0}"' - [int]$result[0] | should be 0 + [int]$result[0] | Should -Be 0 } It 'Test that the bracketed Unicode escape sequence `u{10FFFF} returns maximum surrogate char pair.' { $result = ExecuteCommand '"`u{10FFFF}"' - [int]$result[0] | should be 0xDBFF # max value for high surrogate of surrogate pair - [int]$result[1] | should be 0xDFFF # max value for low surrogate of surrogate pair + [int]$result[0] | Should -BeExactly 0xDBFF # max value for high surrogate of surrogate pair + [int]$result[1] | Should -BeExactly 0xDFFF # max value for low surrogate of surrogate pair } It 'Test that the bracketed Unicode escape sequence `u{a9} returns the © character.' { $result = ExecuteCommand '"`u{a9}"' - $result | should be '©' + $result | Should -BeExactly '©' } It 'Test that Unicode escape sequence `u{2195} in string returns the ↕ character.' { $result = ExecuteCommand '"foo`u{2195}abc"' - $result | should be "foo↕abc" + $result | Should -BeExactly "foo↕abc" } It 'Test that the bracketed Unicode escape sequence `u{1f44d} returns surrogate pair for emoji 👍 character.' { $result = ExecuteCommand '"`u{1f44d}"' - $result | should be "👍" + $result | Should -BeExactly "👍" } It 'Test that Unicode escape sequence `u{2195} in here string returns the ↕ character.' { $result = ExecuteCommand ("@`"`n`n" + 'foo`u{2195}abc' + "`n`n`"@") - $result | should be "`nfoo↕abc`n" + $result | Should -BeExactly "`nfoo↕abc`n" } It 'Test that Unicode escape sequence in single quoted is not processed.' { $result = ExecuteCommand '''foo`u{2195}abc''' - $result | should be 'foo`u{2195}abc' + $result | Should -BeExactly 'foo`u{2195}abc' } It 'Test that Unicode escape sequence in single quoted here string is not processed.' { @@ -318,38 +318,38 @@ foo``u{2195}abc '@ "@ - $result | should match "\r?\nfoo``u\{2195\}abc\r?\n" + $result | Should -Match "\r?\nfoo``u\{2195\}abc\r?\n" } It "Test that two consecutive Unicode escape sequences are tokenized correctly." { $result = ExecuteCommand '"`u{007b}`u{007d}"' - $result | should be '{}' + $result | Should -Be '{}' } It "Test that a Unicode escape sequence can be used in a command name." { function xyzzy`u{2195}($p) {$p} $cmd = Get-Command xyzzy`u{2195} -ErrorAction SilentlyContinue - $cmd | should not BeNullOrEmpty - $cmd.Name | should be 'xyzzy↕' - xyzzy`u{2195} 42 | should be 42 + $cmd | Should -Not -BeNullOrEmpty + $cmd.Name | Should -BeExactly 'xyzzy↕' + xyzzy`u{2195} 42 | Should -Be 42 } It "Test that a Unicode escape sequence can be used in a variable name." { ${fooxyzzy`u{2195}} = 42 $var = Get-Variable -Name fooxyzzy* -ErrorAction SilentlyContinue - $var | should not BeNullOrEmpty - $var.Name | should be "fooxyzzy↕" - $var.Value | should be 42 + $var | Should -Not -BeNullOrEmpty + $var.Name | Should -BeExactly "fooxyzzy↕" + $var.Value | Should -Be 42 } It "Test that a Unicode escape sequence can be used in an argument." { - Write-Output `u{a9}` Acme` Inc | should be "© Acme Inc" + Write-Output `u{a9}` Acme` Inc | Should -BeExactly "© Acme Inc" } } It "Test that escaping any character with no special meaning just returns that char. (line 602)" { $result = ExecuteCommand '"fo`obar"' - $result | should be "foobar" + $result | Should -BeExactly "foobar" } Context "Test that we support all of the C# escape sequences. We use the ` instead of \. (line 613)" { @@ -371,39 +371,39 @@ foo``u{2195}abc It "C# escape sequence is supported using `` instead of \. (line 613)" -TestCases $tests { param ( $sequence, $expected ) $result = ExecuteCommand $sequence - $result | should be $expected + $result | Should -BeExactly $expected } } It "This test checks that array substitution occurs inside double quotes. (line 646)" { $result = ExecuteCommand '$MyArray = "a","b";"Hello $MyArray"' - $result | should be "Hello a b" + $result | Should -BeExactly "Hello a b" } It "This tests declaring an array in nested variable tables. (line 761)" { $result = ExecuteCommand "`$Variable:vtbl1:vtbl2:b=@(5,6);`$Variable:vtbl1:vtbl2:b" - $result.Count | should be 2 - $result[0] | should be 5 - $result[1] | should be 6 + $result.Count | Should -Be 2 + $result[0] | Should -Be 5 + $result[1] | Should -Be 6 } It "Test a simple multiple assignment. (line 773)" { $result = ExecuteCommand '$one,$two = 1,2,3; "One = $one"; "Two = $two"' - $result.Count | should be 2 - $result[0] | should be "One = 1" - $result[1] | should be "Two = 2 3" + $result.Count | Should -Be 2 + $result[0] | Should -Be "One = 1" + $result[1] | Should -Be "Two = 2 3" } It "Tests script, global and local scopes from a function inside a script. (line 824)" { "`$var = 'script';function func { `$var; `$var = 'local'; `$local:var; `$script:var; `$global:var };func;`$var;">$testfile ExecuteCommand "`$var = 'global'" $result = ExecuteCommand "$testfile" - $result.Count | should be 5 - $result[0] | should be "script" - $result[1] | should be "local" - $result[2] | should be "script" - $result[3] | should be "global" - $result[4] | should be "script" + $result.Count | Should -Be 5 + $result[0] | Should -BeExactly "script" + $result[1] | Should -BeExactly "local" + $result[2] | Should -BeExactly "script" + $result[3] | Should -BeExactly "global" + $result[4] | Should -BeExactly "script" } It "Use break inside of a loop that is inside another loop. (line 945)" { @@ -415,7 +415,7 @@ foo``u{2195}abc for(;$i -lt $commands.Count;$i++) { $result = ExecuteCommand $commands[$i] - $result | should be $results + $result | Should -Be $results } } @@ -428,7 +428,7 @@ foo``u{2195}abc for(;$i -lt $commands.Count;$i++) { $result = ExecuteCommand $commands[$i] - $result | should be $results + $result | Should -Be $results } } @@ -437,11 +437,11 @@ foo``u{2195}abc " for (`$a = 0;`$a -lt 2; `$a += 1) { 9; continue; 3; } ", " foreach(`$a in 0,1) { `$a; continue; 2; } " $result = ExecuteCommand $commands[0] - $result | should be "0", "1" + $result | Should -Be "0", "1" $result = ExecuteCommand $commands[1] - $result | should be "9", "9" + $result | Should -Be "9", "9" $result = ExecuteCommand $commands[2] - $result | should be "0", "1" + $result | Should -Be "0", "1" } It "Use a label to continue an inner loop. (line 1059)" { @@ -449,11 +449,11 @@ foo``u{2195}abc " for (`$x = 0;`$x -lt 1;`$x += 1) { 1; :foo for(`$a = 0; `$a -lt 2; `$a += 1) { `$a; continue foo; 3; }; 4; continue; 5; } ", " foreach(`$a in 1) { 1; :foo foreach( `$b in 1,2 ) { `$b; continue foo; 3; }; 4; continue; 5; } " $result = ExecuteCommand $commands[0] - $result | should be "1", "1", "2", "4" + $result | Should -Be "1", "1", "2", "4" $result = ExecuteCommand $commands[1] - $result | should be "1", "0", "1", "4" + $result | Should -Be "1", "0", "1", "4" $result = ExecuteCommand $commands[2] - $result | should be "1", "1", "2", "4" + $result | Should -Be "1", "1", "2", "4" } It "Use continue with a label on a nested loop. (line 1059)" { @@ -461,11 +461,11 @@ foo``u{2195}abc " :foo for (`$x = 0;`$x -lt 2;`$x += 1) { 1; :bar for(;;) { 2; continue foo; 3; }; 4; continue; 5; } ", " :foo foreach(`$a in 1,2) { 1; :bar foreach( `$b in 1,2,3 ) { 2; continue foo; 3; }; 4; continue; 5; } " $result = ExecuteCommand $commands[0] - $result | should be "0", "2", "1", "2" + $result | Should -Be "0", "2", "1", "2" $result = ExecuteCommand $commands[1] - $result | should be "1", "2", "1", "2" + $result | Should -Be "1", "2", "1", "2" $result = ExecuteCommand $commands[2] - $result | should be "1", "2", "1", "2" + $result | Should -Be "1", "2", "1", "2" } It "This test will check that it is a syntax error to use if without a code block. (line 1141)" { @@ -474,7 +474,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } @@ -484,7 +484,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } @@ -494,7 +494,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } @@ -504,7 +504,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } @@ -514,7 +514,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "IncompleteParseException" + $_.FullyQualifiedErrorId | Should -Be "IncompleteParseException" } } @@ -524,7 +524,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } @@ -534,7 +534,7 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } @@ -544,60 +544,60 @@ foo``u{2195}abc throw "Execution OK" } catch { - $_.FullyQualifiedErrorId | Should be "ParseException" + $_.FullyQualifiedErrorId | Should -Be "ParseException" } } It "Test that if an exception is thrown from the try block it will be caught in the appropropriate catch block and that the finally block will run regardless of whether an exception is thrown. (line 1317)" { $result = ExecuteCommand 'try { try { throw (new-object System.ArgumentException) } catch [System.DivideByZeroException] { } finally { "Finally" } } catch { $_.Exception.GetType().FullName }' - $result | should be "Finally", "System.ArgumentException" + $result | Should -Be "Finally", "System.ArgumentException" } It "Test that null can be passed to a method that expects a reference type. (line 1439)" { $result = ExecuteCommand '$test = "String";$test.CompareTo($())' - $result | should be 1 + $result | Should -Be 1 } It "Tests that command expansion operators can be used as a parameter to an object method. (line 1507)" { $result = ExecuteCommand '$test = "String";$test.SubString($("hello" | foreach-object { $_.length - 2 } ))' - $result | should be "ing" + $result | Should -Be "ing" } It "Test that & can be used as a parameter as long as it is quoted. (line 1606)" { $result = ExecuteCommand 'testcmd-parserbvt `&get-childitem' - $result | should be "&get-childitem;unset;unset" + $result | Should -Be "&get-childitem;unset;unset" $result = ExecuteCommand 'testcmd-parserbvt `&*' - $result | should be "&*;unset;unset" + $result | Should -Be "&*;unset;unset" } It "Run a command with parameters. (line 1621)" { $result = ExecuteCommand 'testcmd-parserBVT -Property1 set' - $result | should be "set;unset;unset" + $result | Should -Be "set;unset;unset" } It "Test that typing a number at the command line will return that number. (line 1630)" { $result = ExecuteCommand '3' - $result | should be "3" - $result.gettype() |should be ([int]) + $result | Should -Be "3" + $result.gettype() |should -Be ([int]) } It "This test will check that an msh script can be run without invoking. (line 1641)" { "1">$testfile $result = ExecuteCommand ". $testfile" - $result | should be 1 + $result | Should -Be 1 } It "Test that an alias is resolved before a function. (line 1657)" { $result = ExecuteCommand 'set-alias parserInvokeTest testcmd-parserBVT;function parserInvokeTest { 3 };parserInvokeTest' - $result | should be "unset;unset;unset" + $result | Should -Be "unset;unset;unset" } It "Test that functions are resolved before cmdlets. (line 1678)"{ $result_cmdlet = $PowerShell.AddScript('function test-parserfunc { [CmdletBinding()] Param() PROCESS { "cmdlet" } };test-parserfunc').Invoke() $result_func = ExecuteCommand 'function test-parserfunc { "func" };test-parserfunc' $PowerShell.Commands.Clear() - $result_cmdlet | should be "cmdlet" - $result_func | should be "func" + $result_cmdlet | Should -Be "cmdlet" + $result_func | Should -Be "func" } It "Check that a command that uses shell execute can be run from the command line and that no exception is thrown. (line 1702)" { @@ -610,7 +610,7 @@ foo``u{2195}abc else { "@echo Hello, I'm a Cmd script!">$shellfile } - { ExecuteCommand "$shellfile" } | Should Not Throw + { ExecuteCommand "$shellfile" } | Should -Not -Throw } Context "Boolean Tests (starting at line 1723 to line 1772)" { @@ -627,7 +627,7 @@ foo``u{2195}abc ) It "