Skip to content

Commit

Permalink
Migrate tests to Pester 5 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-hughes authored Oct 7, 2024
1 parent 59d533e commit 825cc8a
Show file tree
Hide file tree
Showing 50 changed files with 4,735 additions and 2,700 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and [#9](https://github.com/dsccommunity/DscResource.AnalyzerRules/issues/9).
### Changed

- Renamed default branch to `main`. Fixes [#12](https://github.com/dsccommunity/DscResource.AnalyzerRules/issues/22).
- Migrate to Pester 5

## [0.2.0] - 2019-11-21

Expand Down
3 changes: 2 additions & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = '4.10.1'
Pester = 'latest'
Plaster = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
'DscResource.Test' = 'latest'
}
31 changes: 19 additions & 12 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ModuleBuildTasks:
- '*.build.Sampler.ib.tasks'
Sampler.GitHubTasks:
- '*.ib.tasks'
DscResource.Test:
- 'Task.*'

TaskHeader: |
param($Path)
Expand Down Expand Up @@ -47,6 +49,7 @@ BuildWorkflow:

test:
- Pester_Tests_Stop_On_Fail
- Convert_Pester_Coverage
- Pester_if_Code_Coverage_Under_Threshold

merge:
Expand All @@ -60,24 +63,28 @@ BuildWorkflow:
# Pester Configuration (Sampler) #
####################################################
Pester:
OutputFormat: NUnitXML
# Will look at every *.ps1 & *.psm1 under ModulePath, excepts when $_.FullName -match (Join-Path $ProjectPath $ExcludeFromCodeCoverageItem)
Configuration:
Run:
Path:
- tests/QA
- tests/Unit
Output:
Verbosity: Detailed
StackTraceVisibility: Full
CIFormat: Auto
CodeCoverage:
CoveragePercentTarget: 80
OutputEncoding: ascii
UseBreakpoints: false
ExcludeFromCodeCoverage:
- tasks
- Template
# Default is to use the tests folder in the project folder or source folder (if present)
# can use it to prioritize: tests/QA, tests/Unit, tests/Integration
Script:
# - tests/QA/module.tests.ps1
# - tests/QA
# - tests/Unit
# - tests/Integration
ExcludeTag:
- helpQuality
Tag:
CodeCoverageThreshold: 80 # Set to 0 to bypass
CodeCoverageOutputFileEncoding: ascii

####################################################
# Code Coverage Configuration #
####################################################
CodeCoverage:
CodeCoverageMergedOutputFile: JaCoCo_coverage.xml # the file that is created for the merged code coverage
CodeCoverageFilePattern: Codecov*.xml # the pattern used to search all pipeline test job artifacts
Expand Down
277 changes: 139 additions & 138 deletions source/Private/Get-LocalizedData.ps1

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions source/Public/Measure-CatchClause.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-CatchClause
Expand All @@ -44,19 +44,19 @@ function Measure-CatchClause

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.CatchClauseOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.CatchClauseOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
}

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.CatchClauseOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.CatchClauseOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.CatchClauseOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.CatchClauseOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-DoUntilStatement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-DoUntilStatement
Expand All @@ -41,19 +41,19 @@ function Measure-DoUntilStatement

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoUntilStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoUntilStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoUntilStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoUntilStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoUntilStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoUntilStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-DoWhileStatement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-DoWhileStatement
Expand All @@ -42,19 +42,19 @@ function Measure-DoWhileStatement

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoWhileStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoWhileStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoWhileStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoWhileStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.DoWhileStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.DoWhileStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-ForEachStatement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-ForEachStatement
Expand All @@ -42,19 +42,19 @@ function Measure-ForEachStatement

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForEachStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForEachStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForEachStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForEachStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForEachStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForEachStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-ForStatement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-ForStatement
Expand All @@ -42,19 +42,19 @@ function Measure-ForStatement

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ForStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.ForStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-FunctionBlockBrace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-FunctionBlockBrace
Expand All @@ -42,19 +42,19 @@ function Measure-FunctionBlockBrace

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.FunctionOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.FunctionOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.FunctionOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.FunctionOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.FunctionOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.FunctionOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
4 changes: 2 additions & 2 deletions source/Public/Measure-Hashtable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Measure-Hashtable
$hashtableLines[-1] -notmatch '\s*}')
{
$script:diagnosticRecord['Extent'] = $hashtable.Extent
$script:diagnosticRecord['Message'] = $localizedData.HashtableShouldHaveCorrectFormat
$script:diagnosticRecord['Message'] = $script:localizedData.HashtableShouldHaveCorrectFormat
$script:diagnosticRecord -as $diagnosticRecordType
}
else
Expand All @@ -61,7 +61,7 @@ function Measure-Hashtable
if ($keyValuePair.Item1.Extent.StartColumnNumber -ne $expectedLineIndent)
{
$script:diagnosticRecord['Extent'] = $hashtable.Extent
$script:diagnosticRecord['Message'] = $localizedData.HashtableShouldHaveCorrectFormat
$script:diagnosticRecord['Message'] = $script:localizedData.HashtableShouldHaveCorrectFormat
$script:diagnosticRecord -as $diagnosticRecordType
break
}
Expand Down
8 changes: 4 additions & 4 deletions source/Public/Measure-IfStatement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.OUTPUTS
[Microsoft.Windows.Powershell.ScriptAnalyzer.Generic.DiagnosticRecord[]]
.NOTES
.NOTES
None
#>
function Measure-IfStatement
Expand All @@ -42,19 +42,19 @@ function Measure-IfStatement

if (Test-StatementOpeningBraceOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.IfStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.IfStatementOpeningBraceNotOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsNotFollowedByNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.IfStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.IfStatementOpeningBraceShouldBeFollowedByNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementOpeningBraceIsFollowedByMoreThanOneNewLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.IfStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.IfStatementOpeningBraceShouldBeFollowedByOnlyOneNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
5 changes: 2 additions & 3 deletions source/Public/Measure-Keyword.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ function Measure-Keyword
foreach ($item in $upperCaseTokens)
{
$script:diagnosticRecord['Extent'] = $item.Extent
$script:diagnosticRecord['Message'] = $localizedData.StatementsContainsUpperCaseLetter -f $item.Text
$script:diagnosticRecord['Message'] = $script:localizedData.StatementsContainsUpperCaseLetter -f $item.Text
$suggestedCorrections = New-Object -TypeName Collections.Generic.List[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]
$splat = @{
Extent = $item.Extent
NewString = $item.Text.ToLower()
Description = ('Replace {0} with {1}' -f ($item.Extent.Text, $item.Extent.Text.ToLower()))
}
$suggestedCorrections.Add((New-SuggestedCorrection @splat)) | Out-Null
$suggestedCorrections.Add($suggestedCorrection) | Out-Null

$script:diagnosticRecord['suggestedCorrections'] = $suggestedCorrections
$script:diagnosticRecord -as $diagnosticRecordType
Expand All @@ -64,7 +63,7 @@ function Measure-Keyword
foreach ($item in $tokenWithNoSpace)
{
$script:diagnosticRecord['Extent'] = $item.Extent
$script:diagnosticRecord['Message'] = $localizedData.OneSpaceBetweenKeywordAndParenthesis
$script:diagnosticRecord['Message'] = $script:localizedData.OneSpaceBetweenKeywordAndParenthesis
$suggestedCorrections = New-Object -TypeName Collections.Generic.List[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]
$splat = @{
Extent = $item.Extent
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Measure-ParamBlock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ function Measure-ParamBlock
{
if (Test-StatementOpeningParenthsesOnSameLine @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ParamBlockNotEmptyParenthesesShouldBeOnNewLine
$script:diagnosticRecord['Message'] = $script:localizedData.ParamBlockNotEmptyParenthesesShouldBeOnNewLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
else
{
if (-not (Test-StatementOpeningParenthsesOnSameLine @testParameters))
{
$script:diagnosticRecord['Message'] = $localizedData.ParamBlockEmptyParenthesesShouldBeOnSameLine
$script:diagnosticRecord['Message'] = $script:localizedData.ParamBlockEmptyParenthesesShouldBeOnSameLine
$script:diagnosticRecord -as $diagnosticRecordType
} # if

if (Test-StatementEmptyParenthsesHasWhitespace @testParameters)
{
$script:diagnosticRecord['Message'] = $localizedData.ParamBlockEmptyParenthesesShouldNotHaveWhitespace
$script:diagnosticRecord['Message'] = $script:localizedData.ParamBlockEmptyParenthesesShouldNotHaveWhitespace
$script:diagnosticRecord -as $diagnosticRecordType
} # if
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Measure-ParameterBlockMandatoryNamedArgument
$value = $NamedAttributeArgumentAst.Argument.SafeGetValue()
if ($value -eq $false)
{
$script:diagnosticRecord['Message'] = $localizedData.ParameterBlockNonMandatoryParameterMandatoryAttributeWrongFormat
$script:diagnosticRecord['Message'] = $script:localizedData.ParameterBlockNonMandatoryParameterMandatoryAttributeWrongFormat

$script:diagnosticRecord -as $script:diagnosticRecordType
}
Expand All @@ -73,7 +73,7 @@ function Measure-ParameterBlockMandatoryNamedArgument

if ($invalidFormat)
{
$script:diagnosticRecord['Message'] = $localizedData.ParameterBlockParameterMandatoryAttributeWrongFormat
$script:diagnosticRecord['Message'] = $script:localizedData.ParameterBlockParameterMandatoryAttributeWrongFormat

$script:diagnosticRecord -as $script:diagnosticRecordType
}
Expand Down
Loading

0 comments on commit 825cc8a

Please sign in to comment.