Support '-suppress warnings'
#KT-3319 In Progress
This commit is contained in:
@@ -12,6 +12,8 @@ public abstract class CommonCompilerArguments extends CompilerArguments {
|
||||
public boolean version;
|
||||
@Argument(value = "help", alias = "h", description = "Show help")
|
||||
public boolean help;
|
||||
@Argument(value = "suppress", description = "Suppress compiler messages by severity (warnings)")
|
||||
public String suppress;
|
||||
|
||||
@Override
|
||||
public boolean isHelp() {
|
||||
@@ -40,4 +42,9 @@ public abstract class CommonCompilerArguments extends CompilerArguments {
|
||||
public void setTags(boolean tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean suppressAllWarnings() {
|
||||
return "warnings".equalsIgnoreCase(suppress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.cli.common;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.sampullara.cli.Args;
|
||||
@@ -27,9 +28,7 @@ import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.COMPILATION_ERROR;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.INTERNAL_ERROR;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||
|
||||
public abstract class CLICompiler<A extends CompilerArguments> {
|
||||
|
||||
@@ -108,10 +107,14 @@ public abstract class CLICompiler<A extends CompilerArguments> {
|
||||
|
||||
printVersionIfNeeded(errStream, arguments, messageRenderer);
|
||||
|
||||
PrintingMessageCollector printingCollector = new PrintingMessageCollector(errStream, messageRenderer, arguments.isVerbose());
|
||||
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.isVerbose());
|
||||
|
||||
if (arguments.suppressAllWarnings()) {
|
||||
collector = new FilteringMessageCollector(collector, Predicates.equalTo(CompilerMessageSeverity.WARNING));
|
||||
}
|
||||
|
||||
try {
|
||||
return exec(printingCollector, arguments);
|
||||
return exec(collector, arguments);
|
||||
}
|
||||
finally {
|
||||
errStream.print(messageRenderer.renderConclusion());
|
||||
|
||||
@@ -45,4 +45,6 @@ public abstract class CompilerArguments {
|
||||
public abstract boolean isVerbose();
|
||||
|
||||
public abstract String getSrc();
|
||||
|
||||
public abstract boolean suppressAllWarnings();
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
-output [String] output directory
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-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
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-help (-h) [flag] Show help
|
||||
-suppress [String] Suppress compiler messages by severity (warnings)
|
||||
OK
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1,10 @@
|
||||
import jet.Any
|
||||
import jet.Any
|
||||
|
||||
fun foo(p: Int??) {
|
||||
|
||||
}
|
||||
|
||||
trait T {
|
||||
abstract fun foo()
|
||||
}
|
||||
@@ -14,9 +14,10 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
-output [String] output directory
|
||||
-module [String] module to compile
|
||||
-script [flag] evaluate script
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-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
|
||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
||||
-help (-h) [flag] Show help
|
||||
-suppress [String] Suppress compiler messages by severity (warnings)
|
||||
INTERNAL_ERROR
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||
import org.jetbrains.jet.cli.common.ExitCode;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
@@ -48,12 +49,12 @@ public class CliTest {
|
||||
public final TestName testName = new TestName();
|
||||
|
||||
@NotNull
|
||||
private String executeCompilerGrabOutput(@NotNull String[] args) {
|
||||
private static String executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
PrintStream origOut = System.out;
|
||||
try {
|
||||
System.setOut(new PrintStream(bytes));
|
||||
ExitCode exitCode = CLICompiler.doMainNoExit(new K2JVMCompiler(), args);
|
||||
ExitCode exitCode = CLICompiler.doMainNoExit(compiler, args);
|
||||
return bytes.toString("utf-8") + exitCode + "\n";
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -64,21 +65,28 @@ public class CliTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void executeCompilerCompareOutput(@NotNull String[] args) {
|
||||
String actual = executeCompilerGrabOutput(args)
|
||||
private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) {
|
||||
String actual = executeCompilerGrabOutput(compiler, args)
|
||||
.replace(new File("compiler/testData/cli/").getAbsolutePath(), "$TESTDATA_DIR$")
|
||||
.replace("\\", "/");
|
||||
|
||||
JetTestUtils.assertEqualsToFile(new File("compiler/testData/cli/" + testName.getMethodName() + ".out"), actual);
|
||||
}
|
||||
|
||||
private void executeCompilerCompareOutputJVM(@NotNull String[] args) {
|
||||
executeCompilerCompareOutput(new K2JVMCompiler(), args);
|
||||
}
|
||||
|
||||
private void executeCompilerCompareOutputJS(@NotNull String[] args) {
|
||||
executeCompilerCompareOutput(new K2JSCompiler(), args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simple() throws Exception {
|
||||
String[] args = {
|
||||
"-src", "compiler/testData/cli/simple.kt",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
|
||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
||||
}
|
||||
@@ -90,7 +98,7 @@ public class CliTest {
|
||||
+ File.pathSeparator
|
||||
+ "compiler/testData/cli/diagnosticsOrder2.kt",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,7 +106,7 @@ public class CliTest {
|
||||
String[] args = {
|
||||
"-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,7 +115,7 @@ public class CliTest {
|
||||
"-src", "compiler/testData/cli/wrongKotlinSignature.kt",
|
||||
"-classpath", "compiler/testData/cli/wrongKotlinSignatureLib",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,29 +124,29 @@ public class CliTest {
|
||||
"-src", "compiler/testData/cli/wrongAbiVersion.kt",
|
||||
"-classpath", "compiler/testData/cli/wrongAbiVersionLib",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void help() throws Exception {
|
||||
executeCompilerCompareOutput(new String[] {"-help"});
|
||||
executeCompilerCompareOutputJVM(new String[] {"-help"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void script() throws Exception {
|
||||
executeCompilerCompareOutput(new String[]{ "-script", "compiler/testData/cli/script.ktscript", "hi", "there" });
|
||||
executeCompilerCompareOutputJVM(new String[] {"-script", "compiler/testData/cli/script.ktscript", "hi", "there"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongArgument() {
|
||||
executeCompilerCompareOutput(new String[] { "-wrongArgument" });
|
||||
executeCompilerCompareOutputJVM(new String[] {"-wrongArgument"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printArguments() {
|
||||
try {
|
||||
System.setProperty("kotlin.print.cmd.args", "true");
|
||||
executeCompilerCompareOutput(new String[] {"-script", "compiler/testData/cli/hello.ktscript"});
|
||||
executeCompilerCompareOutputJVM(new String[] {"-script", "compiler/testData/cli/hello.ktscript"});
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("kotlin.print.cmd.args");
|
||||
@@ -152,7 +160,7 @@ public class CliTest {
|
||||
"-classpath", "not/existing/path",
|
||||
"-annotations", "yet/another/not/existing/path",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
|
||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
||||
}
|
||||
@@ -162,7 +170,7 @@ public class CliTest {
|
||||
String[] args = {
|
||||
"-src", "not/existing/path",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutput(args);
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,7 +207,6 @@ public class CliTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testScriptWithScriptDefinition() {
|
||||
LinkedList<AnalyzerScriptParameter> scriptParameters = new LinkedList<AnalyzerScriptParameter>();
|
||||
@@ -216,4 +223,31 @@ public class CliTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressAllWarningsLowercase() {
|
||||
String[] args = {
|
||||
"-src", "compiler/testData/cli/warnings.kt",
|
||||
"-suppress", "warnings",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressAllWarningsMixedCase() {
|
||||
String[] args = {
|
||||
"-src", "compiler/testData/cli/warnings.kt",
|
||||
"-suppress", "WaRnInGs",
|
||||
"-output", tmpdir.getTmpDir().getPath()};
|
||||
executeCompilerCompareOutputJVM(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressAllWarningsJS() {
|
||||
String[] args = {
|
||||
"-sourceFiles", "compiler/testData/cli/warnings.kt",
|
||||
"-suppress", "WaRnInGs",
|
||||
"-output", new File(tmpdir.getTmpDir(), "out.js").getPath()};
|
||||
executeCompilerCompareOutputJS(args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user