From 46879e5a267ee3276cd4e71fcb2fbcae0ab2fd33 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 20 Nov 2013 20:39:58 +0400 Subject: [PATCH] Moved args into test data of cli tests. --- compiler/testData/cli/diagnosticsOrder.args | 4 ++ compiler/testData/cli/help.args | 1 + .../multipleTextRangesInDiagnosticsOrder.args | 4 ++ ...onExistingClassPathAndAnnotationsPath.args | 8 +++ .../testData/cli/nonExistingSourcePath.args | 4 ++ .../cli/outputPostfixFileNotFound.args | 6 ++ .../cli/outputPrefixFileNotFound.args | 6 ++ compiler/testData/cli/printArguments.args | 3 + .../cli/printArgumentsWithManyValue.args | 5 ++ compiler/testData/cli/script.args | 4 ++ compiler/testData/cli/simple.args | 4 ++ compiler/testData/cli/simple2js.args | 4 ++ compiler/testData/cli/simple2js.out | 1 + .../testData/cli/suppressAllWarningsJS.args | 6 ++ .../cli/suppressAllWarningsLowercase.args | 6 ++ .../cli/suppressAllWarningsMixedCase.args | 6 ++ compiler/testData/cli/wrongAbiVersion.args | 6 ++ compiler/testData/cli/wrongArgument.args | 1 + .../testData/cli/wrongKotlinSignature.args | 6 ++ .../jetbrains/jet/cli/jvm/CliBaseTest.java | 41 ++++++++++--- .../jetbrains/jet/cli/jvm/CliCommonTest.java | 58 +++++-------------- .../jetbrains/jet/cli/jvm/K2JsCliTest.java | 34 ++++------- .../jetbrains/jet/cli/jvm/K2JvmCliTest.java | 31 ++-------- .../org/jetbrains/jet/cli/jvm/ScriptTest.java | 2 +- 24 files changed, 151 insertions(+), 100 deletions(-) create mode 100644 compiler/testData/cli/diagnosticsOrder.args create mode 100644 compiler/testData/cli/help.args create mode 100644 compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.args create mode 100644 compiler/testData/cli/nonExistingClassPathAndAnnotationsPath.args create mode 100644 compiler/testData/cli/nonExistingSourcePath.args create mode 100644 compiler/testData/cli/outputPostfixFileNotFound.args create mode 100644 compiler/testData/cli/outputPrefixFileNotFound.args create mode 100644 compiler/testData/cli/printArguments.args create mode 100644 compiler/testData/cli/printArgumentsWithManyValue.args create mode 100644 compiler/testData/cli/script.args create mode 100644 compiler/testData/cli/simple.args create mode 100644 compiler/testData/cli/simple2js.args create mode 100644 compiler/testData/cli/simple2js.out create mode 100644 compiler/testData/cli/suppressAllWarningsJS.args create mode 100644 compiler/testData/cli/suppressAllWarningsLowercase.args create mode 100644 compiler/testData/cli/suppressAllWarningsMixedCase.args create mode 100644 compiler/testData/cli/wrongAbiVersion.args create mode 100644 compiler/testData/cli/wrongArgument.args create mode 100644 compiler/testData/cli/wrongKotlinSignature.args diff --git a/compiler/testData/cli/diagnosticsOrder.args b/compiler/testData/cli/diagnosticsOrder.args new file mode 100644 index 00000000000..160c5ba6928 --- /dev/null +++ b/compiler/testData/cli/diagnosticsOrder.args @@ -0,0 +1,4 @@ +-src +$TESTDATA_DIR$/diagnosticsOrder1.kt:$TESTDATA_DIR$/diagnosticsOrder2.kt +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/help.args b/compiler/testData/cli/help.args new file mode 100644 index 00000000000..e4e7bd57105 --- /dev/null +++ b/compiler/testData/cli/help.args @@ -0,0 +1 @@ +-help \ No newline at end of file diff --git a/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.args b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.args new file mode 100644 index 00000000000..12915cba3b6 --- /dev/null +++ b/compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.args @@ -0,0 +1,4 @@ +-src +$TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/nonExistingClassPathAndAnnotationsPath.args b/compiler/testData/cli/nonExistingClassPathAndAnnotationsPath.args new file mode 100644 index 00000000000..a99bf8c0359 --- /dev/null +++ b/compiler/testData/cli/nonExistingClassPathAndAnnotationsPath.args @@ -0,0 +1,8 @@ +-src +$TESTDATA_DIR$/simple.kt +-classpath +not/existing/path +-annotations +yet/another/not/existing/path +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/nonExistingSourcePath.args b/compiler/testData/cli/nonExistingSourcePath.args new file mode 100644 index 00000000000..79d1e80bd75 --- /dev/null +++ b/compiler/testData/cli/nonExistingSourcePath.args @@ -0,0 +1,4 @@ +-src +not/existing/path +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/outputPostfixFileNotFound.args b/compiler/testData/cli/outputPostfixFileNotFound.args new file mode 100644 index 00000000000..f9e5f026e0b --- /dev/null +++ b/compiler/testData/cli/outputPostfixFileNotFound.args @@ -0,0 +1,6 @@ +-sourceFiles +$TESTDATA_DIR$/simple2js.kt +-output +$TEMP_DIR$/out.js +-outputPostfix +not/existing/path \ No newline at end of file diff --git a/compiler/testData/cli/outputPrefixFileNotFound.args b/compiler/testData/cli/outputPrefixFileNotFound.args new file mode 100644 index 00000000000..1a7231917e8 --- /dev/null +++ b/compiler/testData/cli/outputPrefixFileNotFound.args @@ -0,0 +1,6 @@ +-sourceFiles +$TESTDATA_DIR$/simple2js.kt +-output +$TEMP_DIR$/out.js +-outputPrefix +not/existing/path \ No newline at end of file diff --git a/compiler/testData/cli/printArguments.args b/compiler/testData/cli/printArguments.args new file mode 100644 index 00000000000..ceb04a4ed2c --- /dev/null +++ b/compiler/testData/cli/printArguments.args @@ -0,0 +1,3 @@ +-printArgs +-script +$TESTDATA_DIR$/hello.ktscript \ No newline at end of file diff --git a/compiler/testData/cli/printArgumentsWithManyValue.args b/compiler/testData/cli/printArgumentsWithManyValue.args new file mode 100644 index 00000000000..8eb693c988b --- /dev/null +++ b/compiler/testData/cli/printArgumentsWithManyValue.args @@ -0,0 +1,5 @@ +-printArgs +-sourceFiles +$TESTDATA_DIR$/simple2js.kt,$TESTDATA_DIR$/warnings.kt +-suppress +warnings \ No newline at end of file diff --git a/compiler/testData/cli/script.args b/compiler/testData/cli/script.args new file mode 100644 index 00000000000..1430ed2a05d --- /dev/null +++ b/compiler/testData/cli/script.args @@ -0,0 +1,4 @@ +-script +$TESTDATA_DIR$/script.ktscript +hi +there \ No newline at end of file diff --git a/compiler/testData/cli/simple.args b/compiler/testData/cli/simple.args new file mode 100644 index 00000000000..99d41888d68 --- /dev/null +++ b/compiler/testData/cli/simple.args @@ -0,0 +1,4 @@ +-src +$TESTDATA_DIR$/simple.kt +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/simple2js.args b/compiler/testData/cli/simple2js.args new file mode 100644 index 00000000000..40f1df7ca8a --- /dev/null +++ b/compiler/testData/cli/simple2js.args @@ -0,0 +1,4 @@ +-sourceFiles +$TESTDATA_DIR$/simple2js.kt +-output +$TEMP_DIR$/out.js \ No newline at end of file diff --git a/compiler/testData/cli/simple2js.out b/compiler/testData/cli/simple2js.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/simple2js.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/cli/suppressAllWarningsJS.args b/compiler/testData/cli/suppressAllWarningsJS.args new file mode 100644 index 00000000000..684763cee1a --- /dev/null +++ b/compiler/testData/cli/suppressAllWarningsJS.args @@ -0,0 +1,6 @@ +-sourceFiles +$TESTDATA_DIR$/warnings.kt +-suppress +WaRnInGs +-output +$TEMP_DIR$/out.js \ No newline at end of file diff --git a/compiler/testData/cli/suppressAllWarningsLowercase.args b/compiler/testData/cli/suppressAllWarningsLowercase.args new file mode 100644 index 00000000000..733cede08a6 --- /dev/null +++ b/compiler/testData/cli/suppressAllWarningsLowercase.args @@ -0,0 +1,6 @@ +-src +$TESTDATA_DIR$/warnings.kt +-suppress +warnings +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/suppressAllWarningsMixedCase.args b/compiler/testData/cli/suppressAllWarningsMixedCase.args new file mode 100644 index 00000000000..0bc9cfe26db --- /dev/null +++ b/compiler/testData/cli/suppressAllWarningsMixedCase.args @@ -0,0 +1,6 @@ +-src +$TESTDATA_DIR$/warnings.kt +-suppress +WaRnInGs +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/wrongAbiVersion.args b/compiler/testData/cli/wrongAbiVersion.args new file mode 100644 index 00000000000..8a843010987 --- /dev/null +++ b/compiler/testData/cli/wrongAbiVersion.args @@ -0,0 +1,6 @@ +-src +$TESTDATA_DIR$/wrongAbiVersion.kt +-classpath +$TESTDATA_DIR$/wrongAbiVersionLib +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/wrongArgument.args b/compiler/testData/cli/wrongArgument.args new file mode 100644 index 00000000000..432b203f156 --- /dev/null +++ b/compiler/testData/cli/wrongArgument.args @@ -0,0 +1 @@ +-wrongArgument \ No newline at end of file diff --git a/compiler/testData/cli/wrongKotlinSignature.args b/compiler/testData/cli/wrongKotlinSignature.args new file mode 100644 index 00000000000..152602e4770 --- /dev/null +++ b/compiler/testData/cli/wrongKotlinSignature.args @@ -0,0 +1,6 @@ +-src +$TESTDATA_DIR$/wrongKotlinSignature.kt +-classpath +$TESTDATA_DIR$/wrongKotlinSignatureLib +-output +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/CliBaseTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/CliBaseTest.java index 06c9104caaf..c04a28f8b70 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/CliBaseTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/CliBaseTest.java @@ -16,6 +16,10 @@ package org.jetbrains.jet.cli.jvm; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.ArrayUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.cli.common.CLICompiler; @@ -28,10 +32,12 @@ import org.junit.rules.TestName; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.PrintStream; +import java.util.List; public class CliBaseTest { - protected static final String NOT_EXISTING_PATH = "not/existing/path"; + private static final String TEST_DATA_HOME = "compiler/testData/cli"; @Rule public final Tmpdir tmpdir = new Tmpdir(); @@ -55,19 +61,36 @@ public class CliBaseTest { } } - private void executeCompilerCompareOutput(@NotNull CLICompiler compiler, @NotNull String[] args) { - String actual = executeCompilerGrabOutput(compiler, args) - .replace(new File("compiler/testData/cli/").getAbsolutePath(), "$TESTDATA_DIR$") + private void executeCompilerCompareOutput(@NotNull CLICompiler compiler) throws Exception { + String actual = executeCompilerGrabOutput(compiler, readArgs()) + .replace(new File(TEST_DATA_HOME).getAbsolutePath(), "$TESTDATA_DIR$") .replace("\\", "/"); - JetTestUtils.assertEqualsToFile(new File("compiler/testData/cli/" + testName.getMethodName() + ".out"), actual); + JetTestUtils.assertEqualsToFile(new File(TEST_DATA_HOME + "/" + testName.getMethodName() + ".out"), actual); } - protected void executeCompilerCompareOutputJVM(@NotNull String[] args) { - executeCompilerCompareOutput(new K2JVMCompiler(), args); + private String[] readArgs() throws IOException { + List lines = FileUtil.loadLines(TEST_DATA_HOME + "/" + testName.getMethodName() + ".args"); + + return ArrayUtil.toStringArray(ContainerUtil.mapNotNull(lines, new Function() { + @Override + public String fun(String arg) { + if (arg.isEmpty()) { + return null; + } + return arg + .replace(":", File.pathSeparator) + .replace("$TEMP_DIR$", tmpdir.getTmpDir().getPath()) + .replace("$TESTDATA_DIR$", TEST_DATA_HOME); + } + })); } - protected void executeCompilerCompareOutputJS(@NotNull String[] args) { - executeCompilerCompareOutput(new K2JSCompiler(), args); + protected void executeCompilerCompareOutputJVM() throws Exception { + executeCompilerCompareOutput(new K2JVMCompiler()); + } + + protected void executeCompilerCompareOutputJS() throws Exception { + executeCompilerCompareOutput(new K2JSCompiler()); } } diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/CliCommonTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/CliCommonTest.java index 084803c4650..e5130f7dcbb 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/CliCommonTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/CliCommonTest.java @@ -26,79 +26,53 @@ import java.io.File; public class CliCommonTest extends CliBaseTest { @Test public void help() throws Exception { - executeCompilerCompareOutputJVM(new String[] {"-help"}); + executeCompilerCompareOutputJVM(); } @Test - public void wrongArgument() { - executeCompilerCompareOutputJVM(new String[] {"-wrongArgument"}); + public void wrongArgument() throws Exception { + executeCompilerCompareOutputJVM(); } @Test - public void printArguments() { - executeCompilerCompareOutputJVM(new String[] {"-printArgs", "-script", "compiler/testData/cli/hello.ktscript"}); + public void printArguments() throws Exception { + executeCompilerCompareOutputJVM(); } @Test - public void printArgumentsWithManyValue() { - executeCompilerCompareOutputJS(new String[] { - "-printArgs", - "-sourceFiles", "compiler/testData/cli/simple2js.kt,compiler/testData/cli/warnings.kt", - "-suppress", "warnings"}); + public void printArgumentsWithManyValue() throws Exception { + executeCompilerCompareOutputJS(); } @Test public void simple() throws Exception { - String[] args = { - "-src", "compiler/testData/cli/simple.kt", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + executeCompilerCompareOutputJVM(); Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile()); } @Test public void diagnosticsOrder() throws Exception { - String[] args = { - "-src", "compiler/testData/cli/diagnosticsOrder1.kt" - + File.pathSeparator - + "compiler/testData/cli/diagnosticsOrder2.kt", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + executeCompilerCompareOutputJVM(); } @Test public void multipleTextRangesInDiagnosticsOrder() throws Exception { - String[] args = { - "-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + executeCompilerCompareOutputJVM(); } @Test - public void suppressAllWarningsLowercase() { - String[] args = { - "-src", "compiler/testData/cli/warnings.kt", - "-suppress", "warnings", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + public void suppressAllWarningsLowercase() throws Exception { + executeCompilerCompareOutputJVM(); } @Test - public void suppressAllWarningsMixedCase() { - String[] args = { - "-src", "compiler/testData/cli/warnings.kt", - "-suppress", "WaRnInGs", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + public void suppressAllWarningsMixedCase() throws Exception { + executeCompilerCompareOutputJVM(); } @Test - public void suppressAllWarningsJS() { - String[] args = { - "-sourceFiles", "compiler/testData/cli/warnings.kt", - "-suppress", "WaRnInGs", - "-output", new File(tmpdir.getTmpDir(), "out.js").getPath()}; - executeCompilerCompareOutputJS(args); + public void suppressAllWarningsJS() throws Exception { + executeCompilerCompareOutputJS(); } } diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/K2JsCliTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/K2JsCliTest.java index 87a1fd8ec4d..0693dae5807 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/K2JsCliTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/K2JsCliTest.java @@ -16,42 +16,30 @@ package org.jetbrains.jet.cli.jvm; -import com.google.common.collect.Lists; -import com.intellij.util.ArrayUtil; import junit.framework.Assert; import org.junit.Test; import java.io.File; -import java.util.Collections; -import java.util.List; public class K2JsCliTest extends CliBaseTest { @Test - public void simple() { - doSimpleTest(/*expectedOutFile =*/ true); + public void simple2js() throws Exception { + executeCompilerCompareOutputJS(); + + Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test - public void outputPrefixFileNotFound() { - doSimpleTest(/*expectedOutFile =*/ false, - "-outputPrefix", NOT_EXISTING_PATH); + public void outputPrefixFileNotFound() throws Exception { + executeCompilerCompareOutputJS(); + + Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test - public void outputPostfixFileNotFound() { - doSimpleTest(/*expectedOutFile =*/ false, - "-outputPostfix", NOT_EXISTING_PATH); - } + public void outputPostfixFileNotFound() throws Exception { + executeCompilerCompareOutputJS(); - private void doSimpleTest(boolean expectedOutFile, String... additionalArgs) { - File outputFile = new File(tmpdir.getTmpDir(), "out.js"); - List args = Lists.newArrayList( - "-sourceFiles", "compiler/testData/cli/simple2js.kt", - "-output", outputFile.getPath()); - Collections.addAll(args, additionalArgs); - - executeCompilerCompareOutputJS(ArrayUtil.toStringArray(args)); - - Assert.assertEquals(expectedOutFile, outputFile.isFile()); + Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile()); } } diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/K2JvmCliTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/K2JvmCliTest.java index 41e6d0722a5..5e1db07e257 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/K2JvmCliTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/K2JvmCliTest.java @@ -24,44 +24,25 @@ import org.junit.Test; import java.io.File; public class K2JvmCliTest extends CliBaseTest { - - protected static final String ANOTHER_NOT_EXISTING_PATH = "yet/another/not/existing/path"; - @Test public void wrongKotlinSignature() throws Exception { - String[] args = { - "-src", "compiler/testData/cli/wrongKotlinSignature.kt", - "-classpath", "compiler/testData/cli/wrongKotlinSignatureLib", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + executeCompilerCompareOutputJVM(); } @Test public void wrongAbiVersion() throws Exception { - String[] args = { - "-src", "compiler/testData/cli/wrongAbiVersion.kt", - "-classpath", "compiler/testData/cli/wrongAbiVersionLib", - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + executeCompilerCompareOutputJVM(); } @Test - public void nonExistingClassPathAndAnnotationsPath() { - String[] args = { - "-src", "compiler/testData/cli/simple.kt", - "-classpath", NOT_EXISTING_PATH, - "-annotations", ANOTHER_NOT_EXISTING_PATH, - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + public void nonExistingClassPathAndAnnotationsPath() throws Exception { + executeCompilerCompareOutputJVM(); Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile()); } @Test - public void nonExistingSourcePath() { - String[] args = { - "-src", NOT_EXISTING_PATH, - "-output", tmpdir.getTmpDir().getPath()}; - executeCompilerCompareOutputJVM(args); + public void nonExistingSourcePath() throws Exception { + executeCompilerCompareOutputJVM(); } } diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/ScriptTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/ScriptTest.java index ae90ac637c6..ed03dc4977d 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/ScriptTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/ScriptTest.java @@ -46,7 +46,7 @@ import java.util.List; public class ScriptTest extends CliBaseTest { @Test public void script() throws Exception { - executeCompilerCompareOutputJVM(new String[] {"-script", "compiler/testData/cli/script.ktscript", "hi", "there"}); + executeCompilerCompareOutputJVM(); } @Test