From c8bc9679bed19c8fbc4229caa01dd083f2d03d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 13 Jun 2024 22:39:30 +0200 Subject: [PATCH] Use functions instead of aliases and patch warning (#2499) * Use functions instead of aliases and patch warning * Skip description check on Should-* * Somehow the sleep sleeps for 0.5 ms, cannot repro --- src/Module.ps1 | 122 ++++-------------- src/Pester.psd1 | 78 +++-------- src/csharp/Pester/VerbsPatcher.cs | 45 +++++++ .../assert/Boolean/Should-BeFalse.ps1 | 2 +- .../assert/Boolean/Should-BeFalsy.ps1 | 2 +- .../assert/Boolean/Should-BeTrue.ps1 | 2 +- .../assert/Boolean/Should-BeTruthy.ps1 | 2 +- .../assert/Collection/Should-All.ps1 | 2 +- .../assert/Collection/Should-Any.ps1 | 2 +- .../assert/Collection/Should-BeCollection.ps1 | 2 +- .../Collection/Should-ContainCollection.ps1 | 2 +- .../Should-NotContainCollection.ps1 | 2 +- .../Equivalence/Should-BeEquivalent.ps1 | 2 +- .../assert/Exception/Should-Throw.ps1 | 2 +- src/functions/assert/General/Should-Be.ps1 | 2 +- .../assert/General/Should-BeGreaterThan.ps1 | 2 +- .../General/Should-BeGreaterThanOrEqual.ps1 | 2 +- .../assert/General/Should-BeLessThan.ps1 | 2 +- .../General/Should-BeLessThanOrEqual.ps1 | 2 +- .../assert/General/Should-BeNull.ps1 | 2 +- .../assert/General/Should-BeSame.ps1 | 2 +- .../assert/General/Should-HaveType.ps1 | 2 +- src/functions/assert/General/Should-NotBe.ps1 | 2 +- .../assert/General/Should-NotBeNull.ps1 | 2 +- .../assert/General/Should-NotBeSame.ps1 | 2 +- .../assert/General/Should-NotHaveType.ps1 | 2 +- .../assert/String/Should-BeEmptyString.ps1 | 2 +- .../assert/String/Should-BeLikeString.ps1 | 2 +- .../assert/String/Should-BeString.ps1 | 2 +- .../assert/String/Should-NotBeEmptyString.ps1 | 16 +-- .../assert/String/Should-NotBeLikeString.ps1 | 2 +- .../assert/String/Should-NotBeString.ps1 | 2 +- .../String/Should-NotBeWhiteSpaceString.ps1 | 18 +-- src/functions/assert/Time/Should-BeAfter.ps1 | 2 +- src/functions/assert/Time/Should-BeBefore.ps1 | 2 +- .../assert/Time/Should-BeFasterThan.ps1 | 2 +- .../assert/Time/Should-BeSlowerThan.ps1 | 2 +- tst/Help.Tests.ps1 | 4 +- .../Should-NotBeNullOrEmptyString.Tests.ps1 | 18 +-- ...ould-NotBeNullOrWhiteSpaceString.Tests.ps1 | 18 +-- .../assert/Time/Should-BeSlowerThan.Tests.ps1 | 2 +- 41 files changed, 160 insertions(+), 225 deletions(-) create mode 100644 src/csharp/Pester/VerbsPatcher.cs diff --git a/src/Module.ps1 b/src/Module.ps1 index 7748dfd9f..0828140be 100644 --- a/src/Module.ps1 +++ b/src/Module.ps1 @@ -8,50 +8,15 @@ $script:SafeCommands['Set-DynamicParameterVariable'] = $ExecutionContext.Session & $SafeCommands['Set-Alias'] 'Add-AssertionOperator' 'Add-ShouldOperator' & $SafeCommands['Set-Alias'] 'Get-AssertionOperator' 'Get-ShouldOperator' -& $SafeCommands['Set-Alias'] 'Should-BeFalse' 'Assert-False' -& $SafeCommands['Set-Alias'] 'Should-BeTrue' 'Assert-True' -& $SafeCommands['Set-Alias'] 'Should-BeFalsy' 'Assert-Falsy' -& $SafeCommands['Set-Alias'] 'Should-BeTruthy' 'Assert-Truthy' -& $SafeCommands['Set-Alias'] 'Should-All' 'Assert-All' -& $SafeCommands['Set-Alias'] 'Should-Any' 'Assert-Any' -& $SafeCommands['Set-Alias'] 'Should-BeCollection' 'Assert-Collection' -& $SafeCommands['Set-Alias'] 'Should-ContainCollection' 'Assert-Contain' -& $SafeCommands['Set-Alias'] 'Should-NotContainCollection' 'Assert-NotContain' -& $SafeCommands['Set-Alias'] 'Should-BeEquivalent' 'Assert-Equivalent' -& $SafeCommands['Set-Alias'] 'Should-Throw' 'Assert-Throw' -& $SafeCommands['Set-Alias'] 'Should-Be' 'Assert-Equal' -& $SafeCommands['Set-Alias'] 'Should-BeGreaterThan' 'Assert-GreaterThan' -& $SafeCommands['Set-Alias'] 'Should-BeGreaterThanOrEqual' 'Assert-GreaterThanOrEqual' -& $SafeCommands['Set-Alias'] 'Should-BeLessThan' 'Assert-LessThan' -& $SafeCommands['Set-Alias'] 'Should-BeLessThanOrEqual' 'Assert-LessThanOrEqual' -& $SafeCommands['Set-Alias'] 'Should-NotBe' 'Assert-NotEqual' -& $SafeCommands['Set-Alias'] 'Should-NotBeNull' 'Assert-NotNull' -& $SafeCommands['Set-Alias'] 'Should-NotBeSame' 'Assert-NotSame' -& $SafeCommands['Set-Alias'] 'Should-NotHaveType' 'Assert-NotType' -& $SafeCommands['Set-Alias'] 'Should-BeNull' 'Assert-Null' -& $SafeCommands['Set-Alias'] 'Should-BeSame' 'Assert-Same' -& $SafeCommands['Set-Alias'] 'Should-HaveType' 'Assert-Type' - -& $SafeCommands['Set-Alias'] 'Should-BeString' 'Assert-StringEqual' -& $SafeCommands['Set-Alias'] 'Should-NotBeString' 'Assert-StringNotEqual' -& $SafeCommands['Set-Alias'] 'Should-BeLikeString' 'Assert-Like' -& $SafeCommands['Set-Alias'] 'Should-NotBeLikeString' 'Assert-NotLike' - -& $SafeCommands['Set-Alias'] 'Should-BeEmptyString' 'Assert-StringEmpty' -& $SafeCommands['Set-Alias'] 'Should-NotBeNullOrWhiteSpaceString' 'Assert-StringNotWhiteSpace' -& $SafeCommands['Set-Alias'] 'Should-NotBeNullOrEmptyString' 'Assert-StringNotEmpty' - -& $SafeCommands['Set-Alias'] 'Should-BeFasterThan' 'Assert-Faster' -& $SafeCommands['Set-Alias'] 'Should-BeSlowerThan' 'Assert-Slower' -& $SafeCommands['Set-Alias'] 'Should-BeBefore' 'Assert-Before' -& $SafeCommands['Set-Alias'] 'Should-BeAfter' 'Assert-After' & $SafeCommands['Update-TypeData'] -TypeName PesterConfiguration -TypeConverter 'PesterConfigurationDeserializer' -SerializationDepth 5 -Force & $SafeCommands['Update-TypeData'] -TypeName 'Deserialized.PesterConfiguration' -TargetTypeForDeserialization PesterConfiguration -Force -& $script:SafeCommands['Export-ModuleMember'] @( +[Pester.VerbsPatcher]::AllowShouldVerb($PSVersionTable.PSVersion.Major) + +& $script:SafeCommands['Export-ModuleMember'] -Function @( 'Invoke-Pester' # blocks @@ -80,62 +45,6 @@ $script:SafeCommands['Set-DynamicParameterVariable'] = $ExecutionContext.Session 'New-PesterConfiguration' # assert - 'Assert-False' - 'Assert-True' - 'Assert-Falsy' - 'Assert-Truthy' - 'Assert-All' - 'Assert-Any' - 'Assert-Contain' - 'Assert-NotContain' - 'Assert-Collection' - 'Assert-Equivalent' - 'Assert-Throw' - 'Assert-Equal' - 'Assert-GreaterThan' - 'Assert-GreaterThanOrEqual' - 'Assert-LessThan' - 'Assert-LessThanOrEqual' - 'Assert-NotEqual' - 'Assert-NotNull' - 'Assert-NotSame' - 'Assert-NotType' - 'Assert-Null' - 'Assert-Same' - 'Assert-Type' - - 'Assert-Like' - 'Assert-NotLike' - 'Assert-StringEqual' - 'Assert-StringNotEqual' - - 'Assert-StringEmpty' - 'Assert-StringNotWhiteSpace' - 'Assert-StringNotEmpty' - - 'Assert-Faster' - 'Assert-Slower' - 'Assert-Before' - 'Assert-After' - - 'Get-EquivalencyOption' - - # export - 'Export-NUnitReport' - 'ConvertTo-NUnitReport' - 'Export-JUnitReport' - 'ConvertTo-JUnitReport' - 'ConvertTo-Pester4Result' - - # helpers - 'New-MockObject' - 'New-Fixture' - 'Set-ItResult' -) -Alias @( - 'Add-AssertionOperator' - 'Get-AssertionOperator' - - # assertion functions # bool 'Should-BeFalse' 'Should-BeTrue' @@ -145,9 +54,9 @@ $script:SafeCommands['Set-DynamicParameterVariable'] = $ExecutionContext.Session # collection 'Should-All' 'Should-Any' - 'Should-BeCollection' 'Should-ContainCollection' 'Should-NotContainCollection' + 'Should-BeCollection' 'Should-BeEquivalent' 'Should-Throw' 'Should-Be' @@ -168,15 +77,32 @@ $script:SafeCommands['Set-DynamicParameterVariable'] = $ExecutionContext.Session 'Should-NotBeString' 'Should-BeEmptyString' - 'Should-NotBeNullOrWhiteSpaceString' - 'Should-NotBeNullOrEmptyString' + + 'Should-NotBeWhiteSpaceString' + 'Should-NotBeEmptyString' 'Should-BeLikeString' 'Should-NotBeLikeString' - # time 'Should-BeFasterThan' 'Should-BeSlowerThan' 'Should-BeBefore' 'Should-BeAfter' + + 'Get-EquivalencyOption' + + # export + 'Export-NUnitReport' + 'ConvertTo-NUnitReport' + 'Export-JUnitReport' + 'ConvertTo-JUnitReport' + 'ConvertTo-Pester4Result' + + # helpers + 'New-MockObject' + 'New-Fixture' + 'Set-ItResult' +) -Alias @( + 'Add-AssertionOperator' + 'Get-AssertionOperator' ) diff --git a/src/Pester.psd1 b/src/Pester.psd1 index b54bad2a8..82b41cf98 100644 --- a/src/Pester.psd1 +++ b/src/Pester.psd1 @@ -67,61 +67,6 @@ 'New-PesterConfiguration' # assert - 'Assert-False' - 'Assert-True' - 'Assert-Falsy' - 'Assert-Truthy' - 'Assert-All' - 'Assert-Any' - 'Assert-Contain' - 'Assert-NotContain' - 'Assert-Collection' - 'Assert-Equivalent' - 'Assert-Throw' - 'Assert-Equal' - 'Assert-GreaterThan' - 'Assert-GreaterThanOrEqual' - 'Assert-LessThan' - 'Assert-LessThanOrEqual' - 'Assert-NotEqual' - 'Assert-NotNull' - 'Assert-NotSame' - 'Assert-NotType' - 'Assert-Null' - 'Assert-Same' - 'Assert-Type' - 'Assert-Like' - 'Assert-NotLike' - 'Assert-StringEqual' - 'Assert-StringNotEqual' - 'Assert-StringEmpty' - 'Assert-StringNotWhiteSpace' - 'Assert-StringNotEmpty' - 'Assert-Faster' - 'Assert-Slower' - 'Assert-Before' - 'Assert-After' - - 'Get-EquivalencyOption' - - # helpers - 'New-MockObject' - 'New-Fixture' - 'Set-ItResult' - ) - - # # Cmdlets to export from this module - CmdletsToExport = '' - - # Variables to export from this module - VariablesToExport = @() - - # # Aliases to export from this module - AliasesToExport = @( - 'Add-AssertionOperator' - 'Get-AssertionOperator' - - # assertion functions # bool 'Should-BeFalse' 'Should-BeTrue' @@ -155,8 +100,8 @@ 'Should-BeEmptyString' - 'Should-NotBeNullOrWhiteSpaceString' - 'Should-NotBeNullOrEmptyString' + 'Should-NotBeWhiteSpaceString' + 'Should-NotBeEmptyString' 'Should-BeLikeString' 'Should-NotBeLikeString' @@ -165,6 +110,25 @@ 'Should-BeSlowerThan' 'Should-BeBefore' 'Should-BeAfter' + + 'Get-EquivalencyOption' + + # helpers + 'New-MockObject' + 'New-Fixture' + 'Set-ItResult' + ) + + # # Cmdlets to export from this module + CmdletsToExport = '' + + # Variables to export from this module + VariablesToExport = @() + + # # Aliases to export from this module + AliasesToExport = @( + 'Add-AssertionOperator' + 'Get-AssertionOperator' ) diff --git a/src/csharp/Pester/VerbsPatcher.cs b/src/csharp/Pester/VerbsPatcher.cs new file mode 100644 index 000000000..b56473175 --- /dev/null +++ b/src/csharp/Pester/VerbsPatcher.cs @@ -0,0 +1,45 @@ +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Reflection; +using System.Threading.Tasks; + +namespace Pester +{ + /// + /// Modifies that list of recommended Verbs, so we can export Should-* functions directly without + /// showing a warning to the user. Reverts the change after few seconds. + /// + public static class VerbsPatcher + { + // Keep the tasks we started so they finish and are not garbage collected. + // Concurrent bag in case we start this multiple times, and god forbid in parallel. + private static ConcurrentBag s_tasks = new ConcurrentBag(); + + public static void AllowShouldVerb(int powershellVersion) + { + var should = "Should"; + + var fieldName = powershellVersion == 5 ? "validVerbs" : "s_validVerbs"; + var verbsType = typeof(System.Management.Automation.VerbsCommon).Assembly.GetType("System.Management.Automation.Verbs"); + var verbsField = verbsType.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic); + + // private static readonly Dictionary s_validVerbs; + Dictionary validVerbs = (Dictionary)verbsField.GetValue(null); + // Overwrite when we call this multiple times. + validVerbs[should] = true; // The bool does not matter. + + s_tasks.Add(Task.Run(async () => + { + await Task.Delay(5_000); + try + { + if (validVerbs.ContainsKey(should)) + { + validVerbs.Remove(should); + } + } + catch { } + })); + } + } +} diff --git a/src/functions/assert/Boolean/Should-BeFalse.ps1 b/src/functions/assert/Boolean/Should-BeFalse.ps1 index 94a8e4900..af92842db 100644 --- a/src/functions/assert/Boolean/Should-BeFalse.ps1 +++ b/src/functions/assert/Boolean/Should-BeFalse.ps1 @@ -1,4 +1,4 @@ -function Assert-False { +function Should-BeFalse { <# .SYNOPSIS Compares the actual value to a boolean $false. It does not convert input values to boolean, and will fail for any value that is not $false. diff --git a/src/functions/assert/Boolean/Should-BeFalsy.ps1 b/src/functions/assert/Boolean/Should-BeFalsy.ps1 index d937516f0..c7148077f 100644 --- a/src/functions/assert/Boolean/Should-BeFalsy.ps1 +++ b/src/functions/assert/Boolean/Should-BeFalsy.ps1 @@ -1,4 +1,4 @@ -function Assert-Falsy { +function Should-BeFalsy { <# .SYNOPSIS Compares the actual value to a boolean $false or a falsy value: 0, "", $null or @(). It converts the input value to a boolean. diff --git a/src/functions/assert/Boolean/Should-BeTrue.ps1 b/src/functions/assert/Boolean/Should-BeTrue.ps1 index fab550f97..c268d6e90 100644 --- a/src/functions/assert/Boolean/Should-BeTrue.ps1 +++ b/src/functions/assert/Boolean/Should-BeTrue.ps1 @@ -1,4 +1,4 @@ -function Assert-True { +function Should-BeTrue { <# .SYNOPSIS Compares the actual value to a boolean $true. It does not convert input values to boolean, and will fail for any value is not $true. diff --git a/src/functions/assert/Boolean/Should-BeTruthy.ps1 b/src/functions/assert/Boolean/Should-BeTruthy.ps1 index 28538ab7c..323a1bd39 100644 --- a/src/functions/assert/Boolean/Should-BeTruthy.ps1 +++ b/src/functions/assert/Boolean/Should-BeTruthy.ps1 @@ -1,4 +1,4 @@ -function Assert-Truthy { +function Should-BeTruthy { <# .SYNOPSIS Compares the actual value to a boolean $true. It converts input values to boolean, and will fail for any value is not $true, or truthy. diff --git a/src/functions/assert/Collection/Should-All.ps1 b/src/functions/assert/Collection/Should-All.ps1 index 126a7db6a..df9220396 100644 --- a/src/functions/assert/Collection/Should-All.ps1 +++ b/src/functions/assert/Collection/Should-All.ps1 @@ -1,4 +1,4 @@ -function Assert-All { +function Should-All { <# .SYNOPSIS Compares all items in a collection to a filter script. If the filter returns true, or does not throw for all the items in the collection, the assertion passes. diff --git a/src/functions/assert/Collection/Should-Any.ps1 b/src/functions/assert/Collection/Should-Any.ps1 index f546babfd..b2625068d 100644 --- a/src/functions/assert/Collection/Should-Any.ps1 +++ b/src/functions/assert/Collection/Should-Any.ps1 @@ -1,4 +1,4 @@ -function Assert-Any { +function Should-Any { <# .SYNOPSIS Compares all items in a collection to a filter script. If the filter returns true, or does not throw for any of the items in the collection, the assertion passes. diff --git a/src/functions/assert/Collection/Should-BeCollection.ps1 b/src/functions/assert/Collection/Should-BeCollection.ps1 index 93624ec20..33e3461c4 100644 --- a/src/functions/assert/Collection/Should-BeCollection.ps1 +++ b/src/functions/assert/Collection/Should-BeCollection.ps1 @@ -1,4 +1,4 @@ -function Assert-Collection { +function Should-BeCollection { <# .SYNOPSIS Compares collections for equality, by comparing their sizes and each item in them. It does not compare the types of the input collections. diff --git a/src/functions/assert/Collection/Should-ContainCollection.ps1 b/src/functions/assert/Collection/Should-ContainCollection.ps1 index f74b57ebc..84d4f982f 100644 --- a/src/functions/assert/Collection/Should-ContainCollection.ps1 +++ b/src/functions/assert/Collection/Should-ContainCollection.ps1 @@ -1,4 +1,4 @@ -function Assert-Contain { +function Should-ContainCollection { <# .SYNOPSIS Compares collections to see if the expected collection is present in the provided collection. It does not compare the types of the input collections. diff --git a/src/functions/assert/Collection/Should-NotContainCollection.ps1 b/src/functions/assert/Collection/Should-NotContainCollection.ps1 index 57a9e2555..78ab32a30 100644 --- a/src/functions/assert/Collection/Should-NotContainCollection.ps1 +++ b/src/functions/assert/Collection/Should-NotContainCollection.ps1 @@ -1,4 +1,4 @@ -function Assert-NotContain { +function Should-NotContainCollection { <# .SYNOPSIS Compares collections to ensure that the expected collection is not present in the provided collection. It does not compare the types of the input collections. diff --git a/src/functions/assert/Equivalence/Should-BeEquivalent.ps1 b/src/functions/assert/Equivalence/Should-BeEquivalent.ps1 index f8bd218c9..d6c1202ce 100644 --- a/src/functions/assert/Equivalence/Should-BeEquivalent.ps1 +++ b/src/functions/assert/Equivalence/Should-BeEquivalent.ps1 @@ -613,7 +613,7 @@ function Compare-Equivalent { Compare-ObjectEquivalent -Expected $Expected -Actual $Actual -Property $Path -Options $Options } -function Assert-Equivalent { +function Should-BeEquivalent { <# .SYNOPSIS Compares two objects for equivalency, by recursively comparing their properties for equivalency. diff --git a/src/functions/assert/Exception/Should-Throw.ps1 b/src/functions/assert/Exception/Should-Throw.ps1 index a4b564a58..6b0fdaf40 100644 --- a/src/functions/assert/Exception/Should-Throw.ps1 +++ b/src/functions/assert/Exception/Should-Throw.ps1 @@ -1,4 +1,4 @@ -function Assert-Throw { +function Should-Throw { <# .SYNOPSIS Asserts that a script block throws an exception. diff --git a/src/functions/assert/General/Should-Be.ps1 b/src/functions/assert/General/Should-Be.ps1 index 4537aad70..35f7350d3 100644 --- a/src/functions/assert/General/Should-Be.ps1 +++ b/src/functions/assert/General/Should-Be.ps1 @@ -1,4 +1,4 @@ -function Assert-Equal { +function Should-Be { <# .SYNOPSIS Compares the expected value to actual value, to see if they are equal. diff --git a/src/functions/assert/General/Should-BeGreaterThan.ps1 b/src/functions/assert/General/Should-BeGreaterThan.ps1 index cf2728009..3e355025c 100644 --- a/src/functions/assert/General/Should-BeGreaterThan.ps1 +++ b/src/functions/assert/General/Should-BeGreaterThan.ps1 @@ -1,4 +1,4 @@ -function Assert-GreaterThan { +function Should-BeGreaterThan { <# .SYNOPSIS Compares the expected value to actual value, to see if the actual value is greater than the expected value. diff --git a/src/functions/assert/General/Should-BeGreaterThanOrEqual.ps1 b/src/functions/assert/General/Should-BeGreaterThanOrEqual.ps1 index c528c5b5c..118bc17ed 100644 --- a/src/functions/assert/General/Should-BeGreaterThanOrEqual.ps1 +++ b/src/functions/assert/General/Should-BeGreaterThanOrEqual.ps1 @@ -1,4 +1,4 @@ -function Assert-GreaterThanOrEqual { +function Should-BeGreaterThanOrEqual { <# .SYNOPSIS Compares the expected value to actual value, to see if the actual value is greater than or equal to the expected value. diff --git a/src/functions/assert/General/Should-BeLessThan.ps1 b/src/functions/assert/General/Should-BeLessThan.ps1 index 17fc6c926..add3b16b1 100644 --- a/src/functions/assert/General/Should-BeLessThan.ps1 +++ b/src/functions/assert/General/Should-BeLessThan.ps1 @@ -1,4 +1,4 @@ -function Assert-LessThan { +function Should-BeLessThan { <# .SYNOPSIS Compares the expected value to actual value, to see if the actual value is less than the expected value. diff --git a/src/functions/assert/General/Should-BeLessThanOrEqual.ps1 b/src/functions/assert/General/Should-BeLessThanOrEqual.ps1 index 69ed80355..5182f24fb 100644 --- a/src/functions/assert/General/Should-BeLessThanOrEqual.ps1 +++ b/src/functions/assert/General/Should-BeLessThanOrEqual.ps1 @@ -1,4 +1,4 @@ -function Assert-LessThanOrEqual { +function Should-BeLessThanOrEqual { <# .SYNOPSIS Compares the expected value to actual value, to see if the actual value is less than or equal to the expected value. diff --git a/src/functions/assert/General/Should-BeNull.ps1 b/src/functions/assert/General/Should-BeNull.ps1 index 2d4145ca1..c6dd5342e 100644 --- a/src/functions/assert/General/Should-BeNull.ps1 +++ b/src/functions/assert/General/Should-BeNull.ps1 @@ -1,4 +1,4 @@ -function Assert-Null { +function Should-BeNull { <# .SYNOPSIS Asserts that the input is `$null`. diff --git a/src/functions/assert/General/Should-BeSame.ps1 b/src/functions/assert/General/Should-BeSame.ps1 index ee3193f5a..c3cbdd8b0 100644 --- a/src/functions/assert/General/Should-BeSame.ps1 +++ b/src/functions/assert/General/Should-BeSame.ps1 @@ -1,4 +1,4 @@ -function Assert-Same { +function Should-BeSame { <# .SYNOPSIS Compares the expected value to actual value, to see if they are the same instance. diff --git a/src/functions/assert/General/Should-HaveType.ps1 b/src/functions/assert/General/Should-HaveType.ps1 index 1ec6a24a9..097533c04 100644 --- a/src/functions/assert/General/Should-HaveType.ps1 +++ b/src/functions/assert/General/Should-HaveType.ps1 @@ -1,4 +1,4 @@ -function Assert-Type { +function Should-HaveType { <# .SYNOPSIS Asserts that the input is of the expected type. diff --git a/src/functions/assert/General/Should-NotBe.ps1 b/src/functions/assert/General/Should-NotBe.ps1 index 59700808b..386a04995 100644 --- a/src/functions/assert/General/Should-NotBe.ps1 +++ b/src/functions/assert/General/Should-NotBe.ps1 @@ -1,4 +1,4 @@ -function Assert-NotEqual { +function Should-NotBe { <# .SYNOPSIS Compares the expected value to actual value, to see if they are not equal. diff --git a/src/functions/assert/General/Should-NotBeNull.ps1 b/src/functions/assert/General/Should-NotBeNull.ps1 index 8387fca23..3d6cad334 100644 --- a/src/functions/assert/General/Should-NotBeNull.ps1 +++ b/src/functions/assert/General/Should-NotBeNull.ps1 @@ -1,4 +1,4 @@ -function Assert-NotNull { +function Should-NotBeNull { <# .SYNOPSIS Asserts that the input is not `$null`. diff --git a/src/functions/assert/General/Should-NotBeSame.ps1 b/src/functions/assert/General/Should-NotBeSame.ps1 index 056b6d83c..9798fd0d3 100644 --- a/src/functions/assert/General/Should-NotBeSame.ps1 +++ b/src/functions/assert/General/Should-NotBeSame.ps1 @@ -1,4 +1,4 @@ -function Assert-NotSame { +function Should-NotBeSame { <# .SYNOPSIS Compares the expected value to actual value, to see if the actual value is not the same instance as the expected value. diff --git a/src/functions/assert/General/Should-NotHaveType.ps1 b/src/functions/assert/General/Should-NotHaveType.ps1 index 762397371..2a0033496 100644 --- a/src/functions/assert/General/Should-NotHaveType.ps1 +++ b/src/functions/assert/General/Should-NotHaveType.ps1 @@ -1,4 +1,4 @@ -function Assert-NotType { +function Should-NotHaveType { <# .SYNOPSIS Asserts that the input is not of the expected type. diff --git a/src/functions/assert/String/Should-BeEmptyString.ps1 b/src/functions/assert/String/Should-BeEmptyString.ps1 index 3a53dc2d1..b8b712f60 100644 --- a/src/functions/assert/String/Should-BeEmptyString.ps1 +++ b/src/functions/assert/String/Should-BeEmptyString.ps1 @@ -1,4 +1,4 @@ -function Assert-StringEmpty { +function Should-BeEmptyString { <# .SYNOPSIS Ensures that input is an empty string. diff --git a/src/functions/assert/String/Should-BeLikeString.ps1 b/src/functions/assert/String/Should-BeLikeString.ps1 index 0ae136a08..c6a32a3fd 100644 --- a/src/functions/assert/String/Should-BeLikeString.ps1 +++ b/src/functions/assert/String/Should-BeLikeString.ps1 @@ -13,7 +13,7 @@ } } -function Assert-Like { +function Should-BeLikeString { <# .SYNOPSIS Asserts that the actual value is like the expected value. diff --git a/src/functions/assert/String/Should-BeString.ps1 b/src/functions/assert/String/Should-BeString.ps1 index 3471c99b5..1d05bbfbe 100644 --- a/src/functions/assert/String/Should-BeString.ps1 +++ b/src/functions/assert/String/Should-BeString.ps1 @@ -23,7 +23,7 @@ } } -function Assert-StringEqual { +function Should-BeString { <# .SYNOPSIS Asserts that the actual value is equal to the expected value. diff --git a/src/functions/assert/String/Should-NotBeEmptyString.ps1 b/src/functions/assert/String/Should-NotBeEmptyString.ps1 index 3d6352ce2..2c5c3b909 100644 --- a/src/functions/assert/String/Should-NotBeEmptyString.ps1 +++ b/src/functions/assert/String/Should-NotBeEmptyString.ps1 @@ -1,4 +1,4 @@ -function Assert-StringNotEmpty { +function Should-NotBeEmptyString { <# .SYNOPSIS Ensures that the input is a string, and that the input is not $null or empty string. @@ -12,7 +12,7 @@ .EXAMPLE ```powershell $actual = "hello" - $actual | Should-NotBeNullOrEmptyString + $actual | Should-NotBeEmptyString ``` This test will pass. @@ -20,23 +20,23 @@ .EXAMPLE ```powershell $actual = "" - $actual | Should-NotBeNullOrEmptyString + $actual | Should-NotBeEmptyString ``` This test will fail, the input is an empty string. .EXAMPLE ``` - $null | Should-NotBeNullOrEmptyString - $() | Should-NotBeNullOrEmptyString - $false | Should-NotBeNullOrEmptyString - 1 | Should-NotBeNullOrEmptyString + $null | Should-NotBeEmptyString + $() | Should-NotBeEmptyString + $false | Should-NotBeEmptyString + 1 | Should-NotBeEmptyString ``` All the tests above will fail, the input is not a string. .LINK - https://pester.dev/docs/commands/Should-NotBeNullOrEmptyString + https://pester.dev/docs/commands/Should-NotBeEmptyString .LINK https://pester.dev/docs/assertions diff --git a/src/functions/assert/String/Should-NotBeLikeString.ps1 b/src/functions/assert/String/Should-NotBeLikeString.ps1 index d66c11992..f745bcd77 100644 --- a/src/functions/assert/String/Should-NotBeLikeString.ps1 +++ b/src/functions/assert/String/Should-NotBeLikeString.ps1 @@ -21,7 +21,7 @@ function Get-NotLikeDefaultFailureMessage ([String]$Expected, $Actual, [switch]$ "Expected the string '$Actual' to$caseSensitiveMessage not match '$Expected' but it matched it." } -function Assert-NotLike { +function Should-NotBeLikeString { <# .SYNOPSIS Asserts that the actual value is not like the expected value. diff --git a/src/functions/assert/String/Should-NotBeString.ps1 b/src/functions/assert/String/Should-NotBeString.ps1 index 6cc0a2019..25917041c 100644 --- a/src/functions/assert/String/Should-NotBeString.ps1 +++ b/src/functions/assert/String/Should-NotBeString.ps1 @@ -2,7 +2,7 @@ "Expected the strings to be different but they were the same '$Expected'." } -function Assert-StringNotEqual { +function Should-NotBeString { <# .SYNOPSIS Asserts that the actual value is not equal to the expected value. diff --git a/src/functions/assert/String/Should-NotBeWhiteSpaceString.ps1 b/src/functions/assert/String/Should-NotBeWhiteSpaceString.ps1 index c75ee0548..8de038673 100644 --- a/src/functions/assert/String/Should-NotBeWhiteSpaceString.ps1 +++ b/src/functions/assert/String/Should-NotBeWhiteSpaceString.ps1 @@ -1,4 +1,4 @@ -function Assert-StringNotWhiteSpace { +function Should-NotBeWhiteSpaceString { <# .SYNOPSIS Ensures that the input is a string, and that the input is not $null, empty, or whitespace only string. @@ -12,7 +12,7 @@ .EXAMPLE ```powershell $actual = "hello" - $actual | Should-NotBeNullOrWhiteSpaceString + $actual | Should-NotBeWhiteSpaceString ``` This test will pass. @@ -20,24 +20,24 @@ .EXAMPLE ```powershell $actual = " " - $actual | Should-NotBeNullOrWhiteSpaceString + $actual | Should-NotBeWhiteSpaceString ``` This test will fail, the input is a whitespace only string. .EXAMPLE ``` - $null | Should-NotBeNullOrWhiteSpaceString - "" | Should-NotBeNullOrWhiteSpaceString - $() | Should-NotBeNullOrWhiteSpaceString - $false | Should-NotBeNullOrWhiteSpaceString - 1 | Should-NotBeNullOrWhiteSpaceString + $null | Should-NotBeWhiteSpaceString + "" | Should-NotBeWhiteSpaceString + $() | Should-NotBeWhiteSpaceString + $false | Should-NotBeWhiteSpaceString + 1 | Should-NotBeWhiteSpaceString ``` All the tests above will fail, the input is not a string. .LINK - https://pester.dev/docs/commands/Should-NotBeNullOrWhiteSpaceString + https://pester.dev/docs/commands/Should-NotBeWhiteSpaceString .LINK https://pester.dev/docs/assertions diff --git a/src/functions/assert/Time/Should-BeAfter.ps1 b/src/functions/assert/Time/Should-BeAfter.ps1 index 9e456a8da..0d68b1e1d 100644 --- a/src/functions/assert/Time/Should-BeAfter.ps1 +++ b/src/functions/assert/Time/Should-BeAfter.ps1 @@ -1,4 +1,4 @@ -function Assert-After { +function Should-BeAfter { <# .SYNOPSIS Asserts that the provided [datetime] is after the expected [datetime]. diff --git a/src/functions/assert/Time/Should-BeBefore.ps1 b/src/functions/assert/Time/Should-BeBefore.ps1 index 1cdb98bb7..b27ecf3dd 100644 --- a/src/functions/assert/Time/Should-BeBefore.ps1 +++ b/src/functions/assert/Time/Should-BeBefore.ps1 @@ -1,4 +1,4 @@ -function Assert-Before { +function Should-BeBefore { <# .SYNOPSIS Asserts that the provided [datetime] is before the expected [datetime]. diff --git a/src/functions/assert/Time/Should-BeFasterThan.ps1 b/src/functions/assert/Time/Should-BeFasterThan.ps1 index ee3fffb96..c97b4559b 100644 --- a/src/functions/assert/Time/Should-BeFasterThan.ps1 +++ b/src/functions/assert/Time/Should-BeFasterThan.ps1 @@ -1,4 +1,4 @@ -function Assert-Faster { +function Should-BeFasterThan { <# .SYNOPSIS Asserts that the provided [timespan] or [scriptblock] is faster than the expected [timespan]. diff --git a/src/functions/assert/Time/Should-BeSlowerThan.ps1 b/src/functions/assert/Time/Should-BeSlowerThan.ps1 index a20db90c2..fe86b82f2 100644 --- a/src/functions/assert/Time/Should-BeSlowerThan.ps1 +++ b/src/functions/assert/Time/Should-BeSlowerThan.ps1 @@ -1,4 +1,4 @@ -function Assert-Slower { +function Should-BeSlowerThan { <# .SYNOPSIS Asserts that the provided [timespan] is slower than the expected [timespan]. diff --git a/tst/Help.Tests.ps1 b/tst/Help.Tests.ps1 index 7151e12fa..b751b32c2 100644 --- a/tst/Help.Tests.ps1 +++ b/tst/Help.Tests.ps1 @@ -23,8 +23,8 @@ Describe "Testing module help" -Tag 'Help' -ForEach @{ exportedFunctions = $expo $help.Synopsis | Should -Not -Match "^\s*$($_.Name)((\s+\[+?-\w+)|$)" } - # TODO: Missing on new Assert-* assertions - It 'Description is defined' -Skip:($_.Name -match '^Assert-') { + # TODO: Missing on new Should-* assertions + It 'Description is defined' -Skip:($_.Name -match '^Should-') { # Property is missing if undefined $help.description | Should -Not -BeNullOrEmpty } diff --git a/tst/functions/assert/String/Should-NotBeNullOrEmptyString.Tests.ps1 b/tst/functions/assert/String/Should-NotBeNullOrEmptyString.Tests.ps1 index 7dd692ae8..25147290f 100644 --- a/tst/functions/assert/String/Should-NotBeNullOrEmptyString.Tests.ps1 +++ b/tst/functions/assert/String/Should-NotBeNullOrEmptyString.Tests.ps1 @@ -1,20 +1,20 @@ Set-StrictMode -Version Latest -Describe "Should-NotBeNullOrEmptyString" { +Describe "Should-NotBeEmptyString" { It "Does not throw when string has value" -ForEach @( @{ Actual = "1" } @{ Actual = " " } @{ Actual = "`t" } @{ Actual = "`n" } ) { - $Actual | Should-NotBeNullOrEmptyString + $Actual | Should-NotBeEmptyString } It "Throws when string is `$null or empty" -ForEach @( @{ Actual = "" } @{ Actual = $null } ) { - { $Actual | Should-NotBeNullOrEmptyString } | Verify-AssertionFailed + { $Actual | Should-NotBeEmptyString } | Verify-AssertionFailed } It "Throws when value is not string" -ForEach @( @@ -22,24 +22,24 @@ Describe "Should-NotBeNullOrEmptyString" { @{ Actual = @() } @{ Actual = $true } ) { - { $Actual | Should-NotBeNullOrEmptyString } | Verify-AssertionFailed + { $Actual | Should-NotBeEmptyString } | Verify-AssertionFailed } It "Allows actual to be passed from pipeline" { - "abc" | Should-NotBeNullOrEmptyString + "abc" | Should-NotBeEmptyString } It "Allows actual to be passed by position" { - Should-NotBeNullOrEmptyString "abc" + Should-NotBeEmptyString "abc" } It "Fails when empty collection is passed in by pipeline" { - { @() | Should-NotBeNullOrEmptyString } | Verify-AssertionFailed + { @() | Should-NotBeEmptyString } | Verify-AssertionFailed } It "Fails when `$null collection is passed in by pipeline" { - { $null | Should-NotBeNullOrEmptyString } | Verify-AssertionFailed + { $null | Should-NotBeEmptyString } | Verify-AssertionFailed } It "Fails with the expected message" -ForEach @( @@ -49,7 +49,7 @@ Describe "Should-NotBeNullOrEmptyString" { ) { $actual = $Actual $expectedMessage = $ExpectedMessage - $err = { Should-NotBeNullOrEmptyString -Actual $actual -Because $Because } | Verify-AssertionFailed + $err = { Should-NotBeEmptyString -Actual $actual -Because $Because } | Verify-AssertionFailed $err.Exception.Message | Verify-Equal $ExpectedMessage } } diff --git a/tst/functions/assert/String/Should-NotBeNullOrWhiteSpaceString.Tests.ps1 b/tst/functions/assert/String/Should-NotBeNullOrWhiteSpaceString.Tests.ps1 index 0a9dc12e4..6fb5770af 100644 --- a/tst/functions/assert/String/Should-NotBeNullOrWhiteSpaceString.Tests.ps1 +++ b/tst/functions/assert/String/Should-NotBeNullOrWhiteSpaceString.Tests.ps1 @@ -1,8 +1,8 @@ Set-StrictMode -Version Latest -Describe "Should-NotBeNullOrWhiteSpaceString" { +Describe "Should-NotBeWhiteSpaceString" { It "Does not throw when string has value" { - "bde" | Should-NotBeNullOrWhiteSpaceString + "bde" | Should-NotBeWhiteSpaceString } It "Throws when string is emptyish" -ForEach @( @@ -12,7 +12,7 @@ Describe "Should-NotBeNullOrWhiteSpaceString" { @{ Actual = "`n" } @{ Actual = "`r" } ) { - { $Actual | Should-NotBeNullOrWhiteSpaceString } | Verify-AssertionFailed + { $Actual | Should-NotBeWhiteSpaceString } | Verify-AssertionFailed } It "Throws when value is not string" -ForEach @( @@ -21,24 +21,24 @@ Describe "Should-NotBeNullOrWhiteSpaceString" { @{ Actual = $true } @{ Actual = $null } ) { - { $Actual | Should-NotBeNullOrWhiteSpaceString } | Verify-AssertionFailed + { $Actual | Should-NotBeWhiteSpaceString } | Verify-AssertionFailed } It "Allows actual to be passed from pipeline" { - "abc" | Should-NotBeNullOrWhiteSpaceString + "abc" | Should-NotBeWhiteSpaceString } It "Allows actual to be passed by position" { - Should-NotBeNullOrWhiteSpaceString "abc" + Should-NotBeWhiteSpaceString "abc" } It "Fails when empty collection is passed in by pipeline" { - { @() | Should-NotBeNullOrWhiteSpaceString } | Verify-AssertionFailed + { @() | Should-NotBeWhiteSpaceString } | Verify-AssertionFailed } It "Fails when `$null collection is passed in by pipeline" { - { $null | Should-NotBeNullOrWhiteSpaceString } | Verify-AssertionFailed + { $null | Should-NotBeWhiteSpaceString } | Verify-AssertionFailed } It "Fails with the expected message" -ForEach @( @@ -48,7 +48,7 @@ Describe "Should-NotBeNullOrWhiteSpaceString" { ) { $actual = $Actual $expectedMessage = $ExpectedMessage - $err = { Should-NotBeNullOrWhiteSpaceString -Actual $actual -Because $Because } | Verify-AssertionFailed + $err = { Should-NotBeWhiteSpaceString -Actual $actual -Because $Because } | Verify-AssertionFailed $err.Exception.Message | Verify-Equal $ExpectedMessage } } diff --git a/tst/functions/assert/Time/Should-BeSlowerThan.Tests.ps1 b/tst/functions/assert/Time/Should-BeSlowerThan.Tests.ps1 index 1f2179d72..79da1bb79 100644 --- a/tst/functions/assert/Time/Should-BeSlowerThan.Tests.ps1 +++ b/tst/functions/assert/Time/Should-BeSlowerThan.Tests.ps1 @@ -2,7 +2,7 @@ Describe "Should-BeSlowerThan" { It "Does not throw when actual is slower than expected" -ForEach @( - @{ Actual = { Start-Sleep -Milliseconds 10 }; Expected = "1ms" } + @{ Actual = { Start-Sleep -Milliseconds 100 }; Expected = "1ms" } ) { $Actual | Should-BeSlowerThan -Expected $Expected }