You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.6 KiB
113 lines
3.6 KiB
/* |
|
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. |
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. |
|
*/ |
|
|
|
package org.jetbrains.compose.test.tests.unit |
|
|
|
import org.jetbrains.compose.internal.ComposeCompilerArtifactProvider |
|
import org.jetbrains.compose.internal.copy |
|
import org.jetbrains.compose.test.utils.TestProperties |
|
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact |
|
import org.junit.jupiter.api.Test |
|
|
|
import org.junit.jupiter.api.Assertions.* |
|
|
|
internal class ComposeCompilerArtifactProviderTest { |
|
@Test |
|
fun defaultCompilerArtifact() { |
|
assertArtifactEquals( |
|
Expected.jbCompiler, |
|
Actual.compiler(null, TestProperties.composeCompilerCompatibleKotlinVersion) |
|
) |
|
} |
|
|
|
@Test |
|
fun defaultCompilerHostedArtifact() { |
|
assertArtifactEquals( |
|
Expected.jbCompilerHosted, |
|
Actual.compilerHosted(null, TestProperties.composeCompilerCompatibleKotlinVersion) |
|
) |
|
} |
|
|
|
@Test |
|
fun customVersion() { |
|
assertArtifactEquals( |
|
Expected.jbCompiler.copy(version = "10.20.30"), |
|
Actual.compiler("10.20.30", TestProperties.composeCompilerCompatibleKotlinVersion) |
|
) |
|
} |
|
|
|
@Test |
|
fun customCompiler() { |
|
assertArtifactEquals( |
|
Expected.googleCompiler.copy(version = "1.3.1"), |
|
Actual.compiler( |
|
"androidx.compose.compiler:compiler:1.3.1", |
|
TestProperties.androidxCompilerCompatibleKotlinVersion |
|
) |
|
) |
|
} |
|
|
|
@Test |
|
fun customCompilerHosted() { |
|
// check that we don't replace artifactId for non-jb compiler |
|
assertArtifactEquals( |
|
Expected.googleCompiler.copy(version = "1.3.1"), |
|
Actual.compilerHosted( |
|
"androidx.compose.compiler:compiler:1.3.1", |
|
TestProperties.composeCompilerCompatibleKotlinVersion |
|
) |
|
) |
|
} |
|
|
|
@Test |
|
fun illegalCompiler() { |
|
testIllegalCompiler("androidx.compose.compiler:compiler") |
|
testIllegalCompiler("a:b:c:d") |
|
testIllegalCompiler("") |
|
} |
|
|
|
private fun testIllegalCompiler(pluginString: String?) { |
|
try { |
|
Actual.compiler(pluginString, "") |
|
} catch (e: Exception) { |
|
return |
|
} |
|
|
|
error("Expected error, but illegal value was accepted: '$pluginString'") |
|
} |
|
|
|
object Actual { |
|
fun compiler(pluginString: String?, kotlinVersion: String) = |
|
ComposeCompilerArtifactProvider(kotlinVersion) { pluginString }.compilerArtifact |
|
|
|
fun compilerHosted(pluginString: String?, kotlinVersion: String) = |
|
ComposeCompilerArtifactProvider(kotlinVersion) { pluginString }.compilerHostedArtifact |
|
} |
|
|
|
object Expected { |
|
val jbCompiler: SubpluginArtifact |
|
get() = SubpluginArtifact( |
|
groupId = "org.jetbrains.compose.compiler", |
|
artifactId = "compiler", |
|
version = TestProperties.composeCompilerVersion |
|
) |
|
|
|
val jbCompilerHosted: SubpluginArtifact |
|
get() = jbCompiler.copy(artifactId = "compiler-hosted") |
|
|
|
val googleCompiler: SubpluginArtifact |
|
get() = jbCompiler.copy(groupId = "androidx.compose.compiler") |
|
} |
|
|
|
private fun assertArtifactEquals( |
|
expected: SubpluginArtifact, |
|
actual: SubpluginArtifact |
|
) { |
|
assertEquals(expected.asString(), actual.asString()) |
|
} |
|
|
|
private fun SubpluginArtifact.asString(): String = |
|
"SubpluginArtifact(groupId = '$groupId', artifactId = '$artifactId', version = '$version')" |
|
} |