From 15bda773b1b640e51d25228e7fae35ceb5df6a57 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:20:54 -0700 Subject: [PATCH] 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. --- Tests/Engine/GetScriptAnalyzerRule.tests.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 index 8e433d071..422b585bf 100644 --- a/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 +++ b/Tests/Engine/GetScriptAnalyzerRule.tests.ps1 @@ -63,8 +63,13 @@ Describe "Test Name parameters" { It "get Rules with no parameters supplied" { $defaultRules = Get-ScriptAnalyzerRule - $expectedNumRules = 72 - $defaultRules.Count | Should -Be $expectedNumRules + # Dynamically count the expected number of rules from source files + # by finding all C# files with [Export(typeof(I...Rule))] attributes + $rulesRoot = Resolve-Path "$PSScriptRoot/../../Rules" + $expectedNumRules = (Get-ChildItem -Path $rulesRoot -Filter '*.cs' -Recurse | + Select-String -Pattern 'Export\(typeof\s*\(I\w+Rule\)\)' | + Select-Object -ExpandProperty Path -Unique).Count + $defaultRules.Count | Should -Be $expectedNumRules } It "is a positional parameter" {