Skip to content

Commit

Permalink
test: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slisson committed Jan 28, 2025
1 parent f01fe88 commit fee1f72
Show file tree
Hide file tree
Showing 67 changed files with 2,092 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin

Expand Down Expand Up @@ -49,6 +47,13 @@ for ((majorVersion, fullVersion) in mpsVersions) {
into(mpsDir)
}
}
// The build number of a local IDE is expected to contain a product code, otherwise an exception is thrown.
val buildTxt = mpsDir.get().asFile.resolve("build.txt")
val buildNumber = buildTxt.readText()
val prefix = "MPS-"
if (!buildNumber.startsWith(prefix)) {
buildTxt.writeText("$prefix$buildNumber")
}

dependencies {
"implementation"(project(":api"))
Expand All @@ -69,6 +74,15 @@ for ((majorVersion, fullVersion) in mpsVersions) {
}
}

if (majorVersion < 242) { // MPS is not yet compatible with the new intellij plugin
project(":test:$majorVersion") {
apply(plugin = "org.jetbrains.kotlin.jvm")
tasks.named("test") {
dependsOn(":lib:shadowJar")
}
}
}

previousMajorVersions_ += majorVersion
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.configuration-cache=true
org.gradle.configuration-cache=false
org.gradle.parallel=true
org.gradle.caching=true
kotlin.daemon.jvmargs=-Xmx2g
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.1.10" }
shadow = { id = "com.gradleup.shadow", version = "9.0.0-beta6" }
binaryCompatibility = { id ="org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.17.0" }
intellij = { id = "org.jetbrains.intellij", version = "1.17.4" }
intellij2 = { id = "org.jetbrains.intellij.platform", version = "2.2.1" }
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
rootProject.name = "modelix.mps-api"
include("api")
include("lib")
include("test")

// https://artifacts.itemis.cloud/service/rest/repository/browse/maven-mps/com/jetbrains/mps/
val mpsVersions = mapOf<Int, String>(
Expand All @@ -23,4 +24,7 @@ val mpsVersions = mapOf<Int, String>(

for (majorVersion in mpsVersions.keys) {
include("impl$majorVersion")
if (majorVersion < 242) { // MPS is not yet compatible with the new intellij plugin
include(":test:$majorVersion")
}
}
19 changes: 19 additions & 0 deletions test/203/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.intellij)
alias(libs.plugins.kotlin.jvm)
}

intellij {
localPath = project(":impl203").layout.buildDirectory.dir("mps").map { it.asFile.absolutePath }
instrumentCode = false
}

tasks {
buildSearchableOptions {
enabled = false
}
}

dependencies {
testImplementation(project(":lib"))
}
103 changes: 103 additions & 0 deletions test/203/src/test/kotlin/TestBase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import com.intellij.ide.impl.OpenProjectTask
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.util.Disposer
import com.intellij.testFramework.TestApplicationManager
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.io.delete
import jetbrains.mps.ide.ThreadUtils
import jetbrains.mps.ide.project.ProjectHelper
import jetbrains.mps.project.MPSProject
import java.io.File
import java.nio.file.Files
import java.nio.file.Path

/**
* Based on org.jetbrains.uast.test.env.AbstractLargeProjectTest
*/
@Suppress("removal")
abstract class TestBase(val testDataName: String?) : UsefulTestCase() {
init {
// workaround for MPS 2023.3 failing to start in test mode
System.setProperty("intellij.platform.load.app.info.from.resources", "true")
}

protected lateinit var project: Project

override fun runInDispatchThread() = false

override fun setUp() {
super.setUp()
TestApplicationManager.getInstance()
project = openTestProject()
}

override fun tearDown() {
super.tearDown()
}

private fun openTestProject(): Project {
val projectDirParent = Path.of("build", "test-projects").toAbsolutePath()
projectDirParent.toFile().mkdirs()
val projectDir = Files.createTempDirectory(projectDirParent, "mps-project")
projectDir.delete(recursively = true)
projectDir.toFile().mkdirs()
projectDir.toFile().deleteOnExit()
val project = if (testDataName != null) {
val sourceDir = File("testdata/$testDataName")
sourceDir.copyRecursively(projectDir.toFile(), overwrite = true)
ProjectManagerEx.getInstanceEx().openProject(projectDir, OpenProjectTask())!!
} else {
ProjectManagerEx.getInstanceEx().newProject(projectDir, OpenProjectTask())!!
}

disposeOnTearDownInEdt { runCatching { ProjectManager.getInstance().closeAndDispose(project) } }

ApplicationManager.getApplication().invokeAndWait {
// empty - openTestProject executed not in EDT, so, invokeAndWait just forces
// processing of all events that were queued during project opening
}

return project
}

private fun disposeOnTearDownInEdt(runnable: Runnable) {
Disposer.register(
testRootDisposable,
Disposable {
ApplicationManager.getApplication().invokeAndWait(runnable)
},
)
}

protected val mpsProject: MPSProject get() {
return checkNotNull(ProjectHelper.fromIdeaProject(project)) { "MPS project not loaded" }
}

protected fun <R> writeAction(body: () -> R): R {
return mpsProject.modelAccess.computeWriteAction(body)
}

protected fun <R> writeActionOnEdt(body: () -> R): R {
return onEdt { writeAction { body() } }
}

protected fun <R> onEdt(body: () -> R): R {
var result: R? = null
ThreadUtils.runInUIThreadAndWait {
result = body()
}
return result as R
}

protected fun <R> readAction(body: () -> R): R {
var result: R? = null
mpsProject.modelAccess.runReadAction {
result = body()
}
return result as R
}
}
10 changes: 10 additions & 0 deletions test/203/src/test/kotlin/VirtualFolderTests203.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.modelix.mps.api.ModelixMpsApi

class VirtualFolderTests203 : TestBase("SimpleProject") {

fun `test getVirtualFolder`() {
val module = ModelixMpsApi.getMPSProjects().single().projectModules.single()
val folder = ModelixMpsApi.getVirtualFolder(module)
assertEquals("myFolder", folder)
}
}
8 changes: 8 additions & 0 deletions test/203/testdata/SimpleProject/.mps/modules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MPSProject">
<projectModules>
<modulePath path="$PROJECT_DIR$/solutions/Solution1/Solution1.msd" folder="myFolder" />
</projectModules>
</component>
</project>
22 changes: 22 additions & 0 deletions test/203/testdata/SimpleProject/solutions/Solution1/Solution1.msd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<solution name="Solution1" uuid="6517ba0d-f632-49c5-a166-401587c2c3ca" moduleVersion="0" compileInMPS="true">
<models>
<modelRoot contentPath="${module}" type="default">
<sourceRoot location="models" />
</modelRoot>
</models>
<facets>
<facet type="java">
<classes generated="true" path="${module}/classes_gen" />
</facet>
</facets>
<sourcePath />
<languageVersions>
<language slang="l:f3061a53-9226-4cc5-a443-f952ceaf5816:jetbrains.mps.baseLanguage" version="11" />
<language slang="l:ceab5195-25ea-4f22-9b92-103b95ca8c0c:jetbrains.mps.lang.core" version="2" />
<language slang="l:9ded098b-ad6a-4657-bfd9-48636cfe8bc3:jetbrains.mps.lang.traceable" version="0" />
</languageVersions>
<dependencyVersions>
<module reference="6517ba0d-f632-49c5-a166-401587c2c3ca(Solution1)" version="0" />
</dependencyVersions>
</solution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<model ref="r:630db018-71e0-498d-8b21-6ec252b3533a(Solution1.model1)">
<persistence version="9" />
<languages>
<use id="f3061a53-9226-4cc5-a443-f952ceaf5816" name="jetbrains.mps.baseLanguage" version="11" />
</languages>
<imports />
<registry>
<language id="f3061a53-9226-4cc5-a443-f952ceaf5816" name="jetbrains.mps.baseLanguage">
<concept id="1068390468198" name="jetbrains.mps.baseLanguage.structure.ClassConcept" flags="ig" index="312cEu" />
<concept id="1068580123132" name="jetbrains.mps.baseLanguage.structure.BaseMethodDeclaration" flags="ng" index="3clF44">
<child id="1068580123133" name="returnType" index="3clF45" />
<child id="1068580123135" name="body" index="3clF47" />
</concept>
<concept id="1068580123165" name="jetbrains.mps.baseLanguage.structure.InstanceMethodDeclaration" flags="ig" index="3clFb_" />
<concept id="1068580123136" name="jetbrains.mps.baseLanguage.structure.StatementList" flags="sn" stub="5293379017992965193" index="3clFbS" />
<concept id="1068581517677" name="jetbrains.mps.baseLanguage.structure.VoidType" flags="in" index="3cqZAl" />
<concept id="1107461130800" name="jetbrains.mps.baseLanguage.structure.Classifier" flags="ng" index="3pOWGL">
<child id="5375687026011219971" name="member" index="jymVt" unordered="true" />
</concept>
<concept id="1178549954367" name="jetbrains.mps.baseLanguage.structure.IVisible" flags="ng" index="1B3ioH">
<child id="1178549979242" name="visibility" index="1B3o_S" />
</concept>
<concept id="1146644602865" name="jetbrains.mps.baseLanguage.structure.PublicVisibility" flags="nn" index="3Tm1VV" />
</language>
<language id="ceab5195-25ea-4f22-9b92-103b95ca8c0c" name="jetbrains.mps.lang.core">
<concept id="1169194658468" name="jetbrains.mps.lang.core.structure.INamedConcept" flags="ng" index="TrEIO">
<property id="1169194664001" name="name" index="TrG5h" />
</concept>
</language>
</registry>
<node concept="312cEu" id="3cIAtmcX1Sw">
<property role="TrG5h" value="Class1" />
<node concept="3clFb_" id="3cIAtmcX1Te" role="jymVt">
<property role="TrG5h" value="method1" />
<node concept="3cqZAl" id="3cIAtmcX1Tg" role="3clF45" />
<node concept="3Tm1VV" id="3cIAtmcX1Th" role="1B3o_S" />
<node concept="3clFbS" id="3cIAtmcX1Ti" role="3clF47" />
</node>
<node concept="3Tm1VV" id="3cIAtmcX1Sx" role="1B3o_S" />
</node>
</model>
19 changes: 19 additions & 0 deletions test/211/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.intellij)
alias(libs.plugins.kotlin.jvm)
}

intellij {
localPath = project(":impl211").layout.buildDirectory.dir("mps").map { it.asFile.absolutePath }
instrumentCode = false
}

tasks {
buildSearchableOptions {
enabled = false
}
}

dependencies {
testImplementation(project(":lib"))
}
Loading

0 comments on commit fee1f72

Please sign in to comment.