Skip to content

Commit

Permalink
chore: Cleanup code (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju authored Jul 12, 2024
1 parent e973c82 commit a6f3855
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 77 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Public commands:
- `Convert-PesterSyntax`

### Fixed

- Improve code to resolve ScriptAnalyzer warnings and errors.
- Localize all the strings.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PesterConverter

Commands ta convert Pester tests.
Commands to convert Pester tests.

[![Build Status](https://dev.azure.com/viscalyx/PesterConverter/_apis/build/status/viscalyx.PesterConverter?branchName=main)](https://dev.azure.com/viscalyx/PesterConverter/_build/latest?definitionId=33&branchName=main)
![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/viscalyx/PesterConverter/33/main)
Expand Down
2 changes: 1 addition & 1 deletion source/PesterConverter.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Copyright = 'Copyright the PesterConverter contributors. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Commands ta convert Pester tests.'
Description = 'Commands to convert Pester tests.'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.0'
Expand Down
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Convert-ShouldBe

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -83,7 +83,7 @@ function Convert-ShouldBe
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -196,7 +196,7 @@ function Convert-ShouldBe
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBeExactly.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Convert-ShouldBeExactly

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -83,7 +83,7 @@ function Convert-ShouldBeExactly
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -199,7 +199,7 @@ function Convert-ShouldBeExactly
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBeFalse.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Convert-ShouldBeFalse

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -84,7 +84,7 @@ function Convert-ShouldBeFalse
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -174,7 +174,7 @@ function Convert-ShouldBeFalse
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBeNullOrEmpty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Convert-ShouldBeNullOrEmpty

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -92,7 +92,7 @@ function Convert-ShouldBeNullOrEmpty
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -182,7 +182,7 @@ function Convert-ShouldBeNullOrEmpty
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBeOfType.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Convert-ShouldBeOfType

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -96,7 +96,7 @@ function Convert-ShouldBeOfType
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -221,7 +221,7 @@ function Convert-ShouldBeOfType
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldBeTrue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Convert-ShouldBeTrue

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -87,7 +87,7 @@ function Convert-ShouldBeTrue
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -177,7 +177,7 @@ function Convert-ShouldBeTrue
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldContain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function Convert-ShouldContain

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -82,7 +82,7 @@ function Convert-ShouldContain
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -196,7 +196,7 @@ function Convert-ShouldContain
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldMatch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function Convert-ShouldMatch

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -84,7 +84,7 @@ function Convert-ShouldMatch
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -196,7 +196,7 @@ function Convert-ShouldMatch
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldMatchExactly.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Convert-ShouldMatchExactly

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -83,7 +83,7 @@ function Convert-ShouldMatchExactly
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -199,7 +199,7 @@ function Convert-ShouldMatchExactly
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldNotThrow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function Convert-ShouldNotThrow

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -89,7 +89,7 @@ function Convert-ShouldNotThrow
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

if ($isNegated)
{
Expand All @@ -114,7 +114,7 @@ function Convert-ShouldNotThrow
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
6 changes: 3 additions & 3 deletions source/Private/Convert-ShouldThrow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Convert-ShouldThrow

Assert-BoundParameter @assertBoundParameterParameters

Write-Debug -Message ('Parsing the command AST: {0}' -f $CommandAst.Extent.Text)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ParsingCommandAst -f $CommandAst.Extent.Text)

# Determine if the command is negated
$isNegated = Test-PesterCommandNegated -CommandAst $CommandAst
Expand All @@ -94,7 +94,7 @@ function Convert-ShouldThrow
# Parse the command elements and convert them to Pester 6 syntax
if ($PSCmdlet.ParameterSetName -eq 'Pester6')
{
Write-Debug -Message ('Converting from Pester v{0} to Pester v6 syntax.' -f $sourceSyntaxVersion)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertingFromTo -f $sourceSyntaxVersion, '6')

# Add the correct Pester command based on negation
if ($isNegated)
Expand Down Expand Up @@ -235,7 +235,7 @@ function Convert-ShouldThrow
}
}

Write-Debug -Message ('Converted the command `{0}` to `{1}`.' -f $CommandAst.Extent.Text, $newExtentText)
Write-Debug -Message ($script:localizedData.Convert_Should_Debug_ConvertedCommand -f $CommandAst.Extent.Text, $newExtentText)

return $newExtentText
}
10 changes: 1 addition & 9 deletions source/Private/Get-AstDefinition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
Retrieves the ScriptBlockAst definition of the 'Script.ps1' file.
.EXAMPLE
'C:\Scripts\Script.ps1' | Get-AstDefinition
Retrieves the ScriptBlockAst definition of the 'Script.ps1' file using
pipeline input.
.EXAMPLE
Get-ChildItem -Path './scripts' | Get-AstDefinition
Get-AstDefinition -Path (Get-ChildItem -Path './scripts')
Retrieves the ScriptBlockAst definition of all the files in the path pass
as pipeline input.
Expand All @@ -53,8 +47,6 @@ function Get-AstDefinition
{
$tokens, $parseErrors = $null

Write-Verbose -Message "Parsing the script file: $filePath"

[System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref] $tokens, [ref] $parseErrors)

if ($parseErrors)
Expand Down
4 changes: 2 additions & 2 deletions source/Private/Get-CommandAst.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Specifies the PowerShell command for which to retrieve the AST.
.EXAMPLE
Get-CommandAst -Command 'Should'
Get-CommandAst -CommandName 'Should'
This example retrieves the AST of the 'Should' command.
Expand Down Expand Up @@ -45,7 +45,7 @@ function Get-CommandAst

process
{
Write-Verbose -Message "Retrieving the AST of the command: $CommandName"
Write-Debug -Message ($script:localizedData.Get_CommandAst_Debug_RetrievingCommandAsts -f $CommandName)

$commandAsts = $Ast.FindAll({
param
Expand Down
Loading

0 comments on commit a6f3855

Please sign in to comment.