Skip to content

Commit

Permalink
test: groundwork for inspection tests (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Jun 21, 2023
1 parent 3c356e9 commit 6d3c760
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.qodana
build
.testSdk
45 changes: 44 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.*

fun properties(key: String) = project.findProperty(key).toString()

Expand Down Expand Up @@ -77,7 +80,7 @@ tasks {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"

with (it.lines()) {
with(it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
Expand Down Expand Up @@ -122,4 +125,44 @@ tasks {
// https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first()))
}

test {
doFirst {
// TODO can we use some gradle caching for this?
val file = file(".testSdk")
if (!file.exists()) {
println("Downloading IntelliJ sources for Mock SDKs...")
file.createNewFile()
}
val targetDir = file.readText()
if (targetDir.isBlank() || !Files.exists(Path.of(targetDir))) {
val path = Files.createTempDirectory("intellij-community").toAbsolutePath()
downloadFromIntelliJRepo("java/mockJDK-11/jre/lib/annotations.jar", path)
downloadFromIntelliJRepo("java/mockJDK-11/jre/lib/rt.jar", path)
file.writeText(path.toString())
}
systemProperty("idea.home.path", file.readText())
}
}

clean {
doFirst {
val testSdkFile = file(".testSdk").toPath()
// TODO probably clean up unneeded files?
Files.deleteIfExists(testSdkFile)
}
}
}

fun downloadFromIntelliJRepo(filePath: String, targetBase: Path) {
val outputFile = targetBase.resolve(filePath)
outputFile.parent.createDirectories()
val res = exec {
executable = "curl"
args = listOf(
"-o", outputFile.toString(),
"https://raw.githubusercontent.com/JetBrains/intellij-community/master/$filePath"
)
}
res.rethrowFailure()
}
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = "HandleHints"

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.sirywell.methodhandleplugin.mhtype

import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import de.sirywell.methodhandleplugin.inspection.MethodHandleCreationInspection

class MethodHandleInspectionsTest : LightJavaCodeInsightFixtureTestCase() {

private fun doTest() {
projectDescriptor.sdk
myFixture.enableInspections(MethodHandleCreationInspection())
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java")
}

override fun getProjectDescriptor() = JAVA_LATEST_WITH_LATEST_JDK

override fun getTestDataPath(): String {
return "src/test/testData/"
}

fun testVoidInIdentity() = doTest()


}
6 changes: 6 additions & 0 deletions src/test/testData/VoidInIdentity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

class VoidInIdentity {
private static final MethodHandle A = MethodHandles.identity(<warning descr="Parameter must not be of type void.">void.class</warning>);
}

0 comments on commit 6d3c760

Please sign in to comment.