more tests for compiler
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
0813e6bc1c
commit
a8cd11f0f9
@@ -148,22 +148,30 @@ public abstract class CLICompiler<A extends CompilerArguments> {
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
public static void doMain(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
||||
ExitCode exitCode = doDoMain(compiler, args);
|
||||
if (exitCode != OK) {
|
||||
System.exit(exitCode.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ExitCode doDoMain(CLICompiler compiler, String[] args) {
|
||||
try {
|
||||
ExitCode rc = compiler.exec(System.out, args);
|
||||
if (rc != OK) {
|
||||
System.err.println("exec() finished with " + rc + " return code");
|
||||
if (Boolean.parseBoolean(System.getProperty("kotlin.print.cmd.args"))) {
|
||||
System.err.println("Command line arguments: ");
|
||||
for (String arg : args) {
|
||||
System.err.println(arg);
|
||||
}
|
||||
}
|
||||
System.exit(rc.getCode());
|
||||
}
|
||||
if (Boolean.parseBoolean(System.getProperty("kotlin.print.cmd.args"))) {
|
||||
System.out.println("Command line arguments:");
|
||||
for (String arg : args) {
|
||||
System.out.println(arg);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(INTERNAL_ERROR.getCode());
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
println("hello")
|
||||
@@ -15,4 +15,4 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
-help (-h) [flag] show help
|
||||
INTERNAL_ERROR
|
||||
OK
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
hello
|
||||
Command line arguments:
|
||||
-script
|
||||
compiler/testData/cli/hello.ktscript
|
||||
OK
|
||||
@@ -0,0 +1,19 @@
|
||||
Invalid argument: -wrongArgument
|
||||
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
|
||||
-annotations [String] paths to external annotations
|
||||
-includeRuntime [flag] include Kotlin runtime in to resulting jar
|
||||
-noJdk [flag] don't include Java runtime into classpath
|
||||
-noStdlib [flag] don't include Kotlin runtime into classpath
|
||||
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
|
||||
-builtins [flag] compile builtin classes (internal)
|
||||
-output [String] output directory
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||
-verbose [flag] Enable verbose logging output
|
||||
-version [flag] Display compiler version
|
||||
-help (-h) [flag] show help
|
||||
INTERNAL_ERROR
|
||||
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.jet.cli.jvm;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
@@ -37,10 +37,8 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -57,9 +55,8 @@ public class CliTest {
|
||||
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);
|
||||
ExitCode exitCode = CLICompiler.doDoMain(new K2JVMCompiler(), args);
|
||||
return bytes.toString("utf-8") + exitCode + "\n";
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -115,7 +112,7 @@ public class CliTest {
|
||||
|
||||
@Test
|
||||
public void help() throws Exception {
|
||||
executeCompilerCompareOutput(new String[] {"--help"});
|
||||
executeCompilerCompareOutput(new String[] {"-help"});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,6 +125,17 @@ public class CliTest {
|
||||
executeCompilerCompareOutput(new String[]{ "-src", "compiler/testData/cli/ideTemplates.kt", "-output", tmpdir.getTmpDir().getPath()});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongArgument() {
|
||||
executeCompilerCompareOutput(new String[] { "-wrongArgument" });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printArguments() {
|
||||
System.setProperty("kotlin.print.cmd.args", "true");
|
||||
executeCompilerCompareOutput(new String[] {"-script", "compiler/testData/cli/hello.ktscript"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScript() {
|
||||
LinkedList<AnalyzerScriptParameter> scriptParameters = new LinkedList<AnalyzerScriptParameter>();
|
||||
|
||||
Reference in New Issue
Block a user