|
|
@ -1,11 +1,10 @@ |
|
|
|
package org.jetbrains.compose.test.tests.integration |
|
|
|
package org.jetbrains.compose.test.tests.integration |
|
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.GradlePluginTestBase |
|
|
|
import org.jetbrains.compose.test.utils.* |
|
|
|
import org.jetbrains.compose.test.utils.assertEqualTextFiles |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.assertNotEqualTextFiles |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.checks |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import kotlin.io.path.Path |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
import java.util.zip.ZipFile |
|
|
|
|
|
|
|
import kotlin.test.* |
|
|
|
|
|
|
|
|
|
|
|
class ResourcesTest : GradlePluginTestBase() { |
|
|
|
class ResourcesTest : GradlePluginTestBase() { |
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -33,72 +32,88 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
file("src/commonMain/composeResources/drawable-ren") |
|
|
|
file("src/commonMain/composeResources/drawable-ren") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
contains unknown qualifier: 'ren'. |
|
|
|
contains unknown qualifier: 'ren'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/drawable-ren").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-ren").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-rUS-en") |
|
|
|
file("src/commonMain/composeResources/drawable-rUS-en") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
Region qualifier must be declared after language: 'en-rUS'. |
|
|
|
Region qualifier must be declared after language: 'en-rUS'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/drawable-rUS-en").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-rUS-en").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-rUS") |
|
|
|
file("src/commonMain/composeResources/drawable-rUS") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
Region qualifier must be used only with language. |
|
|
|
Region qualifier must be used only with language. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/drawable-rUS").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-rUS").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-en-fr") |
|
|
|
file("src/commonMain/composeResources/drawable-en-fr") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
contains repetitive qualifiers: 'en' and 'fr'. |
|
|
|
contains repetitive qualifiers: 'en' and 'fr'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/drawable-en-fr").renameTo( |
|
|
|
file("src/commonMain/composeResources/drawable-en-fr").renameTo( |
|
|
|
file("src/commonMain/composeResources/image") |
|
|
|
file("src/commonMain/composeResources/image") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
Unknown resource type: 'image' |
|
|
|
Unknown resource type: 'image' |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/image").renameTo( |
|
|
|
file("src/commonMain/composeResources/image").renameTo( |
|
|
|
file("src/commonMain/composeResources/files-de") |
|
|
|
file("src/commonMain/composeResources/files-de") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
The 'files' directory doesn't support qualifiers: 'files-de'. |
|
|
|
The 'files' directory doesn't support qualifiers: 'files-de'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/files-de").renameTo( |
|
|
|
file("src/commonMain/composeResources/files-de").renameTo( |
|
|
|
file("src/commonMain/composeResources/strings") |
|
|
|
file("src/commonMain/composeResources/strings") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
Unknown resource type: 'strings'. |
|
|
|
Unknown resource type: 'strings'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("src/commonMain/composeResources/strings").renameTo( |
|
|
|
file("src/commonMain/composeResources/strings").renameTo( |
|
|
|
file("src/commonMain/composeResources/string-us") |
|
|
|
file("src/commonMain/composeResources/string-us") |
|
|
|
) |
|
|
|
) |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
gradle("generateComposeResClass").checks { |
|
|
|
check.logContains(""" |
|
|
|
check.logContains( |
|
|
|
|
|
|
|
""" |
|
|
|
Forbidden directory name 'string-us'! String resources should be declared in 'values/strings.xml'. |
|
|
|
Forbidden directory name 'string-us'! String resources should be declared in 'values/strings.xml'. |
|
|
|
""".trimIndent()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//restore defaults |
|
|
|
//restore defaults |
|
|
@ -111,10 +126,91 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testCopyFontsInAndroidApp(): Unit = with(testProject("misc/commonResources")) { |
|
|
|
fun testFinalArtefacts(): Unit = with(testProject("misc/commonResources")) { |
|
|
|
|
|
|
|
//https://developer.android.com/build/build-variants?utm_source=android-studio#product-flavors |
|
|
|
|
|
|
|
file("build.gradle.kts").appendText(""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kotlin { |
|
|
|
|
|
|
|
js { |
|
|
|
|
|
|
|
browser { |
|
|
|
|
|
|
|
testTask(Action { |
|
|
|
|
|
|
|
enabled = false |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
binaries.executable() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
android { |
|
|
|
|
|
|
|
flavorDimensions += "version" |
|
|
|
|
|
|
|
productFlavors { |
|
|
|
|
|
|
|
create("demo") |
|
|
|
|
|
|
|
create("full") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
""".trimIndent()) |
|
|
|
|
|
|
|
file("src/androidDemoDebug/composeResources/files/platform.txt").writeNewFile("android demo-debug") |
|
|
|
|
|
|
|
file("src/androidDemoRelease/composeResources/files/platform.txt").writeNewFile("android demo-release") |
|
|
|
|
|
|
|
file("src/androidFullDebug/composeResources/files/platform.txt").writeNewFile("android full-debug") |
|
|
|
|
|
|
|
file("src/androidFullRelease/composeResources/files/platform.txt").writeNewFile("android full-release") |
|
|
|
|
|
|
|
file("src/desktopMain/composeResources/files/platform.txt").writeNewFile("desktop") |
|
|
|
|
|
|
|
file("src/jsMain/composeResources/files/platform.txt").writeNewFile("js") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val commonResourcesDir = file("src/commonMain/composeResources") |
|
|
|
|
|
|
|
val commonResourcesFiles = commonResourcesDir.walkTopDown() |
|
|
|
|
|
|
|
.filter { !it.isDirectory && !it.isHidden } |
|
|
|
|
|
|
|
.map { it.relativeTo(commonResourcesDir).invariantSeparatorsPath } |
|
|
|
|
|
|
|
|
|
|
|
gradle("build").checks { |
|
|
|
gradle("build").checks { |
|
|
|
check.taskSuccessful(":copyDebugFontsToAndroidAssets") |
|
|
|
check.taskSuccessful(":copyDemoDebugFontsToAndroidAssets") |
|
|
|
check.taskSuccessful(":copyReleaseFontsToAndroidAssets") |
|
|
|
check.taskSuccessful(":copyDemoReleaseFontsToAndroidAssets") |
|
|
|
|
|
|
|
check.taskSuccessful(":copyFullDebugFontsToAndroidAssets") |
|
|
|
|
|
|
|
check.taskSuccessful(":copyFullReleaseFontsToAndroidAssets") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkAndroidApk("demo", "debug", commonResourcesFiles) |
|
|
|
|
|
|
|
checkAndroidApk("demo", "release", commonResourcesFiles) |
|
|
|
|
|
|
|
checkAndroidApk("full", "debug", commonResourcesFiles) |
|
|
|
|
|
|
|
checkAndroidApk("full", "release", commonResourcesFiles) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val desktopJar = file("build/libs/resources_test-desktop.jar") |
|
|
|
|
|
|
|
assertTrue(desktopJar.exists()) |
|
|
|
|
|
|
|
ZipFile(desktopJar).use { zip -> |
|
|
|
|
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry(res)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
val platformTxt = zip.getEntry("files/platform.txt") |
|
|
|
|
|
|
|
assertNotNull(platformTxt) |
|
|
|
|
|
|
|
val text = zip.getInputStream(platformTxt).readBytes().decodeToString() |
|
|
|
|
|
|
|
assertEquals("desktop", text) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val jsBuildDir = file("build/dist/js/productionExecutable") |
|
|
|
|
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
|
|
|
|
assertTrue(jsBuildDir.resolve(res).exists()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assertEquals("js", jsBuildDir.resolve("files/platform.txt").readText()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun File.writeNewFile(text: String) { |
|
|
|
|
|
|
|
parentFile.mkdirs() |
|
|
|
|
|
|
|
createNewFile() |
|
|
|
|
|
|
|
writeText(text) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun TestProject.checkAndroidApk(flavor: String, type: String, commonResourcesFiles: Sequence<String>) { |
|
|
|
|
|
|
|
val apk = file("build/outputs/apk/$flavor/$type/resources_test-$flavor-$type.apk") |
|
|
|
|
|
|
|
assertTrue(apk.exists()) |
|
|
|
|
|
|
|
ZipFile(apk).use { zip -> |
|
|
|
|
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry(res)) |
|
|
|
|
|
|
|
//todo fix duplicate fonts |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry("assets/font/emptyFont.otf")) |
|
|
|
|
|
|
|
val platformTxt = zip.getEntry("files/platform.txt") |
|
|
|
|
|
|
|
assertNotNull(platformTxt) |
|
|
|
|
|
|
|
val text = zip.getInputStream(platformTxt).readBytes().decodeToString() |
|
|
|
|
|
|
|
assertEquals("android $flavor-$type", text) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -122,7 +218,7 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
fun testUpToDateChecks(): Unit = with(testProject("misc/commonResources")) { |
|
|
|
fun testUpToDateChecks(): Unit = with(testProject("misc/commonResources")) { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
assert(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertTrue(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
check.taskUpToDate(":generateComposeResClass") |
|
|
|
check.taskUpToDate(":generateComposeResClass") |
|
|
@ -136,12 +232,12 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
assert(!file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertFalse(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gradle("prepareKotlinIdeaImport", "-Pcompose.resources.always.generate.accessors=true").checks { |
|
|
|
gradle("prepareKotlinIdeaImport", "-Pcompose.resources.always.generate.accessors=true").checks { |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
assert(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertTrue(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
modifyText("build.gradle.kts") { str -> |
|
|
|
modifyText("build.gradle.kts") { str -> |
|
|
@ -152,7 +248,7 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
check.taskUpToDate(":generateComposeResClass") |
|
|
|
check.taskUpToDate(":generateComposeResClass") |
|
|
|
assert(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertTrue(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
modifyText("build.gradle.kts") { str -> |
|
|
|
modifyText("build.gradle.kts") { str -> |
|
|
@ -163,8 +259,8 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
gradle("prepareKotlinIdeaImport").checks { |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
assert(!file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertFalse(file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assert(file("build/generated/compose/resourceGenerator/kotlin/io/company/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
assertTrue(file("build/generated/compose/resourceGenerator/kotlin/io/company/resources_test/generated/resources/Res.kt").exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -270,7 +366,7 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
gradle("desktopJar").checks { |
|
|
|
gradle("desktopJar").checks { |
|
|
|
check.taskSuccessful(":generateStringFiles") |
|
|
|
check.taskSuccessful(":generateStringFiles") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
check.taskSuccessful(":generateComposeResClass") |
|
|
|
assert(file("src/commonMain/composeResources/values/strings.xml").readLines().size == 513) |
|
|
|
assertEquals(513, file("src/commonMain/composeResources/values/strings.xml").readLines().size) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|