private static CFamilySonarWayRulesConfigProvider CreateTestSubject() { var resourcesPath = Path.Combine( Path.GetDirectoryName(typeof(CFamilySonarWayRulesConfigProvider).Assembly.Location), "CFamily", "TestResources", "RulesMetadataCache"); Directory.Exists(resourcesPath).Should().BeTrue($"Test setup error: expected test resources directory does not exist: {resourcesPath}"); var testSubject = new CFamilySonarWayRulesConfigProvider(resourcesPath); return(testSubject); }
public void GetKeyValueOptionsList_UsingRealEmbeddedRulesJson() { var sonarWayProvider = new CFamilySonarWayRulesConfigProvider(CFamilyShared.CFamilyFilesDirectory); var options = CFamilyHelper.GetKeyValueOptionsList(sonarWayProvider.GetRulesConfiguration("cpp")); // QP option CheckHasOption("internal.qualityProfile="); // Check a few known rules with parameters CheckHasOption("ClassComplexity.maximumClassComplexityThreshold=80"); CheckHasOption("S1142.max=3"); CheckHasOption("S1578.format=^[A-Za-z_-][A-Za-z0-9_-]+\\.(c|m|cpp|cc|cxx)$"); options.Count().Should().Be(38); string CheckHasOption(string optionName) { var matches = options.Where(x => x.StartsWith(optionName, StringComparison.InvariantCulture)); matches.Count().Should().Be(1); return(matches.First()); } }