Skip to content

Commit

Permalink
Tests for MpsExecute
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmar committed Nov 23, 2023
1 parent 13b18c5 commit 026105d
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/main/kotlin/de/itemis/mps/gradle/tasks/MpsExecute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ abstract class MpsExecute : JavaExec() {
abstract val mpsHome: DirectoryProperty

@get:Internal
@get:Optional
abstract val mpsVersion: Property<String>

@get:Internal
@get:Optional
abstract val projectLocation: DirectoryProperty

@get:Classpath
Expand Down
6 changes: 2 additions & 4 deletions src/test/kotlin/test/de/itemis/mps/gradle/MpsCheckTaskTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package test.de.itemis.mps.gradle

import de.itemis.mps.gradle.tasks.MpsCheckErrors
import org.gradle.api.GradleException
import org.gradle.api.invocation.Gradle
import de.itemis.mps.gradle.ErrorMessages
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.hamcrest.CoreMatchers.containsString
Expand Down Expand Up @@ -67,7 +65,7 @@ class MpsCheckTaskTest {
val result = gradleRunner().withArguments("checkProject").buildAndFail()

Assert.assertEquals(TaskOutcome.FAILED, result.task(":checkProject")?.outcome)
assertThat(result.output, containsString(MpsCheckErrors.noMpsProjectIn(testProjectDir.root.canonicalFile)))
assertThat(result.output, containsString(ErrorMessages.noMpsProjectIn(testProjectDir.root.canonicalFile)))
}

@Test
Expand Down
118 changes: 118 additions & 0 deletions src/test/kotlin/test/de/itemis/mps/gradle/MpsExecuteTaskTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package test.de.itemis.mps.gradle

import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File

class MpsExecuteTaskTest {
@Rule
@JvmField
val testProjectDir: TemporaryFolder = TemporaryFolder()

private lateinit var buildFile: File
private lateinit var mpsTestProjectPath: File

@Before
fun setUp() {
buildFile = testProjectDir.newFile("build.gradle.kts")

val settingsFile = testProjectDir.newFile("settings.gradle.kts")
settingsFile.writeText(settingsScriptBoilerplate())

mpsTestProjectPath = testProjectDir.newFolder("mps-prj")
extractTestProject("test-project", mpsTestProjectPath)
}

private fun settingsScriptBoilerplate() = """
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version ("0.7.0")
}
""".trimIndent()

private fun buildScriptBoilerplate(mpsVersion: String) = """
import de.itemis.mps.gradle.tasks.MpsExecute
plugins {
id("de.itemis.mps.gradle.common")
id("generate-models")
}
repositories {
mavenCentral()
maven("https://artifacts.itemis.cloud/repository/maven-mps")
}
val mps = configurations.create("mps")
dependencies {
mps("com.jetbrains:mps:$mpsVersion")
}
val resolveMps by tasks.registering(Sync::class) {
from({ zipTree(mps.singleFile) })
into(layout.buildDirectory.dir("mps"))
}
generate {
projectLocation = file("${mpsTestProjectPath.canonicalPath}")
mpsConfig = mps
}
val generate by tasks.existing {
dependsOn(resolveMps)
doFirst {
println(layout.buildDirectory.dir("mps").get().asFile.listFiles()?.toList())
}
}
val execute by tasks.registering(MpsExecute::class) {
dependsOn(generate)
mpsHome.set(layout.buildDirectory.dir("mps"))
projectLocation.set(file("${mpsTestProjectPath.canonicalPath}"))
doFirst {
println(resolveMps.map { it.destinationDir }.get())
}
}
""".trimIndent() + "\n"

@Test
fun `execute with Project`() {
buildFile.writeText(buildScriptBoilerplate("2021.3.4") + """
execute {
module.set("NewSolution")
className.set("NewSolution.myModel.MyClass")
method.set("onlyProject")
}
""".trimIndent())

val result = gradleRunner().withArguments("execute").build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":execute")?.outcome)
}

@Test
fun `execute with Project and args`() {
buildFile.writeText(buildScriptBoilerplate("2021.3.4") + """
execute {
module.set("NewSolution")
className.set("NewSolution.myModel.MyClass")
method.set("projectAndArgs")
methodArguments.set(listOf("arg1", "arg2"))
}
""".trimIndent())

val result = gradleRunner().withArguments("execute").build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":execute")?.outcome)
}

private fun gradleRunner(): GradleRunner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withPluginClasspath()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<sourcePath />
<dependencies>
<dependency reexport="false">6354ebe7-c22a-4a0f-ac54-50b52ab9b065(JDK)</dependency>
<dependency reexport="false">6ed54515-acc8-4d1e-a16c-9fd6cfe951ea(MPS.Core)</dependency>
</dependencies>
<languageVersions>
<language slang="l:f3061a53-9226-4cc5-a443-f952ceaf5816:jetbrains.mps.baseLanguage" version="11" />
Expand All @@ -29,7 +30,10 @@
<language slang="l:9ded098b-ad6a-4657-bfd9-48636cfe8bc3:jetbrains.mps.lang.traceable" version="0" />
</languageVersions>
<dependencyVersions>
<module reference="3f233e7f-b8a6-46d2-a57f-795d56775243(Annotations)" version="0" />
<module reference="6354ebe7-c22a-4a0f-ac54-50b52ab9b065(JDK)" version="0" />
<module reference="6ed54515-acc8-4d1e-a16c-9fd6cfe951ea(MPS.Core)" version="0" />
<module reference="8865b7a8-5271-43d3-884c-6fd1d9cfdd34(MPS.OpenAPI)" version="0" />
<module reference="c8280d06-5919-4f51-97f9-263af08eef9c(NewSolution)" version="0" />
</dependencyVersions>
</solution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
<devkit ref="fbc25dd2-5da4-483a-8b19-70928e1b62d7(jetbrains.mps.devkit.general-purpose)" />
</languages>
<imports>
<import index="z1c3" ref="6ed54515-acc8-4d1e-a16c-9fd6cfe951ea/java:jetbrains.mps.project(MPS.Core/)" />
<import index="wyt6" ref="6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.lang(JDK/)" implicit="true" />
<import index="guwi" ref="6354ebe7-c22a-4a0f-ac54-50b52ab9b065/java:java.io(JDK/)" implicit="true" />
</imports>
<registry>
<language id="f3061a53-9226-4cc5-a443-f952ceaf5816" name="jetbrains.mps.baseLanguage">
<concept id="1202948039474" name="jetbrains.mps.baseLanguage.structure.InstanceMethodCallOperation" flags="nn" index="liA8E" />
<concept id="1465982738277781862" name="jetbrains.mps.baseLanguage.structure.PlaceholderMember" flags="nn" index="2tJIrI" />
<concept id="1154032098014" name="jetbrains.mps.baseLanguage.structure.AbstractLoopStatement" flags="nn" index="2LF5Ji">
<child id="1154032183016" name="body" index="2LFqv$" />
</concept>
<concept id="1197027756228" name="jetbrains.mps.baseLanguage.structure.DotExpression" flags="nn" index="2OqwBi">
<child id="1197027771414" name="operand" index="2Oq$k0" />
<child id="1197027833540" name="operation" index="2OqNvi" />
Expand Down Expand Up @@ -53,16 +58,35 @@
<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="1107535904670" name="jetbrains.mps.baseLanguage.structure.ClassifierType" flags="in" index="3uibUv">
<reference id="1107535924139" name="classifier" index="3uigEE" />
</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="760a0a8c-eabb-4521-8bfd-65db761a9ba3" name="jetbrains.mps.baseLanguage.logging">
<concept id="2034914114981261497" name="jetbrains.mps.baseLanguage.logging.structure.LogLowLevelStatement" flags="ng" index="RRSsy">
<property id="2034914114981261751" name="severity" index="RRSoG" />
<child id="2034914114981261753" name="message" index="RRSoy" />
</concept>
</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>
<language id="83888646-71ce-4f1c-9c53-c54016f6ad4f" name="jetbrains.mps.baseLanguage.collections">
<concept id="1153943597977" name="jetbrains.mps.baseLanguage.collections.structure.ForEachStatement" flags="nn" index="2Gpval">
<child id="1153944400369" name="variable" index="2Gsz3X" />
<child id="1153944424730" name="inputSequence" index="2GsD0m" />
</concept>
<concept id="1153944193378" name="jetbrains.mps.baseLanguage.collections.structure.ForEachVariable" flags="nr" index="2GrKxI" />
<concept id="1153944233411" name="jetbrains.mps.baseLanguage.collections.structure.ForEachVariableReference" flags="nn" index="2GrUjf">
<reference id="1153944258490" name="variable" index="2Gs0qQ" />
</concept>
</language>
</registry>
<node concept="312cEu" id="1wd9AaS6sTY">
<property role="TrG5h" value="MyClass" />
Expand Down Expand Up @@ -93,6 +117,68 @@
</node>
</node>
</node>
<node concept="2tJIrI" id="6SsfRvSJOA0" role="jymVt" />
<node concept="2YIFZL" id="6SsfRvSJQ_P" role="jymVt">
<property role="TrG5h" value="onlyProject" />
<node concept="3clFbS" id="6SsfRvSJQ_S" role="3clF47">
<node concept="RRSsy" id="6SsfRvSJSNm" role="3cqZAp">
<property role="RRSoG" value="h1akgim/info" />
<node concept="37vLTw" id="6SsfRvSJSUN" role="RRSoy">
<ref role="3cqZAo" node="6SsfRvSJSI8" resolve="project" />
</node>
</node>
</node>
<node concept="3Tm1VV" id="6SsfRvSJQp0" role="1B3o_S" />
<node concept="3cqZAl" id="6SsfRvSJQ$o" role="3clF45" />
<node concept="37vLTG" id="6SsfRvSJSI8" role="3clF46">
<property role="TrG5h" value="project" />
<node concept="3uibUv" id="6SsfRvSJSI7" role="1tU5fm">
<ref role="3uigEE" to="z1c3:~Project" resolve="Project" />
</node>
</node>
</node>
<node concept="2tJIrI" id="6SsfRvSJSnL" role="jymVt" />
<node concept="2YIFZL" id="nRJS0RMQyI" role="jymVt">
<property role="TrG5h" value="projectAndArgs" />
<node concept="3clFbS" id="nRJS0RMQyK" role="3clF47">
<node concept="RRSsy" id="5Csmp2j9mXf" role="3cqZAp">
<property role="RRSoG" value="h1akgim/info" />
<node concept="37vLTw" id="5Csmp2j9nnN" role="RRSoy">
<ref role="3cqZAo" node="nRJS0RMQz1" resolve="project" />
</node>
</node>
<node concept="2Gpval" id="nRJS0RMQyQ" role="3cqZAp">
<node concept="2GrKxI" id="nRJS0RMQyR" role="2Gsz3X">
<property role="TrG5h" value="arg" />
</node>
<node concept="37vLTw" id="nRJS0RMQyS" role="2GsD0m">
<ref role="3cqZAo" node="nRJS0RMQz3" resolve="args" />
</node>
<node concept="3clFbS" id="nRJS0RMQyT" role="2LFqv$">
<node concept="RRSsy" id="5Csmp2j9nGa" role="3cqZAp">
<property role="RRSoG" value="h1akgim/info" />
<node concept="2GrUjf" id="5Csmp2j9nPl" role="RRSoy">
<ref role="2Gs0qQ" node="nRJS0RMQyR" resolve="arg" />
</node>
</node>
</node>
</node>
</node>
<node concept="3cqZAl" id="nRJS0RMQz0" role="3clF45" />
<node concept="37vLTG" id="nRJS0RMQz1" role="3clF46">
<property role="TrG5h" value="project" />
<node concept="3uibUv" id="nRJS0RMQz2" role="1tU5fm">
<ref role="3uigEE" to="z1c3:~Project" resolve="Project" />
</node>
</node>
<node concept="37vLTG" id="nRJS0RMQz3" role="3clF46">
<property role="TrG5h" value="args" />
<node concept="10Q1$e" id="nRJS0RMQz4" role="1tU5fm">
<node concept="17QB3L" id="nRJS0RMQz5" role="10Q1$1" />
</node>
</node>
<node concept="3Tm1VV" id="nRJS0RMQyZ" role="1B3o_S" />
</node>
<node concept="3Tm1VV" id="1wd9AaS6sTZ" role="1B3o_S" />
</node>
</model>
Expand Down

0 comments on commit 026105d

Please sign in to comment.