From c27636cf3aaeeee27f956cc5a48f638bfdf18556 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 21 Apr 2017 14:52:24 +0300 Subject: [PATCH] CLI: fix non-XML rendering of argument parse error, simplify code If the compiler is invoked through JPS, an instance of XmlMessageRenderer is used and the output should be a valid XML. Previously, we reported the argument parse error (and the note to try "-help") before calling messageRenderer.renderPreamble, which resulted in invalid XML. The same was happening for the usage printed on "-help". Both of these problems are fixed #KT-14848 Fixed Original commit: a802e7fb71206739f4b283f3904cd10a257ef917 --- jps/jps-plugin/jps-tests/jps-tests.iml | 1 + .../kotlin/jps/build/KotlinJpsBuildTest.kt | 23 +++++++++++++++++++ .../testData/general/Help/kotlinProject.iml | 12 ++++++++++ .../testData/general/Help/kotlinProject.ipr | 17 ++++++++++++++ .../testData/general/Help/src/test.kt | 0 .../general/WrongArgument/kotlinProject.iml | 12 ++++++++++ .../general/WrongArgument/kotlinProject.ipr | 17 ++++++++++++++ .../general/WrongArgument/src/test.kt | 0 8 files changed, 82 insertions(+) create mode 100644 jps/jps-plugin/testData/general/Help/kotlinProject.iml create mode 100644 jps/jps-plugin/testData/general/Help/kotlinProject.ipr create mode 100644 jps/jps-plugin/testData/general/Help/src/test.kt create mode 100644 jps/jps-plugin/testData/general/WrongArgument/kotlinProject.iml create mode 100644 jps/jps-plugin/testData/general/WrongArgument/kotlinProject.ipr create mode 100644 jps/jps-plugin/testData/general/WrongArgument/src/test.kt diff --git a/jps/jps-plugin/jps-tests/jps-tests.iml b/jps/jps-plugin/jps-tests/jps-tests.iml index 1772d1a64c3..4cec7e15e41 100644 --- a/jps/jps-plugin/jps-tests/jps-tests.iml +++ b/jps/jps-plugin/jps-tests/jps-tests.iml @@ -19,5 +19,6 @@ + \ No newline at end of file diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 944ed4380cd..d8f87476e2e 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -51,6 +51,9 @@ import org.jetbrains.jps.model.java.JpsJavaSdkType import org.jetbrains.jps.model.library.JpsOrderRootType import org.jetbrains.jps.model.module.JpsModule import org.jetbrains.jps.util.JpsPathUtil +import org.jetbrains.kotlin.cli.common.Usage +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.config.KotlinCompilerVersion.TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY @@ -787,6 +790,26 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { ) } + fun testHelp() { + initProject() + + val result = buildAllModules() + result.assertSuccessful() + val warning = result.getMessages(BuildMessage.Kind.WARNING).single() + + Assert.assertEquals(Usage.render(K2JVMCompiler(), K2JVMCompilerArguments()), warning.messageText) + } + + fun testWrongArgument() { + initProject() + + val result = buildAllModules() + result.assertFailed() + val errors = result.getMessages(BuildMessage.Kind.ERROR).joinToString("\n\n") { it.messageText } + + Assert.assertEquals("Invalid argument: -abcdefghij-invalid-argument", errors) + } + fun testCodeInKotlinPackage() { initProject(JVM_MOCK_RUNTIME) diff --git a/jps/jps-plugin/testData/general/Help/kotlinProject.iml b/jps/jps-plugin/testData/general/Help/kotlinProject.iml new file mode 100644 index 00000000000..a0cbe548242 --- /dev/null +++ b/jps/jps-plugin/testData/general/Help/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps/jps-plugin/testData/general/Help/kotlinProject.ipr b/jps/jps-plugin/testData/general/Help/kotlinProject.ipr new file mode 100644 index 00000000000..102bdf0ea20 --- /dev/null +++ b/jps/jps-plugin/testData/general/Help/kotlinProject.ipr @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/Help/src/test.kt b/jps/jps-plugin/testData/general/Help/src/test.kt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.iml b/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.iml new file mode 100644 index 00000000000..a0cbe548242 --- /dev/null +++ b/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.ipr b/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.ipr new file mode 100644 index 00000000000..a9c7f866ea1 --- /dev/null +++ b/jps/jps-plugin/testData/general/WrongArgument/kotlinProject.ipr @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/WrongArgument/src/test.kt b/jps/jps-plugin/testData/general/WrongArgument/src/test.kt new file mode 100644 index 00000000000..e69de29bb2d