Skip to content

Commit

Permalink
Make tests file system agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
joshafeinberg committed Feb 28, 2020
1 parent c48f9c7 commit 58fc19a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class BaselineReporter(val out: PrintStream) : Reporter {
Paths.get("").toAbsolutePath().relativize(File(file).toPath()).toString().replace('\\', '/')
} catch (e: IllegalArgumentException) {
file
}.let { name ->
if (name[0] != '/') {
"/$name"
} else {
name
}
}
out.println(""" <file name="${fileName.escapeXMLAttrValue()}">""")
for ((line, col, ruleId, _) in errList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ package com.pinterest.ktlint.reporter.baseline
import com.pinterest.ktlint.core.LintError
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.nio.file.Paths
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

class BaselineReporterTest {

@Test
fun testReportGeneration() {
val basePath = Paths.get("")
val out = ByteArrayOutputStream()
val reporter = BaselineReporter(PrintStream(out, true))
reporter.onLintError(
"/one-fixed-and-one-not.kt",
"$basePath/one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
"<\"&'>"
),
false
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
"$basePath/one-fixed-and-one-not.kt",
LintError(
2, 1, "rule-2",
"And if you see my friend"
Expand All @@ -30,15 +32,15 @@ class BaselineReporterTest {
)

reporter.onLintError(
"/two-not-fixed.kt",
"$basePath/two-not-fixed.kt",
LintError(
1, 10, "rule-1",
"I thought I would again"
),
false
)
reporter.onLintError(
"/two-not-fixed.kt",
"$basePath/two-not-fixed.kt",
LintError(
2, 20, "rule-2",
"A single thin straight line"
Expand All @@ -47,7 +49,7 @@ class BaselineReporterTest {
)

reporter.onLintError(
"/all-corrected.kt",
"$basePath/all-corrected.kt",
LintError(
1, 1, "rule-1",
"I thought we had more time"
Expand Down

0 comments on commit 58fc19a

Please sign in to comment.