Skip to content

Commit 15bda77

Browse files
committed
Dynamically count expected rules in GetScriptAnalyzerRule test
Replace hardcoded rule count with dynamic counting of [Export(typeof(I...Rule))] attributes in C# source files. This prevents the test from breaking every time a new rule is added.
1 parent 520d2aa commit 15bda77

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ Describe "Test Name parameters" {
6363

6464
It "get Rules with no parameters supplied" {
6565
$defaultRules = Get-ScriptAnalyzerRule
66-
$expectedNumRules = 72
67-
$defaultRules.Count | Should -Be $expectedNumRules
66+
# Dynamically count the expected number of rules from source files
67+
# by finding all C# files with [Export(typeof(I...Rule))] attributes
68+
$rulesRoot = Resolve-Path "$PSScriptRoot/../../Rules"
69+
$expectedNumRules = (Get-ChildItem -Path $rulesRoot -Filter '*.cs' -Recurse |
70+
Select-String -Pattern 'Export\(typeof\s*\(I\w+Rule\)\)' |
71+
Select-Object -ExpandProperty Path -Unique).Count
72+
$defaultRules.Count | Should -Be $expectedNumRules
6873
}
6974

7075
It "is a positional parameter" {

0 commit comments

Comments
 (0)