-
Notifications
You must be signed in to change notification settings - Fork 121
Fix related to XML suppressions not working #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vamsipolavarapu-msft
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
vamsipolavarapu-msft:SuppressionAndProgressBarChanges
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43e9975
Committing changes related XML suppressions not working (https://gith…
vamsipolavarapu 325a1fc
New integration tests for XML suppressions
vamsipolavarapu 09fd8e7
Refactored the tests in DevSkimRuleProcessorTests.cs file
vamsipolavarapu 0e6135c
Cleaned up the unused method GenerateSuppressionByLanguage from the D…
vamsipolavarapu 2004e3f
Update Changelog for version 1.0.67
vamsipolavarapu-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
DevSkim-DotNet/Microsoft.DevSkim.Tests/DevSkimRuleProcessorTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| namespace Microsoft.DevSkim.Tests | ||
| { | ||
| [TestClass] | ||
| public class DevSkimRuleProcessorTests | ||
| { | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", "// DevSkim: ignore DS123456", DisplayName = "C# Basic Suppression")] | ||
| [DataRow("python", "DS123456", "# DevSkim: ignore DS123456", DisplayName = "Python Basic Suppression")] | ||
| [DataRow("sql", "DS123456", "-- DevSkim: ignore DS123456", DisplayName = "SQL Basic Suppression")] | ||
| [DataRow("vb", "DS123456", "' DevSkim: ignore DS123456", DisplayName = "VB Basic Suppression")] | ||
| [DataRow("csharp", "DS123456,DS789012", "// DevSkim: ignore DS123456,DS789012", DisplayName = "Multiple Rule IDs")] | ||
| [DataRow("csharp", "", "// DevSkim: ignore ", DisplayName = "Empty Rule ID")] | ||
| public void GenerateSuppressionByLanguageTest_BasicSuppressions(string language, string ruleId, string expected) | ||
| { | ||
| // Test basic suppression generation for various languages | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId); | ||
| Assert.AreEqual(expected, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", 30, DisplayName = "C# with 30 days duration")] | ||
| [DataRow("python", "DS789012", 15, DisplayName = "Python with 15 days duration")] | ||
| [DataRow("sql", "DS111213", 60, DisplayName = "SQL with 60 days duration")] | ||
| [DataRow("vb", "DS141516", 7, DisplayName = "VB with 7 days duration")] | ||
| public void GenerateSuppressionByLanguageTest_WithDuration(string language, string ruleId, int duration) | ||
| { | ||
| // Test suppression with expiration date | ||
| DateTime testDate = DateTime.Now.AddDays(duration); | ||
| string expectedDate = testDate.ToString("yyyy-MM-dd"); | ||
|
|
||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId, duration: duration); | ||
|
|
||
| Assert.IsTrue(result.Contains("until")); | ||
| Assert.IsTrue(result.Contains(expectedDate)); | ||
| Assert.IsTrue(result.Contains($"ignore {ruleId} until")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", "JohnDoe", "// DevSkim: ignore DS123456 by JohnDoe", DisplayName = "C# with reviewer")] | ||
| [DataRow("python", "DS789012", "JaneSmith", "# DevSkim: ignore DS789012 by JaneSmith", DisplayName = "Python with reviewer")] | ||
| [DataRow("sql", "DS111213", "BobJones", "-- DevSkim: ignore DS111213 by BobJones", DisplayName = "SQL with reviewer")] | ||
| [DataRow("vb", "DS141516", "AliceWilliams", "' DevSkim: ignore DS141516 by AliceWilliams", DisplayName = "VB with reviewer")] | ||
| public void GenerateSuppressionByLanguageTest_WithReviewer(string language, string ruleId, string reviewerName, string expected) | ||
| { | ||
| // Test suppression with reviewer name | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId, reviewerName: reviewerName); | ||
|
|
||
| Assert.AreEqual(expected, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", 15, "JaneSmith", DisplayName = "C# with duration and reviewer")] | ||
| [DataRow("python", "DS789012", 30, "JohnDoe", DisplayName = "Python with duration and reviewer")] | ||
| [DataRow("sql", "DS111213", 7, "BobJones", DisplayName = "SQL with duration and reviewer")] | ||
| [DataRow("vb", "DS141516", 45, "AliceWilliams", DisplayName = "VB with duration and reviewer")] | ||
| public void GenerateSuppressionByLanguageTest_WithDurationAndReviewer(string language, string ruleId, int duration, string reviewerName) | ||
| { | ||
| // Test suppression with both duration and reviewer | ||
| DateTime testDate = DateTime.Now.AddDays(duration); | ||
| string expectedDate = testDate.ToString("yyyy-MM-dd"); | ||
|
|
||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId, duration: duration, reviewerName: reviewerName); | ||
|
|
||
| Assert.IsTrue(result.Contains($"until {expectedDate}")); | ||
| Assert.IsTrue(result.Contains($"by {reviewerName}")); | ||
| Assert.IsTrue(result.Contains($"ignore {ruleId} until")); | ||
| Assert.IsTrue(result.EndsWith($" by {reviewerName}")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", "/*", " */", DisplayName = "C# Multiline")] | ||
| [DataRow("python", "DS123456", "#", "\n", DisplayName = "Python Multiline")] | ||
| public void GenerateSuppressionByLanguageTest_MultiLinePreferred(string language, string ruleId, string expectedStart, string expectedEnd) | ||
| { | ||
| // Test multiline comment preference | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId, preferMultiLine: true); | ||
|
|
||
| Assert.IsTrue(result.StartsWith($"{expectedStart} DevSkim: ignore {ruleId}")); | ||
| Assert.IsTrue(result.EndsWith(expectedEnd)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("xml", "DS123456", "<!-- DevSkim: ignore DS123456 -->", DisplayName = "XML Language")] | ||
| public void GenerateSuppressionByLanguageTest_XMLLanguage(string language, string ruleId, string expected) | ||
| { | ||
| // Test XML-like languages | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId); | ||
|
|
||
| Console.WriteLine($"{language} suppression result: '{result}'"); | ||
| Assert.AreEqual(expected, result); | ||
| Assert.IsNotNull(result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(null, DisplayName = "Null Language")] | ||
| [DataRow("unknownlang", DisplayName = "Unknown Language")] | ||
| public void GenerateSuppressionByLanguageTest_InvalidLanguages(string language) | ||
| { | ||
| // Test with invalid language parameters | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, "DS123456"); | ||
|
|
||
| Assert.IsNotNull(result); | ||
| // Should handle invalid languages gracefully | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("csharp", "DS123456", "// DevSkim: ignore DS123456", DisplayName = "C# with custom languages")] | ||
| [DataRow("python", "DS789012", "# DevSkim: ignore DS789012", DisplayName = "Python with custom languages")] | ||
| [DataRow("sql", "DS111213", "-- DevSkim: ignore DS111213", DisplayName = "SQL with custom languages")] | ||
| public void GenerateSuppressionByLanguageTest_CustomLanguagesObject(string language, string ruleId, string expected) | ||
| { | ||
| // Test with custom languages object | ||
| var customLanguages = DevSkimLanguages.LoadEmbedded(); | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(language, ruleId, languages: customLanguages); | ||
|
|
||
| Assert.AreEqual(expected, result); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.