-
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 1 commit
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
170 changes: 170 additions & 0 deletions
170
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,170 @@ | ||
| namespace Microsoft.DevSkim.Tests | ||
| { | ||
| [TestClass] | ||
| public class DevSkimRuleProcessorTests | ||
| { | ||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguage() | ||
| { | ||
| var languages = DevSkimLanguages.LoadEmbedded(); | ||
|
|
||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_BasicSuppression() | ||
| { | ||
| // Test basic suppression generation for C# (inline comment style) | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456"); | ||
|
|
||
| Assert.AreEqual("// DevSkim: ignore DS123456", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_WithDuration() | ||
| { | ||
| // Test suppression with expiration date | ||
| DateTime testDate = DateTime.Now.AddDays(30); | ||
| string expectedDate = testDate.ToString("yyyy-MM-dd"); | ||
|
|
||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456", duration: 30); | ||
|
|
||
| Assert.IsTrue(result.Contains("until")); | ||
| Assert.IsTrue(result.Contains(expectedDate)); | ||
| Assert.IsTrue(result.StartsWith("// DevSkim: ignore DS123456 until")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_WithReviewer() | ||
| { | ||
| // Test suppression with reviewer name | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456", reviewerName: "JohnDoe"); | ||
|
|
||
| Assert.AreEqual("// DevSkim: ignore DS123456 by JohnDoe", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_WithDurationAndReviewer() | ||
| { | ||
| // Test suppression with both duration and reviewer | ||
| DateTime testDate = DateTime.Now.AddDays(15); | ||
| string expectedDate = testDate.ToString("yyyy-MM-dd"); | ||
|
|
||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456", duration: 15, reviewerName: "JaneSmith"); | ||
|
|
||
| Assert.IsTrue(result.Contains($"until {expectedDate}")); | ||
| Assert.IsTrue(result.Contains("by JaneSmith")); | ||
| Assert.IsTrue(result.StartsWith("// DevSkim: ignore DS123456 until")); | ||
| Assert.IsTrue(result.EndsWith(" by JaneSmith")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_MultiLinePreferred() | ||
| { | ||
| // Test multiline comment preference for C# | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456", preferMultiLine: true); | ||
|
|
||
| Assert.IsTrue(result.StartsWith("/* DevSkim: ignore DS123456")); | ||
| Assert.IsTrue(result.EndsWith(" */")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_PythonLanguage() | ||
| { | ||
| // Test Python-style comments | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("python", "DS123456"); | ||
|
|
||
| Assert.AreEqual("# DevSkim: ignore DS123456", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_PythonMultiLine() | ||
| { | ||
| // Test Python multiline (should use prefix/suffix style) | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("python", "DS123456", preferMultiLine: true); | ||
|
|
||
| // Python uses # as both inline and prefix, with \n as suffix for multiline | ||
| Assert.IsTrue(result.StartsWith("# DevSkim: ignore DS123456")); | ||
| Assert.IsTrue(result.EndsWith("\n")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_SQLLanguage() | ||
| { | ||
| // Test SQL-style comments | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("sql", "DS123456"); | ||
|
|
||
| Assert.AreEqual("-- DevSkim: ignore DS123456", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_MultipleRuleIds() | ||
| { | ||
| // Test suppression with multiple rule IDs | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456,DS789012"); | ||
|
|
||
| Assert.AreEqual("// DevSkim: ignore DS123456,DS789012", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_UnsupportedLanguage() | ||
| { | ||
| // Test with a language that doesn't have comment configuration | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("unknownlang", "DS123456"); | ||
|
|
||
| // Should return empty string or basic format depending on implementation | ||
| Assert.IsNotNull(result); | ||
| // The method should handle unknown languages gracefully | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_EmptyRuleId() | ||
| { | ||
| // Test with empty rule ID | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", ""); | ||
|
|
||
| Assert.AreEqual("// DevSkim: ignore ", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_VBLanguage() | ||
| { | ||
| // Test Visual Basic style comments | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("vb", "DS123456"); | ||
|
|
||
| Assert.AreEqual("' DevSkim: ignore DS123456", result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_XMLLanguage() | ||
| { | ||
| // Test XML language | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("xml", "DS123456"); | ||
|
|
||
| Console.WriteLine($"XML suppression result: '{result}'"); | ||
| Assert.AreEqual("<!-- DevSkim: ignore DS123456 -->", result); | ||
|
|
||
| // This test documents the current behavior for XML | ||
| Assert.IsNotNull(result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_NullLanguage() | ||
| { | ||
| // Test with null language parameter | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage(null, "DS123456"); | ||
|
|
||
| Assert.IsNotNull(result); | ||
| // Should handle null gracefully | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GenerateSuppressionByLanguageTest_CustomLanguagesObject() | ||
| { | ||
| // Test with custom languages object | ||
| var customLanguages = DevSkimLanguages.LoadEmbedded(); | ||
| string result = DevSkimRuleProcessor.GenerateSuppressionByLanguage("csharp", "DS123456", languages: customLanguages); | ||
|
|
||
| Assert.AreEqual("// DevSkim: ignore DS123456", 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
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.