Skip to content

Commit df57148

Browse files
committed
Add test for generate android project
1 parent f65b105 commit df57148

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-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
@@ -51,20 +51,24 @@ private fun generateBuildScript(kotlinVersion: String, jvmToolchain: Int) =
5151
repositories {
5252
$kotlin_repo
5353
$plugin_repo_url
54+
google()
5455
mavenCentral()
5556
}
5657
dependencies {
5758
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion'
5859
classpath 'org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.5.0-SNAPSHOT'
60+
classpath 'com.android.tools.build:gradle:7.3.1'
5961
}
6062
}
6163
6264
apply plugin: 'kotlin-multiplatform'
6365
apply plugin: 'org.jetbrains.kotlinx.benchmark'
66+
apply plugin: 'com.android.library'
6467
6568
repositories {
6669
$kotlin_repo
6770
$runtime_repo_url
71+
google()
6872
mavenCentral()
6973
}
7074

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,10 @@ class Runner(
9393
projectDir.resolve("build/benchmarks/${targetName}/sources/kotlinx/benchmark/generated").resolve(filePath)
9494
)
9595
}
96+
97+
fun generatedAndroidDir(targetName: String, targetCompilation: String, filePath: String, fileTestAction: (File) -> Unit) {
98+
fileTestAction(
99+
projectDir.resolve("build/benchmarks/$targetName/$targetCompilation/GeneratedAndroidProject").resolve(filePath)
100+
)
101+
}
96102
}
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: 20 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
wasmJs { d8() }
26+
androidTarget {}
827

928
if (HostManager.hostIsLinux) linuxX64('native')
1029
if (HostManager.hostIsMingw) mingwX64('native')
@@ -18,5 +37,6 @@ benchmark {
1837
register("js")
1938
register("wasmJs")
2039
register("native")
40+
register("android")
2141
}
2242
}

0 commit comments

Comments
 (0)