diff --git a/testing/tests/src/main/kotlin/CompileTestDriver.kt b/testing/tests/src/main/kotlin/CompileTestDriver.kt index a7d449c8..434a3717 100644 --- a/testing/tests/src/main/kotlin/CompileTestDriver.kt +++ b/testing/tests/src/main/kotlin/CompileTestDriver.kt @@ -16,6 +16,7 @@ package com.yandex.yatagan.testing.tests +import com.yandex.yatagan.processor.common.Option import com.yandex.yatagan.testing.source_set.SourceSet import org.junit.Rule import org.junit.rules.TestWatcher @@ -29,6 +30,8 @@ interface CompileTestDriver : SourceSet { sources: SourceSet, ) + fun givenOption(option: Option, value: V) + /** * Runs the test and validates the output against the golden output file. * The golden output file resource path is computed from the junit test name. diff --git a/testing/tests/src/main/kotlin/CompileTestDriverBase.kt b/testing/tests/src/main/kotlin/CompileTestDriverBase.kt index 733daabe..7b95a848 100644 --- a/testing/tests/src/main/kotlin/CompileTestDriverBase.kt +++ b/testing/tests/src/main/kotlin/CompileTestDriverBase.kt @@ -22,6 +22,7 @@ import com.yandex.yatagan.generated.CompiledApiClasspath import com.yandex.yatagan.generated.DynamicApiClasspath import com.yandex.yatagan.processor.common.IntOption import com.yandex.yatagan.processor.common.LoggerDecorator +import com.yandex.yatagan.processor.common.Option import com.yandex.yatagan.testing.source_set.SourceFile import com.yandex.yatagan.testing.source_set.SourceSet import org.junit.Assert @@ -39,6 +40,10 @@ abstract class CompileTestDriverBase private constructor( private val mainSourceSet: SourceSet, ) : CompileTestDriver, SourceSet by mainSourceSet { private var precompiledModuleOutputDirs: List? = null + private val options = mutableMapOf( + IntOption.MaxIssueEncounterPaths.key to "100", + IntOption.MaxSlotsPerSwitch.key to "100", + ) protected constructor( apiType: ApiType = ApiType.Compiled, @@ -95,6 +100,10 @@ abstract class CompileTestDriverBase private constructor( abstract fun generatedFilesSubDir(): String? + override fun givenOption(option: Option, value: V) { + options[option.key] = value.toString() + } + override fun compileRunAndValidate() { val goldenResourcePath = "golden/${testNameRule.testClassSimpleName}/${testNameRule.testMethodName}.golden.txt" @@ -162,10 +171,7 @@ abstract class CompileTestDriverBase private constructor( "-opt-in=com.yandex.yatagan.VariantApi", "-P", "plugin:org.jetbrains.kotlin.kapt3:correctErrorTypes=true", ), - processorOptions = mapOf( - IntOption.MaxIssueEncounterPaths.key to "100", - IntOption.MaxSlotsPerSwitch.key to "100", - ), + processorOptions = options, ) protected open fun createCompilationArguments() = createBaseCompilationArguments() diff --git a/testing/tests/src/main/kotlin/DynamicCompileTestDriver.kt b/testing/tests/src/main/kotlin/DynamicCompileTestDriver.kt index f7d95324..e4e0b6ff 100644 --- a/testing/tests/src/main/kotlin/DynamicCompileTestDriver.kt +++ b/testing/tests/src/main/kotlin/DynamicCompileTestDriver.kt @@ -20,8 +20,10 @@ import com.squareup.javapoet.ClassName import com.yandex.yatagan.Component import com.yandex.yatagan.lang.jap.asTypeElement import com.yandex.yatagan.lang.jap.isAnnotatedWith +import com.yandex.yatagan.processor.common.IntOption import com.yandex.yatagan.processor.common.Logger import com.yandex.yatagan.processor.common.LoggerDecorator +import com.yandex.yatagan.processor.common.Option import com.yandex.yatagan.testing.source_set.SourceFile import org.intellij.lang.annotations.Language import java.io.File @@ -39,6 +41,9 @@ class DynamicCompileTestDriver( apiType: ApiType = ApiType.Dynamic, ) : CompileTestDriverBase(apiType) { private val accumulator = ComponentBootstrapperGenerator() + private val options = mutableMapOf, Any>( + IntOption.MaxIssueEncounterPaths to 100, + ) private val runnerSource = SourceFile.java("RuntimeTestRunner", """ import com.yandex.yatagan.Yatagan; @@ -60,8 +65,25 @@ class DynamicCompileTestDriver( } """.trimIndent()) + private fun formatOptions() = buildString { + for ((option, value) in options) { + val argument = when(value) { + is Boolean -> value.toString() + is Int -> value.toString() + else -> throw AssertionError("Unexpected option value type, please, support it explicitly") + } + append('.') + append(option.key.substringAfterLast('.')) + append('(').append(argument).append(')') + } + } + override fun generatedFilesSubDir(): String? = null + override fun givenOption(option: Option, value: V) { + options[option] = value + } + override fun doCompile(): TestCompilationResult { val testCompilationResult = super.doCompile() check(testCompilationResult.success) { @@ -136,7 +158,7 @@ class DynamicCompileTestDriver( return success } - private class ComponentBootstrapperGenerator : AbstractProcessor() { + private inner class ComponentBootstrapperGenerator : AbstractProcessor() { private val _bootstrapperNames: MutableSet = TreeSet() val bootstrapperNames: Set get() = _bootstrapperNames @@ -196,10 +218,9 @@ class DynamicCompileTestDriver( Yatagan.setupReflectionBackend() .validation(delegate) - .maxIssueEncounterPaths(100) - .strictMode(true) .useCompiledImplementationIfAvailable(true) .logger(logger) + ${formatOptions()} .apply(); try { diff --git a/testing/tests/src/test/kotlin/CoreBindingsFailureTest.kt b/testing/tests/src/test/kotlin/CoreBindingsFailureTest.kt index d0efac5e..a02cd7fe 100644 --- a/testing/tests/src/test/kotlin/CoreBindingsFailureTest.kt +++ b/testing/tests/src/test/kotlin/CoreBindingsFailureTest.kt @@ -16,6 +16,7 @@ package com.yandex.yatagan.testing.tests +import com.yandex.yatagan.processor.common.BooleanOption import com.yandex.yatagan.testing.source_set.SourceSet import org.junit.Before import org.junit.Test @@ -576,6 +577,31 @@ class CoreBindingsFailureTest( compileRunAndValidate() } + @Test + fun `conflicting aliases with an option`() { + givenOption(BooleanOption.ReportDuplicateAliasesAsErrors, true) + givenKotlinSource("test.TestCase", """ + import com.yandex.yatagan.* + import javax.inject.* + + interface Api + class Impl1 @Inject constructor(): Api + class Impl2 @Inject constructor(): Api + + @Module interface MyModule { + @Binds fun bind1(i: Impl1): Api + @Binds fun bind2(i: Impl2): Api + } + + @Component(modules = [MyModule::class]) + interface MyComponent { + val api: Api + } + """.trimIndent()) + + compileRunAndValidate() + } + @Test fun `manual framework type usage`() { givenKotlinSource("test.TestCase", """ diff --git a/testing/tests/src/test/resources/golden/CoreBindingsFailureTest/conflicting-aliases-with-an-option.golden.txt b/testing/tests/src/test/resources/golden/CoreBindingsFailureTest/conflicting-aliases-with-an-option.golden.txt new file mode 100644 index 00000000..20fee8e6 --- /dev/null +++ b/testing/tests/src/test/resources/golden/CoreBindingsFailureTest/conflicting-aliases-with-an-option.golden.txt @@ -0,0 +1,6 @@ +error: Conflicting bindings for `test.Api` +NOTE: Conflicting binding: `alias test.MyModule::bind1(test.Impl1)` +NOTE: Conflicting binding: `alias test.MyModule::bind2(test.Impl2)` +Encountered: + here: graph for root-component test.MyComponent + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \ No newline at end of file