Skip to content

Commit 0266ff3

Browse files
committed
Framework for integration tests
1 parent 23b1c1c commit 0266ff3

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

api/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ publishing {
3636
}
3737
}
3838
}
39+
repositories {
40+
maven {
41+
name = "test"
42+
url = uri("${rootProject.buildDir}/repos/test")
43+
}
44+
}
3945
}

gradle-plugin/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,10 @@ publishing {
6464
}
6565
}
6666
}
67+
repositories {
68+
maven {
69+
name = "test"
70+
url = uri("${rootProject.buildDir}/repos/test")
71+
}
72+
}
6773
}

integration-tests/build.gradle.kts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
val junitVersion: String by project
2+
val kotlinBaseVersion: String by project
3+
4+
plugins {
5+
kotlin("jvm")
6+
}
7+
8+
dependencies {
9+
testImplementation("junit:junit:$junitVersion")
10+
testImplementation(gradleTestKit())
11+
}
12+
13+
tasks.test {
14+
systemProperty("kotlinVersion", kotlinBaseVersion)
15+
systemProperty("kspVersion", version)
16+
systemProperty("testRepo", File(rootProject.buildDir, "repos/test").absolutePath)
17+
dependsOn(":api:publishAllPublicationsToTestRepository")
18+
dependsOn(":gradle-plugin:publishAllPublicationsToTestRepository")
19+
dependsOn(":symbol-processing:publishAllPublicationsToTestRepository")
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import org.junit.*
2+
import java.io.File
3+
import java.util.zip.ZipFile
4+
5+
// A snapshot of the digest of output jar.
6+
class Artifact(file: File) {
7+
private fun getCRCs(file: File): Map<String, Long> {
8+
Assert.assertTrue(file.exists())
9+
return ZipFile(file).use {
10+
it.entries().asSequence().map {
11+
it.name to it.crc
12+
}.toMap()
13+
}
14+
}
15+
16+
val crcs: Map<String, Long> = getCRCs(file)
17+
18+
override fun equals(other: Any?): Boolean {
19+
if (other !is Artifact)
20+
return false
21+
22+
return crcs == other.crcs
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.google.devtools.ksp.test
2+
3+
import org.junit.rules.TemporaryFolder
4+
import java.io.File
5+
6+
class TemporaryTestProject(projectName: String) : TemporaryFolder() {
7+
private val testProjectSrc = File("src/test/resources", projectName)
8+
9+
override fun before() {
10+
super.before()
11+
12+
testProjectSrc.copyRecursively(root)
13+
14+
val kotlinVersion = System.getProperty("kotlinVersion")
15+
val kspVersion = System.getProperty("kspVersion")
16+
val testRepo = System.getProperty("testRepo")
17+
val gradleProperties = File(root, "gradle.properties")
18+
gradleProperties.appendText("\nkotlinVersion=$kotlinVersion")
19+
gradleProperties.appendText("\nkspVersion=$kspVersion")
20+
gradleProperties.appendText("\ntestRepo=$testRepo")
21+
}
22+
23+
fun restore(file: String) {
24+
File(testProjectSrc, file).copyTo(File(root, file), true)
25+
}
26+
}

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include("api")
99
include("gradle-plugin")
1010
include("compiler-plugin")
1111
include("symbol-processing")
12+
include("integration-tests")
1213

1314
val kotlinProjectPath: String? by settings
1415
if (kotlinProjectPath != null) {

symbol-processing/build.gradle.kts

+6
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ publishing {
6969
}
7070
}
7171
}
72+
repositories {
73+
maven {
74+
name = "test"
75+
url = uri("${rootProject.buildDir}/repos/test")
76+
}
77+
}
7278
}

0 commit comments

Comments
 (0)