[K/N] Added a test for KT-56611
This commit is contained in:
+24
-4
@@ -31,7 +31,7 @@ class CachesAutoBuildTest : AbstractNativeSimpleTest() {
|
|||||||
fun testSimple() {
|
fun testSimple() {
|
||||||
val rootDir = File("$TEST_SUITE_PATH/simple")
|
val rootDir = File("$TEST_SUITE_PATH/simple")
|
||||||
val lib = compileToLibrary(rootDir.resolve("lib"), buildDir)
|
val lib = compileToLibrary(rootDir.resolve("lib"), buildDir)
|
||||||
val main = compileToExecutable(rootDir.resolve("main"), autoCacheFrom = buildDir, lib)
|
val main = compileToExecutable(rootDir.resolve("main"), autoCacheFrom = buildDir, emptyList(), lib)
|
||||||
|
|
||||||
assertTrue(main.executableFile.exists())
|
assertTrue(main.executableFile.exists())
|
||||||
assertTrue(autoCacheDir.resolve(cacheFlavor).resolve("lib").exists())
|
assertTrue(autoCacheDir.resolve(cacheFlavor).resolve("lib").exists())
|
||||||
@@ -43,21 +43,41 @@ class CachesAutoBuildTest : AbstractNativeSimpleTest() {
|
|||||||
val rootDir = File("$TEST_SUITE_PATH/dontCacheUserLib")
|
val rootDir = File("$TEST_SUITE_PATH/dontCacheUserLib")
|
||||||
val externalLib = compileToLibrary(rootDir.resolve("externalLib"), buildDir.resolve("external"))
|
val externalLib = compileToLibrary(rootDir.resolve("externalLib"), buildDir.resolve("external"))
|
||||||
val userLib = compileToLibrary(rootDir.resolve("userLib"), buildDir.resolve("user"), externalLib)
|
val userLib = compileToLibrary(rootDir.resolve("userLib"), buildDir.resolve("user"), externalLib)
|
||||||
val main = compileToExecutable(rootDir.resolve("main"), autoCacheFrom = buildDir.resolve("external"), externalLib, userLib)
|
val main = compileToExecutable(
|
||||||
|
rootDir.resolve("main"),
|
||||||
|
autoCacheFrom = buildDir.resolve("external"), emptyList(),
|
||||||
|
externalLib, userLib
|
||||||
|
)
|
||||||
|
|
||||||
assertTrue(main.executableFile.exists())
|
assertTrue(main.executableFile.exists())
|
||||||
assertTrue(autoCacheDir.resolve(cacheFlavor).resolve("externalLib").exists())
|
assertTrue(autoCacheDir.resolve(cacheFlavor).resolve("externalLib").exists())
|
||||||
assertFalse(autoCacheDir.resolve(cacheFlavor).resolve("userLib").exists())
|
assertFalse(autoCacheDir.resolve(cacheFlavor).resolve("userLib").exists())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compileToExecutable(sourcesDir: File, autoCacheFrom: File, vararg dependencies: KLIB) =
|
@Test
|
||||||
|
@TestMetadata("cacheDirPrioritizesOverAutoCacheDir")
|
||||||
|
fun testCacheDirPrioritizesOverAutoCacheDir() {
|
||||||
|
val rootDir = File("$TEST_SUITE_PATH/simple")
|
||||||
|
val lib = compileToLibrary(rootDir.resolve("lib"), buildDir)
|
||||||
|
val cacheDir = buildDir.resolve("lib_cache")
|
||||||
|
cacheDir.mkdirs()
|
||||||
|
compileToStaticCache(lib, cacheDir)
|
||||||
|
val makePerFileCache = testRunSettings.get<CacheMode>().makePerFileCaches
|
||||||
|
assertTrue(cacheDir.resolve("lib-${if (makePerFileCache) "per-file-cache" else "cache"}").exists())
|
||||||
|
val main = compileToExecutable(rootDir.resolve("main"), autoCacheFrom = buildDir, listOf(cacheDir), lib)
|
||||||
|
|
||||||
|
assertTrue(main.executableFile.exists())
|
||||||
|
assertFalse(autoCacheDir.resolve(cacheFlavor).resolve("lib").exists())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun compileToExecutable(sourcesDir: File, autoCacheFrom: File, cacheDirectories: List<File>, vararg dependencies: KLIB) =
|
||||||
compileToExecutable(
|
compileToExecutable(
|
||||||
sourcesDir,
|
sourcesDir,
|
||||||
freeCompilerArgs = TestCompilerArgs(
|
freeCompilerArgs = TestCompilerArgs(
|
||||||
listOf(
|
listOf(
|
||||||
"-Xauto-cache-from=${autoCacheFrom.absolutePath}",
|
"-Xauto-cache-from=${autoCacheFrom.absolutePath}",
|
||||||
"-Xauto-cache-dir=${autoCacheDir.absolutePath}",
|
"-Xauto-cache-dir=${autoCacheDir.absolutePath}",
|
||||||
)
|
) + cacheDirectories.map { "-Xcache-directory=${it.absolutePath}" }
|
||||||
),
|
),
|
||||||
*dependencies
|
*dependencies
|
||||||
).assertSuccess().resultingArtifact
|
).assertSuccess().resultingArtifact
|
||||||
|
|||||||
+15
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestRunnerType
|
|||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExecutableCompilation
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExecutableCompilation
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExistingDependency
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.ExistingDependency
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.LibraryCompilation
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.LibraryCompilation
|
||||||
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.StaticCacheCompilation
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependency
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependency
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependencyType
|
import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependencyType
|
||||||
@@ -71,6 +72,20 @@ internal fun AbstractNativeSimpleTest.compileToExecutable(
|
|||||||
internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
|
internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
|
||||||
compileToExecutable(testCase, dependencies.asList())
|
compileToExecutable(testCase, dependencies.asList())
|
||||||
|
|
||||||
|
internal fun AbstractNativeSimpleTest.compileToStaticCache(
|
||||||
|
klib: TestCompilationArtifact.KLIB,
|
||||||
|
cacheDir: File,
|
||||||
|
): TestCompilationResult<out TestCompilationArtifact.KLIBStaticCache> {
|
||||||
|
val compilation = StaticCacheCompilation(
|
||||||
|
settings = testRunSettings,
|
||||||
|
freeCompilerArgs = TestCompilerArgs.EMPTY,
|
||||||
|
StaticCacheCompilation.Options.Regular,
|
||||||
|
dependencies = listOf(klib.asLibraryDependency()),
|
||||||
|
expectedArtifact = TestCompilationArtifact.KLIBStaticCache(cacheDir, klib)
|
||||||
|
)
|
||||||
|
return compilation.result
|
||||||
|
}
|
||||||
|
|
||||||
internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleModule(
|
internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleModule(
|
||||||
moduleDir: File?,
|
moduleDir: File?,
|
||||||
freeCompilerArgs: TestCompilerArgs = TestCompilerArgs.EMPTY
|
freeCompilerArgs: TestCompilerArgs = TestCompilerArgs.EMPTY
|
||||||
|
|||||||
Reference in New Issue
Block a user