Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AndroidLibrarySupport: Add functional tests for Kotlin Android libraries
Related: #94
- Loading branch information
1 parent
89c1b22
commit 0a88ad6
Showing
8 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/functionalTest/kotlin/kotlinx/validation/test/AndroidLibraryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.test | ||
|
||
import kotlinx.validation.api.* | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
internal class AndroidLibraryTest : BaseKotlinGradleTest() { | ||
|
||
//region Kotlin Android Library | ||
|
||
@Test | ||
fun `Given a Kotlin Android Library, when api is dumped, then task should be successful`() { | ||
val runner = test { | ||
createProjectWithSubModules() | ||
runner { | ||
arguments.add(":kotlin-library:apiDump") | ||
arguments.add("--full-stacktrace") | ||
} | ||
} | ||
|
||
runner.build().apply { | ||
assertTaskSuccess(":kotlin-library:apiDump") | ||
} | ||
} | ||
|
||
@Test | ||
fun `Given a Kotlin Android Library, when api is checked, then it should match the expected`() { | ||
test { | ||
createProjectWithSubModules() | ||
runner { | ||
arguments.add(":kotlin-library:apiCheck") | ||
} | ||
}.build().apply { | ||
assertTaskSuccess(":kotlin-library:apiCheck") | ||
} | ||
} | ||
|
||
//endregion | ||
|
||
//region Java Android Library | ||
|
||
// TODO #94 Java Android Library functional test cases | ||
|
||
//endregion | ||
|
||
/** | ||
* Creates a single project with 2 (Kotlin and Java Android Library) modules, applies | ||
* the plugin on the root project. | ||
*/ | ||
private fun BaseKotlinScope.createProjectWithSubModules() { | ||
settingsGradleKts { | ||
resolve("examples/gradle/settings/settings-android-project.gradle.kts") | ||
} | ||
buildGradleKts { | ||
resolve("examples/gradle/base/androidProjectRoot.gradle.kts") | ||
} | ||
initLocalProperties() | ||
|
||
dir("kotlin-library") { | ||
buildGradleKts { | ||
resolve("examples/gradle/base/androidKotlinLibrary.gradle.kts") | ||
} | ||
kotlin("KotlinLib.kt") { | ||
resolve("examples/classes/KotlinLib.kt") | ||
} | ||
apiFile(projectName = "kotlin-library") { | ||
resolve("examples/classes/KotlinLib.dump") | ||
} | ||
} | ||
dir("java-library") { | ||
buildGradleKts { | ||
resolve("examples/gradle/base/androidJavaLibrary.gradle.kts") | ||
} | ||
// TODO #94 Add sample Java class and expected api dump file | ||
} | ||
} | ||
|
||
private fun initLocalProperties() { | ||
val home = System.getenv("ANDROID_HOME") ?: System.getenv("HOME") | ||
File(rootProjectDir, "local.properties").apply { | ||
writeText("sdk.dir=$home/Android/Sdk") | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/functionalTest/resources/examples/classes/KotlinLib.dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public final class examples/classes/KotlinLib { | ||
public fun <init> ()V | ||
public final fun foo ()Ljava/lang/String; | ||
} | ||
|
||
public final class org/jetbrains/kotlinx/android/kotlin/library/BuildConfig { | ||
public static final field BUILD_TYPE Ljava/lang/String; | ||
public static final field DEBUG Z | ||
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; | ||
public fun <init> ()V | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
src/functionalTest/resources/examples/classes/KotlinLib.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package examples.classes | ||
|
||
class KotlinLib { | ||
|
||
fun foo(): String = "foo" | ||
internal fun bar(): String = "bar" | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/functionalTest/resources/examples/gradle/base/androidJavaLibrary.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlinx.binary-compatibility-validator") | ||
} | ||
|
||
android { | ||
|
||
namespace = "org.jetbrains.kotlinx.android.java.library" | ||
|
||
compileSdk = 32 | ||
|
||
defaultConfig { | ||
minSdk = 31 | ||
targetSdk = 32 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = true | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
// no dependencies required | ||
} |
40 changes: 40 additions & 0 deletions
40
src/functionalTest/resources/examples/gradle/base/androidKotlinLibrary.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("kotlin-android") | ||
id("org.jetbrains.kotlinx.binary-compatibility-validator") | ||
} | ||
|
||
android { | ||
|
||
namespace = "org.jetbrains.kotlinx.android.kotlin.library" | ||
|
||
compileSdk = 32 | ||
|
||
defaultConfig { | ||
minSdk = 31 | ||
targetSdk = 32 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = true | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
// no dependencies required | ||
} |
10 changes: 10 additions & 0 deletions
10
src/functionalTest/resources/examples/gradle/base/androidProjectRoot.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
plugins { | ||
id("com.android.application").version("7.2.2").apply(false) | ||
id("com.android.library").version("7.2.2").apply(false) | ||
id("org.jetbrains.kotlin.android").version("1.7.10").apply(false) | ||
id("org.jetbrains.kotlinx.binary-compatibility-validator").apply(false) | ||
} | ||
|
||
tasks.register("clean", Delete::class) { | ||
delete(rootProject.buildDir) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/functionalTest/resources/examples/gradle/settings/settings-android-project.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
gradlePluginPortal() | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
dependencyResolutionManagement { | ||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
rootProject.name = "android-project" | ||
include(":kotlin-library") | ||
include(":java-library") |