mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Checkout files with LF line endings on Windows (#3782)
* Use LF line endings in working directory * Ensure LF & CRLF test assertions are OS-independent
This commit is contained in:
8
.gitattributes
vendored
8
.gitattributes
vendored
@@ -1,11 +1,11 @@
|
||||
* text eol=auto
|
||||
* text eol=lf
|
||||
|
||||
*.bat text eol=crlf
|
||||
|
||||
*.css diff=css
|
||||
*.htm eol=lf diff=html
|
||||
*.html eol=lf diff=html
|
||||
*.md eol=lf diff=markdown
|
||||
*.htm diff=html
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
|
||||
*.jar binary
|
||||
*.png binary
|
||||
|
||||
@@ -19,20 +19,38 @@ class KtCompilerTest : Spek({
|
||||
val path = resourceAsPath("/cases")
|
||||
val ktCompiler by memoized(CachingMode.SCOPE) { KtCompiler() }
|
||||
|
||||
it("Kotlin file has extra user data") {
|
||||
val ktFile = ktCompiler.compile(path, path.resolve("Default.kt"))
|
||||
it("Kotlin file with LF line separators has extra user data") {
|
||||
val ktFile = ktCompiler.compile(path, path.resolve("DefaultLf.kt"))
|
||||
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo(System.lineSeparator())
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo("\n")
|
||||
assertThat(ktFile.getUserData(RELATIVE_PATH))
|
||||
.isEqualTo("Default.kt")
|
||||
.isEqualTo("DefaultLf.kt")
|
||||
assertThat(ktFile.getUserData(BASE_PATH))
|
||||
.endsWith("cases")
|
||||
}
|
||||
|
||||
it("Kotlin file does not store extra data for relative path if not provided") {
|
||||
val ktFile = ktCompiler.compile(null, path.resolve("Default.kt"))
|
||||
it("Kotlin file with CRLF line separators has extra user data") {
|
||||
val ktFile = ktCompiler.compile(path, path.resolve("DefaultCrLf.kt"))
|
||||
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo(System.lineSeparator())
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo("\r\n")
|
||||
assertThat(ktFile.getUserData(RELATIVE_PATH))
|
||||
.isEqualTo("DefaultCrLf.kt")
|
||||
assertThat(ktFile.getUserData(BASE_PATH))
|
||||
.endsWith("cases")
|
||||
}
|
||||
|
||||
it("Kotlin file with LF line separators does not store extra data for relative path if not provided") {
|
||||
val ktFile = ktCompiler.compile(null, path.resolve("DefaultLf.kt"))
|
||||
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo("\n")
|
||||
assertThat(ktFile.getUserData(RELATIVE_PATH)).isNull()
|
||||
assertThat(ktFile.getUserData(BASE_PATH)).isNull()
|
||||
}
|
||||
|
||||
it("Kotlin file with CRLF line separators does not store extra data for relative path if not provided") {
|
||||
val ktFile = ktCompiler.compile(null, path.resolve("DefaultCrLf.kt"))
|
||||
|
||||
assertThat(ktFile.getUserData(LINE_SEPARATOR)).isEqualTo("\r\n")
|
||||
assertThat(ktFile.getUserData(RELATIVE_PATH)).isNull()
|
||||
assertThat(ktFile.getUserData(BASE_PATH)).isNull()
|
||||
}
|
||||
|
||||
2
detekt-parser/src/test/resources/cases/.gitattributes
vendored
Normal file
2
detekt-parser/src/test/resources/cases/.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
DefaultLf.kt text eol=lf
|
||||
DefaultCrLf.kt text eol=crlf
|
||||
7
detekt-parser/src/test/resources/cases/DefaultCrLf.kt
Normal file
7
detekt-parser/src/test/resources/cases/DefaultCrLf.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package cases
|
||||
|
||||
/**
|
||||
* A comment
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class DefaultCrLf
|
||||
@@ -4,4 +4,4 @@ package cases
|
||||
* A comment
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class Default
|
||||
class DefaultLf
|
||||
Reference in New Issue
Block a user