Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build/tests on Windows #640

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import com.google.common.jimfs.Configuration
import com.google.common.jimfs.Jimfs
import java.nio.file.FileSystem
import java.nio.file.Files
import java.nio.file.Path
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Test

class EditorConfigInternalTest {
private val tempFileSystem = Jimfs.newFileSystem(Configuration.forCurrentPlatform())

private fun FileSystem.normalizedPath(path: String): Path {
val root = rootDirectories.joinToString(separator = "/")
return getPath("$root$path")
}

private fun FileSystem.writeEditorConfigFile(
filePath: String,
content: String
) {
Files.createDirectories(getPath(filePath))
Files.write(getPath("$filePath/.editorconfig"), content.toByteArray())
Files.createDirectories(normalizedPath(filePath))
Files.write(normalizedPath("$filePath/.editorconfig"), content.toByteArray())
}

@After
Expand All @@ -28,7 +34,7 @@ class EditorConfigInternalTest {
fun testParentDirectoryFallback() {
val projectDir = "/projects/project-1"
val projectSubDirectory = "$projectDir/project-1-subdirectory"
Files.createDirectories(tempFileSystem.getPath(projectSubDirectory))
Files.createDirectories(tempFileSystem.normalizedPath(projectSubDirectory))
val editorConfigFiles = arrayOf(
"""
[*]
Expand Down Expand Up @@ -57,7 +63,7 @@ class EditorConfigInternalTest {
tempFileSystem.writeEditorConfigFile(projectDir, editorConfigFileContent)

val editorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(projectSubDirectory)
tempFileSystem.normalizedPath(projectSubDirectory)
)

assertThat(editorConfig?.parent).isNull()
Expand Down Expand Up @@ -106,7 +112,7 @@ class EditorConfigInternalTest {
)

var parsedEditorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(project1Subdirectory)
tempFileSystem.normalizedPath(project1Subdirectory)
)
assertThat(parsedEditorConfig?.parent).isNotNull
assertThat(parsedEditorConfig?.parent?.parent).isNull()
Expand All @@ -119,7 +125,7 @@ class EditorConfigInternalTest {
)

parsedEditorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(project1Dir)
tempFileSystem.normalizedPath(project1Dir)
)
assertThat(parsedEditorConfig?.parent).isNull()
assertThat(parsedEditorConfig?.toMap()).isEqualTo(
Expand All @@ -131,7 +137,7 @@ class EditorConfigInternalTest {
)

parsedEditorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(rootDir)
tempFileSystem.normalizedPath(rootDir)
)
assertThat(parsedEditorConfig?.parent).isNull()
assertThat(parsedEditorConfig?.toMap()).isEqualTo(
Expand Down Expand Up @@ -174,7 +180,7 @@ class EditorConfigInternalTest {
tempFileSystem.writeEditorConfigFile(projectDir, editorconfigFile)

val parsedEditorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(projectDir)
tempFileSystem.normalizedPath(projectDir)
)

assertThat(parsedEditorConfig).isNotNull
Expand All @@ -197,7 +203,7 @@ class EditorConfigInternalTest {
tempFileSystem.writeEditorConfigFile(projectDir, editorconfigFile)

val parsedEditorConfig = EditorConfigInternal.of(
tempFileSystem.getPath(projectDir)
tempFileSystem.normalizedPath(projectDir)
)

assertThat(parsedEditorConfig).isNotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.reporter.plain.internal.Color
import com.pinterest.ktlint.reporter.plain.internal.color
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintStream
import org.assertj.core.api.Assertions.assertThat
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -76,7 +77,7 @@ class PlainReporterTest {
outputColor = outputColor
)
reporter.onLintError(
"/one-fixed-and-one-not.kt",
File.separator + "one-fixed-and-one-not.kt",
LintError(
1, 1, "rule-1",
"<\"&'>"
Expand All @@ -88,12 +89,13 @@ class PlainReporterTest {

// We don't expect class name, or first line to be colored
val expectedOutput =
"/".color(outputColor) +
File.separator.color(outputColor) +
"one-fixed-and-one-not.kt" +
":".color(outputColor) +
"1" +
":1:".color(outputColor) +
" <\"&'>\n"
" <\"&'>" +
System.lineSeparator()

assertEquals(expectedOutput, outputString)
}
Expand Down