Alexey Tsvetkov
4 years ago
committed by
Alexey Tsvetkov
18 changed files with 313 additions and 12 deletions
@ -0,0 +1,53 @@
|
||||
package org.jetbrains.compose |
||||
|
||||
import org.gradle.testkit.runner.TaskOutcome |
||||
import org.jetbrains.compose.desktop.application.internal.OS |
||||
import org.jetbrains.compose.desktop.application.internal.currentOS |
||||
import org.jetbrains.compose.test.* |
||||
import org.junit.Assert.assertEquals |
||||
import org.junit.Test |
||||
|
||||
class DesktopApplicationTest : GradlePluginTestBase() { |
||||
@Test |
||||
fun smokeTestRunTask() = with(testProject(TestProjects.jvm)) { |
||||
file("build.gradle").modify { |
||||
it + """ |
||||
afterEvaluate { |
||||
tasks.getByName("run").doFirst { |
||||
throw new StopExecutionException("Skip run task") |
||||
} |
||||
} |
||||
""".trimIndent() |
||||
} |
||||
val result = gradle("run").build() |
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":run")?.outcome) |
||||
} |
||||
|
||||
@Test |
||||
fun kotlinDsl(): Unit = with(testProject(TestProjects.jvmKotlinDsl)) { |
||||
gradle(":package", "--dry-run").build() |
||||
} |
||||
|
||||
@Test |
||||
fun packageJvm() = with(testProject(TestProjects.jvm)) { |
||||
testPackage() |
||||
} |
||||
|
||||
@Test |
||||
fun packageMpp() = with(testProject(TestProjects.mpp)) { |
||||
testPackage() |
||||
} |
||||
|
||||
private fun TestProject.testPackage() { |
||||
val result = gradle(":package").build() |
||||
val ext = when (currentOS) { |
||||
OS.Linux -> "deb" |
||||
OS.Windows -> "msi" |
||||
OS.MacOS -> "dmg" |
||||
} |
||||
file("build/compose/binaries/main/$ext/simple-1.0.$ext") |
||||
.checkExists() |
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":package${ext.capitalize()}")?.outcome) |
||||
assertEquals(TaskOutcome.SUCCESS, result.task(":package")?.outcome) |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package org.jetbrains.compose.test |
||||
|
||||
import org.junit.Rule |
||||
import org.junit.rules.TemporaryFolder |
||||
|
||||
abstract class GradlePluginTestBase { |
||||
@Rule |
||||
@JvmField |
||||
val testDir: TemporaryFolder = TemporaryFolder() |
||||
|
||||
fun testProject(name: String): TestProject = |
||||
TestProject(name, workingDir = testDir.root) |
||||
} |
@ -0,0 +1,48 @@
|
||||
package org.jetbrains.compose.test |
||||
|
||||
import org.gradle.testkit.runner.GradleRunner |
||||
import java.io.File |
||||
|
||||
data class TestProject( |
||||
private val name: String, |
||||
private val workingDir: File, |
||||
private val defaultGradleVersion: String = TestProperties.defaultGradleVersionForTests |
||||
) { |
||||
private val additionalArgs = listOf("--stacktrace") |
||||
|
||||
init { |
||||
val originalTestRoot = File("src/test/test-projects").resolve(name).also { |
||||
check(it.exists()) { "Test project is not found: ${it.absolutePath}" } |
||||
} |
||||
for (orig in originalTestRoot.walk()) { |
||||
if (!orig.isFile) continue |
||||
|
||||
val target = workingDir.resolve(orig.relativeTo(originalTestRoot)) |
||||
target.parentFile.mkdirs() |
||||
|
||||
if (orig.name.endsWith(".gradle") || orig.name.endsWith(".gradle.kts")) { |
||||
val origContent = orig.readText() |
||||
val newContent = origContent.replace("COMPOSE_VERSION_PLACEHOLDER", TestProperties.composeVersion) |
||||
target.writeText(newContent) |
||||
} else { |
||||
orig.copyTo(target) |
||||
} |
||||
} |
||||
} |
||||
|
||||
fun gradle(vararg args: String): GradleRunner = |
||||
GradleRunner.create().apply { |
||||
withGradleVersion(defaultGradleVersion) |
||||
withProjectDir(workingDir) |
||||
withArguments(args.toList() + additionalArgs) |
||||
} |
||||
|
||||
@Suppress("DeprecatedCallableAddReplaceWith") |
||||
@Deprecated("Do not commit!") |
||||
fun gradleDebug(vararg args: String): GradleRunner = |
||||
gradle(*args).withDebug(true) |
||||
|
||||
fun file(path: String): File = |
||||
workingDir.resolve(path) |
||||
} |
||||
|
@ -0,0 +1,7 @@
|
||||
package org.jetbrains.compose.test |
||||
|
||||
object TestProjects { |
||||
const val jvm = "application/jvm" |
||||
const val mpp = "application/mpp" |
||||
const val jvmKotlinDsl = "application/jvmKotlinDsl" |
||||
} |
@ -0,0 +1,12 @@
|
||||
package org.jetbrains.compose.test |
||||
|
||||
object TestProperties { |
||||
val java14Home: String |
||||
get() = System.getProperty("jdk.14.home") ?: error("Run test using JDK 14 or set JDK_14 env var") |
||||
|
||||
val composeVersion: String |
||||
get() = System.getProperty("compose.plugin.version")!! |
||||
|
||||
val defaultGradleVersionForTests: String |
||||
get() = System.getProperty("gradle.version.for.tests")!! |
||||
} |
@ -0,0 +1,13 @@
|
||||
package org.jetbrains.compose.test |
||||
|
||||
import java.io.File |
||||
|
||||
fun File.modify(fn: (String) -> String) { |
||||
val content = readText() |
||||
val newContent = fn(content) |
||||
writeText(newContent) |
||||
} |
||||
|
||||
fun File.checkExists(): File = apply { |
||||
check(exists()) { "File does not exist: $absolutePath" } |
||||
} |
@ -0,0 +1,29 @@
|
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
||||
|
||||
plugins { |
||||
id "org.jetbrains.kotlin.jvm" |
||||
id "org.jetbrains.compose" |
||||
} |
||||
|
||||
repositories { |
||||
google() |
||||
mavenCentral() |
||||
jcenter() |
||||
maven { |
||||
url "https://maven.pkg.jetbrains.space/public/p/compose/dev" |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib" |
||||
implementation compose.desktop.currentOs |
||||
} |
||||
|
||||
compose.desktop { |
||||
application { |
||||
mainClass = "MainKt" |
||||
nativeDistributions { |
||||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
pluginManagement { |
||||
plugins { |
||||
id 'org.jetbrains.kotlin.jvm' version '1.4.10' |
||||
id 'org.jetbrains.compose' version 'COMPOSE_VERSION_PLACEHOLDER' |
||||
} |
||||
repositories { |
||||
mavenLocal() |
||||
gradlePluginPortal() |
||||
} |
||||
} |
||||
rootProject.name = "simple" |
@ -0,0 +1 @@
|
||||
fun main() {} |
@ -0,0 +1,28 @@
|
||||
import org.jetbrains.compose.compose |
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
||||
|
||||
plugins { |
||||
id("org.jetbrains.kotlin.jvm") |
||||
id("org.jetbrains.compose") |
||||
} |
||||
|
||||
repositories { |
||||
google() |
||||
mavenCentral() |
||||
jcenter() |
||||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") |
||||
} |
||||
|
||||
dependencies { |
||||
implementation(kotlin("stdlib")) |
||||
implementation(compose.desktop.currentOs) |
||||
} |
||||
|
||||
compose.desktop { |
||||
application { |
||||
mainClass = "MainKt" |
||||
nativeDistributions { |
||||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
pluginManagement { |
||||
plugins { |
||||
id 'org.jetbrains.kotlin.jvm' version '1.4.10' |
||||
id 'org.jetbrains.compose' version 'COMPOSE_VERSION_PLACEHOLDER' |
||||
} |
||||
repositories { |
||||
mavenLocal() |
||||
gradlePluginPortal() |
||||
} |
||||
} |
||||
rootProject.name = "simple" |
@ -0,0 +1 @@
|
||||
fun main() {} |
@ -0,0 +1,39 @@
|
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
||||
|
||||
plugins { |
||||
id "org.jetbrains.kotlin.multiplatform" |
||||
id "org.jetbrains.compose" |
||||
} |
||||
|
||||
repositories { |
||||
google() |
||||
mavenCentral() |
||||
jcenter() |
||||
maven { |
||||
url "https://maven.pkg.jetbrains.space/public/p/compose/dev" |
||||
} |
||||
} |
||||
|
||||
kotlin { |
||||
jvm { |
||||
withJava() |
||||
} |
||||
sourceSets { |
||||
named("jvmMain") { |
||||
dependencies { |
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib") |
||||
implementation(compose.desktop.currentOs) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
compose.desktop { |
||||
application { |
||||
mainClass = "MainKt" |
||||
nativeDistributions { |
||||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,11 @@
|
||||
pluginManagement { |
||||
plugins { |
||||
id 'org.jetbrains.kotlin.multiplatform' version '1.4.10' |
||||
id 'org.jetbrains.compose' version 'COMPOSE_VERSION_PLACEHOLDER' |
||||
} |
||||
repositories { |
||||
mavenLocal() |
||||
gradlePluginPortal() |
||||
} |
||||
} |
||||
rootProject.name = "simple" |
Loading…
Reference in new issue