public static IEnumerable GetTests()

in src/Analyzer.Core.BuiltInRuleTests/TestRunner.cs [72:122]


        public static IEnumerable<object[]> GetTests()
        {
            var testDirectories = Directory.GetDirectories("Tests");
            foreach (var testDirectoryName in testDirectories)
            {
                var ruleId = testDirectoryName.Split(Path.DirectorySeparatorChar)[^1];
                var testConfigFile = Path.Combine(testDirectoryName, ruleId + ".json");

                if (!File.Exists(testConfigFile))
                {
                    yield return InvalidTestConfig(testDirectoryName, "Directory and inner test configuration file must both be named the same as the RuleId being tested.");
                    continue;
                }

                TestConfiguration[] tests = null;
                string errorMessage = null;

                try
                {
                    tests = JsonConvert.DeserializeObject<TestConfiguration[]>(File.ReadAllText(testConfigFile));
                }
                catch (Exception e)
                {
                    errorMessage = e.Message;
                }

                if (errorMessage != null)
                {
                    // yield return is not allowed inside a catch block.
                    yield return InvalidTestConfig(testDirectoryName, errorMessage);
                    continue;
                }
                
                foreach (var test in tests)
                {
                    if (string.IsNullOrEmpty(test.Template) || test.ReportedFailures == null)
                    {
                        yield return InvalidTestConfig(testDirectoryName,
                            test.ReportedFailures == null
                            ? "No reported failures were specified.  If no failures are expected, assign an empty array to ReportedFailures property."
                            : "No template file was specified to analyze - make sure the 'Template' property is set in the test config.");
                        continue;
                    }

                    test.DisplayName = $"{ruleId} - {test.Template}";
                    test.RuleId = ruleId;
                    test.Template = Path.Combine(testDirectoryName, test.Template);
                    yield return new object[] { test };
                }
            }
        }