Skip to content

Commit

Permalink
Unify behavior with the IDEA-based linters in case when baseline file…
Browse files Browse the repository at this point in the history
… is not present.
  • Loading branch information
hybloid committed Apr 30, 2024
1 parent e4cd397 commit 79d60f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions baseline-cli/src/main/kotlin/BaselineCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ internal object BaselineCli {
cliPrinter: (String) -> Unit,
errPrinter: (String) -> Unit
): Int {
if (!Files.exists(baselinePath)) {
errPrinter("Please provide valid baseline report path")
return ERROR_EXIT
}
val baseline: SarifReport
try {
baseline = SarifUtil.readReport(baselinePath) ?: createSarifReport(emptyList())
if (!Files.exists(baselinePath)) {
cliPrinter("Can't find baseline report file: $baselinePath. Baseline will be calculated against empty report.")
baseline = createSarifReport(emptyList())
} else {
baseline = SarifUtil.readReport(baselinePath) ?: createSarifReport(emptyList())
}
} catch (e: JsonSyntaxException) {
errPrinter("Error reading baseline report: ${e.message}")
return ERROR_EXIT
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 @@ -47,8 +47,9 @@ class BaselineCliTest {
}

// Assert
assertEquals(ERROR_EXIT, exitCode)
assertEquals("Please provide valid baseline report path", stderr.toString())
assertEquals(0, exitCode)
assertTrue(stdout.contains("Can't find baseline report file: nonExistentBaselineReport.sarif."))
assertTrue(stderr.contains("Found 2 new problems according to the checks applied"))
}

@Test
Expand Down

0 comments on commit 79d60f5

Please sign in to comment.