From 078aa18479eb92092f38bdfbe95dc03538e59627 Mon Sep 17 00:00:00 2001 From: Ivan Gavrilovic Date: Fri, 4 Dec 2020 17:42:50 +0000 Subject: [PATCH] Fix KAPT cli tests on windows - Fix line separator issue - Always quote args with delimiters (=, :) - fix one of args files by removing obsolete stdlib reference - Fix kotlinc.bat to ensure lazy evaluation of additional classpath --- compiler/cli/bin/kotlinc.bat | 3 ++- .../kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt | 2 +- .../kapt/cli/test/AbstractKaptToolIntegrationTest.kt | 9 ++++++++- .../kapt3-cli/testData/integration/argfile/kaptArgs.txt | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/cli/bin/kotlinc.bat b/compiler/cli/bin/kotlinc.bat index 8f6ea431f69..fdcd6af6171 100644 --- a/compiler/cli/bin/kotlinc.bat +++ b/compiler/cli/bin/kotlinc.bat @@ -49,6 +49,7 @@ if "%_KOTLIN_RUNNER%"=="1" ( "%_JAVACMD%" %JAVA_OPTS% "-Dkotlin.home=%_KOTLIN_HOME%" -cp "%_KOTLIN_HOME%\lib\kotlin-runner.jar" ^ org.jetbrains.kotlin.runner.Main %KOTLIN_OPTS% ) else ( + setlocal EnableDelayedExpansion SET _ADDITIONAL_CLASSPATH= if not "%_KOTLIN_TOOL%"=="" ( @@ -56,7 +57,7 @@ if "%_KOTLIN_RUNNER%"=="1" ( ) "%_JAVACMD%" %JAVA_OPTS% -noverify -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^ - org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar%_ADDITIONAL_CLASSPATH%" ^ + org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar!_ADDITIONAL_CLASSPATH!" ^ %_KOTLIN_COMPILER% %KOTLIN_OPTS% ) diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt index e5c1f339192..6186619eb29 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt +++ b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractArgumentParsingTest.kt @@ -25,7 +25,7 @@ abstract class AbstractArgumentParsingTest : TestCase() { val before = sections.single { it.name == "before" } val messageCollector = TestMessageCollector() - val transformedArgs = transformArgs(before.content.split(LINE_SEPARATOR), messageCollector, isTest = true) + val transformedArgs = transformArgs(before.content.lines(), messageCollector, isTest = true) val actualAfter = if (messageCollector.hasErrors()) messageCollector.toString() else transformedArgs.joinToString(LINE_SEPARATOR) val actual = sections.replacingSection("after", actualAfter).render() diff --git a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt index 78ac71494fd..5863eaadbb3 100644 --- a/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt +++ b/plugins/kapt3/kapt3-cli/test/org/jetbrains/kotlin/kapt/cli/test/AbstractKaptToolIntegrationTest.kt @@ -103,7 +103,14 @@ abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() { } private fun transformArguments(args: List): List { - return args.map { it.replace("%KOTLIN_STDLIB%", File("dist/kotlinc/lib/kotlin-stdlib.jar").absolutePath) } + return args.map { + val arg = it.replace("%KOTLIN_STDLIB%", File("dist/kotlinc/lib/kotlin-stdlib.jar").absolutePath) + if (SystemInfo.isWindows && (arg.contains("=") || arg.contains(":"))) { + "\"" + arg + "\"" + } else { + arg + } + } } private fun getJdk8Home(): File { diff --git a/plugins/kapt3/kapt3-cli/testData/integration/argfile/kaptArgs.txt b/plugins/kapt3/kapt3-cli/testData/integration/argfile/kaptArgs.txt index b391192ee61..68cf0ee1b86 100644 --- a/plugins/kapt3/kapt3-cli/testData/integration/argfile/kaptArgs.txt +++ b/plugins/kapt3/kapt3-cli/testData/integration/argfile/kaptArgs.txt @@ -4,5 +4,5 @@ -Kapt-classpath=output/ap -Kapt-processors=apt.SampleApt -d output/classes --cp output/ap:%KOTLIN_STDLIB% +-cp output/ap Test.kt \ No newline at end of file