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:
Matthew Haughton
2021-05-17 05:37:24 +10:00
committed by GitHub
parent 6a92af522c
commit 9f364d8a71
5 changed files with 39 additions and 12 deletions

8
.gitattributes vendored
View File

@@ -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

View File

@@ -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()
}

View File

@@ -0,0 +1,2 @@
DefaultLf.kt text eol=lf
DefaultCrLf.kt text eol=crlf

View File

@@ -0,0 +1,7 @@
package cases
/**
* A comment
*/
@Suppress("Unused")
class DefaultCrLf

View File

@@ -4,4 +4,4 @@ package cases
* A comment
*/
@Suppress("Unused")
class Default
class DefaultLf