Skip to content

Commit 3dd14ba

Browse files
committed
Add Gradle DSL unit test
Verify that hovers and code completion work correctly in *.gradle.kts build files.
1 parent 1226788 commit 3dd14ba

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

server/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ task copyPropertiesToTestWorkspace(type: Copy) {
9797
into file('src/test/resources/additionalWorkspace')
9898
}
9999

100+
task copyPropertiesToDSLTestWorkspace(type: Copy) {
101+
from "$rootDir/gradle.properties"
102+
into file('src/test/resources/kotlinDSLWorkspace')
103+
}
104+
100105
task fixFilePermissions(type: Exec) {
101106
// When running on macOS or Linux the start script
102107
// needs executable permissions to run.
@@ -133,7 +138,7 @@ run {
133138
}
134139

135140
test {
136-
dependsOn copyPropertiesToTestWorkspace
141+
dependsOn copyPropertiesToTestWorkspace, copyPropertiesToDSLTestWorkspace
137142

138143
testLogging {
139144
events 'failed'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.javacs.kt
2+
3+
import org.junit.Test
4+
import org.junit.Assert.assertThat
5+
import org.hamcrest.Matchers.*
6+
import org.eclipse.lsp4j.MarkedString
7+
8+
class GradleDSLScriptTest : SingleFileTestFixture("kotlinDSLWorkspace", "build.gradle.kts") {
9+
@Test fun `edit repositories`() {
10+
val completions = languageServer.textDocumentService.completion(completionParams(file, 7, 13)).get().right!!
11+
val labels = completions.items.map { it.label }
12+
13+
assertThat(labels, hasItem("repositories"))
14+
}
15+
16+
@Test fun `hover plugin`() {
17+
val hover = languageServer.textDocumentService.hover(textDocumentPosition(file, 4, 8)).get()!!
18+
val contents = hover.contents.left.first().right
19+
20+
assertThat(contents, equalTo(MarkedString("kotlin", "fun PluginDependenciesSpec.kotlin(module: String): PluginDependencySpec")))
21+
}
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto-generated by :server:copyPropertiesToDSLTestWorkspace
2+
gradle.properties
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
// TODO: Currently not possible, see https://github.com/gradle/gradle/issues/9830
3+
// kotlin("jvm") version "$kotlinVersion"
4+
kotlin("jvm") version "1.3.50"
5+
}
6+
7+
repositories {
8+
jcenter()
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "Kotlin DSL Workspace"

0 commit comments

Comments
 (0)