Skip to content

Commit 19701ed

Browse files
test(android): add instrumentation tests
the unit tests don't work
1 parent c282b00 commit 19701ed

File tree

16 files changed

+967
-30
lines changed

16 files changed

+967
-30
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
lib_arch: aarch64
5050
# - os: ubuntu-latest
5151
# platform: Android
52-
# targets: testDebugUnitTest
52+
# targets: connectedDebugAndroidTest
5353
- os: ubuntu-latest
5454
platform: Linux
5555
targets: compileKotlinLinuxArm64 linuxX64Test

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ jobs:
9393
- os: ubuntu-latest
9494
platform: JVM
9595
targets: :ktreesitter:publishJvmPublicationToLocalRepository
96-
# - os: ubuntu-latest
97-
# platform: Android
98-
# targets: :ktreesitter:publishAndroidReleasePublicationToLocalRepository
96+
- os: ubuntu-latest
97+
platform: Android
98+
targets: :ktreesitter:publishAndroidReleasePublicationToLocalRepository
9999
- os: ubuntu-latest
100100
platform: Linux
101101
targets: >-

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project.version=0.1.0
44
# The Android SDK version that is used to compile the project.
55
sdk.version.compile=34
66
# The minimum supported Android SDK version.
7-
sdk.version.min=21
7+
sdk.version.min=23
88
# The Android NDK version that is used to compile the project.
99
ndk.version=26.3.11579264
1010
# The CMake version that is used to compile the project.

gradle/libs.versions.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ version.ref = "kotest"
2525
module = "io.kotest:kotest-extensions-junitxml"
2626
version.ref = "kotest"
2727

28+
[libraries.kotest-android-runner]
29+
module = "br.com.colman:kotest-runner-android"
30+
version = "1.1.1"
31+
32+
[libraries.androidx-test-runner]
33+
module = "androidx.test:runner"
34+
version = "1.5.2"
35+
2836
[libraries.dokka-base]
2937
module = "org.jetbrains.dokka:dokka-base"
3038
version.ref = "dokka"
@@ -54,3 +62,7 @@ kotest-junit = [
5462
"kotest-junit-runner",
5563
"kotest-junit-reporter",
5664
]
65+
kotest-android = [
66+
"kotest-android-runner",
67+
"androidx-test-runner",
68+
]

ktreesitter/build.gradle.kts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,22 @@ kotlin {
9898
}
9999
}
100100

101+
/*
101102
getByName("androidUnitTest") {
102103
dependencies {
103104
implementation(libs.kotest.junit.runner)
104105
}
105106
}
107+
*/
108+
getByName("androidInstrumentedTest") {
109+
dependencies {
110+
implementation(libs.bundles.kotest.core)
111+
implementation(libs.bundles.kotest.android)
112+
rootProject.project("languages").subprojects.forEach {
113+
implementation(project(":languages:${it.name}"))
114+
}
115+
}
116+
}
106117
}
107118
}
108119

@@ -117,6 +128,7 @@ android {
117128
//noinspection ChromeOsAbiSupport
118129
abiFilters += setOf("x86_64", "arm64-v8a", "armeabi-v7a")
119130
}
131+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
120132
}
121133
externalNativeBuild {
122134
cmake {
@@ -132,6 +144,15 @@ android {
132144
testOptions.unitTests.all {
133145
it.useJUnitPlatform()
134146
}
147+
packaging.resources {
148+
excludes += setOf(
149+
"META-INF/AL2.0",
150+
"META-INF/LGPL2.1",
151+
"META-INF/licenses/ASM",
152+
"win32-x86-64/attach_hotspot_windows.dll",
153+
"win32-x86/attach_hotspot_windows.dll"
154+
)
155+
}
135156
buildFeatures {
136157
resValues = false
137158
}
@@ -302,22 +323,3 @@ tasks.getByName<Test>("jvmTest") {
302323
tasks.withType<AbstractPublishToMaven>().configureEach {
303324
mustRunAfter(tasks.withType<Sign>())
304325
}
305-
306-
gradle.taskGraph.whenReady {
307-
tasks.getByName<Test>("testDebugUnitTest") {
308-
val buildTasks = rootProject.subprojects.mapNotNull {
309-
it.tasks.findByName("buildCMakeDebug[x86_64]")
310-
}
311-
val sep = if (os.isWindows) ";" else ":"
312-
val path = buildTasks.joinToString(sep) {
313-
it.outputs.files.singleFile.path
314-
}
315-
systemProperty("java.library.path", path)
316-
val toolchain = android.ndkDirectory.resolve(
317-
"toolchains/llvm/prebuilt/linux-x86_64/sysroot" +
318-
"/usr/lib/x86_64-linux-android/${android.compileSdk}"
319-
)
320-
assert(toolchain.isDirectory) { "$toolchain is not a directory" }
321-
environment("LD_LIBRARY_PATH", toolchain.path)
322-
}
323-
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package io.github.treesitter.ktreesitter
2+
3+
import br.com.colman.kotest.KotestRunnerAndroid
4+
import io.github.treesitter.ktreesitter.java.TreeSitterJava
5+
import io.kotest.assertions.throwables.shouldNotThrowAny
6+
import io.kotest.core.spec.style.FunSpec
7+
import io.kotest.matchers.*
8+
import io.kotest.matchers.comparables.*
9+
import io.kotest.matchers.nulls.*
10+
import io.kotest.matchers.string.*
11+
import io.kotest.matchers.types.*
12+
import org.junit.runner.RunWith
13+
14+
@RunWith(KotestRunnerAndroid::class)
15+
class LanguageTest : FunSpec({
16+
val language = Language(TreeSitterJava.language())
17+
18+
test("version") {
19+
language.version shouldBe 14U
20+
}
21+
22+
test("symbolCount") {
23+
language.symbolCount shouldBeGreaterThan 1U
24+
}
25+
26+
test("stateCount") {
27+
language.stateCount shouldBeGreaterThan 1U
28+
}
29+
30+
test("fieldCount") {
31+
language.fieldCount shouldBeGreaterThan 1U
32+
}
33+
34+
test("symbolName()") {
35+
language.symbolName(1U) shouldBe "identifier"
36+
}
37+
38+
test("symbolForName()") {
39+
language.symbolForName(";", false) shouldBeGreaterThan 0U
40+
language.symbolForName("program", true) shouldBeGreaterThan 0U
41+
}
42+
43+
test("isNamed()") {
44+
language.isNamed(1U) shouldBe true
45+
}
46+
47+
test("isVisible()") {
48+
language.isVisible(1U) shouldBe true
49+
}
50+
51+
test("fieldNameForId()") {
52+
language.fieldNameForId(1U).shouldNotBeNull()
53+
}
54+
55+
test("fieldIdForName()") {
56+
language.fieldIdForName("body") shouldBeGreaterThan 0U
57+
}
58+
59+
test("nextState()") {
60+
val program = language.symbolForName("program", true)
61+
language.nextState(1U, program) shouldBeGreaterThan 0U
62+
}
63+
64+
test("lookaheadIterator()") {
65+
val program = language.symbolForName("program", true)
66+
val state = language.nextState(1U, program)
67+
val lookahead = language.lookaheadIterator(state)
68+
lookahead.language shouldBe language
69+
}
70+
71+
test("query()") {
72+
shouldNotThrowAny { language.query("(program) @root") }
73+
}
74+
75+
test("equals()") {
76+
Language(TreeSitterJava.language()) shouldBe Language(TreeSitterJava.language())
77+
}
78+
79+
test("hashCode()") {
80+
language shouldHaveSameHashCodeAs TreeSitterJava.language()
81+
}
82+
83+
test("toString()") {
84+
language.toString() shouldMatch Regex("""Language\(id=0x[0-9a-z]+, version=14\)""")
85+
}
86+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package io.github.treesitter.ktreesitter
2+
3+
import br.com.colman.kotest.KotestRunnerAndroid
4+
import io.github.treesitter.ktreesitter.java.TreeSitterJava
5+
import io.kotest.core.spec.style.FunSpec
6+
import io.kotest.matchers.*
7+
import io.kotest.matchers.collections.*
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(KotestRunnerAndroid::class)
11+
class LookaheadIteratorTest : FunSpec({
12+
val language = Language(TreeSitterJava.language())
13+
val state = language.nextState(1U, 138U)
14+
val lookahead = language.lookaheadIterator(state)
15+
16+
test("currentSymbol") {
17+
lookahead.currentSymbol shouldBe UShort.MAX_VALUE
18+
lookahead.currentSymbolName shouldBe "ERROR"
19+
}
20+
21+
test("next()") {
22+
lookahead.next() shouldBe true
23+
}
24+
25+
test("reset()") {
26+
lookahead.reset(state) shouldBe true
27+
lookahead.reset(state, language) shouldBe true
28+
}
29+
30+
test("symbols()") {
31+
lookahead.symbols().shouldBeStrictlyIncreasing()
32+
}
33+
34+
test("names()") {
35+
val names = lookahead.symbolNames().toList()
36+
names shouldContainExactly listOf("end", "line_comment", "block_comment")
37+
}
38+
39+
test("iterator()") {
40+
for ((symbol, name) in lookahead) {
41+
symbol shouldBe lookahead.currentSymbol
42+
name shouldBe lookahead.currentSymbolName
43+
}
44+
}
45+
})

0 commit comments

Comments
 (0)