move some cli tests from CompilerSmokeTest to CliTest
This commit is contained in:
@@ -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.*;
|
import static junit.framework.Assert.*;
|
||||||
|
|
||||||
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||||
@Test
|
|
||||||
public void help() throws Exception {
|
|
||||||
runCompiler("help", "--help");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compileAndRunHelloApp() throws Exception {
|
public void compileAndRunHelloApp() throws Exception {
|
||||||
@@ -58,8 +54,4 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
|||||||
runCompiler("test.compile", "-src", "test.kt", "-jar", jar);
|
runCompiler("test.compile", "-src", "test.kt", "-jar", jar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void script() throws Exception {
|
|
||||||
runCompiler("script", "-script", "hello.ktscript", "hi", "there");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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 com.intellij.openapi.util.io.FileUtil;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
import org.jetbrains.jet.test.Tmpdir;
|
import org.jetbrains.jet.test.Tmpdir;
|
||||||
|
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TestName;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -34,20 +37,55 @@ public class CliTest {
|
|||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final Tmpdir tmpdir = new Tmpdir();
|
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
|
@Test
|
||||||
public void simple() throws Exception {
|
public void simple() throws Exception {
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
String[] args = {
|
||||||
ExitCode exitCode = new K2JVMCompiler().exec(new PrintStream(bytes),
|
|
||||||
"-src", "compiler/testData/cli/simple.kt",
|
"-src", "compiler/testData/cli/simple.kt",
|
||||||
"-output", tmpdir.getTmpDir().getPath());
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
String actual = bytes.toString("utf-8") + exitCode + "\n";
|
executeCompilerCompareOutput(args);
|
||||||
|
|
||||||
String expected = FileUtil.loadFile(new File("compiler/testData/cli/simple.out"));
|
|
||||||
|
|
||||||
Assert.assertEquals(expected, actual);
|
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "namespace.class").isFile());
|
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" });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user