From d7e0649d93be9911ba2ead50f47fc8e427090265 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 1 Oct 2020 22:31:02 +0200 Subject: [PATCH] Automatically add -- after script/expression in kotlin runner #KT-37987 fixed --- .../org/jetbrains/kotlin/runner/runners.kt | 6 ++++ compiler/testData/launcher/printargs.kts | 1 + .../kotlin/cli/LauncherScriptTest.kt | 35 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 compiler/testData/launcher/printargs.kts diff --git a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt index d88202cc0d6..279c13c77be 100644 --- a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt +++ b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt @@ -141,6 +141,9 @@ class ScriptRunner(private val path: String) : RunnerWithCompiler() { addClasspathArgIfNeeded(classpath) add("-script") add(path) + if (arguments.isNotEmpty() && arguments.first() != "--") { + add("--") + } addAll(arguments) } runCompiler(compilerClasspath, compilerArgs) @@ -153,6 +156,9 @@ class ExpressionRunner(private val code: String) : RunnerWithCompiler() { addClasspathArgIfNeeded(classpath) add("-expression") add(code) + if (arguments.isNotEmpty() && arguments.first() != "--") { + add("--") + } addAll(arguments) } runCompiler(compilerClasspath, compilerArgs) diff --git a/compiler/testData/launcher/printargs.kts b/compiler/testData/launcher/printargs.kts new file mode 100644 index 00000000000..728dfec8f8f --- /dev/null +++ b/compiler/testData/launcher/printargs.kts @@ -0,0 +1 @@ +println(args.joinToString()) \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt index 9b7f7d29b93..1ecc167fa79 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt @@ -176,6 +176,41 @@ class LauncherScriptTest : TestCaseWithTmpdir() { ) } + fun testCommandlineProcessing() { + runProcess( + "kotlin", + "-e", + "println(args.joinToString())", + "-a", + "b", + expectedStdout = "-a, b\n" + ) + runProcess( + "kotlin", + "-e", + "println(args.joinToString())", + "--", + "-a", + "b", + expectedStdout = "-a, b\n" + ) + runProcess( + "kotlin", + "$testDataDirectory/printargs.kts", + "-a", + "b", + expectedStdout = "-a, b\n" + ) + runProcess( + "kotlin", + "$testDataDirectory/printargs.kts", + "--", + "-a", + "b", + expectedStdout = "-a, b\n" + ) + } + fun testLegacyAssert() { runProcess( "kotlinc",