Skip to content

Commit 39c1dfa

Browse files
committed
test(bulk-model-sync-gradle): add functional test for module exclusion
1 parent 5db8de9 commit 39c1dfa

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

bulk-model-sync-gradle/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies {
1313
implementation(libs.ktor.client.cio)
1414
testImplementation(libs.kotest.assertions.coreJvm)
1515
testImplementation(kotlin("test"))
16+
testImplementation(gradleTestKit())
1617
}
1718

1819
gradlePlugin {
@@ -36,5 +37,6 @@ tasks.named("processResources") {
3637
}
3738

3839
tasks.test {
40+
setEnvironment("MODELIX_CORE_PATH" to rootDir.absolutePath)
3941
useJUnitPlatform()
4042
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2024.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.modelix.model.sync.bulk.gradle
18+
19+
import io.kotest.matchers.file.shouldContainFile
20+
import io.kotest.matchers.file.shouldContainNFiles
21+
import org.gradle.testkit.runner.GradleRunner
22+
import org.junit.jupiter.api.io.CleanupMode
23+
import org.junit.jupiter.api.io.TempDir
24+
import java.io.File
25+
import kotlin.test.BeforeTest
26+
import kotlin.test.Test
27+
28+
class ExportFunctionalTest {
29+
30+
private val corePath: String = System.getenv("MODELIX_CORE_PATH")
31+
32+
@TempDir(cleanup = CleanupMode.ON_SUCCESS)
33+
private lateinit var projectDir: File
34+
private val gradle by lazy { GradleRunner.create().withProjectDir(projectDir) }
35+
36+
@BeforeTest
37+
fun setup() {
38+
writeSettingsFile()
39+
}
40+
41+
private fun writeSettingsFile() {
42+
// language=kotlin
43+
val settingsFileContent = """
44+
pluginManagement {
45+
includeBuild("$corePath")
46+
includeBuild("$corePath/build-logic")
47+
}
48+
plugins {
49+
id("modelix-repositories")
50+
}
51+
includeBuild("$corePath")
52+
53+
""".trimIndent()
54+
55+
projectDir.resolve("settings.gradle.kts").writeText(settingsFileContent)
56+
}
57+
58+
private fun writeBuildScript(testCode: String) {
59+
// language=kotlin
60+
val commonBuildScript = """
61+
plugins {
62+
id("modelix-kotlin-jvm")
63+
id("org.modelix.bulk-model-sync")
64+
}
65+
mpsBuild {
66+
mpsVersion("2021.2.5")
67+
}
68+
""".trimIndent()
69+
70+
projectDir.resolve("build.gradle.kts").writeText("$commonBuildScript\n\n$testCode")
71+
}
72+
73+
@Test
74+
fun `module exclusion works`() {
75+
val expectedModule = "jetbrains.mps.baseLanguage.builders"
76+
77+
// language=kotlin
78+
writeBuildScript(
79+
"""
80+
modelSync {
81+
direction("push") {
82+
val module = "jetbrains.mps.baseLanguage.classifiers"
83+
val prefix = "jetbrains.mps.baseLanguage.regexp"
84+
includeModule("$expectedModule")
85+
includeModule(module)
86+
excludeModule(module)
87+
includeModulesByPrefix(prefix)
88+
excludeModulesByPrefix(prefix)
89+
fromLocal {
90+
repositoryDir = File("${projectDir.path}")
91+
}
92+
toModelServer {
93+
url = "localhost"
94+
repositoryId = "abc"
95+
branchName = "master"
96+
}
97+
}
98+
}
99+
""".trimIndent(),
100+
)
101+
gradle.withArguments("pushExportFromMPS").build()
102+
103+
val jsonDir = gradle.projectDir.resolve("build/model-sync/push")
104+
jsonDir shouldContainNFiles 1
105+
jsonDir shouldContainFile "$expectedModule.json"
106+
}
107+
}

0 commit comments

Comments
 (0)