From 42526bf5e1c0586f92881e89b0a7471c0e6a1d77 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 2 Aug 2024 18:26:28 +0200 Subject: [PATCH] Add integration tests (#27) --- .../workflows/code-analysis-built-module.yml | 2 +- .github/workflows/code-analysis.yml | 2 +- CHANGELOG.md | 52 +++-- azure-pipelines.yml | 108 +++++++---- source/Private/Convert-ShouldBeFalse.ps1 | 23 ++- .../Private/Convert-ShouldBeGreaterThan.ps1 | 12 +- source/Private/Convert-ShouldBeLessThan.ps1 | 12 +- .../Private/Convert-ShouldBeNullOrEmpty.ps1 | 15 +- source/Private/Convert-ShouldBeOfType.ps1 | 20 +- source/Private/Convert-ShouldBeTrue.ps1 | 23 ++- .../Private/ConvertTo-ActualParameterName.ps1 | 161 +++++++++++++++ source/Private/Get-AstDefinition.ps1 | 7 +- source/Private/Get-PesterCommandParameter.ps1 | 24 ++- source/Public/Convert-PesterSyntax.ps1 | 156 +++++++++++---- source/en-US/PesterConverter.strings.psd1 | 12 +- .../Syntax/v5/ShouldBe.v5.tests.ps1 | 183 ++++++++++++++++++ .../Syntax/v5/ShouldBeExactly.v5.tests.ps1 | 152 +++++++++++++++ .../Syntax/v5/ShouldBeFalse.v5.tests.ps1 | 71 +++++++ .../v5/ShouldBeGreaterOrEqual.v5.tests.ps1 | 140 ++++++++++++++ .../v5/ShouldBeGreaterThan.v5.tests.ps1 | 140 ++++++++++++++ .../Syntax/v5/ShouldBeIn.v5.tests.ps1 | 57 ++++++ .../v5/ShouldBeLessOrEqual.v5.tests.ps1 | 140 ++++++++++++++ .../Syntax/v5/ShouldBeLessThan.v5.tests.ps1 | 140 ++++++++++++++ .../Syntax/v5/ShouldBeLike.v5.tests.ps1 | 138 +++++++++++++ .../v5/ShouldBeLikeExactly.v5.tests.ps1 | 138 +++++++++++++ .../v5/ShouldBeNullOrEmpty.v5.tests.ps1 | 74 +++++++ .../Syntax/v5/ShouldBeOfType.v5.tests.ps1 | 70 +++++++ .../Syntax/v5/ShouldBeTrue.v5.tests.ps1 | 66 +++++++ .../Syntax/v5/ShouldContain.v5.tests.ps1 | 158 +++++++++++++++ .../Syntax/v5/ShouldMatch.v5.tests.ps1 | 143 ++++++++++++++ .../Syntax/v5/ShouldMatchExactly.v5.tests.ps1 | 143 ++++++++++++++ .../Syntax/v5/ShouldNotThrow.v5.tests.ps1 | 41 ++++ .../Syntax/v5/ShouldThrow.v5.tests.ps1 | 61 ++++++ tests/Unit/Private/Convert-ShouldBe.tests.ps1 | 2 +- .../Private/Convert-ShouldBeExactly.tests.ps1 | 2 +- .../Private/Convert-ShouldBeFalse.tests.ps1 | 21 +- .../Convert-ShouldBeGreaterOrEqual.tests.ps1 | 4 +- .../Convert-ShouldBeGreaterThan.tests.ps1 | 34 ++-- .../Convert-ShouldBeLessOrEqual.tests.ps1 | 16 +- .../Convert-ShouldBeLessThan.tests.ps1 | 30 +-- .../Private/Convert-ShouldBeLike.tests.ps1 | 4 +- .../Convert-ShouldBeLikeExactly.tests.ps1 | 4 +- .../Convert-ShouldBeNullOrEmpty.tests.ps1 | 8 +- .../Private/Convert-ShouldBeOfType.tests.ps1 | 24 +-- .../Private/Convert-ShouldBeTrue.tests.ps1 | 6 +- .../Private/Convert-ShouldNotThrow.tests.ps1 | 2 +- .../Private/Convert-ShouldThrow.tests.ps1 | 4 +- .../ConvertTo-ActualParameterName.tests.ps1 | 92 +++++++++ .../Get-PesterCommandParameter.Tests.ps1 | 27 +++ .../Public/Convert-PesterSyntax.tests.ps1 | 165 +++++++++++++++- 50 files changed, 2919 insertions(+), 210 deletions(-) create mode 100644 source/Private/ConvertTo-ActualParameterName.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBe.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeExactly.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeFalse.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeGreaterOrEqual.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeGreaterThan.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeIn.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeLessOrEqual.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeLessThan.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeLike.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeLikeExactly.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeNullOrEmpty.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeOfType.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldBeTrue.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldContain.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldMatch.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldMatchExactly.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldNotThrow.v5.tests.ps1 create mode 100644 tests/Integration/Syntax/v5/ShouldThrow.v5.tests.ps1 create mode 100644 tests/Unit/Private/ConvertTo-ActualParameterName.tests.ps1 diff --git a/.github/workflows/code-analysis-built-module.yml b/.github/workflows/code-analysis-built-module.yml index 3e9d92b..f8c7171 100644 --- a/.github/workflows/code-analysis-built-module.yml +++ b/.github/workflows/code-analysis-built-module.yml @@ -24,7 +24,7 @@ jobs: - name: Install GitVersion shell: pwsh run: | - dotnet tool install --global GitVersion.Tool + dotnet tool install --global GitVersion.Tool --version 5.* - name: Run GitVersion shell: pwsh run: | diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index 3cc722d..9042539 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -24,7 +24,7 @@ jobs: - name: Install GitVersion shell: pwsh run: | - dotnet tool install --global GitVersion.Tool + dotnet tool install --global GitVersion.Tool --version 5.* - name: Run GitVersion shell: pwsh run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 63df71e..5b18764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,26 +9,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Public commands: - `Convert-PesterSyntax` -- Add support for Should operators: - - Be - - BeExactly - - BeFalse - - BeGreaterOrEqual - - BeGreaterThan - - BeIn - - BeLessOrEqual - - BeLessThan - - BeLike - - BeLikeExactly - - BeNullOrEmpty - - BeOfType - - BeTrue - - Contain - - Match - - MatchExactly - - Throw + - Add support for Should operators: + - Be + - BeExactly + - BeFalse + - BeGreaterOrEqual + - BeGreaterThan + - BeIn + - BeLessOrEqual + - BeLessThan + - BeLike + - BeLikeExactly + - BeNullOrEmpty + - BeOfType + - BeTrue + - Contain + - Match + - MatchExactly + - Throw + - Added new parameter `OutputPath` to write the resulting file to + a separate path. +- Add integration tests. ### Fixed - Improve code to resolve ScriptAnalyzer warnings and errors. - Localize all the strings. +- `Convert-PesterSyntax` + - The `Should` operators `BeLike` and `BeLikeExactly` was mistakenly not + calling their respectively conversion function. + - Correctly handle abbreviated named parameters. +- `Should -BeFalse`, `Should -BeTrue` and `Should -BeNullOrEmpty` are now + correctly converted when `Because` is the only positional parameter. +- Negated `Should -Not -BeLessThan` now converts to `Should-BeGreaterThanOrEqual` + to correctly handle scenario when actual value and expected value are the same. +- Negated `Should -Not -BeGreaterThan` now converts to `Should-BeLessThanOrEqual` + to correctly handle scenario when actual value and expected value are the same. +- Fix parameter name in `Convert-ShouldBeOfType` +- Minor change to `Get-AstDefinition` to handle when a file is not correctly + parsed. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ecfa873..3be3408 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -20,7 +20,7 @@ variables: defaultBranch: main Agent.Source.Git.ShallowFetchDepth: 0 -# cSpell: ignore setvariable updatebuildnumber hqrmtest quickconfig viscalyx +# cSpell: ignore setvariable updatebuildnumber hqrmtest quickconfig viscalyx psresourceget stages: - stage: Build jobs: @@ -30,7 +30,7 @@ stages: vmImage: 'windows-latest' steps: - pwsh: | - dotnet tool install --global GitVersion.Tool + dotnet tool install --global GitVersion.Tool --version 5.* $gitVersionObject = dotnet-gitversion | ConvertFrom-Json $gitVersionObject.PSObject.Properties.ForEach{ Write-Host -Object "Setting Task Variable '$($_.Name)' with value '$($_.Value)'." @@ -251,46 +251,70 @@ stages: bash <(curl -s https://codecov.io/bash) -f "./$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml" -F unit displayName: 'Publish Code Coverage to Codecov.io' - # - job: Test_Integration - # displayName: 'Integration' - # strategy: - # matrix: - # WIN2019_PWSH: - # JOB_VMIMAGE: 'windows-2019' - # PWSH: true - # WIN2022_PWSH: - # JOB_VMIMAGE: 'windows-2022' - # PWSH: true - # UBUNTU: - # JOB_VMIMAGE: 'ubuntu-latest' - # PWSH: true - # MACOS: - # JOB_VMIMAGE: 'macos-latest' - # PWSH: true - # pool: - # vmImage: $(JOB_VMIMAGE) - # timeoutInMinutes: 0 - # steps: - # - task: DownloadPipelineArtifact@2 - # displayName: 'Download Build Artifact' - # inputs: - # buildType: 'current' - # artifactName: $(buildArtifactName) - # targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)' - # - task: PowerShell@2 - # name: test - # displayName: 'Run Integration Test' - # inputs: - # filePath: './build.ps1' - # arguments: "-Tasks test -CodeCoverageThreshold 0 -PesterPath 'tests/Integration' -PesterExcludeTag @('BootstrapScript','DSC')" - # pwsh: $(PWSH) - # - task: PublishTestResults@2 - # displayName: 'Publish Test Results' - # condition: succeededOrFailed() - # inputs: - # testResultsFormat: 'NUnit' - # testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml' - # testRunTitle: 'Integration ($(Agent.JobName))' + - job: Test_Integration + displayName: 'Integration' + strategy: + matrix: + WINDOWS: + JOB_VMIMAGE: 'windows-latest' + UBUNTU: + JOB_VMIMAGE: 'ubuntu-latest' + MACOS: + JOB_VMIMAGE: 'macos-latest' + pool: + vmImage: $(JOB_VMIMAGE) + timeoutInMinutes: 0 + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + artifactName: $(buildArtifactName) + targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)' + - pwsh: | + ./build.ps1 -Tasks noop + New-Item -ItemType Directory -Path (Get-PSModulePath -Scope CurrentUser) -Force + name: currentUserModulePath + displayName: 'Validate CurrentUser Module Path' + - pwsh: | + & ([ScriptBlock]::Create((iwr 'bit.ly/psresourceget'))) -Force -Verbose + Get-Module -Name Microsoft.PowerShell.PSResourceGet -ListAvailable + name: bootstrapPSResourceGet + displayName: 'Bootstrap PSResourceGet' + - pwsh: | + Install-PSResource -Name 'Pester' -Version '[5.0,6.0)' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru + Import-Module -Name Pester -MaximumVersion '5.*' -ErrorAction 'Stop' -PassThru + Invoke-Pester -Path '.\tests\Integration\Syntax\v5' -Output Detailed + name: validatePesterSyntax_v5 + displayName: 'Validate Pester 5 Syntax' + - pwsh: | + ./build.ps1 -Tasks noop + Import-Module -Name PesterConverter -PassThru + New-Item -ItemType Directory -Path './ConversionTest/v6' -Force + Convert-PesterSyntax -Path (Get-ChildItem -Path './tests/Integration/Syntax/v5') -OutputPath './ConversionTest/v6' -Force -Verbose + name: convert_v5_to_v6 + displayName: 'Convert v5 syntax to v6' + - task: PublishPipelineArtifact@1 + displayName: 'Publish Converted v6 Artifact' + inputs: + targetPath: './ConversionTest/v6' + artifact: 'ConvertedTests_v6_$(System.JobName)_Attempt_$(System.JobAttempt)' + publishLocation: 'pipeline' + parallel: true + - pwsh: | + Install-PSResource -Name 'Pester' -Prerelease -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru + Import-Module -Name Pester -MaximumVersion '6.*' -ErrorAction 'Stop' -PassThru + Invoke-Pester -Path './ConversionTest/v6' -Output Detailed + name: validatePesterSyntax_v6 + displayName: 'Validate Pester 6 Syntax' + ## Currently there are no test result to upload since we are not using the normal test pipeline. + # - task: PublishTestResults@2 + # displayName: 'Publish Test Results' + # condition: succeededOrFailed() + # inputs: + # testResultsFormat: 'NUnit' + # testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml' + # testRunTitle: 'Integration ($(Agent.JobName))' - stage: Deploy dependsOn: Test diff --git a/source/Private/Convert-ShouldBeFalse.ps1 b/source/Private/Convert-ShouldBeFalse.ps1 index 55f07f7..811258c 100644 --- a/source/Private/Convert-ShouldBeFalse.ps1 +++ b/source/Private/Convert-ShouldBeFalse.ps1 @@ -119,19 +119,32 @@ function Convert-ShouldBeFalse If a previous positional parameter is missing then the ones behind it cannot be set to positional. #> - if ($commandParameters.ActualValue) + if ($commandParameters.Because) { - $commandParameters.ActualValue.Positional = $true + $commandParameters.Because.Positional = $true - if ($commandParameters.Because) + if ($commandParameters.ActualValue) { - $commandParameters.Because.Positional = $true + $commandParameters.ActualValue.Positional = $true } } } $newExtentText += $commandParameters.ActualValue.Positional ? (' {0}' -f $commandParameters.ActualValue.ExtentText) : '' - $newExtentText += $commandParameters.Because.Positional ? (' {0}' -f $commandParameters.Because.ExtentText) : '' + + if ($commandParameters.Because -and $commandParameters.Because.Positional) + { + # Only add second positional if the first positional was present. + if ($commandParameters.ActualValue.Positional) + { + $newExtentText += ' {0}' -f $commandParameters.Because.ExtentText + } + else + { + # First positional parameter was not present, so set the second to named parameter. + $commandParameters.Because.Positional = $false + } + } # Holds the new parameter names so they can be added in alphabetical order. $parameterNames = @() diff --git a/source/Private/Convert-ShouldBeGreaterThan.ps1 b/source/Private/Convert-ShouldBeGreaterThan.ps1 index 2cdfb05..6dc117f 100644 --- a/source/Private/Convert-ShouldBeGreaterThan.ps1 +++ b/source/Private/Convert-ShouldBeGreaterThan.ps1 @@ -36,11 +36,19 @@ Pester 6 Syntax: Should-BeGreaterThan [[-Actual] ] [-Expected] [-Because ] - Should-BeLessThan [[-Actual] ] [-Expected] [-Because ] + Should-BeLessThanOrEqual [[-Actual] ] [-Expected] [-Because ] Positional parameters: Position 1: Expected Position 2: Actual + + Conversion notes: + If the command is negated, the `Should-BeLessThanOrEqual` command is used. + Assume the actual value is 2 and the expected value should not be greater + than 2, then we need to use the `Should-BeLessThanOrEqual` command for + the logic to be the same: + Pester 5: 2 | Should -Not -BeGreaterThan 2 + Pester 6: 2 | Should-BeLessThanOrEqual 2 #> function Convert-ShouldBeGreaterThan { @@ -88,7 +96,7 @@ function Convert-ShouldBeGreaterThan # Add the correct Pester command based on negation if ($isNegated) { - $newExtentText = 'Should-BeLessThan' + $newExtentText = 'Should-BeLessThanOrEqual' } else { diff --git a/source/Private/Convert-ShouldBeLessThan.ps1 b/source/Private/Convert-ShouldBeLessThan.ps1 index 88c3012..147708c 100644 --- a/source/Private/Convert-ShouldBeLessThan.ps1 +++ b/source/Private/Convert-ShouldBeLessThan.ps1 @@ -36,11 +36,19 @@ Pester 6 Syntax: Should-BeLessThan [[-Actual] ] [-Expected] [-Because ] - Should-BeGreaterThan [[-Actual] ] [-Expected] [-Because ] + Should-BeGreaterThanOrEqual [[-Actual] ] [-Expected] [-Because ] Positional parameters: Position 1: Expected Position 2: Actual + + Conversion notes: + If the command is negated, the `Should-BeGreaterThanOrEqual` command is + used. Assume the actual value is 2 and the expected value should not be + less than 2, then we need to use the `Should-BeLessThanOrEqual` command + for the logic to be the same: + Pester 5: 2 | Should -Not -BeLessThan 2 + Pester 6: 2 | Should-BeGreaterThanOrEqual 2 #> function Convert-ShouldBeLessThan { @@ -88,7 +96,7 @@ function Convert-ShouldBeLessThan # Add the correct Pester command based on negation if ($isNegated) { - $newExtentText = 'Should-BeGreaterThan' + $newExtentText = 'Should-BeGreaterThanOrEqual' } else { diff --git a/source/Private/Convert-ShouldBeNullOrEmpty.ps1 b/source/Private/Convert-ShouldBeNullOrEmpty.ps1 index 89ab5e2..51a3a68 100644 --- a/source/Private/Convert-ShouldBeNullOrEmpty.ps1 +++ b/source/Private/Convert-ShouldBeNullOrEmpty.ps1 @@ -139,7 +139,20 @@ function Convert-ShouldBeNullOrEmpty } $newExtentText += $commandParameters.ActualValue.Positional ? (' {0}' -f $commandParameters.ActualValue.ExtentText) : '' - $newExtentText += $commandParameters.Because.Positional ? (' {0}' -f $commandParameters.Because.ExtentText) : '' + + if ($commandParameters.Because -and $commandParameters.Because.Positional) + { + # Only add second positional if the first positional was present. + if ($commandParameters.ActualValue.Positional) + { + $newExtentText += ' {0}' -f $commandParameters.Because.ExtentText + } + else + { + # First positional parameter was not present, so set the second to named parameter. + $commandParameters.Because.Positional = $false + } + } # Holds the new parameter names so they can be added in alphabetical order. $parameterNames = @() diff --git a/source/Private/Convert-ShouldBeOfType.ps1 b/source/Private/Convert-ShouldBeOfType.ps1 index e152236..1a1ce5a 100644 --- a/source/Private/Convert-ShouldBeOfType.ps1 +++ b/source/Private/Convert-ShouldBeOfType.ps1 @@ -30,7 +30,7 @@ Should -BeOfType [[-ActualValue] ] [[-ExpectedType] ] [[-Because] ] [-Not] Positional parameters: - Position 1: ExpectedValue + Position 1: ExpectedType Position 2: Because Pester 6 Syntax: @@ -117,7 +117,7 @@ function Convert-ShouldBeOfType 'Not' ) PositionalParameter = @( - 'ExpectedValue' + 'ExpectedType' 'Because' ) NamedParameter = @( @@ -147,9 +147,9 @@ function Convert-ShouldBeOfType If a previous positional parameter is missing then the ones behind it cannot be set to positional. #> - if ($commandParameters.ExpectedValue) + if ($commandParameters.ExpectedType) { - $commandParameters.ExpectedValue.Positional = $true + $commandParameters.ExpectedType.Positional = $true if ($commandParameters.ActualValue) { @@ -159,11 +159,11 @@ function Convert-ShouldBeOfType } # '[System.String]' -match '^\[.+\]$' - if ($commandParameters.ExpectedValue.Positional) + if ($commandParameters.ExpectedType.Positional) { # Add the expected value in parenthesis only if the extent text is a type defined in square brackets. - $extentTextFormat = $commandParameters.ExpectedValue.ExtentText -match '^\[.+\]$' ? ' ({0})' : ' {0}' - $newExtentText += $extentTextFormat -f $commandParameters.ExpectedValue.ExtentText + $extentTextFormat = $commandParameters.ExpectedType.ExtentText -match '^\[.+\]$' ? ' ({0})' : ' {0}' + $newExtentText += $extentTextFormat -f $commandParameters.ExpectedType.ExtentText } $newExtentText += $commandParameters.ActualValue.Positional ? (' {0}' -f $commandParameters.ActualValue.ExtentText) : '' @@ -189,10 +189,10 @@ function Convert-ShouldBeOfType break } - 'ExpectedValue' + 'ExpectedType' { $parameterNames += @{ - Expected = 'ExpectedValue' + Expected = 'ExpectedType' } break @@ -215,7 +215,7 @@ function Convert-ShouldBeOfType $originalParameterName = $parameterNames.$currentParameter # Add the expected value in parenthesis only if the extent text is a type defined in square brackets. - $extentTextFormat = $originalParameterName -eq 'ExpectedValue' -and $commandParameters.$originalParameterName.ExtentText -match '^\[.+\]$' ? '({1})' : '{1}' + $extentTextFormat = $originalParameterName -eq 'ExpectedType' -and $commandParameters.$originalParameterName.ExtentText -match '^\[.+\]$' ? '({1})' : '{1}' $newExtentText += " -{0} $extentTextFormat" -f $currentParameter, $commandParameters.$originalParameterName.ExtentText } diff --git a/source/Private/Convert-ShouldBeTrue.ps1 b/source/Private/Convert-ShouldBeTrue.ps1 index a3f2a98..fef0f90 100644 --- a/source/Private/Convert-ShouldBeTrue.ps1 +++ b/source/Private/Convert-ShouldBeTrue.ps1 @@ -122,19 +122,32 @@ function Convert-ShouldBeTrue If a previous positional parameter is missing then the ones behind it cannot be set to positional. #> - if ($commandParameters.ActualValue) + if ($commandParameters.Because) { - $commandParameters.ActualValue.Positional = $true + $commandParameters.Because.Positional = $true - if ($commandParameters.Because) + if ($commandParameters.ActualValue) { - $commandParameters.Because.Positional = $true + $commandParameters.ActualValue.Positional = $true } } } $newExtentText += $commandParameters.ActualValue.Positional ? (' {0}' -f $commandParameters.ActualValue.ExtentText) : '' - $newExtentText += $commandParameters.Because.Positional ? (' {0}' -f $commandParameters.Because.ExtentText) : '' + + if ($commandParameters.Because -and $commandParameters.Because.Positional) + { + # Only add second positional if the first positional was present. + if ($commandParameters.ActualValue.Positional) + { + $newExtentText += ' {0}' -f $commandParameters.Because.ExtentText + } + else + { + # First positional parameter was not present, so set the second to named parameter. + $commandParameters.Because.Positional = $false + } + } # Holds the new parameter names so they can be added in alphabetical order. $parameterNames = @() diff --git a/source/Private/ConvertTo-ActualParameterName.ps1 b/source/Private/ConvertTo-ActualParameterName.ps1 new file mode 100644 index 0000000..b57ac49 --- /dev/null +++ b/source/Private/ConvertTo-ActualParameterName.ps1 @@ -0,0 +1,161 @@ +<# + .SYNOPSIS + Converts a unambiguous abbreviated named parameter to its actual parameter + name. + + .DESCRIPTION + The ConvertTo-ActualParameterName function returns the actual parameter + name of a unambiguous abbreviated named parameter. + + .PARAMETER CommandName + Specifies the name of the command. Must be one supported. + + .PARAMETER NamedParameter + Specifies the unambiguous abbreviated named parameter to convert. + + .OUTPUTS + System.String + + Holds the converted parameter name. + + .EXAMPLE + ConvertTo-ActualParameterName -CommandName 'Should' -NamedParameter 'Actual' + + Returns the correct parameter name `ActualValue`. +#> +function ConvertTo-ActualParameterName +{ + [CmdletBinding()] + [OutputType([System.String])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateSet('Should')] + [System.String] + $CommandName, + + [Parameter(Mandatory = $true)] + [System.String] + $NamedParameter + ) + + switch ($CommandName) + { + # Should in Pester 5. + 'Should' + { + $parametersName = @( + # Parameters names. + 'ActualValue' + 'Alias' + 'Be' + 'Because' + 'BeExactly' + 'BeFalse' + 'BeGreaterOrEqual' + 'BeGreaterThan' + 'BeIn' + 'BeLessOrEqual' + 'BeLessThan' + 'BeLike' + 'BeLikeExactly' + 'BeNullOrEmpty' + 'BeOfType' + 'BeTrue' + 'CallerSessionState' + 'CommandName' + 'Contain' + 'Debug' + 'DefaultValue' + 'ErrorAction' + 'ErrorId' + 'ErrorVariable' + 'Exactly' + 'ExceptionType' + 'ExclusiveFilter' + 'Exist' + 'ExpectedContent' + 'ExpectedMessage' + 'ExpectedType' + 'ExpectedValue' + 'FileContentMatch' + 'FileContentMatchExactly' + 'FileContentMatchMultiline' + 'FileContentMatchMultilineExactly' + 'HasArgumentCompleter' + 'HaveCount' + 'HaveParameter' + 'InformationAction' + 'InformationVariable' + 'InParameterSet' + 'Invoke' + 'InvokeVerifiable' + 'Mandatory' + 'Match' + 'MatchExactly' + 'ModuleName' + 'Not' + 'OutBuffer' + 'OutVariable' + 'ParameterFilter' + 'ParameterName' + 'PassThru' + 'PipelineVariable' + 'ProgressAction' + 'RegularExpression' + 'Scope' + 'Throw' + 'Times' + 'Type' + 'Verbose' + 'WarningAction' + 'WarningVariable' + + # Alias parameter names. + 'EQ' + 'CEQ' + 'GT' + 'LE' + 'LT' + 'GE' + 'HaveType' + 'CMATCH' + ) + } + } + + # Try to match exact name. + $result = $parametersName -match "^$NamedParameter$" + + if (-not $result) + { + # Try to match abbreviated name. + $result = $parametersName -match "^$NamedParameter" + + if ($result.Count -gt 1) + { + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + ($script:localizedData.AmbiguousNamedParameter -f $NamedParameter, $CommandName), + 'CTAPN0001', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidOperation, + $NamedParameter + ) + ) + } + } + + if (-not $result) + { + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + ($script:localizedData.UnknownNamedParameter -f $NamedParameter, $CommandName), + 'CTAPN0002', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidOperation, + $NamedParameter + ) + ) + } + + return $result +} diff --git a/source/Private/Get-AstDefinition.ps1 b/source/Private/Get-AstDefinition.ps1 index e7d11e6..a2471b9 100644 --- a/source/Private/Get-AstDefinition.ps1 +++ b/source/Private/Get-AstDefinition.ps1 @@ -47,7 +47,7 @@ function Get-AstDefinition { $tokens, $parseErrors = $null - [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref] $tokens, [ref] $parseErrors) + $ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref] $tokens, [ref] $parseErrors) if ($parseErrors) { @@ -60,6 +60,11 @@ function Get-AstDefinition ) ) } + + if ($ast) + { + $ast + } } } } diff --git a/source/Private/Get-PesterCommandParameter.ps1 b/source/Private/Get-PesterCommandParameter.ps1 index cdc182a..ac1b9df 100644 --- a/source/Private/Get-PesterCommandParameter.ps1 +++ b/source/Private/Get-PesterCommandParameter.ps1 @@ -84,9 +84,10 @@ function Get-PesterCommandParameter #> $commandElement = $commandElement | Where-Object -FilterScript { + # Calls ConvertTo-ActualParameterName to handle abbreviated parameter names. -not ( $_ -is [System.Management.Automation.Language.CommandParameterAst] ` - -and $_.ParameterName -in $IgnoreParameter + -and (ConvertTo-ActualParameterName -NamedParameter $_.ParameterName -CommandName $CommandName) -in $IgnoreParameter ) } @@ -103,7 +104,18 @@ function Get-PesterCommandParameter - ExpectedValue - Because #> - $parameterElements = $commandElement.Where({ $_ -is [System.Management.Automation.Language.CommandParameterAst] -and ($_.ParameterName -in $PositionalParameter -or $_.ParameterName -in $NamedParameter) }) + $parameterElements = $commandElement.Where({ + $result = $false + + if ($_ -is [System.Management.Automation.Language.CommandParameterAst]) + { + $actualParameterName = ConvertTo-ActualParameterName -NamedParameter $_.ParameterName -CommandName $CommandName + + $result = $actualParameterName -in $PositionalParameter -or $actualParameterName -in $NamedParameter + } + + $result + }) $filterCommandElements = @() @@ -114,7 +126,13 @@ function Get-PesterCommandParameter # Above returned -1 if parameter name was not found. if ($parameterIndex -ne -1) { - $parameterName = $commandElement[$parameterIndex].ParameterName + $convertToActualParameterNameParameters = @{ + CommandName = $CommandName + NamedParameter = $commandElement[$parameterIndex].ParameterName + } + + # Handle abbreviated parameter names. + $parameterName = ConvertTo-ActualParameterName @convertToActualParameterNameParameters $positionalParameterHashtable.$parameterName = @{ Position = 0 diff --git a/source/Public/Convert-PesterSyntax.ps1 b/source/Public/Convert-PesterSyntax.ps1 index 167c17b..da2ea38 100644 --- a/source/Public/Convert-PesterSyntax.ps1 +++ b/source/Public/Convert-PesterSyntax.ps1 @@ -30,6 +30,10 @@ passed in, the script of all the files will be returned as an array. If PassThru is specified, no file will not be modified. + .PARAMETER OutputPath + Specifies the path to save the converted file(s). If this parameter is + not specified, the original file(s) will be overwritten. + .EXAMPLE Convert-PesterSyntax -Path "C:\Scripts\Test.ps1" -Pester6 @@ -39,9 +43,14 @@ Get-ChildItem -Path "C:\Scripts" -Recurse -Filter "*.ps1" | Convert-PesterSyntax -Pester6 Converts the syntax of all PowerShell files in the C:\Scripts directory and - its subdirectories to the default (newest) Pester syntax. -#> + its subdirectories to Pester 6 syntax. + + .EXAMPLE + Convert-PesterSyntax -Path (Get-ChildItem -Path "C:\Scripts" -Recurse -Filter "*.ps1") -Pester6 + Converts the syntax of all PowerShell files in the C:\Scripts directory and + its subdirectories to Pester 6 syntax. +#> function Convert-PesterSyntax { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidMultipleTypeAttributes', '', Justification = 'We want to pass in both strings and FileInfo objects to parameter Path.')] @@ -71,7 +80,12 @@ function Convert-PesterSyntax [Parameter()] [System.Management.Automation.SwitchParameter] - $PassThru + $PassThru, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $OutputPath ) begin @@ -89,10 +103,46 @@ function Convert-PesterSyntax Assert-BoundParameter @assertBoundParameterParameters + $assertBoundParameterParameters = @{ + BoundParameterList = $PSBoundParameters + MutuallyExclusiveList1 = @('PassThru') + MutuallyExclusiveList2 = @('OutputPath') + } + + Assert-BoundParameter @assertBoundParameterParameters + + if ($OutputPath) + { + if (-not (Test-Path -Path $OutputPath)) + { + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + $script:localizedData.Convert_PesterSyntax_OutputPathDoesNotExist -f $OutputPath, + 'CPS0002', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidArgument, + $OutputPath + ) + ) + } + + if ((Test-Path -Path $OutputPath) -and (Get-Item -Path $OutputPath).PSIsContainer -eq $false) + { + $PSCmdlet.ThrowTerminatingError( + [System.Management.Automation.ErrorRecord]::new( + $script:localizedData.Convert_PesterSyntax_OutputPathIsNotDirectory -f $OutputPath, + 'CPS0003', # cSpell: disable-line + [System.Management.Automation.ErrorCategory]::InvalidArgument, + $OutputPath + ) + ) + } + } + $convertParameters = @{} + $PSBoundParameters $convertParameters.Remove('Path') $convertParameters.Remove('Force') $convertParameters.Remove('PassThru') + $convertParameters.Remove('OutputPath') if ($PSCmdlet.ParameterSetName -eq 'Pester6' -and -not $Pester6.IsPresent) { @@ -216,13 +266,6 @@ function Convert-PesterSyntax break } - 'BeTrue' - { - $newExtentText = Convert-ShouldBeTrue -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' - - break - } - 'BeFalse' { $newExtentText = Convert-ShouldBeFalse -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' @@ -230,99 +273,121 @@ function Convert-PesterSyntax break } - 'BeNullOrEmpty' + 'BeGreaterOrEqual' { - $newExtentText = Convert-ShouldBeNullOrEmpty -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeGreaterOrEqual -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeOfType' + 'BeGreaterThan' { - $newExtentText = Convert-ShouldBeOfType -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeGreaterThan -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'Throw' + 'BeIn' { - $isNegated = Test-PesterCommandNegated -CommandAst $commandAst + $newExtentText = Convert-ShouldBeIn -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' - if ($isNegated) + if ((Test-IsPipelinePart -CommandAst $commandAst -ErrorAction 'Stop')) { - $newExtentText = Convert-ShouldNotThrow -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' - # Change start and end offsets to replace the entire commandAst.Parent.Extent.Text. $startOffset = $commandAst.Parent.Extent.StartOffset $endOffset = $commandAst.Parent.Extent.EndOffset } - else - { - $newExtentText = Convert-ShouldThrow -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' - } break } - 'Match' + 'BeLessOrEqual' { - $newExtentText = Convert-ShouldMatch -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeLessOrEqual -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'MatchExactly' + 'BeLessThan' { - $newExtentText = Convert-ShouldMatchExactly -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeLessThan -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'Contain' + 'BeLike' { - $newExtentText = Convert-ShouldContain -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeLike -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeGreaterThan' + 'BeLikeExactly' { - $newExtentText = Convert-ShouldBeGreaterThan -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeLikeExactly -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeLessThan' + + 'BeNullOrEmpty' { - $newExtentText = Convert-ShouldBeLessThan -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeNullOrEmpty -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeGreaterOrEqual' + 'BeOfType' { - $newExtentText = Convert-ShouldBeGreaterOrEqual -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeOfType -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeLessOrEqual' + 'BeTrue' { - $newExtentText = Convert-ShouldBeLessOrEqual -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldBeTrue -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' break } - 'BeIn' + 'Contain' { - $newExtentText = Convert-ShouldBeIn -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + $newExtentText = Convert-ShouldContain -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' - if ((Test-IsPipelinePart -CommandAst $commandAst -ErrorAction 'Stop')) + break + } + + 'Match' + { + $newExtentText = Convert-ShouldMatch -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + + break + } + + 'MatchExactly' + { + $newExtentText = Convert-ShouldMatchExactly -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + + break + } + + 'Throw' + { + $isNegated = Test-PesterCommandNegated -CommandAst $commandAst + + if ($isNegated) { + $newExtentText = Convert-ShouldNotThrow -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + # Change start and end offsets to replace the entire commandAst.Parent.Extent.Text. $startOffset = $commandAst.Parent.Extent.StartOffset $endOffset = $commandAst.Parent.Extent.EndOffset } + else + { + $newExtentText = Convert-ShouldThrow -CommandAst $commandAst @convertParameters -ErrorAction 'Stop' + } break } @@ -360,7 +425,16 @@ function Convert-PesterSyntax } else { - Set-Content -Path $filePath -Value $convertedScriptText -NoNewLine -ErrorAction 'Stop' + if ($OutputPath) + { + $newFilePath = Join-Path -Path $OutputPath -ChildPath (Split-Path -Path $filePath -Leaf) + + Set-Content -Path $newFilePath -Value $convertedScriptText -NoNewLine -ErrorAction 'Stop' + } + else + { + Set-Content -Path $filePath -Value $convertedScriptText -NoNewLine -ErrorAction 'Stop' + } } } } diff --git a/source/en-US/PesterConverter.strings.psd1 b/source/en-US/PesterConverter.strings.psd1 index dad609b..fbe8148 100644 --- a/source/en-US/PesterConverter.strings.psd1 +++ b/source/en-US/PesterConverter.strings.psd1 @@ -31,19 +31,25 @@ ConvertFrom-StringData @' Convert_PesterSyntax_Warning_UnsupportedCommandOperator = Unsupported command operator '{0}' in extent: `{1}` Convert_PesterSyntax_MissingSupportedCommandOperator = Did not found any of the supported command operators in extent: `{0}` Convert_PesterSyntax_NoShouldCommand = "No 'Should' command found in '{0}'. + Convert_PesterSyntax_OutputPathDoesNotExist = The output path '{0}' does not exist. Please specify an existing path. + Convert_PesterSyntax_OutputPathIsNotDirectory = The output path '{0}' is not a directory. Please specify a directory path. - # Common for all Convert-Should* functions + ## Common for all Convert-Should* functions Convert_Should_Debug_ParsingCommandAst = Parsing the command AST: `{0}` Convert_Should_Debug_ConvertingFromTo = Converting from Pester v{0} to Pester v{1} syntax. Convert_Should_Debug_ConvertedCommand = Converted the command `{0}` to `{1}`. - # Get-PesterCommandParameter + ## Get-PesterCommandParameter Get_PesterCommandParameter_Debug_RetrievingParameters = Retrieving the parameters of the extent: {0} Get_PesterCommandParameter_Debug_RetrievingCommandName = Retrieving parameters for the command name: {0} Get_PesterCommandParameter_Debug_IgnoreParameters = Ignoring (filtering out) the parameters: {0} Get_PesterCommandParameter_Debug_NamedParameters = Parsing named parameters: {0} Get_PesterCommandParameter_Debug_PositionalParameters = Parsing positional parameters: {0} - # Get-CommandAst + ## Get-CommandAst Get_CommandAst_Debug_RetrievingCommandAsts = Retrieving AST's for command '{0}'. + + ## ConvertTo-ActualParameterName + AmbiguousNamedParameter = The named parameter '{0}' is ambiguous for command '{1}'. Please specify a unique named parameter. + UnknownNamedParameter = The named parameter '{0}' is unknown for command '{1}'. Please specify a valid named parameter. '@ diff --git a/tests/Integration/Syntax/v5/ShouldBe.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBe.v5.tests.ps1 new file mode 100644 index 0000000..259724b --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBe.v5.tests.ps1 @@ -0,0 +1,183 @@ +Describe 'Should -Be' { + Context 'When the tests are affirming' { + It 'Should convert `Should -Be 1` correctly' { + 1 | Should -Be 1 + } + + It 'Should convert `Should -Be "AnyString"` correctly' { + 'AnyString' | Should -Be 'AnyString' + } + + It 'Should convert `Should -Be ''AnyString''` correctly' { + 'AnyString' | Should -Be 'AnyString' + } + + It 'Should convert `Should -Be $true` correctly' { + $true | Should -Be $true + } + + It 'Should convert `Should -Be $anyValue` correctly' { + $anyValue = 1 + + 1 | Should -Be $anyValue + } + + It 'Should convert `Should -ActualValue $true -Be $true` correctly' { + Should -ActualValue $true -Be $true + } + + It 'Should convert `Should -Be $true -ActualValue $true` correctly' { + Should -Be $true -ActualValue $true + } + + It 'Should convert `Should -ActualValue $true -Be -ExpectedValue $true` correctly' { + Should -ActualValue $true -Be -ExpectedValue $true + } + + It 'Should convert `Should -Be -ActualValue $true -ExpectedValue $true` correctly' { + Should -Be -ActualValue $true -ExpectedValue $true + } + + It 'Should convert `Should -Be -ExpectedValue $false -ActualValue $false` correctly' { + Should -Be -ExpectedValue $false -ActualValue $false + } + + It 'Should convert `Should -ExpectedValue $false -Be -ActualValue $false` correctly' { + Should -ExpectedValue $false -Be -ActualValue $false + } + + It 'Should convert `Should -ExpectedValue $true -ActualValue $true -Be` correctly' { + Should -ExpectedValue $true -ActualValue $true -Be + } + + It 'Should convert `Should -Not:$false -Be $false` correctly' { + $false | Should -Not:$false -Be $false + } + + It 'Should convert `Should -Be (Get-Something)` correctly' { + function Get-Something + { + return 'AnyString' + } + + 'AnyString' | Should -Be (Get-Something) + } + + It 'Should convert `Should -Be $false -Because ''mock should test correct value'' $false` correctly' { + Should -Be $false -Because 'mock should test correct value' $false + } + + It 'Should convert `Should -Be ''ExpectedString'' ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -Be 'ExpectedString' 'mock should test correct value' 'ExpectedString' + } + + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' -Be ''mock should test correct value'' ''ExpectedString''` correctly' { + # Should 'ExpectedString' -Be 'mock should test correct value' 'ExpectedString' + # } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' ''mock should test correct value'' -Be ''ExpectedString''` correctly' { + # Should 'ExpectedString' 'mock should test correct value' -Be 'ExpectedString' + # } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' ''mock should test correct value'' ''ExpectedString'' -Be` correctly' { + # Should 'ExpectedString' 'mock should test correct value' 'ActualString' -Be + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -Be 1` correctly' { + 2 | Should -Not -Be 1 + } + + It 'Should convert `Should -Be 1 -Not` correctly' { + 2 | Should -Be 1 -Not + } + + It 'Should convert `Should -Not -Be "AnyString"` correctly' { + 'OtherString' | Should -Not -Be 'AnyString' + } + + It 'Should convert `Should -Not -Be ''AnyString''` correctly' { + 'OtherString' | Should -Not -Be 'AnyString' + } + + It 'Should convert `Should -Not -Be $true` correctly' { + $false | Should -Not -Be $true + } + + It 'Should convert `Should -Not -Be $anyValue` correctly' { + $anyValue = 2 + + 1 | Should -Not -Be $anyValue + } + + It 'Should convert `Should -Be $true -Not` correctly' { + $false | Should -Be $true -Not + } + + It 'Should convert `Should -Not:$true -Be $true` correctly' { + $false | Should -Not:$true -Be $true + } + + It 'Should convert `Should -Not -ActualValue $true -Be $false` correctly' { + Should -Not -ActualValue $true -Be $false + } + + It 'Should convert `Should -ActualValue $true -Not -Be $false` correctly' { + Should -ActualValue $true -Not -Be $false + } + + It 'Should convert `Should -ActualValue $true -Be $false -Not` correctly' { + Should -ActualValue $true -Be $false -Not + } + + It 'Should convert `Should -Be $false -ActualValue $true -Not` correctly' { + Should -Be $false -ActualValue $true -Not + } + + It 'Should convert `Should -Be $false -Not -ActualValue $true` correctly' { + Should -Be $false -Not -ActualValue $true + } + + It 'Should convert `Should -Not -Be $false -ActualValue $true` correctly' { + Should -Not -Be $false -ActualValue $true + } + + It 'Should convert `Should -ActualValue $true -Be -Not -ExpectedValue $false` correctly' { + Should -ActualValue $true -Be -Not -ExpectedValue $false + } + + It 'Should convert `Should -ActualValue $true -Not -Be -ExpectedValue $false` correctly' { + Should -ActualValue $true -Not -Be -ExpectedValue $false + } + + It 'Should convert `Should -ActualValue $true -Be -ExpectedValue $false -Not` correctly' { + Should -ActualValue $true -Be -ExpectedValue $false -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -EQ $true -ActualValue $true` correctly' { + Should -EQ $true -ActualValue $true + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeExactly.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeExactly.v5.tests.ps1 new file mode 100644 index 0000000..75d5a02 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeExactly.v5.tests.ps1 @@ -0,0 +1,152 @@ +Describe 'Should -BeExactly' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeExactly ''Test''` correctly' { + 'Test' | Should -BeExactly 'Test' + } + + It 'Should convert `Should -BeExactly "ExpectedString"` correctly' { + 'ExpectedString' | Should -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -BeExactly ''ExpectedString''` correctly' { + 'ExpectedString' | Should -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -BeExactly $anyValue` correctly' { + $anyValue = 'ExpectedString' + + 'ExpectedString' | Should -BeExactly $anyValue + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -BeExactly ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -BeExactly 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -BeExactly -ExpectedValue ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -BeExactly -ExpectedValue 'ExpectedString' + } + + It 'Should convert `Should -BeExactly -ActualValue ''ExpectedString'' -ExpectedValue ''ExpectedString''` correctly' { + Should -BeExactly -ActualValue 'ExpectedString' -ExpectedValue 'ExpectedString' + } + + It 'Should convert `Should -BeExactly -ExpectedValue ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -BeExactly -ExpectedValue 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -ExpectedValue ''ExpectedString'' -BeExactly -ActualValue ''ExpectedString''` correctly' { + Should -ExpectedValue 'ExpectedString' -BeExactly -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -ExpectedValue ''ExpectedString'' -ActualValue ''ExpectedString'' -BeExactly` correctly' { + Should -ExpectedValue 'ExpectedString' -ActualValue 'ExpectedString' -BeExactly + } + + It 'Should convert `Should -Not:$false -BeExactly ''ExpectedString''` correctly' { + 'ExpectedString' | Should -Not:$false -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -BeExactly (Get-Something)` correctly' { + function Get-Something + { + return 'ExpectedString' + } + + 'ExpectedString' | Should -BeExactly (Get-Something) + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' -Because ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -BeExactly 'ExpectedString' -Because 'mock should test correct value' 'ExpectedString' + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' ''mock should test correct value'' ''ActualString''` correctly' { + Should -BeExactly 'ExpectedString' 'mock should test correct value' 'ExpectedString' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' ''mock should test correct value'' ''ActualString'' -BeExactly` correctly' { + # Should 'ExpectedString' 'mock should test correct value' 'ExpectedString' -BeExactly + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeExactly ''ExpectedString''` correctly' { + 'ActualString' | Should -Not -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' -Not` correctly' { + 'ActualString' | Should -BeExactly 'ExpectedString' -Not + } + + It 'Should convert `Should -Not -BeExactly "ExpectedString"` correctly' { + 'ActualString' | Should -Not -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -Not -BeExactly $anyValue` correctly' { + $anyValue = 'ExpectedString' + + 'ActualString' | Should -Not -BeExactly $anyValue + } + + It 'Should convert `Should -BeExactly $anyValue -Not` correctly' { + $anyValue = 'ExpectedString' + + 'ActualString' | Should -BeExactly $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeExactly ''ExpectedString''` correctly' { + 'ActualString' | Should -Not:$true -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -Not -ActualValue ''ActualString'' -BeExactly ''ExpectedString''` correctly' { + Should -Not -ActualValue 'ActualString' -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -BeExactly ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -BeExactly 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -BeExactly ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -BeExactly 'ExpectedString' -Not + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' -ActualValue ''ActualString'' -Not` correctly' { + Should -BeExactly 'ExpectedString' -ActualValue 'ActualString' -Not + } + + It 'Should convert `Should -BeExactly ''ExpectedString'' -Not -ActualValue ''ActualString''` correctly' { + Should -BeExactly 'ExpectedString' -Not -ActualValue 'ActualString' + } + + It 'Should convert `Should -Not -BeExactly ''ExpectedString'' -ActualValue ''ActualString''` correctly' { + Should -Not -BeExactly 'ExpectedString' -ActualValue 'ActualString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -BeExactly -Not -ExpectedValue ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -BeExactly -Not -ExpectedValue 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -BeExactly -ExpectedValue ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -BeExactly -ExpectedValue 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -BeExactly -ExpectedValue ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -BeExactly -ExpectedValue 'ExpectedString' -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -CEQ ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -CEQ 'ExpectedString' -ActualValue 'ExpectedString' + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeFalse.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeFalse.v5.tests.ps1 new file mode 100644 index 0000000..93efdf4 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeFalse.v5.tests.ps1 @@ -0,0 +1,71 @@ +Describe 'Should -BeFalse' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeFalse` correctly' { + $false | Should -BeFalse + } + + It 'Should convert `Should -BeFalse -Because ''BecauseMockString''` correctly' { + $false | Should -BeFalse -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeFalse -ActualValue $true -Because ''BecauseMockString''` correctly' { + Should -BeFalse -ActualValue $false -Because 'BecauseMockString' + } + + # Test intentionally uses abbreviated parameter name for -ActualValue. + It 'Should convert `Should -BeFalse -Actual $false -Because ''BecauseMockString''` correctly' { + Should -BeFalse -Actual $false -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeFalse ''BecauseMockString''` correctly' { + $false | Should -BeFalse 'BecauseMockString' + } + + It 'Should convert `Should -BeFalse ''BecauseMockString'' $false` correctly' { + Should -BeFalse 'BecauseMockString' $false + } + + It 'Should convert `Should -Not:$false -BeFalse ''BecauseMockString'' $false` correctly' { + Should -Not:$false -BeFalse 'BecauseMockString' $false + } + + It 'Should convert `Should -BeFalse -ActualValue $false ''BecauseMockString''` correctly' { + Should -BeFalse -ActualValue $false 'BecauseMockString' + } + + It 'Should convert `Should -BeFalse ''BecauseMockString'' -ActualValue $false` correctly' { + Should -BeFalse 'BecauseMockString' -ActualValue $false + } + + It 'Should convert `Should -BeFalse -Because ''BecauseMockString'' $false` correctly' { + Should -BeFalse -Because 'BecauseMockString' $false + } + + It 'Should convert `Should -BeFalse $false -Because ''BecauseMockString''` correctly' { + Should -BeFalse $false -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeFalse ''BecauseMockString'' (Get-BooleanValue)` correctly' { + function Get-BooleanValue + { + return $false + } + + Should -BeFalse 'BecauseMockString' (Get-BooleanValue) + } + + It 'Should convert `Should -BeFalse -ActualValue $false` correctly' { + Should -BeFalse -ActualValue $false + } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeFalse` correctly' { + $true | Should -Not -BeFalse + } + + It 'Should convert `Should -BeFalse -Not:$true` correctly' { + $true | Should -BeFalse -Not:$true + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeGreaterOrEqual.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeGreaterOrEqual.v5.tests.ps1 new file mode 100644 index 0000000..cb9e18d --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeGreaterOrEqual.v5.tests.ps1 @@ -0,0 +1,140 @@ +Describe 'Should -BeGreaterOrEqual' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeGreaterOrEqual 2` correctly' { + 3 | Should -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -BeGreaterOrEqual $numericValue` correctly' { + $numericValue = 3 + + 3 | Should -BeGreaterOrEqual $numericValue + } + + It 'Should convert `Should -ActualValue 2 -BeGreaterOrEqual 2` correctly' { + Should -ActualValue 2 -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -BeGreaterOrEqual 2 -ActualValue 2` correctly' { + Should -BeGreaterOrEqual 2 -ActualValue 2 + } + + It 'Should convert `Should -ActualValue 2 -BeGreaterOrEqual -ExpectedValue 2` correctly' { + Should -ActualValue 2 -BeGreaterOrEqual -ExpectedValue 2 + } + + It 'Should convert `Should -BeGreaterOrEqual -ActualValue 2 -ExpectedValue 2` correctly' { + Should -BeGreaterOrEqual -ActualValue 2 -ExpectedValue 2 + } + + It 'Should convert `Should -BeGreaterOrEqual -ExpectedValue 2 -ActualValue 2` correctly' { + Should -BeGreaterOrEqual -ExpectedValue 2 -ActualValue 2 + } + + It 'Should convert `Should -ExpectedValue 2 -BeGreaterOrEqual -ActualValue 2` correctly' { + Should -ExpectedValue 2 -BeGreaterOrEqual -ActualValue 2 + } + + It 'Should convert `Should -ExpectedValue 2 -ActualValue 2 -BeGreaterOrEqual` correctly' { + Should -ExpectedValue 2 -ActualValue 2 -BeGreaterOrEqual + } + + It 'Should convert `Should -Not:$false -BeGreaterOrEqual 2` correctly' { + 3 | Should -Not:$false -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -BeGreaterOrEqual (Get-Something)` correctly' { + function Get-Something + { + return 2 + } + + 2 | Should -BeGreaterOrEqual (Get-Something) + } + + It 'Should convert `Should -BeGreaterOrEqual 2 -Because ''mock should test correct value'' 2` correctly' { + Should -BeGreaterOrEqual 2 -Because 'mock should test correct value' 2 + } + + It 'Should convert `Should -BeGreaterOrEqual 2 ''mock should test correct value'' 3` correctly' { + Should -BeGreaterOrEqual 2 'mock should test correct value' 3 + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should 2 ''mock should test correct value'' 3 -BeGreaterOrEqual` correctly' { + # Should 2 'mock should test correct value' 3 -BeGreaterOrEqual + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeGreaterOrEqual 2` correctly' { + 1 | Should -Not -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -BeGreaterOrEqual 2 -Not` correctly' { + 1 | Should -BeGreaterOrEqual 2 -Not + } + + It 'Should convert `Should -Not -BeGreaterOrEqual $anyValue` correctly' { + $anyValue = 2 + + 1 | Should -Not -BeGreaterOrEqual $anyValue + } + + It 'Should convert `Should -BeGreaterOrEqual $anyValue -Not` correctly' { + $anyValue = 2 + + 1 | Should -BeGreaterOrEqual $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeGreaterOrEqual 2` correctly' { + 1 | Should -Not:$true -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -Not -ActualValue 3 -BeGreaterOrEqual 2` correctly' { + Should -Not -ActualValue 1 -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeGreaterOrEqual 2` correctly' { + Should -ActualValue 1 -Not -BeGreaterOrEqual 2 + } + + It 'Should convert `Should -ActualValue 3 -BeGreaterOrEqual 2 -Not` correctly' { + Should -ActualValue 1 -BeGreaterOrEqual 2 -Not + } + + It 'Should convert `Should -BeGreaterOrEqual 2 -ActualValue 3 -Not` correctly' { + Should -BeGreaterOrEqual 2 -ActualValue 1 -Not + } + + It 'Should convert `Should -BeGreaterOrEqual 2 -Not -ActualValue 3` correctly' { + Should -BeGreaterOrEqual 2 -Not -ActualValue 1 + } + + It 'Should convert `Should -Not -BeGreaterOrEqual 2 -ActualValue 3` correctly' { + Should -Not -BeGreaterOrEqual 2 -ActualValue 1 + } + + It 'Should convert `Should -ActualValue 3 -BeGreaterOrEqual -Not -ExpectedValue 2` correctly' { + Should -ActualValue 1 -BeGreaterOrEqual -Not -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeGreaterOrEqual -ExpectedValue 2` correctly' { + Should -ActualValue 1 -Not -BeGreaterOrEqual -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -BeGreaterOrEqual -ExpectedValue 2 -Not` correctly' { + Should -ActualValue 1 -BeGreaterOrEqual -ExpectedValue 2 -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -GE 2 -ActualValue 3` correctly' { + Should -GE 2 -ActualValue 3 + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeGreaterThan.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeGreaterThan.v5.tests.ps1 new file mode 100644 index 0000000..7bd8722 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeGreaterThan.v5.tests.ps1 @@ -0,0 +1,140 @@ +Describe 'Should -BeGreaterThan' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeGreaterThan 2` correctly' { + 3 | Should -BeGreaterThan 2 + } + + It 'Should convert `Should -BeGreaterThan $numericValue` correctly' { + $numericValue = 2 + + 3 | Should -BeGreaterThan $numericValue + } + + It 'Should convert `Should -ActualValue 3 -BeGreaterThan 2` correctly' { + Should -ActualValue 3 -BeGreaterThan 2 + } + + It 'Should convert `Should -BeGreaterThan 2 -ActualValue 3` correctly' { + Should -BeGreaterThan 2 -ActualValue 3 + } + + It 'Should convert `Should -ActualValue 3 -BeGreaterThan -ExpectedValue 2` correctly' { + Should -ActualValue 3 -BeGreaterThan -ExpectedValue 2 + } + + It 'Should convert `Should -BeGreaterThan -ActualValue 3 -ExpectedValue 2` correctly' { + Should -BeGreaterThan -ActualValue 3 -ExpectedValue 2 + } + + It 'Should convert `Should -BeGreaterThan -ExpectedValue 2 -ActualValue 3` correctly' { + Should -BeGreaterThan -ExpectedValue 2 -ActualValue 3 + } + + It 'Should convert `Should -ExpectedValue 2 -BeGreaterThan -ActualValue 3` correctly' { + Should -ExpectedValue 2 -BeGreaterThan -ActualValue 3 + } + + It 'Should convert `Should -ExpectedValue 2 -ActualValue 3 -BeGreaterThan` correctly' { + Should -ExpectedValue 2 -ActualValue 3 -BeGreaterThan + } + + It 'Should convert `Should -Not:$false -BeGreaterThan 2` correctly' { + 3 | Should -Not:$false -BeGreaterThan 2 + } + + It 'Should convert `Should -BeGreaterThan (Get-Something)` correctly' { + function Get-Something + { + return 2 + } + + 3 | Should -BeGreaterThan (Get-Something) + } + + It 'Should convert `Should -BeGreaterThan 2 -Because ''mock should test correct value'' 2` correctly' { + Should -BeGreaterThan 2 -Because 'mock should test correct value' 3 + } + + It 'Should convert `Should -BeGreaterThan 2 ''mock should test correct value'' 3` correctly' { + Should -BeGreaterThan 2 'mock should test correct value' 3 + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should 2 ''mock should test correct value'' 3 -BeGreaterThan` correctly' { + # Should 2 'mock should test correct value' 3 -BeGreaterThan + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeGreaterThan 2` correctly' { + 1 | Should -Not -BeGreaterThan 2 + } + + It 'Should convert `Should -BeGreaterThan 2 -Not` correctly' { + 1 | Should -BeGreaterThan 2 -Not + } + + It 'Should convert `Should -Not -BeGreaterThan $anyValue` correctly' { + $anyValue = 2 + + 1 | Should -Not -BeGreaterThan $anyValue + } + + It 'Should convert `Should -BeGreaterThan $anyValue -Not` correctly' { + $anyValue = 2 + + 1 | Should -BeGreaterThan $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeGreaterThan 2` correctly' { + 2 | Should -Not:$true -BeGreaterThan 2 + } + + It 'Should convert `Should -Not -ActualValue 1 -BeGreaterThan 2` correctly' { + Should -Not -ActualValue 1 -BeGreaterThan 2 + } + + It 'Should convert `Should -ActualValue 1 -Not -BeGreaterThan 2` correctly' { + Should -ActualValue 1 -Not -BeGreaterThan 2 + } + + It 'Should convert `Should -ActualValue 1 -BeGreaterThan 2 -Not` correctly' { + Should -ActualValue 1 -BeGreaterThan 2 -Not + } + + It 'Should convert `Should -BeGreaterThan 2 -ActualValue 1 -Not` correctly' { + Should -BeGreaterThan 2 -ActualValue 1 -Not + } + + It 'Should convert `Should -BeGreaterThan 2 -Not -ActualValue 1` correctly' { + Should -BeGreaterThan 2 -Not -ActualValue 1 + } + + It 'Should convert `Should -Not -BeGreaterThan 2 -ActualValue 1` correctly' { + Should -Not -BeGreaterThan 2 -ActualValue 1 + } + + It 'Should convert `Should -ActualValue 1 -BeGreaterThan -Not -ExpectedValue 2` correctly' { + Should -ActualValue 1 -BeGreaterThan -Not -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 1 -Not -BeGreaterThan -ExpectedValue 2` correctly' { + Should -ActualValue 1 -Not -BeGreaterThan -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 1 -BeGreaterThan -ExpectedValue 2 -Not` correctly' { + Should -ActualValue 1 -BeGreaterThan -ExpectedValue 2 -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -GT 2 -ActualValue 3` correctly' { + Should -GT 2 -ActualValue 3 + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeIn.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeIn.v5.tests.ps1 new file mode 100644 index 0000000..21bcd37 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeIn.v5.tests.ps1 @@ -0,0 +1,57 @@ +Describe 'Should -BeIn' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeIn @(''ExpectedValue1'', ''ExpectedValue2'') ''BecauseString'' ''ExpectedValue2''` correctly' { + Should -BeIn @('ExpectedValue1', 'ExpectedValue2') 'BecauseString' 'ExpectedValue2' + } + + It 'Should convert `Should -BeIn @(''ExpectedValue1'', ''ExpectedValue2'') -Because ''BecauseString'' ''ExpectedValue2''` correctly' { + Should -BeIn @('ExpectedValue1', 'ExpectedValue2') -Because 'BecauseString' 'ExpectedValue2' + } + + It 'Should convert `Should -BeIn -ExpectedValue @(''ExpectedValue1'', ''ExpectedValue2'') -Because ''BecauseString'' ''ExpectedValue2''` correctly' { + Should -BeIn -ExpectedValue @('ExpectedValue1', 'ExpectedValue2') -Because 'BecauseString' 'ExpectedValue2' + } + + It 'Should convert `Should -BeIn -ExpectedValue @(''ExpectedValue1'', ''ExpectedValue2'') -Because ''BecauseString'' -ActualValue ''ExpectedValue2''` correctly' { + Should -BeIn -ExpectedValue @('ExpectedValue1', 'ExpectedValue2') -Because 'BecauseString' -ActualValue 'ExpectedValue2' + } + + It 'Should convert `''ExpectedValue2'' | Should -BeIn @(''ExpectedValue1'', ''ExpectedValue2'') -Because ''BecauseString''` correctly' { + 'ExpectedValue2' | Should -BeIn @('ExpectedValue1', 'ExpectedValue2') -Because 'BecauseString' + } + + It 'Should convert `''ExpectedValue2'' | Should -BeIn -Because ''BecauseString'' -ExpectedValue @(''ExpectedValue1'', ''ExpectedValue2'')` correctly' { + 'ExpectedValue2' | Should -BeIn -Because 'BecauseString' -ExpectedValue @('ExpectedValue1', 'ExpectedValue2') + } + + It 'Should convert `''ExpectedValue2'' | Should -BeIn @(''ExpectedValue1'', ''ExpectedValue2'')` correctly' { + 'ExpectedValue2' | Should -BeIn @('ExpectedValue1', 'ExpectedValue2') + } + + It 'Should convert `''ExpectedValue2'' | Get-Something | Should -BeIn @(''ExpectedValue1'', ''ExpectedValue2'') ''BecauseString''` correctly' { + function Get-Something + { + [CmdletBinding()] + param + ( + [Parameter(ValueFromPipeline = $true)] + [System.String] + $InputString + ) + + process + { + Write-Output $InputString + } + } + + 'ExpectedValue2' | Get-Something | Should -BeIn @('ExpectedValue1', 'ExpectedValue2') 'BecauseString' + } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeIn @(''ExpectedValue1'', ''ExpectedValue2'') ''BecauseString'' ''ActualValue''` correctly' { + Should -Not -BeIn @('ExpectedValue1', 'ExpectedValue2') 'BecauseString' 'ActualValue' + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeLessOrEqual.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeLessOrEqual.v5.tests.ps1 new file mode 100644 index 0000000..6b1cd86 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeLessOrEqual.v5.tests.ps1 @@ -0,0 +1,140 @@ +Describe 'Should -BeLessOrEqual' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeLessOrEqual 2` correctly' { + 1 | Should -BeLessOrEqual 2 + } + + It 'Should convert `Should -BeLessOrEqual $numericValue` correctly' { + $numericValue = 2 + + 1 | Should -BeLessOrEqual $numericValue + } + + It 'Should convert `Should -ActualValue 2 -BeLessOrEqual 2` correctly' { + Should -ActualValue 2 -BeLessOrEqual 2 + } + + It 'Should convert `Should -BeLessOrEqual 2 -ActualValue 2` correctly' { + Should -BeLessOrEqual 2 -ActualValue 2 + } + + It 'Should convert `Should -ActualValue 2 -BeLessOrEqual -ExpectedValue 2` correctly' { + Should -ActualValue 2 -BeLessOrEqual -ExpectedValue 2 + } + + It 'Should convert `Should -BeLessOrEqual -ActualValue 2 -ExpectedValue 2` correctly' { + Should -BeLessOrEqual -ActualValue 2 -ExpectedValue 2 + } + + It 'Should convert `Should -BeLessOrEqual -ExpectedValue 2 -ActualValue 2` correctly' { + Should -BeLessOrEqual -ExpectedValue 2 -ActualValue 2 + } + + It 'Should convert `Should -ExpectedValue 2 -BeLessOrEqual -ActualValue 2` correctly' { + Should -ExpectedValue 2 -BeLessOrEqual -ActualValue 2 + } + + It 'Should convert `Should -ExpectedValue 2 -ActualValue 2 -BeLessOrEqual` correctly' { + Should -ExpectedValue 2 -ActualValue 2 -BeLessOrEqual + } + + It 'Should convert `Should -Not:$false -BeLessOrEqual 2` correctly' { + 2 | Should -Not:$false -BeLessOrEqual 2 + } + + It 'Should convert `Should -BeLessOrEqual (Get-Something)` correctly' { + function Get-Something + { + return 2 + } + + 2 | Should -BeLessOrEqual (Get-Something) + } + + It 'Should convert `Should -BeLessOrEqual 2 -Because ''mock should test correct value'' 2` correctly' { + Should -BeLessOrEqual 2 -Because 'mock should test correct value' 2 + } + + It 'Should convert `Should -BeLessOrEqual 2 ''mock should test correct value'' 1` correctly' { + Should -BeLessOrEqual 2 'mock should test correct value' 1 + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should 2 ''mock should test correct value'' 1 -BeLessOrEqual` correctly' { + # Should 2 'mock should test correct value' 1 -BeLessOrEqual + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeLessOrEqual 2` correctly' { + 3 | Should -Not -BeLessOrEqual 2 + } + + It 'Should convert `Should -BeLessOrEqual 2 -Not` correctly' { + 3 | Should -BeLessOrEqual 2 -Not + } + + It 'Should convert `Should -Not -BeLessOrEqual $anyValue` correctly' { + $anyValue = 2 + + 3 | Should -Not -BeLessOrEqual $anyValue + } + + It 'Should convert `Should -BeLessOrEqual $anyValue -Not` correctly' { + $anyValue = 2 + + 3 | Should -BeLessOrEqual $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeLessOrEqual 2` correctly' { + 3 | Should -Not:$true -BeLessOrEqual 2 + } + + It 'Should convert `Should -Not -ActualValue 3 -BeLessOrEqual 2` correctly' { + Should -Not -ActualValue 3 -BeLessOrEqual 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeLessOrEqual 2` correctly' { + Should -ActualValue 3 -Not -BeLessOrEqual 2 + } + + It 'Should convert `Should -ActualValue 3 -BeLessOrEqual 2 -Not` correctly' { + Should -ActualValue 3 -BeLessOrEqual 2 -Not + } + + It 'Should convert `Should -BeLessOrEqual 2 -ActualValue 3 -Not` correctly' { + Should -BeLessOrEqual 2 -ActualValue 3 -Not + } + + It 'Should convert `Should -BeLessOrEqual 2 -Not -ActualValue 3` correctly' { + Should -BeLessOrEqual 2 -Not -ActualValue 3 + } + + It 'Should convert `Should -Not -BeLessOrEqual 2 -ActualValue 3` correctly' { + Should -Not -BeLessOrEqual 2 -ActualValue 3 + } + + It 'Should convert `Should -ActualValue 3 -BeLessOrEqual -Not -ExpectedValue 2` correctly' { + Should -ActualValue 3 -BeLessOrEqual -Not -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeLessOrEqual -ExpectedValue 2` correctly' { + Should -ActualValue 3 -Not -BeLessOrEqual -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -BeLessOrEqual -ExpectedValue 2 -Not` correctly' { + Should -ActualValue 3 -BeLessOrEqual -ExpectedValue 2 -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -LE 2 -ActualValue 1` correctly' { + Should -LE 2 -ActualValue 1 + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeLessThan.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeLessThan.v5.tests.ps1 new file mode 100644 index 0000000..7c6688b --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeLessThan.v5.tests.ps1 @@ -0,0 +1,140 @@ +Describe 'Should -BeLessThan' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeLessThan 2` correctly' { + 1 | Should -BeLessThan 2 + } + + It 'Should convert `Should -BeLessThan $numericValue` correctly' { + $numericValue = 2 + + 1 | Should -BeLessThan $numericValue + } + + It 'Should convert `Should -ActualValue 1 -BeLessThan 2` correctly' { + Should -ActualValue 1 -BeLessThan 2 + } + + It 'Should convert `Should -BeLessThan 2 -ActualValue 1` correctly' { + Should -BeLessThan 2 -ActualValue 1 + } + + It 'Should convert `Should -ActualValue 1 -BeLessThan -ExpectedValue 2` correctly' { + Should -ActualValue 1 -BeLessThan -ExpectedValue 2 + } + + It 'Should convert `Should -BeLessThan -ActualValue 1 -ExpectedValue 2` correctly' { + Should -BeLessThan -ActualValue 1 -ExpectedValue 2 + } + + It 'Should convert `Should -BeLessThan -ExpectedValue 2 -ActualValue 1` correctly' { + Should -BeLessThan -ExpectedValue 2 -ActualValue 1 + } + + It 'Should convert `Should -ExpectedValue 2 -BeLessThan -ActualValue 1` correctly' { + Should -ExpectedValue 2 -BeLessThan -ActualValue 1 + } + + It 'Should convert `Should -ExpectedValue 2 -ActualValue 1 -BeLessThan` correctly' { + Should -ExpectedValue 2 -ActualValue 1 -BeLessThan + } + + It 'Should convert `Should -Not:$false -BeLessThan 2` correctly' { + 1 | Should -Not:$false -BeLessThan 2 + } + + It 'Should convert `Should -BeLessThan (Get-Something)` correctly' { + function Get-Something + { + return 2 + } + + 1 | Should -BeLessThan (Get-Something) + } + + It 'Should convert `Should -BeLessThan 2 -Because ''mock should test correct value'' 1` correctly' { + Should -BeLessThan 2 -Because 'mock should test correct value' 1 + } + + It 'Should convert `Should -BeLessThan 2 ''mock should test correct value'' 1` correctly' { + Should -BeLessThan 2 'mock should test correct value' 1 + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should 2 ''mock should test correct value'' 1 -BeLessThan` correctly' { + # Should 2 'mock should test correct value' 1 -BeLessThan + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeLessThan 2` correctly' { + 3 | Should -Not -BeLessThan 2 + } + + It 'Should convert `Should -BeLessThan 2 -Not` correctly' { + 3 | Should -BeLessThan 2 -Not + } + + It 'Should convert `Should -Not -BeLessThan $anyValue` correctly' { + $anyValue = 2 + + 3 | Should -Not -BeLessThan $anyValue + } + + It 'Should convert `Should -BeLessThan $anyValue -Not` correctly' { + $anyValue = 2 + + 3 | Should -BeLessThan $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeLessThan 2` correctly' { + 2 | Should -Not:$true -BeLessThan 2 + } + + It 'Should convert `Should -Not -ActualValue 3 -BeLessThan 2` correctly' { + Should -Not -ActualValue 3 -BeLessThan 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeLessThan 2` correctly' { + Should -ActualValue 3 -Not -BeLessThan 2 + } + + It 'Should convert `Should -ActualValue 3 -BeLessThan 2 -Not` correctly' { + Should -ActualValue 3 -BeLessThan 2 -Not + } + + It 'Should convert `Should -BeLessThan 2 -ActualValue 3 -Not` correctly' { + Should -BeLessThan 2 -ActualValue 3 -Not + } + + It 'Should convert `Should -BeLessThan 2 -Not -ActualValue 3` correctly' { + Should -BeLessThan 2 -Not -ActualValue 3 + } + + It 'Should convert `Should -Not -BeLessThan 2 -ActualValue 3` correctly' { + Should -Not -BeLessThan 2 -ActualValue 3 + } + + It 'Should convert `Should -ActualValue 3 -BeLessThan -Not -ExpectedValue 2` correctly' { + Should -ActualValue 3 -BeLessThan -Not -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -Not -BeLessThan -ExpectedValue 2` correctly' { + Should -ActualValue 3 -Not -BeLessThan -ExpectedValue 2 + } + + It 'Should convert `Should -ActualValue 3 -BeLessThan -ExpectedValue 2 -Not` correctly' { + Should -ActualValue 3 -BeLessThan -ExpectedValue 2 -Not + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -LT 3 -ActualValue 2` correctly' { + Should -LT 3 -ActualValue 2 + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeLike.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeLike.v5.tests.ps1 new file mode 100644 index 0000000..d6fc31e --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeLike.v5.tests.ps1 @@ -0,0 +1,138 @@ +Describe 'Should -BeLike' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeLike ''Test*''` correctly' { + 'TestValue' | Should -BeLike 'Test*' + } + + It 'Should convert `Should -BeLike "Test*"` correctly' { + 'TestValue' | Should -BeLike "Test*" + } + + It 'Should convert `Should -BeLike $anyValue` correctly' { + $anyValue = 'Test*' + + 'TestValue' | Should -BeLike $anyValue + } + + It 'Should convert `Should -ActualValue ''TestValue'' -BeLike ''Test*''` correctly' { + Should -ActualValue 'TestValue' -BeLike 'Test*' + } + + It 'Should convert `Should -BeLike ''Test*'' -ActualValue ''TestValue''` correctly' { + Should -BeLike 'Test*' -ActualValue 'TestValue' + } + + It 'Should convert `Should -ActualValue ''TestValue'' -BeLike -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'TestValue' -BeLike -ExpectedValue 'Test*' + } + + It 'Should convert `Should -BeLike -ActualValue ''TestValue'' -ExpectedValue ''Test*''` correctly' { + Should -BeLike -ActualValue 'TestValue' -ExpectedValue 'Test*' + } + + It 'Should convert `Should -BeLike -ExpectedValue ''Test*'' -ActualValue ''TestValue''` correctly' { + Should -BeLike -ExpectedValue 'Test*' -ActualValue 'TestValue' + } + + It 'Should convert `Should -ExpectedValue ''Test*'' -BeLike -ActualValue ''TestValue''` correctly' { + Should -ExpectedValue 'Test*' -BeLike -ActualValue 'TestValue' + } + + It 'Should convert `Should -ExpectedValue ''Test*'' -ActualValue ''TestValue'' -BeLike` correctly' { + Should -ExpectedValue 'Test*' -ActualValue 'TestValue' -BeLike + } + + It 'Should convert `Should -Not:$false -BeLike ''Test*''` correctly' { + 'TestValue' | Should -Not:$false -BeLike 'Test*' + } + + It 'Should convert `Should -BeLike (Get-Something)` correctly' { + function Get-Something + { + return 'Test*' + } + + 'TestValue' | Should -BeLike (Get-Something) + } + + It 'Should convert `Should -BeLike ''Test*'' -Because ''mock should test correct value'' ''TestValue''` correctly' { + Should -BeLike 'Test*' -Because 'mock should test correct value' 'TestValue*' + } + + It 'Should convert `Should -BeLike ''Test*'' ''mock should test correct value'' ''TestValue''` correctly' { + Should -BeLike 'Test*' 'mock should test correct value' 'TestValue' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''Test*'' ''mock should test correct value'' ''TestValue'' -BeLike` correctly' { + # Should 'Test*' 'mock should test correct value' 'TestValue' -BeLike + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeLike ''Test*''` correctly' { + 'OtherValue' | Should -Not -BeLike 'Test*' + } + + It 'Should convert `Should -BeLike ''Test*'' -Not` correctly' { + 'OtherValue' | Should -BeLike 'Test*' -Not + } + + It 'Should convert `Should -Not -BeLike $anyValue` correctly' { + $anyValue = 'Test*' + + 'OtherValue' | Should -Not -BeLike $anyValue + } + + It 'Should convert `Should -BeLike $anyValue -Not` correctly' { + $anyValue = 'Test*' + + 'OtherValue' | Should -BeLike $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeLike ''Test*''` correctly' { + 'OtherValue' | Should -Not:$true -BeLike 'Test*' + } + + It 'Should convert `Should -Not -ActualValue ''OtherValue'' -BeLike ''Test*''` correctly' { + Should -Not -ActualValue 'OtherValue' -BeLike 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -Not -BeLike ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -Not -BeLike 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLike ''Test*'' -Not` correctly' { + Should -ActualValue 'OtherValue' -BeLike 'Test*' -Not + } + + It 'Should convert `Should -BeLike ''Test*'' -ActualValue ''OtherValue'' -Not` correctly' { + Should -BeLike 'Test*' -ActualValue 'OtherValue' -Not + } + + It 'Should convert `Should -BeLike ''Test*'' -Not -ActualValue ''OtherValue''` correctly' { + Should -BeLike 'Test*' -Not -ActualValue 'OtherValue' + } + + It 'Should convert `Should -Not -BeLike ''Test*'' -ActualValue ''OtherValue''` correctly' { + Should -Not -BeLike 'Test*' -ActualValue 'OtherValue' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLike -Not -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -BeLike -Not -ExpectedValue 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -Not -BeLike -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -Not -BeLike -ExpectedValue 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLike -ExpectedValue ''Test*'' -Not` correctly' { + Should -ActualValue 'OtherValue' -BeLike -ExpectedValue 'Test*' -Not + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeLikeExactly.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeLikeExactly.v5.tests.ps1 new file mode 100644 index 0000000..a33e556 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeLikeExactly.v5.tests.ps1 @@ -0,0 +1,138 @@ +Describe 'Should -BeLikeExactly' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeLikeExactly ''Test*''` correctly' { + 'TestValue' | Should -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -BeLikeExactly "Test*"` correctly' { + 'TestValue' | Should -BeLikeExactly "Test*" + } + + It 'Should convert `Should -BeLikeExactly $anyValue` correctly' { + $anyValue = 'Test*' + + 'TestValue' | Should -BeLikeExactly $anyValue + } + + It 'Should convert `Should -ActualValue ''TestValue'' -BeLikeExactly ''Test*''` correctly' { + Should -ActualValue 'TestValue' -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' -ActualValue ''TestValue''` correctly' { + Should -BeLikeExactly 'Test*' -ActualValue 'TestValue' + } + + It 'Should convert `Should -ActualValue ''TestValue'' -BeLikeExactly -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'TestValue' -BeLikeExactly -ExpectedValue 'Test*' + } + + It 'Should convert `Should -BeLikeExactly -ActualValue ''TestValue'' -ExpectedValue ''Test*''` correctly' { + Should -BeLikeExactly -ActualValue 'TestValue' -ExpectedValue 'Test*' + } + + It 'Should convert `Should -BeLikeExactly -ExpectedValue ''Test*'' -ActualValue ''TestValue''` correctly' { + Should -BeLikeExactly -ExpectedValue 'Test*' -ActualValue 'TestValue' + } + + It 'Should convert `Should -ExpectedValue ''Test*'' -BeLikeExactly -ActualValue ''TestValue''` correctly' { + Should -ExpectedValue 'Test*' -BeLikeExactly -ActualValue 'TestValue' + } + + It 'Should convert `Should -ExpectedValue ''Test*'' -ActualValue ''TestValue'' -BeLikeExactly` correctly' { + Should -ExpectedValue 'Test*' -ActualValue 'TestValue' -BeLikeExactly + } + + It 'Should convert `Should -Not:$false -BeLikeExactly ''Test*''` correctly' { + 'TestValue' | Should -Not:$false -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -BeLikeExactly (Get-Something)` correctly' { + function Get-Something + { + return 'Test*' + } + + 'TestValue' | Should -BeLikeExactly (Get-Something) + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' -Because ''mock should test correct value'' ''TestValue''` correctly' { + Should -BeLikeExactly 'Test*' -Because 'mock should test correct value' 'TestValue*' + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' ''mock should test correct value'' ''TestValue''` correctly' { + Should -BeLikeExactly 'Test*' 'mock should test correct value' 'TestValue' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''Test*'' ''mock should test correct value'' ''TestValue'' -BeLikeExactly` correctly' { + # Should 'Test*' 'mock should test correct value' 'TestValue' -BeLikeExactly + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeLikeExactly ''Test*''` correctly' { + 'OtherValue' | Should -Not -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' -Not` correctly' { + 'OtherValue' | Should -BeLikeExactly 'Test*' -Not + } + + It 'Should convert `Should -Not -BeLikeExactly $anyValue` correctly' { + $anyValue = 'Test*' + + 'OtherValue' | Should -Not -BeLikeExactly $anyValue + } + + It 'Should convert `Should -BeLikeExactly $anyValue -Not` correctly' { + $anyValue = 'Test*' + + 'OtherValue' | Should -BeLikeExactly $anyValue -Not + } + + It 'Should convert `Should -Not:$true -BeLikeExactly ''Test*''` correctly' { + 'OtherValue' | Should -Not:$true -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -Not -ActualValue ''OtherValue'' -BeLikeExactly ''Test*''` correctly' { + Should -Not -ActualValue 'OtherValue' -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -Not -BeLikeExactly ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -Not -BeLikeExactly 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLikeExactly ''Test*'' -Not` correctly' { + Should -ActualValue 'OtherValue' -BeLikeExactly 'Test*' -Not + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' -ActualValue ''OtherValue'' -Not` correctly' { + Should -BeLikeExactly 'Test*' -ActualValue 'OtherValue' -Not + } + + It 'Should convert `Should -BeLikeExactly ''Test*'' -Not -ActualValue ''OtherValue''` correctly' { + Should -BeLikeExactly 'Test*' -Not -ActualValue 'OtherValue' + } + + It 'Should convert `Should -Not -BeLikeExactly ''Test*'' -ActualValue ''OtherValue''` correctly' { + Should -Not -BeLikeExactly 'Test*' -ActualValue 'OtherValue' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLikeExactly -Not -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -BeLikeExactly -Not -ExpectedValue 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -Not -BeLikeExactly -ExpectedValue ''Test*''` correctly' { + Should -ActualValue 'OtherValue' -Not -BeLikeExactly -ExpectedValue 'Test*' + } + + It 'Should convert `Should -ActualValue ''OtherValue'' -BeLikeExactly -ExpectedValue ''Test*'' -Not` correctly' { + Should -ActualValue 'OtherValue' -BeLikeExactly -ExpectedValue 'Test*' -Not + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeNullOrEmpty.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeNullOrEmpty.v5.tests.ps1 new file mode 100644 index 0000000..13b41ff --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeNullOrEmpty.v5.tests.ps1 @@ -0,0 +1,74 @@ +Describe 'Should -BeNullOrEmpty' { + Context 'When the tests are affirming' { + It 'Should convert `$null | Should -BeNullOrEmpty` correctly' { + $null | Should -BeNullOrEmpty + } + + It 'Should convert `'' | Should -BeNullOrEmpty` correctly' { + '' | Should -BeNullOrEmpty + } + + It 'Should convert `@() | Should -BeNullOrEmpty` correctly' { + @() | Should -BeNullOrEmpty + } + + It 'Should convert `Should -BeNullOrEmpty -Because ''BecauseMockString''` correctly' { + $null | Should -BeNullOrEmpty -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeNullOrEmpty -ActualValue $null -Because ''BecauseMockString''` correctly' { + Should -BeNullOrEmpty -ActualValue $null -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeNullOrEmpty ''BecauseMockString''` correctly' { + $null | Should -BeNullOrEmpty 'BecauseMockString' + } + + It 'Should convert `Should -BeNullOrEmpty ''BecauseMockString'' $null` correctly' { + Should -BeNullOrEmpty 'BecauseMockString' $null + } + + It 'Should convert `Should -Not:$false -BeNullOrEmpty ''BecauseMockString'' $null` correctly' { + Should -Not:$false -BeNullOrEmpty 'BecauseMockString' $null + } + + It 'Should convert `Should -BeNullOrEmpty -ActualValue $null ''BecauseMockString''` correctly' { + Should -BeNullOrEmpty -ActualValue $null 'BecauseMockString' + } + + It 'Should convert `Should -BeNullOrEmpty ''BecauseMockString'' -ActualValue $true` correctly' { + Should -BeNullOrEmpty 'BecauseMockString' -ActualValue $null + } + + It 'Should convert `Should -BeNullOrEmpty -Because ''BecauseMockString'' $true` correctly' { + Should -BeNullOrEmpty -Because 'BecauseMockString' $null + } + + It 'Should convert `Should -BeNullOrEmpty $null -Because ''BecauseMockString''` correctly' { + Should -BeNullOrEmpty $null -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeNullOrEmpty ''BecauseMockString'' (Get-BooleanValue)` correctly' { + function Get-NullOrEmptyValue + { + return $null + } + + Should -BeNullOrEmpty 'BecauseMockString' (Get-NullOrEmptyValue) + } + + It 'Should convert `Should -BeNullOrEmpty -ActualValue $null` correctly' { + Should -BeNullOrEmpty -ActualValue $null + } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeNullOrEmpty` correctly' { + 'AnyValue' | Should -Not -BeNullOrEmpty + } + + It 'Should convert `Should -BeNullOrEmpty -Not:$true` correctly' { + 'AnyValue' | Should -BeNullOrEmpty -Not:$true + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeOfType.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeOfType.v5.tests.ps1 new file mode 100644 index 0000000..63d49c2 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeOfType.v5.tests.ps1 @@ -0,0 +1,70 @@ +Describe 'Should -BeOfType' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeOfType ''System.String''` correctly' { + 'AnyString' | Should -BeOfType 'System.String' + } + + It 'Should convert `Should -BeOfType [System.String]` correctly' { + 'AnyString' | Should -BeOfType [System.String] + } + + It 'Should convert `Should -BeOfType [System.String] ''BecauseString''` correctly' { + 'AnyString' | Should -BeOfType [System.String] 'BecauseString' + } + + It 'Should convert `Should -ActualValue ''AnyString'' [System.String] -BeOfType ''BecauseString''` correctly' { + Should -ActualValue 'AnyString' [System.String] -BeOfType 'BecauseString' + } + + It 'Should convert `Should -ActualValue ''AnyString'' [System.String] -BeOfType -Because ''BecauseString''` correctly' { + Should -ActualValue 'AnyString' [System.String] -BeOfType 'BecauseString' + } + + It 'Should convert `Should -ActualValue ''AnyString'' -ExpectedType [System.String] -BeOfType -Because ''BecauseString''` correctly' { + Should -ActualValue 'AnyString' -ExpectedType [System.String] -BeOfType -Because 'BecauseString' + } + + It 'Should convert `Should -BeOfType [System.String] -ActualValue ''AnyString''` correctly' { + Should -BeOfType [System.String] -ActualValue 'AnyString' + } + + It 'Should convert `Should -ExpectedType [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { + Should -ExpectedType [System.String] -ActualValue 'AnyString' -BeOfType + } + + It 'Should convert `Should -Not:$false -ExpectedType [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { + Should -Not:$false -ExpectedType [System.String] -ActualValue 'AnyString' -BeOfType + } + + It 'Should convert `Should -BeOfType (Get-Something)` correctly' { + function Get-MyType + { + return ([System.String]) + } + + 'AnyString' | Should -BeOfType (Get-MyType) + } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -Be 1` correctly' { + 2 | Should -Not -BeOfType [System.String] + } + + It 'Should convert `Should -BeOfType [System.String] -Not` correctly' { + 2 | Should -BeOfType [System.String] -Not + } + + It 'Should convert `Should -Not -BeOfType $anyValue` correctly' { + $anyValue = ([System.String]) + + 2 | Should -Not -BeOfType $anyValue + } + } + + Context 'When alias operator name is used' { + It 'Should convert `Should -HaveType [System.String] -ActualValue ''AnyString''` correctly' { + Should -HaveType [System.String] -ActualValue 'AnyString' + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldBeTrue.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldBeTrue.v5.tests.ps1 new file mode 100644 index 0000000..f20f8f4 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldBeTrue.v5.tests.ps1 @@ -0,0 +1,66 @@ +Describe 'Should -BeTrue' { + Context 'When the tests are affirming' { + It 'Should convert `Should -BeTrue` correctly' { + $true | Should -BeTrue + } + + It 'Should convert `Should -BeTrue -Because ''BecauseMockString''` correctly' { + $true | Should -BeTrue -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeTrue -ActualValue $true -Because ''BecauseMockString''` correctly' { + Should -BeTrue -ActualValue $true -Because 'BecauseMockString' + } + + It 'Should convert `Should -BeTrue ''BecauseMockString''` correctly' { + $true | Should -BeTrue 'BecauseMockString' + } + + It 'Should convert `Should -BeTrue ''BecauseMockString'' $true` correctly' { + Should -BeTrue 'BecauseMockString' $true + } + + It 'Should convert `Should -Not:$false -BeTrue ''BecauseMockString'' $true` correctly' { + Should -Not:$false -BeTrue 'BecauseMockString' $true + } + + It 'Should convert `Should -BeTrue -ActualValue $true ''BecauseMockString''` correctly' { + Should -BeTrue -ActualValue $true 'BecauseMockString' + } + + It 'Should convert `Should -BeTrue ''BecauseMockString'' -ActualValue $true` correctly' { + Should -BeTrue 'BecauseMockString' -ActualValue $true + } + + It 'Should convert `Should -BeTrue -Because ''BecauseMockString'' $true` correctly' { + Should -BeTrue -Because 'BecauseMockString' $true + } + + It 'Should convert `Should -BeTrue $true -Because ''BecauseMockString''` correctly' { + Should -BeTrue -Because 'BecauseMockString' $true + } + + It 'Should convert `Should -BeTrue ''BecauseMockString'' (Get-BooleanValue)` correctly' { + function Get-BooleanValue + { + return $true + } + + Should -BeTrue 'BecauseMockString' (Get-BooleanValue) + } + + It 'Should convert `Should -BeTrue -ActualValue $true` correctly' { + Should -BeTrue -ActualValue $true + } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -BeTrue` correctly' { + $false | Should -Not -BeTrue + } + + It 'Should convert `Should -BeTrue -Not:$true` correctly' { + $false | Should -BeTrue -Not:$true + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldContain.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldContain.v5.tests.ps1 new file mode 100644 index 0000000..59851ae --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldContain.v5.tests.ps1 @@ -0,0 +1,158 @@ +Describe 'Should -Contain' { + Context 'When the tests are affirming' { + It 'Should convert `Should -Contain ''b''` correctly' { + @('a', 'b') | Should -Contain 'b' + } + + It 'Should convert `Should -Contain "b"` correctly' { + @('a', 'b') | Should -Contain "b" + } + + It 'Should convert `Should -Contain $anyValue` correctly' { + $anyValue = 'b' + + @('a', 'b') | Should -Contain $anyValue + } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''b'') -Contain ''b''` correctly' { + # Should -ActualValue @('a', 'b') -Contain 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Contain ''b'' -ActualValue @(''a'', ''b'')` correctly' { + # Should -Contain 'b' -ActualValue @('a', 'b') + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''b'') -Contain -ExpectedValue ''b''` correctly' { + # Should -ActualValue @('a', 'b') -Contain -ExpectedValue 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Contain -ActualValue @(''a'', ''b'') -ExpectedValue ''b''` correctly' { + # Should -Contain -ActualValue @('a', 'b') -ExpectedValue 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Contain -ExpectedValue ''b'' -ActualValue @(''a'', ''b'')` correctly' { + # Should -Contain -ExpectedValue 'b' -ActualValue @('a', 'b') + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ExpectedValue ''b'' -Contain -ActualValue @(''a'', ''b'')` correctly' { + # Should -ExpectedValue 'b' -Contain -ActualValue @('a', 'b') + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ExpectedValue ''b'' -ActualValue @(''a'', ''b'') -Contain` correctly' { + # Should -ExpectedValue 'b' -ActualValue @('a', 'b') -Contain + # } + + It 'Should convert `Should -Not:$false -Contain ''b''` correctly' { + @('a', 'b') | Should -Not:$false -Contain 'b' + } + + It 'Should convert `Should -Contain (Get-Something)` correctly' { + function Get-Something + { + return 'b' + } + + @('a', 'b') | Should -Contain (Get-Something) + } + + It 'Should convert `Should -Contain ''b'' -Because ''mock should test correct value''` correctly' { + @('a', 'b') | Should -Contain 'b' -Because 'mock should test correct value' + } + + It 'Should convert `Should -Contain ''b'' ''mock should test correct value''` correctly' { + @('a', 'b') | Should -Contain 'b' 'mock should test correct value' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''b'' ''mock should test correct value'' -Contain` correctly' { + # @('a', 'b') | Should 'b' 'mock should test correct value' -Contain + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -Contain ''b''` correctly' { + @('a', 'c') | Should -Not -Contain 'b' + } + + It 'Should convert `Should -Contain ''Test'' -Not` correctly' { + @('a', 'c') | Should -Contain 'b' -Not + } + + It 'Should convert `Should -Not -Contain "b"` correctly' { + @('a', 'c') | Should -Not -Contain 'b' + } + + It 'Should convert `Should -Not -Contain $anyValue` correctly' { + $anyValue = 'b' + + @('a', 'c') | Should -Not -Contain $anyValue + } + + It 'Should convert `Should -Contain $anyValue -Not` correctly' { + $anyValue = 'b' + + @('a', 'c') | Should -Contain $anyValue -Not + } + + It 'Should convert `Should -Not:$true -Contain ''b''` correctly' { + @('a', 'c') | Should -Not:$true -Contain 'b' + } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Not -ActualValue @(''a'', ''c'') -Contain ''b''` correctly' { + # Should -Not -ActualValue @('a', 'c') -Contain 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''c'') -Not -Contain ''b''` correctly' { + # Should -ActualValue @('a', 'c') -Not -Contain 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''b'') -Contain ''b'' -Not` correctly' { + # Should -ActualValue @('a', 'c') -Contain 'b' -Not + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Contain ''b'' -ActualValue @(''a'', ''c'') -Not` correctly' { + # Should -Contain 'b' -ActualValue @('a', 'c') -Not + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Contain ''b'' -Not -ActualValue @(''a'', ''c'')` correctly' { + # Should -Contain 'b' -Not -ActualValue @('a', 'c') + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -Not -Contain ''b'' -ActualValue @(''a'', ''c'')` correctly' { + # Should -Not -Contain 'b' -ActualValue @('a', 'c') + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''c'') -Contain -Not -ExpectedValue ''b''` correctly' { + # Should -ActualValue @('a', 'c') -Contain -Not -ExpectedValue 'b' + # } + + # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''c'') -Not -Contain -ExpectedValue ''b''` correctly' { + # Should -ActualValue @('a', 'c') -Not -Contain -ExpectedValue 'b' + # } + + # # This is seemingly not supported in Pester v5 to pass an array to -ActualValue. + # It 'Should convert `Should -ActualValue @(''a'', ''c'') -Contain -ExpectedValue ''b'' -Not` correctly' { + # Should -ActualValue @('a', 'c') -Contain -ExpectedValue 'b' -Not + # } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldMatch.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldMatch.v5.tests.ps1 new file mode 100644 index 0000000..94f281d --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldMatch.v5.tests.ps1 @@ -0,0 +1,143 @@ +# TODO: When Pester 6 supports `Should-MatchString` and `Should-NotMatchString` this test should be activated. +Describe 'Should -Match' -Skip:$true { + Context 'When the tests are affirming' { + It 'Should convert `Should -Match ''Test''` correctly' { + 'Test' | Should -Match 'Test' + } + + It 'Should convert `Should -Match "ExpectedString"` correctly' { + 'Test' | Should -Match "Test" + } + + It 'Should convert `Should -Match $anyValue` correctly' { + $anyValue = 'Test' + + 'Test' | Should -Match $anyValue + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -Match ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -Match 'ExpectedString' + } + + It 'Should convert `Should -Match ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -Match 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -Match -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -Match -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -Match -ActualValue ''ExpectedString'' -RegularExpression ''ExpectedString''` correctly' { + Should -Match -ActualValue 'ExpectedString' -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -Match -RegularExpression ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -Match -RegularExpression 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -RegularExpression ''ExpectedString'' -Match -ActualValue ''ExpectedString''` correctly' { + Should -RegularExpression 'ExpectedString' -Match -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -RegularExpression ''ExpectedString'' -ActualValue ''ExpectedString'' -Match` correctly' { + Should -RegularExpression 'ExpectedString' -ActualValue 'ExpectedString' -Match + } + + It 'Should convert `Should -Not:$false -Match ''ExpectedString''` correctly' { + 'ExpectedString' | Should -Not:$false -Match 'ExpectedString' + } + + It 'Should convert `Should -Match (Get-Something)` correctly' { + function Get-Something + { + return 'ExpectedString' + } + + 'ExpectedString' | Should -Match (Get-Something) + } + + It 'Should convert `Should -Match ''ExpectedString'' -Because ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -Match 'ExpectedString' -Because 'mock should test correct value' 'ExpectedString' + } + + It 'Should convert `Should -Match ''ExpectedString'' ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -Match 'ExpectedString' 'mock should test correct value' 'ExpectedString' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' ''mock should test correct value'' ''ExpectedString'' -Match` correctly' { + # Should 'ExpectedString' 'mock should test correct value' 'ExpectedString' -Match + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -Match ''ExpectedString''` correctly' { + 'ActualString' | Should -Not -Match 'ExpectedString' + } + + It 'Should convert `Should -Match ''Test'' -Not` correctly' { + 'ActualString' | Should -Match 'Test' -Not + } + + It 'Should convert `Should -Not -Match "ExpectedString"` correctly' { + 'ActualString' | Should -Not -Match 'ExpectedString' + } + + It 'Should convert `Should -Not -Match $anyValue` correctly' { + $anyValue = 'Test' + + 'ActualString' | Should -Not -Match $anyValue + } + + It 'Should convert `Should -Match $anyValue -Not` correctly' { + $anyValue = 'Test' + + 'ActualString' | Should -Match $anyValue -Not + } + + It 'Should convert `Should -Not:$true -Match ''ExpectedString''` correctly' { + 'ActualString' | Should -Not:$true -Match 'ExpectedString' + } + + It 'Should convert `Should -Not -ActualValue ''ActualString'' -Match ''ExpectedString''` correctly' { + Should -Not -ActualValue 'ActualString' -Match 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -Match ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -Match 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Match ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -Match 'ExpectedString' -Not + } + + It 'Should convert `Should -Match ''ExpectedString'' -ActualValue ''ActualString'' -Not` correctly' { + Should -Match 'ExpectedString' -ActualValue 'ActualString' -Not + } + + It 'Should convert `Should -Match ''ExpectedString'' -Not -ActualValue ''ActualString''` correctly' { + Should -Match 'ExpectedString' -Not -ActualValue 'ActualString' + } + + It 'Should convert `Should -Not -Match ''ExpectedString'' -ActualValue ''ActualString''` correctly' { + Should -Not -Match 'ExpectedString' -ActualValue 'ActualString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Match -Not -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Match -Not -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -Match -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -Match -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Match -RegularExpression ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -Match -RegularExpression 'ExpectedString' -Not + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldMatchExactly.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldMatchExactly.v5.tests.ps1 new file mode 100644 index 0000000..befe6cd --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldMatchExactly.v5.tests.ps1 @@ -0,0 +1,143 @@ +# TODO: When Pester 6 supports `Should-MatchString` and `Should-NotMatchString` this test should be activated. +Describe 'Should -MatchExactly' -Skip:$true { + Context 'When the tests are affirming' { + It 'Should convert `Should -MatchExactly ''Test''` correctly' { + 'Test' | Should -MatchExactly 'Test' + } + + It 'Should convert `Should -MatchExactly "ExpectedString"` correctly' { + 'Test' | Should -MatchExactly "Test" + } + + It 'Should convert `Should -MatchExactly $anyValue` correctly' { + $anyValue = 'Test' + + 'Test' | Should -MatchExactly $anyValue + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -MatchExactly ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -MatchExactly 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ExpectedString'' -MatchExactly -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ExpectedString' -MatchExactly -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly -ActualValue ''ExpectedString'' -RegularExpression ''ExpectedString''` correctly' { + Should -MatchExactly -ActualValue 'ExpectedString' -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly -RegularExpression ''ExpectedString'' -ActualValue ''ExpectedString''` correctly' { + Should -MatchExactly -RegularExpression 'ExpectedString' -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -RegularExpression ''ExpectedString'' -MatchExactly -ActualValue ''ExpectedString''` correctly' { + Should -RegularExpression 'ExpectedString' -MatchExactly -ActualValue 'ExpectedString' + } + + It 'Should convert `Should -RegularExpression ''ExpectedString'' -ActualValue ''ExpectedString'' -MatchExactly` correctly' { + Should -RegularExpression 'ExpectedString' -ActualValue 'ExpectedString' -MatchExactly + } + + It 'Should convert `Should -Not:$false -MatchExactly ''ExpectedString''` correctly' { + 'ExpectedString' | Should -Not:$false -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly (Get-Something)` correctly' { + function Get-Something + { + return 'ExpectedString' + } + + 'ExpectedString' | Should -MatchExactly (Get-Something) + } + + It 'Should convert `Should -MatchExactly ''ExpectedString'' -Because ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -MatchExactly 'ExpectedString' -Because 'mock should test correct value' 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly ''ExpectedString'' ''mock should test correct value'' ''ExpectedString''` correctly' { + Should -MatchExactly 'ExpectedString' 'mock should test correct value' 'ExpectedString' + } + + <# + This was not supported in Pester 5.6.1. There it gave the error message: + + RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5.Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: https://pester.dev/docs/migrations/v3-to-v4 + #> + # It 'Should convert `Should ''ExpectedString'' ''mock should test correct value'' ''ExpectedString'' -MatchExactly` correctly' { + # Should 'ExpectedString' 'mock should test correct value' 'ExpectedString' -MatchExactly + # } + } + + Context 'When the tests are negated' { + It 'Should convert `Should -Not -MatchExactly ''ExpectedString''` correctly' { + 'ActualString' | Should -Not -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -MatchExactly ''Test'' -Not` correctly' { + 'ActualString' | Should -MatchExactly 'Test' -Not + } + + It 'Should convert `Should -Not -MatchExactly "ExpectedString"` correctly' { + 'ActualString' | Should -Not -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -Not -MatchExactly $anyValue` correctly' { + $anyValue = 'Test' + + 'ActualString' | Should -Not -MatchExactly $anyValue + } + + It 'Should convert `Should -MatchExactly $anyValue -Not` correctly' { + $anyValue = 'Test' + + 'ActualString' | Should -MatchExactly $anyValue -Not + } + + It 'Should convert `Should -Not:$true -MatchExactly ''ExpectedString''` correctly' { + 'ActualString' | Should -Not:$true -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -Not -ActualValue ''ActualString'' -MatchExactly ''ExpectedString''` correctly' { + Should -Not -ActualValue 'ActualString' -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -MatchExactly ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -MatchExactly 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -MatchExactly ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -MatchExactly 'ExpectedString' -Not + } + + It 'Should convert `Should -MatchExactly ''ExpectedString'' -ActualValue ''ActualString'' -Not` correctly' { + Should -MatchExactly 'ExpectedString' -ActualValue 'ActualString' -Not + } + + It 'Should convert `Should -MatchExactly ''ExpectedString'' -Not -ActualValue ''ActualString''` correctly' { + Should -MatchExactly 'ExpectedString' -Not -ActualValue 'ActualString' + } + + It 'Should convert `Should -Not -MatchExactly ''ExpectedString'' -ActualValue ''ActualString''` correctly' { + Should -Not -MatchExactly 'ExpectedString' -ActualValue 'ActualString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -MatchExactly -Not -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -MatchExactly -Not -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -Not -MatchExactly -RegularExpression ''ExpectedString''` correctly' { + Should -ActualValue 'ActualString' -Not -MatchExactly -RegularExpression 'ExpectedString' + } + + It 'Should convert `Should -ActualValue ''ActualString'' -MatchExactly -RegularExpression ''ExpectedString'' -Not` correctly' { + Should -ActualValue 'ActualString' -MatchExactly -RegularExpression 'ExpectedString' -Not + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldNotThrow.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldNotThrow.v5.tests.ps1 new file mode 100644 index 0000000..c547d33 --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldNotThrow.v5.tests.ps1 @@ -0,0 +1,41 @@ +Describe 'Should -Not -Throw' { + Context 'When the tests are negated' { + It 'Should convert `Should -Not -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { $null = 1 + 1 }` correctly' { + Should -Not -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' -ActualValue { + $null = 1 + 1 + } + } + + It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage''` correctly' { + { + $null = 1 + 1 + } | Should -Not -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' + } + + It 'Should convert `$scriptBlock | Should -Not -Throw` correctly' { + $scriptBlock = { + $null = 1 + 1 + } + + $scriptBlock | Should -Not -Throw + } + + It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -Because ''BecauseString''` correctly' { + # Intentionally having everything on one line to test the conversion. + { $null = 1 + 1 } | Should -Not -Throw -Because 'BecauseString' + } + + It 'Should convert `{ $null = 1 + 1 } | Should -Not -Throw -Because ''BecauseString'' -ExpectedMessage ''ExpectedString''` correctly' { + # Intentionally splitting over two lines to test the conversion. + { $null = 1 + 1 } | + Should -Not -Throw -Because 'BecauseString' -ExpectedMessage 'ExpectedString' + } + + It 'Should convert `''$null = 1 + 1'' | ForEach-Object { [scriptblock]::Create($_) } | Should -Throw -Not` correctly' { + # Intentionally splitting over three lines to test the conversion. + '$null = 1 + 1' | + ForEach-Object { [scriptblock]::Create($_) } | + Should -Throw -Not + } + } +} diff --git a/tests/Integration/Syntax/v5/ShouldThrow.v5.tests.ps1 b/tests/Integration/Syntax/v5/ShouldThrow.v5.tests.ps1 new file mode 100644 index 0000000..bd7144c --- /dev/null +++ b/tests/Integration/Syntax/v5/ShouldThrow.v5.tests.ps1 @@ -0,0 +1,61 @@ +# TODO: When Pester 6 supports the correct positional parameter for `Should -Throw` this test should be activated. +Describe 'Should -Throw' -Skip:$true { + Context 'When the tests are affirming' { + It 'Should convert `Should -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' }` correctly' { + Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' -ActualValue { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } + } + + It 'Should convert `Should -Throw -Because ''BecauseString'' -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -ExpectedMessage ''MockErrorMessage''` correctly' { + { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } | Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' + } + + It 'Should convert `$scriptBlock | Should -Throw` correctly' { + $scriptBlock = { throw 'mock error' } + + $scriptBlock | Should -Throw + } + + It 'Should convert `{ throw ''myMessage'' } | Should -Throw -Because ''BecauseString''` correctly' { + { throw 'myMessage' } | Should -Throw -Because 'BecauseString' + } + + It 'Should convert `{ throw ''myMessage'' } | Should -Throw -Because ''BecauseString'' -ExpectedMessage ''ExpectedString''` correctly' { + { throw 'myMessage' } | + Should -Throw -Because 'BecauseString' -ExpectedMessage 'myMessage' + } + + It 'Should convert `"throw ''five''" | ForEach-Object { [scriptblock]::Create($_) } | Should -Throw -Not` correctly' { + "throw 'five'" | + ForEach-Object { [scriptblock]::Create($_) } | + Should -Throw + } + + It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId'' ([System.Exception]) ''BecauseString''` correctly' { + { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } | Should -Throw 'MockErrorMessage' 'MockErrorId' ([System.Exception]) 'BecauseString' + } + + It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId'' ([System.Exception])` correctly' { + { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } | Should -Throw 'MockErrorMessage' 'MockErrorId' ([System.Exception]) + } + + It 'Should convert `Should -Throw ''MockErrorMessage'' ''MockErrorId''` correctly' { + { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } | Should -Throw 'MockErrorMessage' 'MockErrorId' + } + + It 'Should convert `Should -Throw ''MockErrorMessage''` correctly' { + { + Write-Error -Message 'MockErrorMessage' -ErrorId 'MockErrorId' -Category 'InvalidOperation' -TargetObject 'MockTargetObject' -ErrorAction 'Stop' + } | Should -Throw 'MockErrorMessage' + } + } +} diff --git a/tests/Unit/Private/Convert-ShouldBe.tests.ps1 b/tests/Unit/Private/Convert-ShouldBe.tests.ps1 index 308bd0a..891a4a8 100644 --- a/tests/Unit/Private/Convert-ShouldBe.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBe.tests.ps1 @@ -499,7 +499,7 @@ Describe 'Convert-ShouldBe' { Context 'When tests should always use positional parameters' { Context 'When the tests are affirming' { - It 'Should convert `Should -Be $true -ActualValue $true` correctly' { + It 'Should convert `Should -Be ''ExpectedString'' -ActualValue ''ActualString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { Should -Be 'ExpectedString' -ActualValue 'ActualString' diff --git a/tests/Unit/Private/Convert-ShouldBeExactly.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeExactly.tests.ps1 index ad0fea7..0fc0bd1 100644 --- a/tests/Unit/Private/Convert-ShouldBeExactly.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeExactly.tests.ps1 @@ -434,7 +434,7 @@ Describe 'Convert-ShouldBeExactly' { } Context 'When alias operator name is used' { - It 'Should convert `Should -EQ $true -ActualValue $true` correctly' { + It 'Should convert `Should -CEQ ''ExpectedString'' -ActualValue ''ActualString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { Should -CEQ 'ExpectedString' -ActualValue 'ActualString' diff --git a/tests/Unit/Private/Convert-ShouldBeFalse.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeFalse.tests.ps1 index 68d6d46..dd07ce0 100644 --- a/tests/Unit/Private/Convert-ShouldBeFalse.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeFalse.tests.ps1 @@ -93,6 +93,19 @@ Describe 'Convert-ShouldBeFalse' { } } + # Test intentionally uses abbreviated parameter name for -ActualValue. + It 'Should convert `Should -BeFalse -Actual $true -Because ''BecauseMockString''` correctly' { + InModuleScope -ScriptBlock { + $mockCommandAstPester5 = { + Should -BeFalse -Actual $true -Because 'BecauseMockString' + }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) + + $result = Convert-ShouldBeFalse -CommandAst $mockCommandAstPester5 + + $result | Should-BeString -CaseSensitive 'Should-BeFalse -Actual $true -Because ''BecauseMockString''' + } + } + It 'Should convert `Should -BeFalse ''BecauseMockString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { @@ -101,7 +114,7 @@ Describe 'Convert-ShouldBeFalse' { $result = Convert-ShouldBeFalse -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalse ''BecauseMockString''' + $result | Should-BeString -CaseSensitive 'Should-BeFalse -Because ''BecauseMockString''' } } @@ -137,7 +150,7 @@ Describe 'Convert-ShouldBeFalse' { $result = Convert-ShouldBeFalse -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalse ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeFalse -Actual $true -Because ''BecauseMockString''' } } @@ -149,7 +162,7 @@ Describe 'Convert-ShouldBeFalse' { $result = Convert-ShouldBeFalse -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalse ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeFalse -Actual $true -Because ''BecauseMockString''' } } @@ -168,7 +181,7 @@ Describe 'Convert-ShouldBeFalse' { It 'Should convert `Should -BeFalse $true -Because ''BecauseMockString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -BeFalse -Because 'BecauseMockString' $true + Should -BeFalse $true -Because 'BecauseMockString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeFalse -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeGreaterOrEqual.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeGreaterOrEqual.tests.ps1 index cdb67da..e1fd47f 100644 --- a/tests/Unit/Private/Convert-ShouldBeGreaterOrEqual.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeGreaterOrEqual.tests.ps1 @@ -168,7 +168,7 @@ Describe 'Convert-ShouldBeGreaterOrEqual' { It 'Should convert `Should -Not:$false -BeGreaterOrEqual 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$false -BeGreaterOrEqual 2 + 3 | Should -Not:$false -BeGreaterOrEqual 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeGreaterOrEqual -CommandAst $mockCommandAstPester5 @@ -279,7 +279,7 @@ Describe 'Convert-ShouldBeGreaterOrEqual' { It 'Should convert `Should -Not:$true -BeGreaterOrEqual 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$true -BeGreaterOrEqual 2 + 1 | Should -Not:$true -BeGreaterOrEqual 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeGreaterOrEqual -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeGreaterThan.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeGreaterThan.tests.ps1 index 82a705c..31f66c1 100644 --- a/tests/Unit/Private/Convert-ShouldBeGreaterThan.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeGreaterThan.tests.ps1 @@ -168,7 +168,7 @@ Describe 'Convert-ShouldBeGreaterThan' { It 'Should convert `Should -Not:$false -BeGreaterThan 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$false -BeGreaterThan 2 + 3 | Should -Not:$false -BeGreaterThan 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 @@ -236,7 +236,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2' } } @@ -248,7 +248,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2' } } @@ -260,7 +260,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan $anyValue' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual $anyValue' } } @@ -272,19 +272,19 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan $anyValue' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual $anyValue' } } It 'Should convert `Should -Not:$true -BeGreaterThan 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$true -BeGreaterThan 2 + 3 | Should -Not:$true -BeGreaterThan 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2' } } @@ -296,7 +296,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -308,7 +308,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -320,7 +320,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -332,7 +332,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -344,7 +344,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -356,7 +356,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 -Actual 3' } } @@ -368,7 +368,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual -Actual 3 -Expected 2' } } @@ -380,7 +380,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual -Actual 3 -Expected 2' } } @@ -392,7 +392,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual -Actual 3 -Expected 2' } } } @@ -485,7 +485,7 @@ Describe 'Convert-ShouldBeGreaterThan' { $result = Convert-ShouldBeGreaterThan -CommandAst $mockCommandAstPester5 -UsePositionalParameters - $result | Should-BeString -CaseSensitive 'Should-BeLessThan 2 3 -Because "this must return true"' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 3 -Because "this must return true"' } } } diff --git a/tests/Unit/Private/Convert-ShouldBeLessOrEqual.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeLessOrEqual.tests.ps1 index a9309ec..bdf21b0 100644 --- a/tests/Unit/Private/Convert-ShouldBeLessOrEqual.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeLessOrEqual.tests.ps1 @@ -168,7 +168,7 @@ Describe 'Convert-ShouldBeLessOrEqual' { It 'Should convert `Should -Not:$false -BeLessOrEqual 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$false -BeLessOrEqual 2 + 2 | Should -Not:$false -BeLessOrEqual 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLessOrEqual -CommandAst $mockCommandAstPester5 @@ -202,27 +202,27 @@ Describe 'Convert-ShouldBeLessOrEqual' { } } - It 'Should convert `Should -BeLessOrEqual 2 ''mock should test correct value'' 3` correctly' { + It 'Should convert `Should -BeLessOrEqual 2 ''mock should test correct value'' 1` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -BeLessOrEqual 2 'mock should test correct value' 3 + Should -BeLessOrEqual 2 'mock should test correct value' 1 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLessOrEqual -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 3 -Because ''mock should test correct value''' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 1 -Because ''mock should test correct value''' } } - It 'Should convert `Should 2 ''mock should test correct value'' 3 -BeLessOrEqual` correctly' { + It 'Should convert `Should 2 ''mock should test correct value'' 1 -BeLessOrEqual` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should 2 'mock should test correct value' 3 -BeLessOrEqual + Should 2 'mock should test correct value' 1 -BeLessOrEqual }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLessOrEqual -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 3 -Because ''mock should test correct value''' + $result | Should-BeString -CaseSensitive 'Should-BeLessThanOrEqual 2 1 -Because ''mock should test correct value''' } } } @@ -279,7 +279,7 @@ Describe 'Convert-ShouldBeLessOrEqual' { It 'Should convert `Should -Not:$true -BeLessOrEqual 2` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$true -BeLessOrEqual 2 + 2 | Should -Not:$true -BeLessOrEqual 2 }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLessOrEqual -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeLessThan.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeLessThan.tests.ps1 index 76d2c94..05202cc 100644 --- a/tests/Unit/Private/Convert-ShouldBeLessThan.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeLessThan.tests.ps1 @@ -236,7 +236,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2' } } @@ -248,7 +248,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2' } } @@ -260,7 +260,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan $anyValue' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual $anyValue' } } @@ -272,7 +272,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan $anyValue' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual $anyValue' } } @@ -284,7 +284,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2' } } @@ -296,7 +296,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -308,7 +308,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -320,7 +320,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -332,7 +332,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -344,7 +344,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -356,7 +356,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 -Actual 3' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 -Actual 3' } } @@ -368,7 +368,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual -Actual 3 -Expected 2' } } @@ -380,7 +380,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual -Actual 3 -Expected 2' } } @@ -392,7 +392,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan -Actual 3 -Expected 2' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual -Actual 3 -Expected 2' } } } @@ -485,7 +485,7 @@ Describe 'Convert-ShouldBeLessThan' { $result = Convert-ShouldBeLessThan -CommandAst $mockCommandAstPester5 -UsePositionalParameters - $result | Should-BeString -CaseSensitive 'Should-BeGreaterThan 2 3 -Because "this must return true"' + $result | Should-BeString -CaseSensitive 'Should-BeGreaterThanOrEqual 2 3 -Because "this must return true"' } } } diff --git a/tests/Unit/Private/Convert-ShouldBeLike.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeLike.tests.ps1 index 903b42d..0fa2b51 100644 --- a/tests/Unit/Private/Convert-ShouldBeLike.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeLike.tests.ps1 @@ -192,7 +192,7 @@ Describe 'Convert-ShouldBeLike' { It 'Should convert `Should -Not:$false -BeLike ''ExpectedString*''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$false -BeLike 'ExpectedString*' + 'TestValue' | Should -Not:$false -BeLike 'ExpectedString*' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLike -CommandAst $mockCommandAstPester5 @@ -315,7 +315,7 @@ Describe 'Convert-ShouldBeLike' { It 'Should convert `Should -Not:$true -BeLike ''ExpectedString*''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$true -BeLike 'ExpectedString*' + 'TestValue' | Should -Not:$true -BeLike 'ExpectedString*' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLike -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeLikeExactly.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeLikeExactly.tests.ps1 index 01d39ad..d8dbbb5 100644 --- a/tests/Unit/Private/Convert-ShouldBeLikeExactly.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeLikeExactly.tests.ps1 @@ -192,7 +192,7 @@ Describe 'Convert-ShouldBeLikeExactly' { It 'Should convert `Should -Not:$false -BeLikeExactly ''ExpectedString*''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$false -BeLikeExactly 'ExpectedString*' + 'TestValue' | Should -Not:$false -BeLikeExactly 'ExpectedString*' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLikeExactly -CommandAst $mockCommandAstPester5 @@ -315,7 +315,7 @@ Describe 'Convert-ShouldBeLikeExactly' { It 'Should convert `Should -Not:$true -BeLikeExactly ''ExpectedString*''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - $false | Should -Not:$true -BeLikeExactly 'ExpectedString*' + 'TestValue' | Should -Not:$true -BeLikeExactly 'ExpectedString*' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeLikeExactly -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeNullOrEmpty.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeNullOrEmpty.tests.ps1 index dec08c2..aaac13f 100644 --- a/tests/Unit/Private/Convert-ShouldBeNullOrEmpty.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeNullOrEmpty.tests.ps1 @@ -101,7 +101,7 @@ Describe 'Convert-ShouldBeNullOrEmpty' { $result = Convert-ShouldBeNullOrEmpty -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalsy ''BecauseMockString''' + $result | Should-BeString -CaseSensitive 'Should-BeFalsy -Because ''BecauseMockString''' } } @@ -137,7 +137,7 @@ Describe 'Convert-ShouldBeNullOrEmpty' { $result = Convert-ShouldBeNullOrEmpty -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalsy ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeFalsy -Actual $true -Because ''BecauseMockString''' } } @@ -149,7 +149,7 @@ Describe 'Convert-ShouldBeNullOrEmpty' { $result = Convert-ShouldBeNullOrEmpty -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeFalsy ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeFalsy -Actual $true -Because ''BecauseMockString''' } } @@ -168,7 +168,7 @@ Describe 'Convert-ShouldBeNullOrEmpty' { It 'Should convert `Should -BeNullOrEmpty $true -Because ''BecauseMockString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -BeNullOrEmpty -Because 'BecauseMockString' $true + Should -BeNullOrEmpty $true -Because 'BecauseMockString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeNullOrEmpty -CommandAst $mockCommandAstPester5 diff --git a/tests/Unit/Private/Convert-ShouldBeOfType.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeOfType.tests.ps1 index 949318a..f42994d 100644 --- a/tests/Unit/Private/Convert-ShouldBeOfType.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeOfType.tests.ps1 @@ -118,10 +118,10 @@ Describe 'Convert-ShouldBeOfType' { } } - It 'Should convert `Should -ActualValue ''AnyString'' -ExpectedValue [System.String] -BeOfType -Because ''BecauseString''` correctly' { + It 'Should convert `Should -ActualValue ''AnyString'' -ExpectedType [System.String] -BeOfType -Because ''BecauseString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -ActualValue 'AnyString' -ExpectedValue [System.String] -BeOfType -Because 'BecauseString' + Should -ActualValue 'AnyString' -ExpectedType [System.String] -BeOfType -Because 'BecauseString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 @@ -142,10 +142,10 @@ Describe 'Convert-ShouldBeOfType' { } } - It 'Should convert `Should -ExpectedValue [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { + It 'Should convert `Should -ExpectedType [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType + Should -ExpectedType [System.String] -ActualValue 'AnyString' -BeOfType }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 @@ -154,10 +154,10 @@ Describe 'Convert-ShouldBeOfType' { } } - It 'Should convert `Should -Not:$false -ExpectedValue [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { + It 'Should convert `Should -Not:$false -ExpectedType [System.String] -ActualValue ''AnyString'' -BeOfType` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -BeOfType -Not:$false -ExpectedValue [System.String] -ActualValue 'AnyString' -BeOfType + Should -Not:$false -ExpectedType [System.String] -ActualValue 'AnyString' -BeOfType }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 @@ -248,10 +248,10 @@ Describe 'Convert-ShouldBeOfType' { Context 'When tests should always use positional parameters' { Context 'When the tests are affirming' { - It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString''` correctly' { + It 'Should convert `Should -BeOfType -ExpectedType ([System.String]) -ActualValue ''AnyString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -HaveType -ExpectedValue ([System.String]) -ActualValue 'AnyString' + Should -BeOfType -ExpectedType ([System.String]) -ActualValue 'AnyString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters @@ -260,10 +260,10 @@ Describe 'Convert-ShouldBeOfType' { } } - It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' { + It 'Should convert `Should -BeOfType -ExpectedType ([System.String]) -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -HaveType -ExpectedValue ([System.String]) -ActualValue 'AnyString' + Should -BeOfType -ExpectedType ([System.String]) -ActualValue 'AnyString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters @@ -274,10 +274,10 @@ Describe 'Convert-ShouldBeOfType' { } Context 'When the tests are negated' { - It 'Should convert `Should -HaveType -ExpectedValue ([System.String]) -Not -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' { + It 'Should convert `Should -BeOfType -ExpectedType ([System.String]) -Not -ActualValue ''AnyString'' -Because ''BecauseString''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -HaveType -ExpectedValue ([System.String]) -Not -ActualValue 'AnyString' -Because 'BecauseString' + Should -BeOfType -ExpectedType ([System.String]) -Not -ActualValue 'AnyString' -Because 'BecauseString' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldBeOfType -CommandAst $mockCommandAstPester5 -UsePositionalParameters diff --git a/tests/Unit/Private/Convert-ShouldBeTrue.tests.ps1 b/tests/Unit/Private/Convert-ShouldBeTrue.tests.ps1 index b0db392..710a784 100644 --- a/tests/Unit/Private/Convert-ShouldBeTrue.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldBeTrue.tests.ps1 @@ -101,7 +101,7 @@ Describe 'Convert-ShouldBeTrue' { $result = Convert-ShouldBeTrue -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeTrue ''BecauseMockString''' + $result | Should-BeString -CaseSensitive 'Should-BeTrue -Because ''BecauseMockString''' } } @@ -137,7 +137,7 @@ Describe 'Convert-ShouldBeTrue' { $result = Convert-ShouldBeTrue -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeTrue ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeTrue -Actual $true -Because ''BecauseMockString''' } } @@ -149,7 +149,7 @@ Describe 'Convert-ShouldBeTrue' { $result = Convert-ShouldBeTrue -CommandAst $mockCommandAstPester5 - $result | Should-BeString -CaseSensitive 'Should-BeTrue ''BecauseMockString'' -Actual $true' + $result | Should-BeString -CaseSensitive 'Should-BeTrue -Actual $true -Because ''BecauseMockString''' } } diff --git a/tests/Unit/Private/Convert-ShouldNotThrow.tests.ps1 b/tests/Unit/Private/Convert-ShouldNotThrow.tests.ps1 index 7565a54..0c3a854 100644 --- a/tests/Unit/Private/Convert-ShouldNotThrow.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldNotThrow.tests.ps1 @@ -74,7 +74,7 @@ Describe 'Convert-ShouldNotThrow' { } } - It 'Should convert `{ Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' } | Should -Not -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExceptionMessage ''MockErrorMessage''` correctly' { + It 'Should convert `{ Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' } | Should -Throw -Because ''BecauseString'' -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -ExpectedMessage ''MockErrorMessage''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { { diff --git a/tests/Unit/Private/Convert-ShouldThrow.tests.ps1 b/tests/Unit/Private/Convert-ShouldThrow.tests.ps1 index b1b2be5..6cf4803 100644 --- a/tests/Unit/Private/Convert-ShouldThrow.tests.ps1 +++ b/tests/Unit/Private/Convert-ShouldThrow.tests.ps1 @@ -120,7 +120,7 @@ Describe 'Convert-ShouldThrow' { It 'Should convert `Should -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage''` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { - Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' + Should -Throw -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -Because 'BecauseString' -ExpectedMessage 'MockErrorMessage' }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) $result = Convert-ShouldThrow -CommandAst $mockCommandAstPester5 @@ -129,7 +129,7 @@ Describe 'Convert-ShouldThrow' { } } - It 'Should convert `Should -Throw -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -Because ''BecauseString'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' }` correctly' { + It 'Should convert `Should -Throw -Because ''BecauseString'' -ExceptionType ([System.Exception]) -ErrorId ''MockErrorId'' -ExpectedMessage ''MockErrorMessage'' -ActualValue { Write-Error -Message ''MockErrorMessage'' -ErrorId ''MockErrorId'' -Category ''InvalidOperation'' -TargetObject ''MockTargetObject'' -ErrorAction ''Stop'' }` correctly' { InModuleScope -ScriptBlock { $mockCommandAstPester5 = { Should -Throw -Because 'BecauseString' -ExceptionType ([System.Exception]) -ErrorId 'MockErrorId' -ExpectedMessage 'MockErrorMessage' -ActualValue { diff --git a/tests/Unit/Private/ConvertTo-ActualParameterName.tests.ps1 b/tests/Unit/Private/ConvertTo-ActualParameterName.tests.ps1 new file mode 100644 index 0000000..11f1801 --- /dev/null +++ b/tests/Unit/Private/ConvertTo-ActualParameterName.tests.ps1 @@ -0,0 +1,92 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies has been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies has not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:moduleName = 'PesterConverter' + + Import-Module -Name $script:moduleName + + $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName + $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName + $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName +} + +AfterAll { + $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') + $PSDefaultParameterValues.Remove('Mock:ModuleName') + $PSDefaultParameterValues.Remove('Should:ModuleName') + + # Unload the module being tested so that it doesn't impact any other tests. + Get-Module -Name $script:moduleName -All | Remove-Module -Force +} + +Describe 'ConvertTo-ActualParameterName' { + It 'Should return the correct parameter name for a valid abbreviation' { + InModuleScope -ScriptBlock { + $result = ConvertTo-ActualParameterName -CommandName 'Should' -NamedParameter 'Actual' + + $result | Should-Be 'ActualValue' + } + } + + It 'Should return the correct parameter name for a actual name' { + InModuleScope -ScriptBlock { + $result = ConvertTo-ActualParameterName -CommandName 'Should' -NamedParameter 'Be' + + $result | Should-Be 'Be' + } + } + + It 'Should throw an error for ambiguous parameter names' { + InModuleScope -ScriptBlock { + $mockErrorMessage = $script:localizedData.AmbiguousNamedParameter -f 'BeL', 'Should' + + { + # Would return BeLessOrEqual, BeLessThan, BeLike, BeLikeExactly which is ambiguous for "BeL". + ConvertTo-ActualParameterName -CommandName 'Should' -NamedParameter 'BeL' + } | Should-Throw -ExceptionMessage $mockErrorMessage + } + } + + It 'Should throw an error for invalid command names' { + InModuleScope -ScriptBlock { + { + ConvertTo-ActualParameterName -CommandName 'InvalidCommand' -NamedParameter 'Actual' + } | Should-Throw + } + } + + It 'Should return an empty result for non-matching parameter names' { + InModuleScope -ScriptBlock { + $mockErrorMessage = $script:localizedData.UnknownNamedParameter -f 'NonExistent', 'Should' + + { + ConvertTo-ActualParameterName -CommandName 'Should' -NamedParameter 'NonExistent' + } | Should-Throw -ExceptionMessage $mockErrorMessage + + $result | Should-BeNull + } + } +} diff --git a/tests/Unit/Private/Get-PesterCommandParameter.Tests.ps1 b/tests/Unit/Private/Get-PesterCommandParameter.Tests.ps1 index c2b7609..6e2348b 100644 --- a/tests/Unit/Private/Get-PesterCommandParameter.Tests.ps1 +++ b/tests/Unit/Private/Get-PesterCommandParameter.Tests.ps1 @@ -168,6 +168,33 @@ Describe 'Get-PesterCommandParameter' { } } + # Test intentionally uses abbreviated parameter name for -ActualValue. + Context 'When the command is `Should ''ExpectedString'' -Be -Actual ''ActualString'' -Not` to be parsed' { + It 'Should return the positional parameters in the correct order' { + InModuleScope -ScriptBlock { + $mockCommandAst = { + Should 'ExpectedString' -Be -Actual 'ActualString' -Not + }.Ast.Find({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $false) + + $result = Get-PesterCommandParameter -CommandAst $mockCommandAst @mockDefaultParameters + + $result | Should-HaveType -Expected ([System.Collections.Hashtable]) + $result | Should-BeEquivalent @{ + ActualValue = @{ + ExtentText = "'ActualString'" + Position = 0 + Positional = $false + } + ExpectedValue = @{ + ExtentText = "'ExpectedString'" + Position = 1 + Positional = $true + } + } + } + } + } + Context 'When the command is `Should -Be $false -Because ''mock should test correct value'' $false` to be parsed' { It 'Should return the positional parameters in the correct order' { InModuleScope -ScriptBlock { diff --git a/tests/Unit/Public/Convert-PesterSyntax.tests.ps1 b/tests/Unit/Public/Convert-PesterSyntax.tests.ps1 index 318fc61..4aaf312 100644 --- a/tests/Unit/Public/Convert-PesterSyntax.tests.ps1 +++ b/tests/Unit/Public/Convert-PesterSyntax.tests.ps1 @@ -952,6 +952,124 @@ Describe 'Convert-PesterSyntax' { } } + Context 'When converting Should -BeLike' { + BeforeAll { + $mockAstExtentText = { + Describe 'Should -BeLike' { + It 'Should -BeLike' { + 'ExpectedString' | Should -BeLike 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $mockScriptFilePath = Join-Path -Path $TestDrive -ChildPath 'Mock.Tests.ps1' + + Set-Content -Path $mockScriptFilePath -Value $mockAstExtentText -Encoding 'utf8' + } + + It 'Should return the correct converted script' { + $mockExpectedConvertedScript = { + + Describe 'Should -BeLike' { + It 'Should -BeLike' { + 'ExpectedString' | Should-BeLikeString 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + + It 'Should return the correct converted script using named parameters' { + $mockExpectedConvertedScript = { + Describe 'Should -BeLike' { + It 'Should -BeLike' { + 'ExpectedString' | Should-BeLikeString -Because 'BecauseString' -Expected 'Expected*' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -UseNamedParameters -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + + It 'Should return the correct converted script using positional parameters' { + $mockExpectedConvertedScript = { + Describe 'Should -BeLike' { + It 'Should -BeLike' { + 'ExpectedString' | Should-BeLikeString 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -UsePositionalParameters -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + } + + Context 'When converting Should -BeLikeExactly' { + BeforeAll { + $mockAstExtentText = { + Describe 'Should -BeLikeExactly' { + It 'Should -BeLikeExactly' { + 'ExpectedString' | Should -BeLikeExactly 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $mockScriptFilePath = Join-Path -Path $TestDrive -ChildPath 'Mock.Tests.ps1' + + Set-Content -Path $mockScriptFilePath -Value $mockAstExtentText -Encoding 'utf8' + } + + It 'Should return the correct converted script' { + $mockExpectedConvertedScript = { + + Describe 'Should -BeLikeExactly' { + It 'Should -BeLikeExactly' { + 'ExpectedString' | Should-BeLikeString -CaseSensitive 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + + It 'Should return the correct converted script using named parameters' { + $mockExpectedConvertedScript = { + Describe 'Should -BeLikeExactly' { + It 'Should -BeLikeExactly' { + 'ExpectedString' | Should-BeLikeString -CaseSensitive -Because 'BecauseString' -Expected 'Expected*' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -UseNamedParameters -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + + It 'Should return the correct converted script using positional parameters' { + $mockExpectedConvertedScript = { + Describe 'Should -BeLikeExactly' { + It 'Should -BeLikeExactly' { + 'ExpectedString' | Should-BeLikeString -CaseSensitive 'Expected*' -Because 'BecauseString' + } + } + }.Ast.GetScriptBlock().ToString() + + $result = Convert-PesterSyntax -Path $mockScriptFilePath -UsePositionalParameters -PassThru + + $result | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace + } + } + Context 'When converting Should -BeIn without a pipeline' { BeforeAll { $mockAstExtentText = { @@ -1143,7 +1261,7 @@ Describe 'Convert-PesterSyntax' { } } - Context 'When saving the converted script back to the file' { + Context 'When saving the converted script back to the original file' { BeforeAll { $mockAstExtentText = { Describe 'Should -Be' { @@ -1174,5 +1292,50 @@ Describe 'Convert-PesterSyntax' { Get-Content -Raw -Path $mockScriptFilePath | Should-BeString -CaseSensitive -Expected $mockExpectedConvertedScript -TrimWhitespace } } + + Context 'When saving the converted script to a different output path' { + BeforeAll { + $mockAstExtentText = { + Describe 'Should -Be' { + It 'Should -Be' { + Should -Be 1 + } + } + }.Ast.GetScriptBlock().ToString() + + $mockScriptFilePath = Join-Path -Path $TestDrive -ChildPath 'Mock.Tests.ps1' + + Set-Content -Path $mockScriptFilePath -Value $mockAstExtentText -Encoding 'utf8' + + # Mock paths for testing + $mockNonExistentPath = Join-Path -Path $TestDrive -ChildPath 'NonExistentPath' + $mockFilePath = Join-Path -Path $TestDrive -ChildPath 'MockFile.txt' + $mockOutputPath = Join-Path -Path $TestDrive -ChildPath 'MockDirectory' + + # Create a mock file + New-Item -Path $mockFilePath -ItemType 'File' -Force | Out-Null + + # Create a mock directory + New-Item -Path $mockOutputPath -ItemType 'Directory' -Force | Out-Null + } + + It 'Should throw an error when the output path does not exist' { + { + Convert-PesterSyntax -Path $mockScriptFilePath -OutputPath $mockNonExistentPath -Force + } | Should -Throw -ErrorId 'CPS0002,Convert-PesterSyntax' + } + + It 'Should throw an error when the output path is not a directory' { + { + Convert-PesterSyntax -Path $mockScriptFilePath -OutputPath $mockFilePath -Force + } | Should-Throw -FullyQualifiedErrorId 'CPS0003,Convert-PesterSyntax' + } + + It 'Should work correctly when the output path is a valid directory' { + $result = Convert-PesterSyntax -Path $mockScriptFilePath -OutputPath $mockOutputPath -Force + + Should-BeNull -Actual $result -Because 'The function should not return anything when saving the converted script to a different output path' + } + } } }