Tests for 'suppress' annotation

This commit is contained in:
Andrey Breslav
2013-09-17 19:28:43 +04:00
parent 1dff2fcf36
commit 2dfaa81995
25 changed files with 265 additions and 3 deletions
@@ -47,7 +47,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
return ContainerUtil.filter(diagnostics, new Condition<Diagnostic>() {
@Override
public boolean value(Diagnostic diagnostic) {
return isSuppressed(diagnostic);
return !isSuppressed(diagnostic);
}
});
}
@@ -100,7 +100,7 @@ public class DiagnosticsWithSuppression implements Diagnostics {
List<CompileTimeConstant<?>> values = arrayValue.getValue();
if (isSuppressedByStrings(diagnostic, strings(values))) {
return true;
}
}
@@ -0,0 +1,7 @@
suppress("warnings")
class C {
fun foo(p: String??) {
// Make sure errors are not suppressed:
<!VAL_REASSIGNMENT!>p<!> = ""
}
}
@@ -0,0 +1,6 @@
class C {
suppress("warnings")
class object {
val foo: String?? = null as Nothing?
}
}
@@ -0,0 +1,4 @@
class C {
suppress("warnings")
fun foo(p: String??) {}
}
@@ -0,0 +1,4 @@
suppress("warnings")
object C {
fun foo(p: String??) {}
}
@@ -0,0 +1,3 @@
class C {
fun foo(suppress("warnings") p: String?? = "" as String) {}
}
@@ -0,0 +1,4 @@
class C {
suppress("warnings")
val foo: String?? = null as Nothing?
}
@@ -0,0 +1,5 @@
class C {
val foo: String?
[suppress("warnings")]
get(): String?? = null as Nothing?
}
@@ -0,0 +1,5 @@
suppress("REDUNDANT_NULLABLE")
class C {
suppress("UNNECESSARY_NOT_NULL_ASSERTION")
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,4 @@
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
class C {
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,6 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
class object {
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
}
@@ -0,0 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,4 @@
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
object C {
fun foo(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,3 @@
class C {
fun foo(suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION") p: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??) = p
}
@@ -0,0 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")
val foo: String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,5 @@
class C {
val foo: String?
[suppress("REDUNDANT_NULLABLE", "UNNECESSARY_NOT_NULL_ASSERTION")]
get(): String?? = ""!! <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> String??
}
@@ -0,0 +1,4 @@
suppress("REDUNDANT_NULLABLE")
class C {
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
}
@@ -0,0 +1,6 @@
class C {
suppress("REDUNDANT_NULLABLE")
class object {
val foo: String?? = null <!USELESS_CAST!>as<!> Nothing??
}
}
@@ -0,0 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE")
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
}
@@ -0,0 +1,7 @@
class C {
fun foo(): Any? {
[suppress("REDUNDANT_NULLABLE")]
val v: String?? = null <!USELESS_CAST!>as<!> Nothing??
return v
}
}
@@ -0,0 +1,4 @@
suppress("REDUNDANT_NULLABLE")
object C {
fun foo(): String?? = null <!USELESS_CAST!>as<!> Nothing??
}
@@ -0,0 +1,3 @@
class C {
fun foo(suppress("REDUNDANT_NULLABLE") p: String?? = null <!USELESS_CAST!>as<!> Nothing??) = p
}
@@ -0,0 +1,4 @@
class C {
suppress("REDUNDANT_NULLABLE")
val foo: String?? = null <!USELESS_CAST!>as<!> Nothing?
}
@@ -0,0 +1,5 @@
class C {
val foo: String?
[suppress("REDUNDANT_NULLABLE")]
get(): String?? = null <!USELESS_CAST!>as<!> Nothing??
}
@@ -33,7 +33,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve {
@TestMetadata("compiler/testData/diagnostics/tests")
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.CallableReference.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Varargs.class, Tests.When.class})
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.CallableReference.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Deparenthesize.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Suppress.class, Tests.ThisAndSuper.class, Tests.Varargs.class, Tests.When.class})
public static class Tests extends AbstractDiagnosticsTestWithEagerResolve {
@TestMetadata("Abstract.kt")
public void testAbstract() throws Exception {
@@ -5565,6 +5565,162 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
}
@TestMetadata("compiler/testData/diagnostics/tests/suppress")
@InnerTestClasses({Suppress.AllWarnings.class, Suppress.ManyWarnings.class, Suppress.OneWarning.class})
public static class Suppress extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInSuppress() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/suppress"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/testData/diagnostics/tests/suppress/allWarnings")
public static class AllWarnings extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInAllWarnings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/suppress/allWarnings"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("suppressWarningsOnClass.kt")
public void testSuppressWarningsOnClass() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClass.kt");
}
@TestMetadata("suppressWarningsOnClassObject.kt")
public void testSuppressWarningsOnClassObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnClassObject.kt");
}
@TestMetadata("suppressWarningsOnFunction.kt")
public void testSuppressWarningsOnFunction() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnFunction.kt");
}
@TestMetadata("suppressWarningsOnObject.kt")
public void testSuppressWarningsOnObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnObject.kt");
}
@TestMetadata("suppressWarningsOnParameter.kt")
public void testSuppressWarningsOnParameter() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnParameter.kt");
}
@TestMetadata("suppressWarningsOnProperty.kt")
public void testSuppressWarningsOnProperty() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnProperty.kt");
}
@TestMetadata("suppressWarningsOnPropertyAccessor.kt")
public void testSuppressWarningsOnPropertyAccessor() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/allWarnings/suppressWarningsOnPropertyAccessor.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/suppress/manyWarnings")
public static class ManyWarnings extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInManyWarnings() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/suppress/manyWarnings"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("mixed.kt")
public void testMixed() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/mixed.kt");
}
@TestMetadata("onClass.kt")
public void testOnClass() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onClass.kt");
}
@TestMetadata("onClassObject.kt")
public void testOnClassObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onClassObject.kt");
}
@TestMetadata("onFunction.kt")
public void testOnFunction() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onFunction.kt");
}
@TestMetadata("onObject.kt")
public void testOnObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onObject.kt");
}
@TestMetadata("onParameter.kt")
public void testOnParameter() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onParameter.kt");
}
@TestMetadata("onProperty.kt")
public void testOnProperty() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onProperty.kt");
}
@TestMetadata("onPropertyAccessor.kt")
public void testOnPropertyAccessor() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/manyWarnings/onPropertyAccessor.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/suppress/oneWarning")
public static class OneWarning extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInOneWarning() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/suppress/oneWarning"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("onClass.kt")
public void testOnClass() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onClass.kt");
}
@TestMetadata("onClassObject.kt")
public void testOnClassObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onClassObject.kt");
}
@TestMetadata("onFunction.kt")
public void testOnFunction() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onFunction.kt");
}
@TestMetadata("onLocalVariable.kt")
public void testOnLocalVariable() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onLocalVariable.kt");
}
@TestMetadata("onObject.kt")
public void testOnObject() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onObject.kt");
}
@TestMetadata("onParameter.kt")
public void testOnParameter() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onParameter.kt");
}
@TestMetadata("onProperty.kt")
public void testOnProperty() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onProperty.kt");
}
@TestMetadata("onPropertyAccessor.kt")
public void testOnPropertyAccessor() throws Exception {
doTest("compiler/testData/diagnostics/tests/suppress/oneWarning/onPropertyAccessor.kt");
}
}
public static Test innerSuite() {
TestSuite suite = new TestSuite("Suppress");
suite.addTestSuite(Suppress.class);
suite.addTestSuite(AllWarnings.class);
suite.addTestSuite(ManyWarnings.class);
suite.addTestSuite(OneWarning.class);
return suite;
}
}
@TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper")
public static class ThisAndSuper extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInThisAndSuper() throws Exception {
@@ -5788,6 +5944,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
suite.addTest(SmartCasts.innerSuite());
suite.addTestSuite(Substitutions.class);
suite.addTestSuite(Subtyping.class);
suite.addTest(Suppress.innerSuite());
suite.addTestSuite(ThisAndSuper.class);
suite.addTestSuite(Varargs.class);
suite.addTestSuite(When.class);