-
Notifications
You must be signed in to change notification settings - Fork 501
/
SimpleCLITest.kt
108 lines (94 loc) · 3.56 KB
/
SimpleCLITest.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.pinterest.ktlint
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledOnOs
import org.junit.jupiter.api.condition.OS
@DisabledOnOs(OS.WINDOWS)
@DisplayName("CLI basic checks")
class SimpleCLITest : BaseCLITest() {
@Test
fun `Given CLI argument --help then return the help output`() {
runKtLintCliProcess(
"no-code-style-error",
listOf("--help")
) {
assertNormalExitCode()
assertErrorOutputIsEmpty()
assert(normalOutput.contains("Usage:") && normalOutput.contains("Examples:")) {
"Did not produced help output!\n ${normalOutput.joinToString(separator = "\n")}"
}
}
}
@Test
fun `Given CLI argument --version then return the version information output`() {
runKtLintCliProcess(
"no-code-style-error",
listOf("--version")
) {
assertNormalExitCode()
assertErrorOutputIsEmpty()
val expectedVersion = System.getProperty("ktlint-version")
assert(normalOutput.contains(expectedVersion)) {
"Output did not contain expected $expectedVersion version:\n ${normalOutput.joinToString(separator = "\n")}"
}
}
}
@Test
fun `Given some code without errors then return from lint with normal exit code and no error output`() {
runKtLintCliProcess(
"no-code-style-error"
) {
assertNormalExitCode()
assertErrorOutputIsEmpty()
}
}
@Test
fun `Given some code with an error then return from lint with the error exit code and error output`() {
runKtLintCliProcess(
"too-many-empty-lines"
) {
assertErrorExitCode()
assert(normalOutput.find { it.contains("Needless blank line(s)") } != null) {
"Unexpected output:\n${normalOutput.joinToString(separator = "\n")}"
}
}
}
@Test
fun `Given some code with an error but a glob which does not select the file`() {
runKtLintCliProcess(
"too-many-empty-lines",
listOf("SomeOtherFile.kt")
) {
assertErrorExitCode()
assert(normalOutput.find { it.contains("No files matched [SomeOtherFile.kt]") } != null) {
"Unexpected output:\n${normalOutput.joinToString(separator = "\n")}"
}
}
}
@Test
fun `Given some code with an error which can be autocorrected then return from from with the normal exit code`() {
runKtLintCliProcess(
"too-many-empty-lines",
listOf("-F")
) {
assertNormalExitCode()
// on JDK11+ contains warning about illegal reflective access operation
// assertErrorOutputIsEmpty()
assertSourceFileWasFormatted("Main.kt")
}
}
@Test
fun `Given some code which only contains errors for rules which are disabled via CLI argument --disabled_rules then return from lint with the normal exit code and without error output`() {
runKtLintCliProcess(
"too-many-empty-lines",
listOf("--disabled_rules=no-consecutive-blank-lines,no-empty-first-line-in-method-block")
) {
assertNormalExitCode()
assertThat(normalOutput).doesNotContain(
"no-consecutive-blank-lines",
"no-empty-first-line-in-method-block"
)
}
}
}