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;
|
public boolean version;
|
||||||
@Argument(value = "help", alias = "h", description = "Show help")
|
@Argument(value = "help", alias = "h", description = "Show help")
|
||||||
public boolean help;
|
public boolean help;
|
||||||
|
@Argument(value = "suppress", description = "Suppress compiler messages by severity (warnings)")
|
||||||
|
public String suppress;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHelp() {
|
public boolean isHelp() {
|
||||||
@@ -40,4 +42,9 @@ public abstract class CommonCompilerArguments extends CompilerArguments {
|
|||||||
public void setTags(boolean tags) {
|
public void setTags(boolean tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean suppressAllWarnings() {
|
||||||
|
return "warnings".equalsIgnoreCase(suppress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.cli.common;
|
package org.jetbrains.jet.cli.common;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
@@ -27,9 +28,7 @@ import org.jetbrains.jet.config.CompilerConfiguration;
|
|||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import static org.jetbrains.jet.cli.common.ExitCode.COMPILATION_ERROR;
|
import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||||
import static org.jetbrains.jet.cli.common.ExitCode.INTERNAL_ERROR;
|
|
||||||
import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
|
||||||
|
|
||||||
public abstract class CLICompiler<A extends CompilerArguments> {
|
public abstract class CLICompiler<A extends CompilerArguments> {
|
||||||
|
|
||||||
@@ -108,10 +107,14 @@ public abstract class CLICompiler<A extends CompilerArguments> {
|
|||||||
|
|
||||||
printVersionIfNeeded(errStream, arguments, messageRenderer);
|
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 {
|
try {
|
||||||
return exec(printingCollector, arguments);
|
return exec(collector, arguments);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
errStream.print(messageRenderer.renderConclusion());
|
errStream.print(messageRenderer.renderConclusion());
|
||||||
|
|||||||
@@ -45,4 +45,6 @@ public abstract class CompilerArguments {
|
|||||||
public abstract boolean isVerbose();
|
public abstract boolean isVerbose();
|
||||||
|
|
||||||
public abstract String getSrc();
|
public abstract String getSrc();
|
||||||
|
|
||||||
|
public abstract boolean suppressAllWarnings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
|||||||
-output [String] output directory
|
-output [String] output directory
|
||||||
-module [String] module to compile
|
-module [String] module to compile
|
||||||
-script [flag] evaluate script
|
-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
|
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||||
-verbose [flag] Enable verbose logging output
|
-verbose [flag] Enable verbose logging output
|
||||||
-version [flag] Display compiler version
|
-version [flag] Display compiler version
|
||||||
-help (-h) [flag] show help
|
-help (-h) [flag] Show help
|
||||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
-suppress [String] Suppress compiler messages by severity (warnings)
|
||||||
OK
|
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
|
-output [String] output directory
|
||||||
-module [String] module to compile
|
-module [String] module to compile
|
||||||
-script [flag] evaluate script
|
-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
|
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
|
||||||
-verbose [flag] Enable verbose logging output
|
-verbose [flag] Enable verbose logging output
|
||||||
-version [flag] Display compiler version
|
-version [flag] Display compiler version
|
||||||
-help (-h) [flag] show help
|
-help (-h) [flag] Show help
|
||||||
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
|
-suppress [String] Suppress compiler messages by severity (warnings)
|
||||||
INTERNAL_ERROR
|
INTERNAL_ERROR
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
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.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||||
@@ -48,12 +49,12 @@ public class CliTest {
|
|||||||
public final TestName testName = new TestName();
|
public final TestName testName = new TestName();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String executeCompilerGrabOutput(@NotNull String[] args) {
|
private static String executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) {
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
PrintStream origOut = System.out;
|
PrintStream origOut = System.out;
|
||||||
try {
|
try {
|
||||||
System.setOut(new PrintStream(bytes));
|
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";
|
return bytes.toString("utf-8") + exitCode + "\n";
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@@ -64,21 +65,28 @@ public class CliTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeCompilerCompareOutput(@NotNull String[] args) {
|
private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String[] args) {
|
||||||
String actual = executeCompilerGrabOutput(args)
|
String actual = executeCompilerGrabOutput(compiler, args)
|
||||||
.replace(new File("compiler/testData/cli/").getAbsolutePath(), "$TESTDATA_DIR$")
|
.replace(new File("compiler/testData/cli/").getAbsolutePath(), "$TESTDATA_DIR$")
|
||||||
.replace("\\", "/");
|
.replace("\\", "/");
|
||||||
|
|
||||||
JetTestUtils.assertEqualsToFile(new File("compiler/testData/cli/" + testName.getMethodName() + ".out"), actual);
|
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
|
@Test
|
||||||
public void simple() throws Exception {
|
public void simple() throws Exception {
|
||||||
String[] args = {
|
String[] args = {
|
||||||
"-src", "compiler/testData/cli/simple.kt",
|
"-src", "compiler/testData/cli/simple.kt",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
||||||
}
|
}
|
||||||
@@ -90,7 +98,7 @@ public class CliTest {
|
|||||||
+ File.pathSeparator
|
+ File.pathSeparator
|
||||||
+ "compiler/testData/cli/diagnosticsOrder2.kt",
|
+ "compiler/testData/cli/diagnosticsOrder2.kt",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -98,7 +106,7 @@ public class CliTest {
|
|||||||
String[] args = {
|
String[] args = {
|
||||||
"-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt",
|
"-src", "compiler/testData/cli/multipleTextRangesInDiagnosticsOrder.kt",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -107,7 +115,7 @@ public class CliTest {
|
|||||||
"-src", "compiler/testData/cli/wrongKotlinSignature.kt",
|
"-src", "compiler/testData/cli/wrongKotlinSignature.kt",
|
||||||
"-classpath", "compiler/testData/cli/wrongKotlinSignatureLib",
|
"-classpath", "compiler/testData/cli/wrongKotlinSignatureLib",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -116,29 +124,29 @@ public class CliTest {
|
|||||||
"-src", "compiler/testData/cli/wrongAbiVersion.kt",
|
"-src", "compiler/testData/cli/wrongAbiVersion.kt",
|
||||||
"-classpath", "compiler/testData/cli/wrongAbiVersionLib",
|
"-classpath", "compiler/testData/cli/wrongAbiVersionLib",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void help() throws Exception {
|
public void help() throws Exception {
|
||||||
executeCompilerCompareOutput(new String[] {"-help"});
|
executeCompilerCompareOutputJVM(new String[] {"-help"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void script() throws Exception {
|
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
|
@Test
|
||||||
public void wrongArgument() {
|
public void wrongArgument() {
|
||||||
executeCompilerCompareOutput(new String[] { "-wrongArgument" });
|
executeCompilerCompareOutputJVM(new String[] {"-wrongArgument"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void printArguments() {
|
public void printArguments() {
|
||||||
try {
|
try {
|
||||||
System.setProperty("kotlin.print.cmd.args", "true");
|
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 {
|
finally {
|
||||||
System.clearProperty("kotlin.print.cmd.args");
|
System.clearProperty("kotlin.print.cmd.args");
|
||||||
@@ -152,7 +160,7 @@ public class CliTest {
|
|||||||
"-classpath", "not/existing/path",
|
"-classpath", "not/existing/path",
|
||||||
"-annotations", "yet/another/not/existing/path",
|
"-annotations", "yet/another/not/existing/path",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
|
||||||
}
|
}
|
||||||
@@ -162,7 +170,7 @@ public class CliTest {
|
|||||||
String[] args = {
|
String[] args = {
|
||||||
"-src", "not/existing/path",
|
"-src", "not/existing/path",
|
||||||
"-output", tmpdir.getTmpDir().getPath()};
|
"-output", tmpdir.getTmpDir().getPath()};
|
||||||
executeCompilerCompareOutput(args);
|
executeCompilerCompareOutputJVM(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -199,7 +207,6 @@ public class CliTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScriptWithScriptDefinition() {
|
public void testScriptWithScriptDefinition() {
|
||||||
LinkedList<AnalyzerScriptParameter> scriptParameters = new LinkedList<AnalyzerScriptParameter>();
|
LinkedList<AnalyzerScriptParameter> scriptParameters = new LinkedList<AnalyzerScriptParameter>();
|
||||||
@@ -216,4 +223,31 @@ public class CliTest {
|
|||||||
throw new RuntimeException(e);
|
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