Skip to content

Commit 49f2301

Browse files
committed
Optimise QA tests
1 parent 5650966 commit 49f2301

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

tests/QA/ScriptAnalyzer.Tests.ps1

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ BeforeDiscovery {
6666

6767
$moduleFiles = Get-ChildItem -Path $sourcePath -Recurse -Include @('*.psm1', '*.ps1')
6868

69-
$testCases = @()
70-
71-
foreach ($moduleFile in $moduleFiles)
69+
$testCases = foreach ($moduleFile in $moduleFiles)
7270
{
7371
# Skipping Examples on Linux and macOS as they cannot be parsed.
7472
if (($IsLinux -or $IsMacOs) -and $moduleFile.FullName -match 'Examples')
@@ -90,8 +88,8 @@ BeforeDiscovery {
9088
$escapedRepositoryPath = [System.Text.RegularExpressions.RegEx]::Escape($repositoryPathNormalized)
9189
$relativePath = $moduleFilePathNormalized -replace ($escapedRepositoryPath + '/')
9290

93-
$testCases += @{
94-
ScriptPath = $moduleFile.FullName
91+
@{
92+
ScriptPath = $moduleFile.FullName
9593
RelativePath = $relativePath
9694
}
9795
}
@@ -102,24 +100,21 @@ Describe 'Script Analyzer Rules' {
102100
BeforeAll {
103101
$repositoryPath = Resolve-Path -Path (Join-Path -Path $PSScriptRoot -ChildPath '../..')
104102
$scriptAnalyzerSettingsPath = Join-Path -Path $repositoryPath -ChildPath '.vscode/analyzersettings.psd1'
105-
}
106-
107-
It 'Should pass all PS Script Analyzer rules for file ''<RelativePath>''' -ForEach $testCases {
108-
$pssaError = Invoke-ScriptAnalyzer -Path $ScriptPath -Settings $scriptAnalyzerSettingsPath
109103

110104
$parseErrorTypes = @(
111105
'TypeNotFound'
112106
'RequiresModuleInvalid'
113107
)
108+
}
114109

110+
It 'Should pass all PS Script Analyzer rules for file ''<RelativePath>''' -ForEach $testCases {
115111
# Filter out reported parse errors that is unable to be resolved in source files
116-
$pssaError = $pssaError |
112+
$pssaError = Invoke-ScriptAnalyzer -Path $ScriptPath -Settings $scriptAnalyzerSettingsPath |
117113
Where-Object -FilterScript {
118114
$_.RuleName -notin $parseErrorTypes
119115
}
120116

121-
$report = $pssaError |
122-
Format-Table -AutoSize | Out-String -Width 200
117+
$report = $pssaError | Format-Table -AutoSize | Out-String -Width 200
123118

124119
$pssaError | Should -HaveCount 0 -Because "all script analyzer rules should pass.`r`n`r`n $report`r`n"
125120
}

tests/QA/module.tests.ps1

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,18 @@ BeforeDiscovery {
127127
$allModuleFunctions = & $mut { Get-Command -Module $args[0] -CommandType Function } $script:moduleName
128128

129129
# Build test cases.
130-
$testCasesAllModuleFunction = @()
131-
132-
foreach ($function in $allModuleFunctions)
130+
$testCasesAllModuleFunction = foreach ($function in $allModuleFunctions)
133131
{
134-
$testCasesAllModuleFunction += @{
132+
@{
135133
Name = $function.Name
136134
}
137135
}
138136

139137
$allPublicCommand = (Get-Command -Module $script:moduleName).Name
140138

141-
$testCasesPublicCommand = @()
142-
143-
foreach ($command in $allPublicCommand)
139+
$testCasesPublicCommand = foreach ($command in $allPublicCommand)
144140
{
145-
$testCasesPublicCommand += @{
141+
@{
146142
Name = $command
147143
}
148144
}
@@ -218,9 +214,7 @@ Describe 'Comment-based help structure' -Tags 'helpQuality' {
218214
# Split into lines to check each one
219215
$helpLines = $helpBlock -split "`n"
220216

221-
$invalidDirectives = @()
222-
223-
foreach ($line in $helpLines)
217+
$invalidDirectives = foreach ($line in $helpLines)
224218
{
225219
# Check if line starts with whitespace followed by a period and text
226220
if ($line -match '^\s+\.([a-zA-Z]+)')
@@ -230,7 +224,7 @@ Describe 'Comment-based help structure' -Tags 'helpQuality' {
230224
# Check if it's a valid directive
231225
if ($directive -notin $validDirectives)
232226
{
233-
$invalidDirectives += $directive
227+
$directive
234228
}
235229
}
236230
}

0 commit comments

Comments
 (0)