Refactoring: utility for working with temp directory in FilePathsInKlibTest
This commit is contained in:
committed by
TeamCityServer
parent
0625446449
commit
b28a79f5d0
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.util.DummyLogger
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
||||
class FilePathsInKlibTest : CodegenTestCase() {
|
||||
|
||||
@@ -111,90 +112,81 @@ class FilePathsInKlibTest : CodegenTestCase() {
|
||||
}
|
||||
|
||||
fun testStableCompilation() {
|
||||
val testFiles = createTestFiles()
|
||||
withTempDir { dirA ->
|
||||
withTempDir { dirB ->
|
||||
val testFiles = createTestFiles()
|
||||
val configuration = setupEnvironment()
|
||||
|
||||
val dirAPath = kotlin.io.path.createTempDirectory()
|
||||
val dirBPath = kotlin.io.path.createTempDirectory()
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(dirA.canonicalPath, dirB.canonicalPath))
|
||||
|
||||
val dirAFile = dirAPath.toFile().also { assert(it.isDirectory) }
|
||||
val dirBFile = dirBPath.toFile().also { assert(it.isDirectory) }
|
||||
val moduleA = compileKlib(testFiles, configuration, dirA)
|
||||
val moduleB = compileKlib(testFiles, configuration, dirB)
|
||||
|
||||
try {
|
||||
val configuration = setupEnvironment()
|
||||
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(dirAFile.canonicalPath, dirBFile.canonicalPath))
|
||||
|
||||
val moduleA = compileKlib(testFiles, configuration, dirAFile)
|
||||
val moduleB = compileKlib(testFiles, configuration, dirBFile)
|
||||
|
||||
assertEquals(moduleA.md5(), moduleB.md5())
|
||||
} finally {
|
||||
dirAFile.deleteRecursively()
|
||||
dirBFile.deleteRecursively()
|
||||
assertEquals(moduleA.md5(), moduleB.md5())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testRelativePaths() {
|
||||
val testFiles = createTestFiles()
|
||||
val workingPath = kotlin.io.path.createTempDirectory()
|
||||
val workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
||||
|
||||
try {
|
||||
withTempDir { testTempDir ->
|
||||
val testFiles = createTestFiles()
|
||||
val configuration = setupEnvironment()
|
||||
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(workingDirFile.canonicalPath))
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(testTempDir.canonicalPath))
|
||||
|
||||
val artifact = compileKlib(testFiles, configuration, workingDirFile)
|
||||
val artifact = compileKlib(testFiles, configuration, testTempDir)
|
||||
val modulePaths = artifact.loadKlibFilePaths().map { it.replace("/", File.separator) }
|
||||
val dirPaths = workingDirFile.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.relativeTo(workingDirFile).path }
|
||||
val dirPaths = testTempDir.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.relativeTo(testTempDir).path }
|
||||
|
||||
assertSameElements(modulePaths, dirPaths)
|
||||
} finally {
|
||||
workingDirFile.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
fun testAbsoluteNormalizedPath() {
|
||||
val testFiles = createTestFiles()
|
||||
val workingPath = kotlin.io.path.createTempDirectory()
|
||||
val workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
||||
withTempDir { testTempDir ->
|
||||
val testFiles = createTestFiles()
|
||||
|
||||
try {
|
||||
val configuration = setupEnvironment()
|
||||
configuration.put(CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH, true)
|
||||
|
||||
val artifact = compileKlib(testFiles, configuration, workingDirFile)
|
||||
val artifact = compileKlib(testFiles, configuration, testTempDir)
|
||||
val modulePaths = artifact.loadKlibFilePaths().map { it.replace("/", File.separator) }
|
||||
val dirCanonicalPaths = workingDirFile.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.canonicalPath }
|
||||
val dirCanonicalPaths = testTempDir.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.canonicalPath }
|
||||
|
||||
assertSameElements(modulePaths, dirCanonicalPaths)
|
||||
} finally {
|
||||
workingDirFile.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.normalizePath(): String = replace(File.separator, "/")
|
||||
|
||||
fun testUnrelatedBase() {
|
||||
val testFiles = createTestFiles()
|
||||
val workingPath = kotlin.io.path.createTempDirectory()
|
||||
val dummyPath = kotlin.io.path.createTempDirectory()
|
||||
withTempDir { testTempDir ->
|
||||
val testFiles = createTestFiles()
|
||||
val dummyPath = kotlin.io.path.createTempDirectory()
|
||||
val dummyFile = dummyPath.toFile().also { assert(it.isDirectory) }
|
||||
|
||||
try {
|
||||
val configuration = setupEnvironment()
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(dummyFile.canonicalPath))
|
||||
|
||||
val artifact = compileKlib(testFiles, configuration, testTempDir)
|
||||
val modulePaths = artifact.loadKlibFilePaths()
|
||||
val dirCanonicalPaths = testTempDir.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.canonicalPath }
|
||||
|
||||
assertSameElements(modulePaths.map { it.normalizePath() }, dirCanonicalPaths.map { it.normalizePath() })
|
||||
} finally {
|
||||
dummyFile.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun withTempDir(f: (File) -> Unit) {
|
||||
val workingPath: Path = kotlin.io.path.createTempDirectory()
|
||||
val workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
||||
val dummyFile = dummyPath.toFile().also { assert(it.isDirectory) }
|
||||
|
||||
try {
|
||||
val configuration = setupEnvironment()
|
||||
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(dummyFile.canonicalPath))
|
||||
|
||||
val artifact = compileKlib(testFiles, configuration, workingDirFile)
|
||||
val modulePaths = artifact.loadKlibFilePaths()
|
||||
val dirCanonicalPaths = workingDirFile.listFiles { _, name -> name.endsWith(".kt") }!!.map { it.canonicalPath }
|
||||
|
||||
assertSameElements(modulePaths.map { it.normalizePath() }, dirCanonicalPaths.map { it.normalizePath() })
|
||||
f(workingDirFile)
|
||||
} finally {
|
||||
workingDirFile.deleteRecursively()
|
||||
dummyFile.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user