From cbaf38f7935f8f5353d9231da944975dce0e62b6 Mon Sep 17 00:00:00 2001 From: e5l Date: Tue, 19 Sep 2017 17:51:23 +0600 Subject: [PATCH] Add CLI test on new jsr305 flag values --- .../testData/cli/jvm/jsr305/Annotated.java | 8 ++++ .../cli/jvm/jsr305/DefaultAnnotated.java | 6 +++ .../cli/jvm/jsr305/MyMigrationNonnull.java | 15 ++++++ .../testData/cli/jvm/jsr305/MyNonnull.java | 15 ++++++ .../testData/cli/jvm/jsr305/MyNonnullApi.java | 14 ++++++ .../testData/cli/jvm/jsr305AllIgnore.args | 7 +++ compiler/testData/cli/jvm/jsr305AllIgnore.out | 1 + .../cli/jvm/jsr305DefaultMigration.args | 5 ++ .../cli/jvm/jsr305DefaultMigration.kt | 3 ++ .../cli/jvm/jsr305DefaultMigration.out | 4 ++ .../testData/cli/jvm/jsr305FqNameIgnore.args | 6 +++ .../testData/cli/jvm/jsr305FqNameIgnore.out | 4 ++ .../testData/cli/jvm/jsr305FqNameStrict.args | 6 +++ .../testData/cli/jvm/jsr305FqNameStrict.out | 7 +++ compiler/testData/cli/jvm/jsr305Migration.kt | 4 ++ .../cli/jvm/jsr305MigrationDefault.args | 5 ++ .../cli/jvm/jsr305MigrationDefault.out | 4 ++ .../cli/jvm/jsr305MigrationFqNameIgnore.args | 6 +++ .../cli/jvm/jsr305MigrationFqNameIgnore.out | 4 ++ .../cli/jvm/jsr305MigrationIgnore.args | 6 +++ .../cli/jvm/jsr305MigrationIgnore.out | 4 ++ .../testData/cli/jvm/jsr305MigrationWarn.args | 6 +++ .../testData/cli/jvm/jsr305MigrationWarn.out | 7 +++ .../kotlin/cli/CliTestGenerated.java | 48 +++++++++++++++++++ 24 files changed, 195 insertions(+) create mode 100644 compiler/testData/cli/jvm/jsr305/Annotated.java create mode 100644 compiler/testData/cli/jvm/jsr305/DefaultAnnotated.java create mode 100644 compiler/testData/cli/jvm/jsr305/MyMigrationNonnull.java create mode 100644 compiler/testData/cli/jvm/jsr305/MyNonnull.java create mode 100644 compiler/testData/cli/jvm/jsr305/MyNonnullApi.java create mode 100644 compiler/testData/cli/jvm/jsr305AllIgnore.args create mode 100644 compiler/testData/cli/jvm/jsr305AllIgnore.out create mode 100644 compiler/testData/cli/jvm/jsr305DefaultMigration.args create mode 100644 compiler/testData/cli/jvm/jsr305DefaultMigration.kt create mode 100644 compiler/testData/cli/jvm/jsr305DefaultMigration.out create mode 100644 compiler/testData/cli/jvm/jsr305FqNameIgnore.args create mode 100644 compiler/testData/cli/jvm/jsr305FqNameIgnore.out create mode 100644 compiler/testData/cli/jvm/jsr305FqNameStrict.args create mode 100644 compiler/testData/cli/jvm/jsr305FqNameStrict.out create mode 100644 compiler/testData/cli/jvm/jsr305Migration.kt create mode 100644 compiler/testData/cli/jvm/jsr305MigrationDefault.args create mode 100644 compiler/testData/cli/jvm/jsr305MigrationDefault.out create mode 100644 compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.args create mode 100644 compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out create mode 100644 compiler/testData/cli/jvm/jsr305MigrationIgnore.args create mode 100644 compiler/testData/cli/jvm/jsr305MigrationIgnore.out create mode 100644 compiler/testData/cli/jvm/jsr305MigrationWarn.args create mode 100644 compiler/testData/cli/jvm/jsr305MigrationWarn.out diff --git a/compiler/testData/cli/jvm/jsr305/Annotated.java b/compiler/testData/cli/jvm/jsr305/Annotated.java new file mode 100644 index 00000000000..4e63f6ca5bb --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/Annotated.java @@ -0,0 +1,8 @@ + +public class Annotated { + public void foo(@MyNonnull String x) { + } + + public void bar(@MyMigrationNonnull String x) { + } +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305/DefaultAnnotated.java b/compiler/testData/cli/jvm/jsr305/DefaultAnnotated.java new file mode 100644 index 00000000000..f47ac320289 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/DefaultAnnotated.java @@ -0,0 +1,6 @@ + +@MyNonnullApi +public class DefaultAnnotated { + public void foo(String x) { + } +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305/MyMigrationNonnull.java b/compiler/testData/cli/jvm/jsr305/MyMigrationNonnull.java new file mode 100644 index 00000000000..849fa721aeb --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/MyMigrationNonnull.java @@ -0,0 +1,15 @@ +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.ALWAYS) +@Retention(RetentionPolicy.RUNTIME) +@kotlin.annotations.jvm.UnderMigration(status = MigrationStatus.STRICT) +public @interface MyMigrationNonnull { +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305/MyNonnull.java b/compiler/testData/cli/jvm/jsr305/MyNonnull.java new file mode 100644 index 00000000000..0368297c0f2 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/MyNonnull.java @@ -0,0 +1,15 @@ +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.ALWAYS) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNonnull { + +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305/MyNonnullApi.java b/compiler/testData/cli/jvm/jsr305/MyNonnullApi.java new file mode 100644 index 00000000000..e4b2a0012b7 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/MyNonnullApi.java @@ -0,0 +1,14 @@ + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.annotation.meta.TypeQualifierDefault; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@MyMigrationNonnull +@TypeQualifierDefault({ ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) +public @interface MyNonnullApi { +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305AllIgnore.args b/compiler/testData/cli/jvm/jsr305AllIgnore.args new file mode 100644 index 00000000000..741bee0bf80 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305AllIgnore.args @@ -0,0 +1,7 @@ +-Xjsr305=ignore +-Xjsr305=under-migration:ignore +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/jsr305AllIgnore.out b/compiler/testData/cli/jvm/jsr305AllIgnore.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305AllIgnore.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/cli/jvm/jsr305DefaultMigration.args b/compiler/testData/cli/jvm/jsr305DefaultMigration.args new file mode 100644 index 00000000000..7213fe2039e --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DefaultMigration.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/jsr305DefaultMigration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/jsr305DefaultMigration.kt b/compiler/testData/cli/jvm/jsr305DefaultMigration.kt new file mode 100644 index 00000000000..e5c91d3ed6d --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DefaultMigration.kt @@ -0,0 +1,3 @@ +fun test(annotated: DefaultAnnotated) { + annotated.foo(null) +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305DefaultMigration.out b/compiler/testData/cli/jvm/jsr305DefaultMigration.out new file mode 100644 index 00000000000..dfc596b5951 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DefaultMigration.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/jsr305DefaultMigration.kt:2:19: error: null can not be a value of a non-null type String + annotated.foo(null) + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/jsr305FqNameIgnore.args b/compiler/testData/cli/jvm/jsr305FqNameIgnore.args new file mode 100644 index 00000000000..e2c1b96fba0 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305FqNameIgnore.args @@ -0,0 +1,6 @@ +-Xjsr305=@MyNonnull:ignore +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305FqNameIgnore.out b/compiler/testData/cli/jvm/jsr305FqNameIgnore.out new file mode 100644 index 00000000000..f64ed0aa7f6 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305FqNameIgnore.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:3:19: error: null can not be a value of a non-null type String + annotated.bar(null) + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/jsr305FqNameStrict.args b/compiler/testData/cli/jvm/jsr305FqNameStrict.args new file mode 100644 index 00000000000..4ec9b759945 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305FqNameStrict.args @@ -0,0 +1,6 @@ +-Xjsr305=@MyNonnull:strict +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305FqNameStrict.out b/compiler/testData/cli/jvm/jsr305FqNameStrict.out new file mode 100644 index 00000000000..d3a633a1fe1 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305FqNameStrict.out @@ -0,0 +1,7 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: error: null can not be a value of a non-null type String + annotated.foo(null) + ^ +compiler/testData/cli/jvm/jsr305Migration.kt:3:19: error: null can not be a value of a non-null type String + annotated.bar(null) + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/jsr305Migration.kt b/compiler/testData/cli/jvm/jsr305Migration.kt new file mode 100644 index 00000000000..0fbd0819b25 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305Migration.kt @@ -0,0 +1,4 @@ +fun test(annotated: Annotated) { + annotated.foo(null) + annotated.bar(null) +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305MigrationDefault.args b/compiler/testData/cli/jvm/jsr305MigrationDefault.args new file mode 100644 index 00000000000..91172f4fb6b --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationDefault.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305MigrationDefault.out b/compiler/testData/cli/jvm/jsr305MigrationDefault.out new file mode 100644 index 00000000000..f64ed0aa7f6 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationDefault.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:3:19: error: null can not be a value of a non-null type String + annotated.bar(null) + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.args b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.args new file mode 100644 index 00000000000..b7dc94756c2 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.args @@ -0,0 +1,6 @@ +-Xjsr305=@MyMigrationNonnull:ignore +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out new file mode 100644 index 00000000000..6a6ee78e833 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin + annotated.foo(null) + ^ +OK diff --git a/compiler/testData/cli/jvm/jsr305MigrationIgnore.args b/compiler/testData/cli/jvm/jsr305MigrationIgnore.args new file mode 100644 index 00000000000..3a47b6f4aae --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationIgnore.args @@ -0,0 +1,6 @@ +-Xjsr305=under-migration:ignore +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305MigrationIgnore.out b/compiler/testData/cli/jvm/jsr305MigrationIgnore.out new file mode 100644 index 00000000000..6a6ee78e833 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationIgnore.out @@ -0,0 +1,4 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin + annotated.foo(null) + ^ +OK diff --git a/compiler/testData/cli/jvm/jsr305MigrationWarn.args b/compiler/testData/cli/jvm/jsr305MigrationWarn.args new file mode 100644 index 00000000000..9274345ed92 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationWarn.args @@ -0,0 +1,6 @@ +-Xjsr305=under-migration:warn +$TESTDATA_DIR$/jsr305Migration.kt +$TESTDATA_DIR$/jsr305 +$FOREIGN_ANNOTATIONS_DIR$ +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/jsr305MigrationWarn.out b/compiler/testData/cli/jvm/jsr305MigrationWarn.out new file mode 100644 index 00000000000..aa2bec44ea5 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305MigrationWarn.out @@ -0,0 +1,7 @@ +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin + annotated.foo(null) + ^ +compiler/testData/cli/jvm/jsr305Migration.kt:3:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin + annotated.bar(null) + ^ +OK diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index baaaa972215..f767e14809f 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -218,6 +218,18 @@ public class CliTestGenerated extends AbstractCliTest { doJvmTest(fileName); } + @TestMetadata("jsr305AllIgnore.args") + public void testJsr305AllIgnore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305AllIgnore.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305DefaultMigration.args") + public void testJsr305DefaultMigration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305DefaultMigration.args"); + doJvmTest(fileName); + } + @TestMetadata("jsr305DeprecatedEnable.args") public void testJsr305DeprecatedEnable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305DeprecatedEnable.args"); @@ -236,12 +248,48 @@ public class CliTestGenerated extends AbstractCliTest { doJvmTest(fileName); } + @TestMetadata("jsr305FqNameIgnore.args") + public void testJsr305FqNameIgnore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305FqNameIgnore.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305FqNameStrict.args") + public void testJsr305FqNameStrict() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305FqNameStrict.args"); + doJvmTest(fileName); + } + @TestMetadata("jsr305Ignore.args") public void testJsr305Ignore() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305Ignore.args"); doJvmTest(fileName); } + @TestMetadata("jsr305MigrationDefault.args") + public void testJsr305MigrationDefault() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305MigrationDefault.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305MigrationFqNameIgnore.args") + public void testJsr305MigrationFqNameIgnore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305MigrationIgnore.args") + public void testJsr305MigrationIgnore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305MigrationIgnore.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305MigrationWarn.args") + public void testJsr305MigrationWarn() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305MigrationWarn.args"); + doJvmTest(fileName); + } + @TestMetadata("jsr305NoFlag.args") public void testJsr305NoFlag() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305NoFlag.args");