Moved args into test data of cli tests.

This commit is contained in:
Evgeny Gerashchenko
2013-11-20 20:39:58 +04:00
parent 139f98a983
commit 46879e5a26
24 changed files with 151 additions and 100 deletions
@@ -0,0 +1,4 @@
-src
$TESTDATA_DIR$/diagnosticsOrder1.kt:$TESTDATA_DIR$/diagnosticsOrder2.kt
-output
$TEMP_DIR$
+1
View File
@@ -0,0 +1 @@
-help
@@ -0,0 +1,4 @@
-src
$TESTDATA_DIR$/multipleTextRangesInDiagnosticsOrder.kt
-output
$TEMP_DIR$
@@ -0,0 +1,8 @@
-src
$TESTDATA_DIR$/simple.kt
-classpath
not/existing/path
-annotations
yet/another/not/existing/path
-output
$TEMP_DIR$
@@ -0,0 +1,4 @@
-src
not/existing/path
-output
$TEMP_DIR$
@@ -0,0 +1,6 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt
-output
$TEMP_DIR$/out.js
-outputPostfix
not/existing/path
@@ -0,0 +1,6 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt
-output
$TEMP_DIR$/out.js
-outputPrefix
not/existing/path
@@ -0,0 +1,3 @@
-printArgs
-script
$TESTDATA_DIR$/hello.ktscript
@@ -0,0 +1,5 @@
-printArgs
-sourceFiles
$TESTDATA_DIR$/simple2js.kt,$TESTDATA_DIR$/warnings.kt
-suppress
warnings
+4
View File
@@ -0,0 +1,4 @@
-script
$TESTDATA_DIR$/script.ktscript
hi
there
+4
View File
@@ -0,0 +1,4 @@
-src
$TESTDATA_DIR$/simple.kt
-output
$TEMP_DIR$
+4
View File
@@ -0,0 +1,4 @@
-sourceFiles
$TESTDATA_DIR$/simple2js.kt
-output
$TEMP_DIR$/out.js
+1
View File
@@ -0,0 +1 @@
OK
@@ -0,0 +1,6 @@
-sourceFiles
$TESTDATA_DIR$/warnings.kt
-suppress
WaRnInGs
-output
$TEMP_DIR$/out.js
@@ -0,0 +1,6 @@
-src
$TESTDATA_DIR$/warnings.kt
-suppress
warnings
-output
$TEMP_DIR$
@@ -0,0 +1,6 @@
-src
$TESTDATA_DIR$/warnings.kt
-suppress
WaRnInGs
-output
$TEMP_DIR$
@@ -0,0 +1,6 @@
-src
$TESTDATA_DIR$/wrongAbiVersion.kt
-classpath
$TESTDATA_DIR$/wrongAbiVersionLib
-output
$TEMP_DIR$
+1
View File
@@ -0,0 +1 @@
-wrongArgument
@@ -0,0 +1,6 @@
-src
$TESTDATA_DIR$/wrongKotlinSignature.kt
-classpath
$TESTDATA_DIR$/wrongKotlinSignatureLib
-output
$TEMP_DIR$
@@ -16,6 +16,10 @@
package org.jetbrains.jet.cli.jvm; 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.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.cli.common.CLICompiler; import org.jetbrains.jet.cli.common.CLICompiler;
@@ -28,10 +32,12 @@ import org.junit.rules.TestName;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.List;
public class CliBaseTest { public class CliBaseTest {
protected static final String NOT_EXISTING_PATH = "not/existing/path"; private static final String TEST_DATA_HOME = "compiler/testData/cli";
@Rule @Rule
public final Tmpdir tmpdir = new Tmpdir(); public final Tmpdir tmpdir = new Tmpdir();
@@ -55,19 +61,36 @@ public class CliBaseTest {
} }
} }
private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) { private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler) throws Exception {
String actual = executeCompilerGrabOutput(compiler, args) String actual = executeCompilerGrabOutput(compiler, readArgs())
.replace(new File("compiler/testData/cli/").getAbsolutePath(), "$TESTDATA_DIR$") .replace(new File(TEST_DATA_HOME).getAbsolutePath(), "$TESTDATA_DIR$")
.replace("\\", "/"); .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) { private String[] readArgs() throws IOException {
executeCompilerCompareOutput(new K2JVMCompiler(), args); List<String> lines = FileUtil.loadLines(TEST_DATA_HOME + "/" + testName.getMethodName() + ".args");
return ArrayUtil.toStringArray(ContainerUtil.mapNotNull(lines, new Function<String, String>() {
@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) { protected void executeCompilerCompareOutputJVM() throws Exception {
executeCompilerCompareOutput(new K2JSCompiler(), args); executeCompilerCompareOutput(new K2JVMCompiler());
}
protected void executeCompilerCompareOutputJS() throws Exception {
executeCompilerCompareOutput(new K2JSCompiler());
} }
} }
@@ -26,79 +26,53 @@ import java.io.File;
public class CliCommonTest extends CliBaseTest { public class CliCommonTest extends CliBaseTest {
@Test @Test
public void help() throws Exception { public void help() throws Exception {
executeCompilerCompareOutputJVM(new String[] {"-help"}); executeCompilerCompareOutputJVM();
} }
@Test @Test
public void wrongArgument() { public void wrongArgument() throws Exception {
executeCompilerCompareOutputJVM(new String[] {"-wrongArgument"}); executeCompilerCompareOutputJVM();
} }
@Test @Test
public void printArguments() { public void printArguments() throws Exception {
executeCompilerCompareOutputJVM(new String[] {"-printArgs", "-script", "compiler/testData/cli/hello.ktscript"}); executeCompilerCompareOutputJVM();
} }
@Test @Test
public void printArgumentsWithManyValue() { public void printArgumentsWithManyValue() throws Exception {
executeCompilerCompareOutputJS(new String[] { executeCompilerCompareOutputJS();
"-printArgs",
"-sourceFiles", "compiler/testData/cli/simple2js.kt,compiler/testData/cli/warnings.kt",
"-suppress", "warnings"});
} }
@Test @Test
public void simple() throws Exception { public void simple() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/simple.kt",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile()); Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
} }
@Test @Test
public void diagnosticsOrder() throws Exception { public void diagnosticsOrder() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/diagnosticsOrder1.kt"
+ File.pathSeparator
+ "compiler/testData/cli/diagnosticsOrder2.kt",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void multipleTextRangesInDiagnosticsOrder() throws Exception { public void multipleTextRangesInDiagnosticsOrder() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void suppressAllWarningsLowercase() { public void suppressAllWarningsLowercase() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/warnings.kt",
"-suppress", "warnings",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void suppressAllWarningsMixedCase() { public void suppressAllWarningsMixedCase() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/warnings.kt",
"-suppress", "WaRnInGs",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void suppressAllWarningsJS() { public void suppressAllWarningsJS() throws Exception {
String[] args = { executeCompilerCompareOutputJS();
"-sourceFiles", "compiler/testData/cli/warnings.kt",
"-suppress", "WaRnInGs",
"-output", new File(tmpdir.getTmpDir(), "out.js").getPath()};
executeCompilerCompareOutputJS(args);
} }
} }
@@ -16,42 +16,30 @@
package org.jetbrains.jet.cli.jvm; package org.jetbrains.jet.cli.jvm;
import com.google.common.collect.Lists;
import com.intellij.util.ArrayUtil;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.util.Collections;
import java.util.List;
public class K2JsCliTest extends CliBaseTest { public class K2JsCliTest extends CliBaseTest {
@Test @Test
public void simple() { public void simple2js() throws Exception {
doSimpleTest(/*expectedOutFile =*/ true); executeCompilerCompareOutputJS();
Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile());
} }
@Test @Test
public void outputPrefixFileNotFound() { public void outputPrefixFileNotFound() throws Exception {
doSimpleTest(/*expectedOutFile =*/ false, executeCompilerCompareOutputJS();
"-outputPrefix", NOT_EXISTING_PATH);
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
} }
@Test @Test
public void outputPostfixFileNotFound() { public void outputPostfixFileNotFound() throws Exception {
doSimpleTest(/*expectedOutFile =*/ false, executeCompilerCompareOutputJS();
"-outputPostfix", NOT_EXISTING_PATH);
}
private void doSimpleTest(boolean expectedOutFile, String... additionalArgs) { Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
File outputFile = new File(tmpdir.getTmpDir(), "out.js");
List<String> 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());
} }
} }
@@ -24,44 +24,25 @@ import org.junit.Test;
import java.io.File; import java.io.File;
public class K2JvmCliTest extends CliBaseTest { public class K2JvmCliTest extends CliBaseTest {
protected static final String ANOTHER_NOT_EXISTING_PATH = "yet/another/not/existing/path";
@Test @Test
public void wrongKotlinSignature() throws Exception { public void wrongKotlinSignature() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/wrongKotlinSignature.kt",
"-classpath", "compiler/testData/cli/wrongKotlinSignatureLib",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void wrongAbiVersion() throws Exception { public void wrongAbiVersion() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/wrongAbiVersion.kt",
"-classpath", "compiler/testData/cli/wrongAbiVersionLib",
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
@Test @Test
public void nonExistingClassPathAndAnnotationsPath() { public void nonExistingClassPathAndAnnotationsPath() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", "compiler/testData/cli/simple.kt",
"-classpath", NOT_EXISTING_PATH,
"-annotations", ANOTHER_NOT_EXISTING_PATH,
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile()); Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
} }
@Test @Test
public void nonExistingSourcePath() { public void nonExistingSourcePath() throws Exception {
String[] args = { executeCompilerCompareOutputJVM();
"-src", NOT_EXISTING_PATH,
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutputJVM(args);
} }
} }
@@ -46,7 +46,7 @@ import java.util.List;
public class ScriptTest extends CliBaseTest { public class ScriptTest extends CliBaseTest {
@Test @Test
public void script() throws Exception { public void script() throws Exception {
executeCompilerCompareOutputJVM(new String[] {"-script", "compiler/testData/cli/script.ktscript", "hi", "there"}); executeCompilerCompareOutputJVM();
} }
@Test @Test