Skip to content

Commit c6f4336

Browse files
committed
Fix tests
1 parent 848188f commit c6f4336

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

TESTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# KMMBridge Project Tests
2+
3+
Gradle guidance suggests using include builds to test Gradle plugins. However, after a significant effort to avoid JVM classpath and other related issues, we decided to run tests by starting external Gradle builds.
4+
5+
To do that, we need to locally publish KMMBridge, then point tests projects at that new version. For each test:
6+
7+
* A temp folder is constructed
8+
* A sample app project is copied to that folder
9+
* A command line process is run, generally running Gradle to perform whatever task we intend to test
10+
11+
## Publishing KMMBridge locally
12+
13+
We want to publish KMMBridge as version `9.9.9`. This is a fake local version, just for testing. To do that, run the following on the root folder of KMMBridge:
14+
15+
```shell
16+
./gradlew publishToMavenLocal -PVERSION_NAME=9.9.9
17+
```
18+
19+
## Editing the test project
20+
21+
Our simple test project lives at `test-projects/basic`. It points at KMMBridge version `9.9.9`. You should be able to open it directly with IJ or AS.
22+
23+
## Tests
24+
25+
See class `co.touchlab.kmmbridge.SimplePluginTest`. `fun setup()` copies the test project an initializes the test project.
26+
27+
Here is a sample test:
28+
29+
```kotlin
30+
@Test
31+
fun runSpmDevBuild() {
32+
val result = ProcessHelper.runSh("./gradlew spmDevBuild --stacktrace", workingDir = testProjectDir)
33+
logExecResult(result)
34+
assertEquals(0, result.status)
35+
}
36+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package co.touchlab.kmmbridge.test
2+
3+
import co.touchlab.kmmbridge.artifactmanager.ArtifactManager
4+
import org.gradle.api.Project
5+
import org.gradle.api.Task
6+
import org.gradle.api.tasks.TaskProvider
7+
import java.io.File
8+
9+
class TestArtifactManager : ArtifactManager {
10+
private lateinit var url: String
11+
12+
override fun configure(
13+
project: Project,
14+
version: String,
15+
uploadTask: TaskProvider<Task>,
16+
kmmPublishTask: TaskProvider<Task>
17+
) {
18+
url = "test://$version"
19+
}
20+
21+
override fun deployArtifact(task: Task, zipFilePath: File, version: String): String = url
22+
}

test-projects/basic/allshared/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import co.touchlab.kmmbridge.artifactmanager.TestArtifactManager
1+
import co.touchlab.kmmbridge.test.TestArtifactManager
22

33
plugins {
44
alias(libs.plugins.kotlin.multiplatform)

0 commit comments

Comments
 (0)