Skip to content

Commit 1ac13a6

Browse files
committed
Add test for generate android project
1 parent 80ea397 commit 1ac13a6

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

integration/src/main/kotlin/kotlinx/benchmark/integration/GradleTestVersion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package kotlinx.benchmark.integration
22

33
enum class GradleTestVersion(val versionString: String) {
44
v8_0("8.0.2"),
5-
MinSupportedGradleVersion("7.4"),
5+
MinSupportedGradleVersion("7.5"),
66
UnsupportedGradleVersion("7.3"),
77
MinSupportedKotlinVersion("2.0.0"),
88
UnsupportedKotlinVersion("1.9.20"),

integration/src/main/kotlin/kotlinx/benchmark/integration/ProjectBuilder.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@ private fun generateBuildScript(kotlinVersion: String) =
4141
repositories {
4242
$kotlin_repo
4343
maven { url '${System.getProperty("plugin_repo_url")}' }
44+
google()
4445
mavenCentral()
4546
}
4647
dependencies {
4748
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion'
4849
classpath 'org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.5.0-SNAPSHOT'
50+
classpath 'com.android.tools.build:gradle:7.3.1'
4951
}
5052
}
5153
5254
apply plugin: 'kotlin-multiplatform'
5355
apply plugin: 'org.jetbrains.kotlinx.benchmark'
56+
apply plugin: 'com.android.library'
5457
5558
repositories {
5659
$kotlin_repo
5760
maven { url '${System.getProperty("runtime_repo_url")}' }
61+
google()
5862
mavenCentral()
5963
}
6064
""".trimIndent()

integration/src/main/kotlin/kotlinx/benchmark/integration/Runner.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,10 @@ class Runner(
8787
projectDir.resolve("build/benchmarks/${targetName}/sources/kotlinx/benchmark/generated").resolve(filePath)
8888
)
8989
}
90+
91+
fun generatedAndroidDir(targetName: String, targetCompilation: String, filePath: String, fileTestAction: (File) -> Unit) {
92+
fileTestAction(
93+
projectDir.resolve("build/benchmarks/$targetName/$targetCompilation/GeneratedAndroidProject").resolve(filePath)
94+
)
95+
}
9096
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package kotlinx.benchmark.integration
2+
3+
import org.junit.Test
4+
import kotlin.test.assertTrue
5+
6+
class AndroidProjectGeneratorTest: GradleTest() {
7+
private fun testAndroidProjectGeneration(setupBlock: Runner.() -> Unit, checkBlock: Runner.() -> Unit) {
8+
project("source-generation").apply {
9+
setupBlock()
10+
runAndSucceed("androidReleaseBenchmarkGenerate")
11+
checkBlock()
12+
}
13+
}
14+
15+
@Test
16+
fun generateAndroidFromResources() {
17+
testAndroidProjectGeneration(
18+
setupBlock = {
19+
runAndSucceed("setupReleaseAndroidProject")
20+
},
21+
checkBlock = {
22+
generatedAndroidDir("android", "release", "") { generatedAndroidDir ->
23+
assertTrue(generatedAndroidDir.exists(), "Generated Android project does not exist")
24+
}
25+
}
26+
)
27+
}
28+
}

integration/src/test/resources/templates/source-generation/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import org.jetbrains.kotlin.konan.target.KonanTarget
22
import org.jetbrains.kotlin.konan.target.HostManager
33

4+
android {
5+
compileSdk 34
6+
7+
defaultConfig {
8+
minSdk = 29
9+
targetSdk = 34
10+
}
11+
12+
13+
buildTypes {
14+
release {}
15+
}
16+
compileOptions {
17+
sourceCompatibility = JavaVersion.VERSION_1_8
18+
targetCompatibility = JavaVersion.VERSION_1_8
19+
}
20+
}
21+
422
kotlin {
523
jvm { }
624
js { nodejs() }
725
wasm('wasmJs') { d8() }
26+
androidTarget {}
827

928
if (HostManager.hostIsLinux) linuxX64('native')
1029
if (HostManager.hostIsMingw) mingwX64('native')
@@ -25,6 +44,8 @@ kotlin {
2544
}
2645
nativeMain {
2746
}
47+
androidMain {
48+
}
2849
}
2950
}
3051

@@ -34,5 +55,6 @@ benchmark {
3455
register("js")
3556
register("wasmJs")
3657
register("native")
58+
register("android")
3759
}
3860
}

0 commit comments

Comments
 (0)