/
OutputFacadeSpec.kt
54 lines (48 loc) · 2.18 KB
/
OutputFacadeSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package io.gitlab.arturbosch.detekt.core.reporting
import io.github.detekt.report.html.HtmlOutputReport
import io.github.detekt.report.md.MdOutputReport
import io.github.detekt.report.txt.TxtOutputReport
import io.github.detekt.report.xml.XmlOutputReport
import io.github.detekt.test.utils.StringPrintStream
import io.github.detekt.test.utils.createTempFileForTest
import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.core.DetektResult
import io.gitlab.arturbosch.detekt.core.createNullLoggingSpec
import io.gitlab.arturbosch.detekt.core.tooling.withSettings
import io.gitlab.arturbosch.detekt.test.createFinding
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import java.nio.file.Path
class OutputFacadeSpec {
@Test
fun `Running the output facade with multiple reports`() {
val printStream = StringPrintStream()
val inputPath: Path = resourceAsPath("/cases")
val defaultResult = DetektResult(mapOf("Key" to listOf(createFinding())))
val plainOutputPath = createTempFileForTest("detekt", ".txt")
val htmlOutputPath = createTempFileForTest("detekt", ".html")
val xmlOutputPath = createTempFileForTest("detekt", ".xml")
val mdOutputPath = createTempFileForTest("detekt", ".md")
val spec = createNullLoggingSpec {
project {
inputPaths = listOf(inputPath)
}
reports {
report { "html" to htmlOutputPath }
report { "txt" to plainOutputPath }
report { "xml" to xmlOutputPath }
report { "md" to mdOutputPath }
}
logging {
outputChannel = printStream
}
}
spec.withSettings { OutputFacade(this).run(defaultResult) }
assertThat(printStream.toString()).contains(
"Successfully generated ${TxtOutputReport().name} at $plainOutputPath",
"Successfully generated ${XmlOutputReport().name} at $xmlOutputPath",
"Successfully generated ${HtmlOutputReport().name} at $htmlOutputPath",
"Successfully generated ${MdOutputReport().name} at $mdOutputPath"
)
}
}