-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ComposeCompilerArtifactProviderTest.kt
91 lines (75 loc) · 2.84 KB
/
ComposeCompilerArtifactProviderTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* 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 customVersion() {
assertArtifactEquals(
Expected.jbCompiler.copy(version = "10.20.30"),
Actual.compiler("10.20.30")
)
}
@Test
fun customCompiler() {
assertArtifactEquals(
Expected.googleCompiler.copy(version = "1.3.1"),
Actual.compiler("androidx.compose.compiler:compiler:1.3.1")
)
}
@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")
)
}
@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) =
ComposeCompilerArtifactProvider { pluginString }.compilerArtifact
fun compilerHosted(pluginString: String) =
ComposeCompilerArtifactProvider { 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')"
}