Skip to content

Commit 14d8042

Browse files
🪲 [Fix]: Fix skip when multiple skips are found (#86)
## Description - Fix skip when multiple skips are found ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent fe8b2bf commit 14d8042

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

scripts/tests/PSModule/SourceCode.Tests.ps1

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ Describe 'PSModule - SourceCode tests' {
111111
if ($skipTest.Matches.Count -gt 0) {
112112
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
113113
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NumberOfProcessors test'
114-
continue
114+
} else {
115+
$issues += " - $($_.Path):L$($_.LineNumber)"
115116
}
116-
$issues += " - $($_.Path):L$($_.LineNumber)"
117117
}
118118
}
119119
$issues -join [Environment]::NewLine |
@@ -128,10 +128,10 @@ Describe 'PSModule - SourceCode tests' {
128128
if ($skipTest.Matches.Count -gt 0) {
129129
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
130130
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping Verbose test'
131-
continue
132-
}
133-
Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object {
134-
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
131+
} else {
132+
Select-String -Path $filePath -Pattern '\s(-Verbose(?::\$true)?)\b(?!:\$false)' -AllMatches | ForEach-Object {
133+
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
134+
}
135135
}
136136
}
137137
$issues -join [Environment]::NewLine |
@@ -146,10 +146,10 @@ Describe 'PSModule - SourceCode tests' {
146146
if ($skipTest.Matches.Count -gt 0) {
147147
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
148148
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping OutNull test'
149-
continue
150-
}
151-
Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object {
152-
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
149+
} else {
150+
Select-String -Path $filePath -Pattern 'Out-Null' -AllMatches | ForEach-Object {
151+
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
152+
}
153153
}
154154
}
155155
$issues -join [Environment]::NewLine |
@@ -164,10 +164,10 @@ Describe 'PSModule - SourceCode tests' {
164164
if ($skipTest.Matches.Count -gt 0) {
165165
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
166166
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping NoTernary test'
167-
continue
168-
}
169-
Select-String -Path $filePath -Pattern '(?<!\|)\s+\?\s' -AllMatches | ForEach-Object {
170-
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
167+
} else {
168+
Select-String -Path $filePath -Pattern '(?<!\|)\s+\?\s' -AllMatches | ForEach-Object {
169+
$issues += " - $relativePath`:L$($_.LineNumber) - $($_.Line)"
170+
}
171171
}
172172
}
173173
$issues -join [Environment]::NewLine |
@@ -182,18 +182,18 @@ Describe 'PSModule - SourceCode tests' {
182182
if ($skipTest.Matches.Count -gt 0) {
183183
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
184184
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping LowercaseKeywords test'
185-
continue
186-
}
187-
$errors = $null
188-
$tokens = $null
189-
[System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$tokens, [ref]$errors)
185+
} else {
186+
$errors = $null
187+
$tokens = $null
188+
[System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$tokens, [ref]$errors)
190189

191-
foreach ($token in $tokens) {
192-
$keyword = $token.Text
193-
$lineNumber = $token.Extent.StartLineNumber
194-
$columnNumber = $token.Extent.StartColumnNumber
195-
if (($token.TokenFlags -match 'Keyword') -and ($keyword -cne $keyword.ToLower())) {
196-
$issues += " - $relativePath`:L$lineNumber`:C$columnNumber - $keyword"
190+
foreach ($token in $tokens) {
191+
$keyword = $token.Text
192+
$lineNumber = $token.Extent.StartLineNumber
193+
$columnNumber = $token.Extent.StartColumnNumber
194+
if (($token.TokenFlags -match 'Keyword') -and ($keyword -cne $keyword.ToLower())) {
195+
$issues += " - $relativePath`:L$lineNumber`:C$columnNumber - $keyword"
196+
}
197197
}
198198
}
199199
}
@@ -238,12 +238,12 @@ Describe 'PSModule - SourceCode tests' {
238238
if ($skipTest.Matches.Count -gt 0) {
239239
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
240240
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionCount test'
241-
continue
242-
}
243-
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
244-
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
245-
if ($tokens.count -ne 1) {
246-
$issues += " - $relativePath - $($tokens.Name)"
241+
} else {
242+
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
243+
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
244+
if ($tokens.count -ne 1) {
245+
$issues += " - $relativePath - $($tokens.Name)"
246+
}
247247
}
248248
}
249249
$issues -join [Environment]::NewLine |
@@ -259,12 +259,12 @@ Describe 'PSModule - SourceCode tests' {
259259
if ($skipTest.Matches.Count -gt 0) {
260260
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
261261
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionName test'
262-
continue
263-
}
264-
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
265-
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
266-
if ($tokens.Name -ne $fileName) {
267-
$issues += " - $relativePath - $($tokens.Name)"
262+
} else {
263+
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
264+
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
265+
if ($tokens.Name -ne $fileName) {
266+
$issues += " - $relativePath - $($tokens.Name)"
267+
}
268268
}
269269
}
270270
$issues -join [Environment]::NewLine |
@@ -280,17 +280,17 @@ Describe 'PSModule - SourceCode tests' {
280280
if ($skipTest.Matches.Count -gt 0) {
281281
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
282282
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping CmdletBinding test'
283-
continue
284-
}
285-
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
286-
$tokens = $scriptAst.FindAll({ $true }, $true)
287-
foreach ($token in $tokens) {
288-
if ($token.TypeName.Name -eq 'CmdletBinding') {
289-
$found = $true
283+
} else {
284+
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
285+
$tokens = $scriptAst.FindAll({ $true }, $true)
286+
foreach ($token in $tokens) {
287+
if ($token.TypeName.Name -eq 'CmdletBinding') {
288+
$found = $true
289+
}
290+
}
291+
if (-not $found) {
292+
$issues += " - $relativePath"
290293
}
291-
}
292-
if (-not $found) {
293-
$issues += " - $relativePath"
294294
}
295295
}
296296
$issues -join [Environment]::NewLine |
@@ -306,17 +306,17 @@ Describe 'PSModule - SourceCode tests' {
306306
if ($skipTest.Matches.Count -gt 0) {
307307
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
308308
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping ParamBlock test'
309-
continue
310-
}
311-
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
312-
$tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true)
313-
foreach ($token in $tokens) {
314-
if ($token.count -eq 1) {
315-
$found = $true
309+
} else {
310+
$scriptAst = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
311+
$tokens = $scriptAst.FindAll({ $args[0] -is [System.Management.Automation.Language.ParamBlockAst] }, $true)
312+
foreach ($token in $tokens) {
313+
if ($token.count -eq 1) {
314+
$found = $true
315+
}
316+
}
317+
if (-not $found) {
318+
$issues += " - $relativePath"
316319
}
317-
}
318-
if (-not $found) {
319-
$issues += " - $relativePath"
320320
}
321321
}
322322
$issues -join [Environment]::NewLine |
@@ -358,14 +358,14 @@ Describe 'PSModule - SourceCode tests' {
358358
if ($skipTest.Matches.Count -gt 0) {
359359
$skipReason = $skipTest.Matches.Groups | Where-Object { $_.Name -eq 'Reason' } | Select-Object -ExpandProperty Value
360360
Write-GitHubWarning -Message " - $relativePath - $skipReason" -Title 'Skipping FunctionTest test'
361-
continue
362-
}
363-
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
364-
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
365-
$functionName = $tokens.Name
366-
# If the file contains a function and the function name is not in the test files, add it as an issue.
367-
if ($functionName.count -eq 1 -and $functionsInTestFiles -notcontains $functionName) {
368-
$issues += " - $relativePath - $functionName"
361+
} else {
362+
$Ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$null, [ref]$null)
363+
$tokens = $Ast.FindAll( { $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] } , $true )
364+
$functionName = $tokens.Name
365+
# If the file contains a function and the function name is not in the test files, add it as an issue.
366+
if ($functionName.count -eq 1 -and $functionsInTestFiles -notcontains $functionName) {
367+
$issues += " - $relativePath - $functionName"
368+
}
369369
}
370370
}
371371
$issues -join [Environment]::NewLine |

0 commit comments

Comments
 (0)