Skip to content

Commit

Permalink
Absent issues statistics should be hidden unless flag supplied (#22)
Browse files Browse the repository at this point in the history
* Absent issues should be hidden if flag supplied

* Don't mutate sarif in the test
  • Loading branch information
hybloid authored Apr 18, 2024
1 parent 502f58f commit 054b0fe
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
3 changes: 2 additions & 1 deletion baseline-cli/src/main/kotlin/CommandLineResultsPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class CommandLineResultsPrinter(
val unchanged = resultsCountByBaselineState[Result.BaselineState.UNCHANGED] ?: 0
val new = resultsCountByBaselineState[Result.BaselineState.NEW] ?: 0
val absent = resultsCountByBaselineState[Result.BaselineState.ABSENT] ?: 0
val absentLine = if (includeAbsent) ", ABSENT: $absent" else ""
val groupingMessage =
"Grouping problems according to baseline: UNCHANGED: $unchanged, NEW: $new, ABSENT: $absent"
"Grouping problems according to baseline: UNCHANGED: $unchanged, NEW: $new$absentLine"

val countedProblems = (
results
Expand Down
5 changes: 3 additions & 2 deletions baseline-cli/src/test/kotlin/BaselineCliTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ class BaselineCliTest {
@Test
fun `test include absent false`() {
// Act
assertDoesNotThrow { BaselineCli.process(BaselineOptions(emptySarif, sarif, includeAbsent = false), stdout::append, stderr::append) }
assertDoesNotThrow { BaselineCli.process(BaselineOptions(copySarifFromResources("single.sarif.json"), sarif, includeAbsent = false), stdout::append, stderr::append) }

// Assert
assertFalse(stdout.contains("ABSENT: 2"))
assertFalse(stdout.contains("ABSENT:"))
assertTrue(stdout.contains("UNCHANGED: 1"))
val content = File(emptySarif).readText(charset("UTF-8"))
assertFalse(content.contains("absent"))
}
Expand Down
70 changes: 70 additions & 0 deletions baseline-cli/src/test/resources/single.sarif.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"runs": [
{
"invocations": [
{
"exitCode": 0,
"executionSuccessful": true
}
],
"language": "en-US",
"results": [
{
"ruleId": "IgnoreResultOfCall",
"kind": "fail",
"level": "warning",
"message": {
"text": "Result of 'A.unusedResult()' is ignored",
"markdown": "Result of `A.unusedResult()` is ignored"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "test-module/A.java",
"uriBaseId": "SRCROOT"
},
"region": {
"startLine": 8,
"startColumn": 5,
"charOffset": 163,
"charLength": 12,
"snippet": {
"text": "unusedResult"
},
"sourceLanguage": "JAVA"
},
"contextRegion": {
"startLine": 6,
"startColumn": 1,
"charOffset": 133,
"charLength": 50,
"snippet": {
"text": " }\n unusedResult();\n unusedResult();\n }\n"
}
}
},
"logicalLocations": [
{
"fullyQualifiedName": "testBaseline_ SARIF only",
"kind": "module"
}
]
}
],
"partialFingerprints": {
"equalIndicator/v1": "9ac736b5dae7725e30bdcce141bc6b126bb32f7c9ea9af7678910adc32180a55"
},
"properties": {
"ideaSeverity": "WARNING",
"qodanaSeverity": "High"
}
}
],
"newlineSequences": [
"\r\n",
"\n"
]
}
]
}

0 comments on commit 054b0fe

Please sign in to comment.