Skip to content

Commit

Permalink
Merge branch 'adam/feat/improve-directory-compare-assertion' into ada…
Browse files Browse the repository at this point in the history
…m/feat/KT-70336/android-integration-tests
  • Loading branch information
adam-enko committed Nov 5, 2024
2 parents 958e662 + 492a055 commit e9a6f7c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.jetbrains.dokka.gradle.utils
import com.github.difflib.DiffUtils
import com.github.difflib.UnifiedDiffUtils
import io.kotest.assertions.fail
import java.io.IOException
import java.nio.file.Path
import kotlin.io.path.*

Expand Down Expand Up @@ -73,8 +74,8 @@ private fun describeFileDifferences(
val expectedFile = expectedDir.resolve(relativePath)
val actualFile = actualDir.resolve(relativePath)

val expectedLines = expectedFile.readLines()
val actualLines = actualFile.readLines()
val expectedLines = expectedFile.readByteLines()
val actualLines = actualFile.readByteLines()

val patch = DiffUtils.diff(expectedLines, actualLines)

Expand All @@ -100,3 +101,20 @@ private fun describeFileDifferences(
*/
private fun Collection<Path>.joinToFormattedList(limit: Int = 10): String =
joinToString("\n", limit = limit) { " - ${it.invariantSeparatorsPathString}" }


/**
* Read lines from a file, leniently.
* Handles text and binary data.
*
* ([kotlin.io.path.readLines] blows up when it reads binary files.)
*/
private fun Path.readByteLines(): List<String> {
try {
inputStream().bufferedReader().use { reader ->
return generateSequence { reader.readLine() }.toList()
}
} catch (e: Exception) {
throw IOException("Could not read lines from $this", e)
}
}

0 comments on commit e9a6f7c

Please sign in to comment.