From d0cd37528a3b2dcd21ba0e94bcefdee3c19ad22a Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Thu, 14 Jun 2012 16:05:16 +0400 Subject: [PATCH] move some cli tests from CompilerSmokeTest to CliTest --- .../integration-tests/data/help/help.expected | 17 ------ .../data/script/script.expected | 3 -- .../jetbrains/kotlin/CompilerSmokeTest.java | 8 --- compiler/testData/cli/help.out | 16 ++++++ .../cli/script.ktscript} | 0 compiler/testData/cli/script.out | 3 ++ .../org/jetbrains/jet/cli/jvm/CliTest.java | 54 ++++++++++++++++--- 7 files changed, 65 insertions(+), 36 deletions(-) delete mode 100644 compiler/integration-tests/data/help/help.expected delete mode 100644 compiler/integration-tests/data/script/script.expected create mode 100644 compiler/testData/cli/help.out rename compiler/{integration-tests/data/script/hello.ktscript => testData/cli/script.ktscript} (100%) create mode 100644 compiler/testData/cli/script.out diff --git a/compiler/integration-tests/data/help/help.expected b/compiler/integration-tests/data/help/help.expected deleted file mode 100644 index 753d2b9d81d..00000000000 --- a/compiler/integration-tests/data/help/help.expected +++ /dev/null @@ -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 diff --git a/compiler/integration-tests/data/script/script.expected b/compiler/integration-tests/data/script/script.expected deleted file mode 100644 index b2109fc9c16..00000000000 --- a/compiler/integration-tests/data/script/script.expected +++ /dev/null @@ -1,3 +0,0 @@ -OUT hi -OUT there -Return code: 0 diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java index 15250683c7b..fed440961cd 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java @@ -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"); - } } diff --git a/compiler/testData/cli/help.out b/compiler/testData/cli/help.out new file mode 100644 index 00000000000..8968ffb3b53 --- /dev/null +++ b/compiler/testData/cli/help.out @@ -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 diff --git a/compiler/integration-tests/data/script/hello.ktscript b/compiler/testData/cli/script.ktscript similarity index 100% rename from compiler/integration-tests/data/script/hello.ktscript rename to compiler/testData/cli/script.ktscript diff --git a/compiler/testData/cli/script.out b/compiler/testData/cli/script.out new file mode 100644 index 00000000000..c64071036cd --- /dev/null +++ b/compiler/testData/cli/script.out @@ -0,0 +1,3 @@ +hi +there +OK diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java b/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java index c703c923c11..c1f82145890 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/CliTest.java @@ -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" }); + } + }