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.test.util.KtTestUtil
|
||||||
import org.jetbrains.kotlin.util.DummyLogger
|
import org.jetbrains.kotlin.util.DummyLogger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
class FilePathsInKlibTest : CodegenTestCase() {
|
class FilePathsInKlibTest : CodegenTestCase() {
|
||||||
|
|
||||||
@@ -111,90 +112,81 @@ class FilePathsInKlibTest : CodegenTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testStableCompilation() {
|
fun testStableCompilation() {
|
||||||
val testFiles = createTestFiles()
|
withTempDir { dirA ->
|
||||||
|
withTempDir { dirB ->
|
||||||
|
val testFiles = createTestFiles()
|
||||||
|
val configuration = setupEnvironment()
|
||||||
|
|
||||||
val dirAPath = kotlin.io.path.createTempDirectory()
|
configuration.put(CommonConfigurationKeys.KLIB_RELATIVE_PATH_BASES, listOf(dirA.canonicalPath, dirB.canonicalPath))
|
||||||
val dirBPath = kotlin.io.path.createTempDirectory()
|
|
||||||
|
|
||||||
val dirAFile = dirAPath.toFile().also { assert(it.isDirectory) }
|
val moduleA = compileKlib(testFiles, configuration, dirA)
|
||||||
val dirBFile = dirBPath.toFile().also { assert(it.isDirectory) }
|
val moduleB = compileKlib(testFiles, configuration, dirB)
|
||||||
|
|
||||||
try {
|
assertEquals(moduleA.md5(), moduleB.md5())
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testRelativePaths() {
|
fun testRelativePaths() {
|
||||||
val testFiles = createTestFiles()
|
withTempDir { testTempDir ->
|
||||||
val workingPath = kotlin.io.path.createTempDirectory()
|
val testFiles = createTestFiles()
|
||||||
val workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
|
||||||
|
|
||||||
try {
|
|
||||||
val configuration = setupEnvironment()
|
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 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)
|
assertSameElements(modulePaths, dirPaths)
|
||||||
} finally {
|
|
||||||
workingDirFile.deleteRecursively()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testAbsoluteNormalizedPath() {
|
fun testAbsoluteNormalizedPath() {
|
||||||
val testFiles = createTestFiles()
|
withTempDir { testTempDir ->
|
||||||
val workingPath = kotlin.io.path.createTempDirectory()
|
val testFiles = createTestFiles()
|
||||||
val workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
|
||||||
|
|
||||||
try {
|
|
||||||
val configuration = setupEnvironment()
|
val configuration = setupEnvironment()
|
||||||
configuration.put(CommonConfigurationKeys.KLIB_NORMALIZE_ABSOLUTE_PATH, true)
|
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 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)
|
assertSameElements(modulePaths, dirCanonicalPaths)
|
||||||
} finally {
|
|
||||||
workingDirFile.deleteRecursively()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.normalizePath(): String = replace(File.separator, "/")
|
private fun String.normalizePath(): String = replace(File.separator, "/")
|
||||||
|
|
||||||
fun testUnrelatedBase() {
|
fun testUnrelatedBase() {
|
||||||
val testFiles = createTestFiles()
|
withTempDir { testTempDir ->
|
||||||
val workingPath = kotlin.io.path.createTempDirectory()
|
val testFiles = createTestFiles()
|
||||||
val dummyPath = kotlin.io.path.createTempDirectory()
|
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 workingDirFile = workingPath.toFile().also { assert(it.isDirectory) }
|
||||||
val dummyFile = dummyPath.toFile().also { assert(it.isDirectory) }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val configuration = setupEnvironment()
|
f(workingDirFile)
|
||||||
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() })
|
|
||||||
} finally {
|
} finally {
|
||||||
workingDirFile.deleteRecursively()
|
workingDirFile.deleteRecursively()
|
||||||
dummyFile.deleteRecursively()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user