mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
Update to Kotlin compile testing 1.2.4 (#1014)
* Update to Kotlin compile testing 1.2.4 This allows us to un-toe-hold a test from before * Fix trailing newline * Add class-based alternative * Use updated test API * Update to 1.2.5 * Update to Kotlin 1.3.60
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
package com.squareup.moshi.kotlin.codegen
|
package com.squareup.moshi.kotlin.codegen
|
||||||
|
|
||||||
import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview
|
import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.JsonReader
|
||||||
import com.tschuchort.compiletesting.KotlinCompilation
|
import com.tschuchort.compiletesting.KotlinCompilation
|
||||||
import com.tschuchort.compiletesting.SourceFile
|
import com.tschuchort.compiletesting.SourceFile
|
||||||
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
|
||||||
@@ -24,6 +26,14 @@ import org.junit.Ignore
|
|||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.TemporaryFolder
|
import org.junit.rules.TemporaryFolder
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KClassifier
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
import kotlin.reflect.KTypeProjection
|
||||||
|
import kotlin.reflect.KVariance
|
||||||
|
import kotlin.reflect.KVariance.INVARIANT
|
||||||
|
import kotlin.reflect.full.createType
|
||||||
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
|
|
||||||
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
||||||
@UseExperimental(KotlinPoetMetadataPreview::class)
|
@UseExperimental(KotlinPoetMetadataPreview::class)
|
||||||
@@ -364,8 +374,6 @@ class JsonClassCodegenProcessorTest {
|
|||||||
assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention")
|
assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Toe-hold test for when " +
|
|
||||||
"https://github.com/tschuchortdev/kotlin-compile-testing/issues/28 is resolved.")
|
|
||||||
@Test
|
@Test
|
||||||
fun `TypeAliases with the same backing type should share the same adapter`() {
|
fun `TypeAliases with the same backing type should share the same adapter`() {
|
||||||
val result = compile(kotlin("source.kt",
|
val result = compile(kotlin("source.kt",
|
||||||
@@ -380,12 +388,14 @@ class JsonClassCodegenProcessorTest {
|
|||||||
"""
|
"""
|
||||||
))
|
))
|
||||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||||
val adapterSource = result.generatedFiles.find { it.name == "PersonJsonAdapter.kt" }!!
|
|
||||||
|
|
||||||
//language=kotlin
|
// We're checking here that we only generate one `stringAdapter` that's used for both the
|
||||||
assertThat(adapterSource.readText()).isEqualTo("""
|
// regular string properties as well as the the aliased ones.
|
||||||
// TODO implement this
|
val adapterClass = result.classLoader.loadClass("PersonJsonAdapter").kotlin
|
||||||
""".trimIndent())
|
assertThat(adapterClass.declaredMemberProperties.map { it.returnType }).containsExactly(
|
||||||
|
JsonReader.Options::class.createType(),
|
||||||
|
JsonAdapter::class.parameterizedBy(String::class)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareCompilation(vararg sourceFiles: SourceFile): KotlinCompilation {
|
private fun prepareCompilation(vararg sourceFiles: SourceFile): KotlinCompilation {
|
||||||
@@ -403,4 +413,18 @@ class JsonClassCodegenProcessorTest {
|
|||||||
return prepareCompilation(*sourceFiles).compile()
|
return prepareCompilation(*sourceFiles).compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KClassifier.parameterizedBy(vararg types: KClass<*>): KType {
|
||||||
|
return parameterizedBy(*types.map { it.createType() }.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KClassifier.parameterizedBy(vararg types: KType): KType {
|
||||||
|
return createType(
|
||||||
|
types.map { it.asProjection() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KType.asProjection(variance: KVariance? = INVARIANT): KTypeProjection {
|
||||||
|
return KTypeProjection(variance, this)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
4
pom.xml
4
pom.xml
@@ -36,7 +36,7 @@
|
|||||||
<incap.version>0.2</incap.version>
|
<incap.version>0.2</incap.version>
|
||||||
<okio.version>1.16.0</okio.version>
|
<okio.version>1.16.0</okio.version>
|
||||||
<okio2.version>2.1.0</okio2.version>
|
<okio2.version>2.1.0</okio2.version>
|
||||||
<kotlin.version>1.3.50</kotlin.version>
|
<kotlin.version>1.3.60</kotlin.version>
|
||||||
<kotlinpoet.version>1.4.4</kotlinpoet.version>
|
<kotlinpoet.version>1.4.4</kotlinpoet.version>
|
||||||
<kotlinx-metadata.version>0.1.0</kotlinx-metadata.version>
|
<kotlinx-metadata.version>0.1.0</kotlinx-metadata.version>
|
||||||
<maven-assembly.version>3.1.0</maven-assembly.version>
|
<maven-assembly.version>3.1.0</maven-assembly.version>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<compile-testing.version>0.15</compile-testing.version>
|
<compile-testing.version>0.15</compile-testing.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<kotlin-compile-testing.version>1.2.3</kotlin-compile-testing.version>
|
<kotlin-compile-testing.version>1.2.5</kotlin-compile-testing.version>
|
||||||
<truth.version>1.0</truth.version>
|
<truth.version>1.0</truth.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user