Skip to content

Commit

Permalink
fix test harness
Browse files Browse the repository at this point in the history
For some reason, our old way of adding libraries to the test environment
stopped working and we need to use a different way.

Also, the test rule need to be updated since the test environment now
is more properly "faked" and the old rule hangs forever
  • Loading branch information
davissuber committed Oct 6, 2023
1 parent e91289e commit 962cb7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
17 changes: 13 additions & 4 deletions intellij/src/test/kotlin/motif/intellij/TestHarness.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import java.io.File
import java.net.URI
import javax.annotation.Nullable
import javax.inject.Inject
import kotlin.reflect.KClass
Expand Down Expand Up @@ -63,10 +64,18 @@ class TestHarness : LightJavaCodeInsightFixtureTestCase() {
}

private fun addLibrary(clazz: KClass<*>) {
val path = clazz.java.protectionDomain.codeSource.location.path
val file = File(path)
val libName = file.name
PsiTestUtil.addLibrary(myFixture.projectDisposable, module, libName, file.parent, libName)
val fileUri =
clazz
.java
.getResource(clazz.simpleName + ".class")
?.toString()
?.let { Regex("file:.*[.]jar").find(it)?.value }
?.let { URI.create(it) }
if (fileUri != null) {
val file = File(fileUri)
val libName = file.name
PsiTestUtil.addLibrary(myFixture.projectDisposable, module, libName, file.parent, libName)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/
package motif.intellij.testing

import com.intellij.openapi.application.ApplicationManager
import com.intellij.testFramework.TestApplicationManager
import java.util.concurrent.CountDownLatch
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
Expand All @@ -29,21 +27,6 @@ class IntelliJRule : TestRule {

override fun evaluate() {
TestApplicationManager.getInstance()
var e: Throwable? = null
val latch = CountDownLatch(1)
ApplicationManager.getApplication().invokeLater {
ApplicationManager.getApplication().runReadAction {
try {
base.evaluate()
} catch (throwable: Throwable) {
e = throwable
} finally {
latch.countDown()
}
}
}
latch.await()
e?.let { throw it }
}
}
}
Expand Down

0 comments on commit 962cb7b

Please sign in to comment.