Improve exception message for directories comparison in tests
It was unclear what dirs were compared (e.g when rebuilding and comparing caches dirs, it's not obvious which dir is "expected" and which is "actual"). To improve this, compare resulting strings with the placeholder for a root dir first. If the comparison fails, then replace the placeholder with an actual directory and call assertEquals.
This commit is contained in:
+13
-2
@@ -36,6 +36,7 @@ import org.jetbrains.org.objectweb.asm.ClassReader
|
||||
import org.jetbrains.org.objectweb.asm.util.TraceClassVisitor
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.ComparisonFailure
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.util.zip.CRC32
|
||||
@@ -71,7 +72,15 @@ fun assertEqualDirectories(expected: File, actual: File, forgiveExtraFiles: Bool
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertEquals(expectedString, actualString)
|
||||
if (expectedString != actualString) {
|
||||
val message: String? = null
|
||||
throw ComparisonFailure(
|
||||
message,
|
||||
expectedString.replaceFirst(DIR_ROOT_PLACEHOLDER, expected.canonicalPath),
|
||||
actualString.replaceFirst(DIR_ROOT_PLACEHOLDER, actual.canonicalPath)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun File.checksumString(): String {
|
||||
@@ -80,6 +89,8 @@ private fun File.checksumString(): String {
|
||||
return java.lang.Long.toHexString(crc32.value)
|
||||
}
|
||||
|
||||
private const val DIR_ROOT_PLACEHOLDER = "<DIR_ROOT_PLACEHOLDER>"
|
||||
|
||||
private fun getDirectoryString(dir: File, interestingPaths: List<String>): String {
|
||||
val buf = StringBuilder()
|
||||
val p = Printer(buf)
|
||||
@@ -108,7 +119,7 @@ private fun getDirectoryString(dir: File, interestingPaths: List<String>): Strin
|
||||
}
|
||||
|
||||
|
||||
p.println(".")
|
||||
p.println(DIR_ROOT_PLACEHOLDER)
|
||||
addDirContent(dir)
|
||||
|
||||
for (path in interestingPaths) {
|
||||
|
||||
Reference in New Issue
Block a user