Skip to content

Commit baf99df

Browse files
authored
Add a consumer smoke test for the published scip-kotlin-analysis (#1076)
Compiles and runs a standalone project that depends only on the published artifact, so missing api dependencies and references to artifacts outside Maven Central fail CI.
1 parent 68eb8e4 commit baf99df

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
- name: scip-kotlin-analysis tests
4141
run: gradle :scip-kotlin-analysis:test --no-daemon
4242

43+
- name: scip-kotlin-analysis consumer smoke test
44+
run: |
45+
gradle --no-daemon :scip-shared:publishToMavenLocal :scip-kotlin-analysis:publishToMavenLocal
46+
gradle --no-daemon -p examples/kotlin-analysis-consumer run
47+
4348
docker_test:
4449
runs-on: ubuntu-latest
4550
name: Docker CLI tests
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
kotlin("jvm") version "2.4.21"
3+
application
4+
}
5+
6+
val scipVersion = providers.gradleProperty("scipVersion").orElse("0.0.0-SNAPSHOT").get()
7+
8+
dependencies {
9+
// Deliberately the only dependency: everything the indexer's public API needs
10+
// must come from scip-kotlin-analysis's published metadata.
11+
implementation("org.scip-code:scip-kotlin-analysis:$scipVersion")
12+
}
13+
14+
application {
15+
mainClass.set("MainKt")
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// A standalone consumer of the published scip-kotlin-analysis artifact. It resolves
2+
// the module only through its published metadata, as library users do, so it catches
3+
// missing `api` dependencies and references to artifacts outside Maven Central.
4+
//
5+
// Run: gradle publishToMavenLocal && gradle -p examples/kotlin-analysis-consumer run
6+
rootProject.name = "kotlin-analysis-consumer"
7+
8+
dependencyResolutionManagement {
9+
repositories {
10+
mavenLocal { content { includeGroup("org.scip-code") } }
11+
mavenCentral()
12+
}
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.nio.file.Files
2+
import java.nio.file.Paths
3+
import kotlin.io.path.writeText
4+
import kotlin.system.exitProcess
5+
import org.scip_code.scip.Document
6+
import org.scip_code.scip_java.kotlin_analysis.KotlinAnalysisIndexer
7+
8+
fun main() {
9+
val sourceroot = Files.createTempDirectory("kotlin-analysis-consumer").toRealPath()
10+
val src = Files.createDirectories(sourceroot.resolve("src"))
11+
src.resolve("Greeter.kt")
12+
.writeText("package demo\n\nclass Greeter(val name: String) { fun greet() = \"Hi \$name\" }\n")
13+
val stdlib = Paths.get(KotlinVersion::class.java.protectionDomain.codeSource.location.toURI())
14+
15+
val streamed = mutableListOf<Document>()
16+
val documents: List<Document> =
17+
KotlinAnalysisIndexer(
18+
sourceroot = sourceroot,
19+
targetroot = sourceroot.resolve("scip-targetroot"),
20+
sourceRoots = listOf(src),
21+
classpath = listOf(stdlib),
22+
callback = { streamed += it },
23+
)
24+
.run()
25+
26+
val symbols = documents.flatMap { doc -> doc.occurrencesList.map { it.symbol } }
27+
if (documents.map { it.relativePath } != listOf("src/Greeter.kt") ||
28+
streamed != documents ||
29+
"demo/Greeter#" !in symbols ||
30+
"kotlin/String#" !in symbols
31+
) {
32+
System.err.println("Unexpected indexer output:\n$documents")
33+
exitProcess(1)
34+
}
35+
println("Indexed ${documents.size} document with ${symbols.size} occurrences")
36+
// The Analysis API leaves non-daemon threads behind; exit explicitly like scip-java.
37+
exitProcess(0)
38+
}

0 commit comments

Comments
 (0)