move some cli tests from CompilerSmokeTest to CliTest

This commit is contained in:
Stepan Koltsov
2012-06-14 16:05:16 +04:00
parent e113294185
commit d0cd37528a
7 changed files with 65 additions and 36 deletions
@@ -1,17 +0,0 @@
OUT Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
OUT -jar [String] jar file name
OUT -src [String] source file or directory
OUT -classpath [String] classpath to use when compiling
OUT -includeRuntime [flag]
OUT -stdlib [String] Path to the stdlib.jar
OUT -jdkHeaders [String] Path to the kotlin-jdk-headers.jar
OUT -mode [String] Special compiler modes: stubs or jdkHeaders
OUT -output [String] output directory
OUT -module [String] module to compile
OUT -script [flag]
OUT -tags [flag]
OUT -verbose [flag]
OUT -version [flag]
OUT -help (-h) [flag]
ERR exec() finished with INTERNAL_ERROR return code
Return code: 2
@@ -1,3 +0,0 @@
OUT hi
OUT there
Return code: 0
@@ -23,10 +23,6 @@ import java.io.File;
import static junit.framework.Assert.*;
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Test
public void help() throws Exception {
runCompiler("help", "--help");
}
@Test
public void compileAndRunHelloApp() throws Exception {
@@ -58,8 +54,4 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
runCompiler("test.compile", "-src", "test.kt", "-jar", jar);
}
@Test
public void script() throws Exception {
runCompiler("script", "-script", "hello.ktscript", "hi", "there");
}
}
+16
View File
@@ -0,0 +1,16 @@
Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
-jar [String] jar file name
-src [String] source file or directory
-classpath [String] classpath to use when compiling
-includeRuntime [flag]
-stdlib [String] Path to the stdlib.jar
-jdkHeaders [String] Path to the kotlin-jdk-headers.jar
-mode [String] Special compiler modes: stubs or jdkHeaders
-output [String] output directory
-module [String] module to compile
-script [flag]
-tags [flag]
-verbose [flag]
-version [flag]
-help (-h) [flag]
INTERNAL_ERROR
+3
View File
@@ -0,0 +1,3 @@
hi
there
OK
@@ -18,10 +18,13 @@ package org.jetbrains.jet.cli.jvm;
import com.intellij.openapi.util.io.FileUtil;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.test.Tmpdir;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -34,20 +37,55 @@ public class CliTest {
@Rule
public final Tmpdir tmpdir = new Tmpdir();
@Rule
public final TestName testName = new TestName();
@NotNull
private String executeCompilerGrabOutput(@NotNull String[] args) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream origOut = System.out;
try {
// we change System.out because scripts ignore passed OutputStream and write to System.out
System.setOut(new PrintStream(bytes));
ExitCode exitCode = new K2JVMCompiler().exec(System.out, args);
return bytes.toString("utf-8") + exitCode + "\n";
} catch (Exception e) {
throw ExceptionUtils.rethrow(e);
} finally {
System.setOut(origOut);
}
}
private void executeCompilerCompareOutput(@NotNull String[] args) {
try {
String actual = executeCompilerGrabOutput(args);
String expected = FileUtil.loadFile(new File("compiler/testData/cli/" + testName.getMethodName() + ".out"));
Assert.assertEquals(expected, actual);
} catch (Exception e) {
throw ExceptionUtils.rethrow(e);
}
}
@Test
public void simple() throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ExitCode exitCode = new K2JVMCompiler().exec(new PrintStream(bytes),
String[] args = {
"-src", "compiler/testData/cli/simple.kt",
"-output", tmpdir.getTmpDir().getPath());
String actual = bytes.toString("utf-8") + exitCode + "\n";
String expected = FileUtil.loadFile(new File("compiler/testData/cli/simple.out"));
Assert.assertEquals(expected, actual);
"-output", tmpdir.getTmpDir().getPath()};
executeCompilerCompareOutput(args);
Assert.assertTrue(new File(tmpdir.getTmpDir(), "namespace.class").isFile());
}
@Test
public void help() throws Exception {
executeCompilerCompareOutput(new String[]{ "--help" });
}
@Test
public void script() throws Exception {
executeCompilerCompareOutput(new String[]{ "-script", "compiler/testData/cli/script.ktscript", "hi", "there" });
}
}