Add tests about metadata rewriting of extension property.
Bug: 70169921
Change-Id: I819f083065a8f61e0f9720d477e6faf32bfb3ce2
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionFunctionTest.java
similarity index 85%
rename from src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java
rename to src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionFunctionTest.java
index 6f9dd7f..8e1e6b7 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionFunctionTest.java
@@ -30,7 +30,7 @@
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
-public class MetadataRenameInExtensionTest extends KotlinMetadataTestBase {
+public class MetadataRenameInExtensionFunctionTest extends KotlinMetadataTestBase {
private final TestParameters parameters;
@@ -40,7 +40,7 @@
getTestParameters().withCfRuntimes().build(), KotlinTargetVersion.values());
}
- public MetadataRenameInExtensionTest(
+ public MetadataRenameInExtensionFunctionTest(
TestParameters parameters, KotlinTargetVersion targetVersion) {
super(targetVersion);
this.parameters = parameters;
@@ -50,7 +50,7 @@
@BeforeClass
public static void createLibJar() throws Exception {
- String extLibFolder = PKG_PREFIX + "/extension_lib";
+ String extLibFolder = PKG_PREFIX + "/extension_function_lib";
extLibJar =
kotlinc(KOTLINC, KotlinTargetVersion.JAVA_8)
.addSourceFiles(getKotlinFileInTest(extLibFolder, "B"))
@@ -58,23 +58,23 @@
}
@Test
- public void testMetadataInExtension_merged() throws Exception {
+ public void testMetadataInExtensionFunction_merged() throws Exception {
R8TestCompileResult compileResult =
testForR8(parameters.getBackend())
.addProgramFiles(extLibJar)
// Keep the B class and its interface (which has the doStuff method).
.addKeepRules("-keep class **.B")
.addKeepRules("-keep class **.I { <methods>; }")
- // Keep the BKt extension method which requires metadata
+ // Keep the BKt extension function which requires metadata
// to be called with Kotlin syntax from other kotlin code.
.addKeepRules("-keep class **.BKt { <methods>; }")
.addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
.addOptionsModification(InternalOptions::enableKotlinMetadataRewriting)
.compile();
String pkg = getClass().getPackage().getName();
- final String superClassName = pkg + ".extension_lib.Super";
- final String bClassName = pkg + ".extension_lib.B";
- final String bKtClassName = pkg + ".extension_lib.BKt";
+ final String superClassName = pkg + ".extension_function_lib.Super";
+ final String bClassName = pkg + ".extension_function_lib.B";
+ final String bKtClassName = pkg + ".extension_function_lib.BKt";
compileResult.inspect(inspector -> {
assertThat(inspector.clazz(superClassName), not(isPresent()));
@@ -101,7 +101,7 @@
Path libJar = compileResult.writeToZip();
- String appFolder = PKG_PREFIX + "/extension_app";
+ String appFolder = PKG_PREFIX + "/extension_function_app";
Path output =
kotlinc(parameters.getRuntime().asCf(), KOTLINC, KotlinTargetVersion.JAVA_8)
.addClasspathFiles(libJar)
@@ -112,12 +112,12 @@
testForJvm()
.addRunClasspathFiles(ToolHelper.getKotlinStdlibJar(), libJar)
.addClasspath(output)
- .run(parameters.getRuntime(), pkg + ".extension_app.MainKt")
+ .run(parameters.getRuntime(), pkg + ".extension_function_app.MainKt")
.assertSuccessWithOutputLines("do stuff", "do stuff");
}
@Test
- public void testMetadataInExtension_renamed() throws Exception {
+ public void testMetadataInExtensionFunction_renamed() throws Exception {
R8TestCompileResult compileResult =
testForR8(parameters.getBackend())
.addProgramFiles(extLibJar)
@@ -126,16 +126,16 @@
.addKeepRules("-keep class **.I { <methods>; }")
// Keep Super, but allow minification.
.addKeepRules("-keep,allowobfuscation class **.Super")
- // Keep the BKt extension method which requires metadata
+ // Keep the BKt extension function which requires metadata
// to be called with Kotlin syntax from other kotlin code.
.addKeepRules("-keep class **.BKt { <methods>; }")
.addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
.addOptionsModification(InternalOptions::enableKotlinMetadataRewriting)
.compile();
String pkg = getClass().getPackage().getName();
- final String superClassName = pkg + ".extension_lib.Super";
- final String bClassName = pkg + ".extension_lib.B";
- final String bKtClassName = pkg + ".extension_lib.BKt";
+ final String superClassName = pkg + ".extension_function_lib.Super";
+ final String bClassName = pkg + ".extension_function_lib.B";
+ final String bKtClassName = pkg + ".extension_function_lib.BKt";
compileResult.inspect(inspector -> {
ClassSubject sup = inspector.clazz(superClassName);
assertThat(sup, isPresent());
@@ -166,7 +166,7 @@
Path libJar = compileResult.writeToZip();
- String appFolder = PKG_PREFIX + "/extension_app";
+ String appFolder = PKG_PREFIX + "/extension_function_app";
Path output =
kotlinc(parameters.getRuntime().asCf(), KOTLINC, KotlinTargetVersion.JAVA_8)
.addClasspathFiles(libJar)
@@ -177,7 +177,7 @@
testForJvm()
.addRunClasspathFiles(ToolHelper.getKotlinStdlibJar(), libJar)
.addClasspath(output)
- .run(parameters.getRuntime(), pkg + ".extension_app.MainKt")
+ .run(parameters.getRuntime(), pkg + ".extension_function_app.MainKt")
.assertSuccessWithOutputLines("do stuff", "do stuff");
}
}
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionPropertyTest.java
similarity index 74%
copy from src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java
copy to src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionPropertyTest.java
index 6f9dd7f..0b327c9 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionTest.java
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRenameInExtensionPropertyTest.java
@@ -1,25 +1,25 @@
-// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.kotlin.metadata;
import static com.android.tools.r8.KotlinCompilerTool.KOTLINC;
-import static com.android.tools.r8.utils.codeinspector.Matchers.isExtension;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
import static com.android.tools.r8.utils.codeinspector.Matchers.isRenamed;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import com.android.tools.r8.R8TestCompileResult;
import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.KotlinTargetVersion;
+import com.android.tools.r8.ToolHelper.ProcessResult;
import com.android.tools.r8.shaking.ProguardKeepAttributes;
import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.codeinspector.ClassSubject;
import com.android.tools.r8.utils.codeinspector.KmClassSubject;
-import com.android.tools.r8.utils.codeinspector.KmFunctionSubject;
import com.android.tools.r8.utils.codeinspector.KmPackageSubject;
import java.nio.file.Path;
import java.util.Collection;
@@ -30,7 +30,7 @@
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
-public class MetadataRenameInExtensionTest extends KotlinMetadataTestBase {
+public class MetadataRenameInExtensionPropertyTest extends KotlinMetadataTestBase {
private final TestParameters parameters;
@@ -40,7 +40,7 @@
getTestParameters().withCfRuntimes().build(), KotlinTargetVersion.values());
}
- public MetadataRenameInExtensionTest(
+ public MetadataRenameInExtensionPropertyTest(
TestParameters parameters, KotlinTargetVersion targetVersion) {
super(targetVersion);
this.parameters = parameters;
@@ -50,7 +50,7 @@
@BeforeClass
public static void createLibJar() throws Exception {
- String extLibFolder = PKG_PREFIX + "/extension_lib";
+ String extLibFolder = PKG_PREFIX + "/extension_property_lib";
extLibJar =
kotlinc(KOTLINC, KotlinTargetVersion.JAVA_8)
.addSourceFiles(getKotlinFileInTest(extLibFolder, "B"))
@@ -58,23 +58,23 @@
}
@Test
- public void testMetadataInExtension_merged() throws Exception {
+ public void testMetadataInExtensionProperty_merged() throws Exception {
R8TestCompileResult compileResult =
testForR8(parameters.getBackend())
.addProgramFiles(extLibJar)
// Keep the B class and its interface (which has the doStuff method).
.addKeepRules("-keep class **.B")
.addKeepRules("-keep class **.I { <methods>; }")
- // Keep the BKt extension method which requires metadata
+ // Keep the BKt extension property which requires metadata
// to be called with Kotlin syntax from other kotlin code.
.addKeepRules("-keep class **.BKt { <methods>; }")
.addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
.addOptionsModification(InternalOptions::enableKotlinMetadataRewriting)
.compile();
String pkg = getClass().getPackage().getName();
- final String superClassName = pkg + ".extension_lib.Super";
- final String bClassName = pkg + ".extension_lib.B";
- final String bKtClassName = pkg + ".extension_lib.BKt";
+ final String superClassName = pkg + ".extension_property_lib.Super";
+ final String bClassName = pkg + ".extension_property_lib.B";
+ final String bKtClassName = pkg + ".extension_property_lib.BKt";
compileResult.inspect(inspector -> {
assertThat(inspector.clazz(superClassName), not(isPresent()));
@@ -95,29 +95,25 @@
KmPackageSubject kmPackage = bKt.getKmPackage();
assertThat(kmPackage, isPresent());
- KmFunctionSubject kmFunction = kmPackage.kmFunctionExtensionWithUniqueName("extension");
- assertThat(kmFunction, isExtension());
+ // TODO(b/70169921): test property details.
});
Path libJar = compileResult.writeToZip();
- String appFolder = PKG_PREFIX + "/extension_app";
- Path output =
+ String appFolder = PKG_PREFIX + "/extension_property_app";
+ ProcessResult processResult =
kotlinc(parameters.getRuntime().asCf(), KOTLINC, KotlinTargetVersion.JAVA_8)
.addClasspathFiles(libJar)
.addSourceFiles(getKotlinFileInTest(appFolder, "main"))
.setOutputPath(temp.newFolder().toPath())
- .compile();
-
- testForJvm()
- .addRunClasspathFiles(ToolHelper.getKotlinStdlibJar(), libJar)
- .addClasspath(output)
- .run(parameters.getRuntime(), pkg + ".extension_app.MainKt")
- .assertSuccessWithOutputLines("do stuff", "do stuff");
+ .compileRaw();
+ // TODO(b/70169921): should be able to compile!
+ assertNotEquals(0, processResult.exitCode);
+ assertThat(processResult.stderr, containsString("unresolved reference: doStuff"));
}
@Test
- public void testMetadataInExtension_renamed() throws Exception {
+ public void testMetadataInExtensionProperty_renamed() throws Exception {
R8TestCompileResult compileResult =
testForR8(parameters.getBackend())
.addProgramFiles(extLibJar)
@@ -126,16 +122,16 @@
.addKeepRules("-keep class **.I { <methods>; }")
// Keep Super, but allow minification.
.addKeepRules("-keep,allowobfuscation class **.Super")
- // Keep the BKt extension method which requires metadata
+ // Keep the BKt extension property which requires metadata
// to be called with Kotlin syntax from other kotlin code.
.addKeepRules("-keep class **.BKt { <methods>; }")
.addKeepAttributes(ProguardKeepAttributes.RUNTIME_VISIBLE_ANNOTATIONS)
.addOptionsModification(InternalOptions::enableKotlinMetadataRewriting)
.compile();
String pkg = getClass().getPackage().getName();
- final String superClassName = pkg + ".extension_lib.Super";
- final String bClassName = pkg + ".extension_lib.B";
- final String bKtClassName = pkg + ".extension_lib.BKt";
+ final String superClassName = pkg + ".extension_property_lib.Super";
+ final String bClassName = pkg + ".extension_property_lib.B";
+ final String bKtClassName = pkg + ".extension_property_lib.BKt";
compileResult.inspect(inspector -> {
ClassSubject sup = inspector.clazz(superClassName);
assertThat(sup, isPresent());
@@ -160,24 +156,20 @@
KmPackageSubject kmPackage = bKt.getKmPackage();
assertThat(kmPackage, isPresent());
- KmFunctionSubject kmFunction = kmPackage.kmFunctionExtensionWithUniqueName("extension");
- assertThat(kmFunction, isExtension());
+ // TODO(b/70169921): test property details.
});
Path libJar = compileResult.writeToZip();
- String appFolder = PKG_PREFIX + "/extension_app";
- Path output =
+ String appFolder = PKG_PREFIX + "/extension_property_app";
+ ProcessResult processResult =
kotlinc(parameters.getRuntime().asCf(), KOTLINC, KotlinTargetVersion.JAVA_8)
.addClasspathFiles(libJar)
.addSourceFiles(getKotlinFileInTest(appFolder, "main"))
.setOutputPath(temp.newFolder().toPath())
- .compile();
-
- testForJvm()
- .addRunClasspathFiles(ToolHelper.getKotlinStdlibJar(), libJar)
- .addClasspath(output)
- .run(parameters.getRuntime(), pkg + ".extension_app.MainKt")
- .assertSuccessWithOutputLines("do stuff", "do stuff");
+ .compileRaw();
+ // TODO(b/70169921): should be able to compile!
+ assertNotEquals(0, processResult.exitCode);
+ assertThat(processResult.stderr, containsString("unresolved reference: doStuff"));
}
-}
+}
\ No newline at end of file
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_app/main.kt b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_app/main.kt
deleted file mode 100644
index 246d3fe..0000000
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_app/main.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8.kotlin.metadata.extension_app
-
-import com.android.tools.r8.kotlin.metadata.extension_lib.B
-import com.android.tools.r8.kotlin.metadata.extension_lib.extension
-
-fun main() {
- B().doStuff()
- B().extension()
-}
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_app/main.kt b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_app/main.kt
new file mode 100644
index 0000000..2196586
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_app/main.kt
@@ -0,0 +1,12 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.kotlin.metadata.extension_function_app
+
+import com.android.tools.r8.kotlin.metadata.extension_function_lib.B
+import com.android.tools.r8.kotlin.metadata.extension_function_lib.extension
+
+fun main() {
+ B().doStuff()
+ B().extension()
+}
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_lib/B.kt
similarity index 84%
rename from src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt
rename to src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_lib/B.kt
index df51d42..84c759a 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_function_lib/B.kt
@@ -1,7 +1,7 @@
// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8.kotlin.metadata.extension_lib
+package com.android.tools.r8.kotlin.metadata.extension_function_lib
interface I {
fun doStuff()
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_app/main.kt b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_app/main.kt
new file mode 100644
index 0000000..320bad9
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_app/main.kt
@@ -0,0 +1,13 @@
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.kotlin.metadata.extension_property_app
+
+import com.android.tools.r8.kotlin.metadata.extension_property_lib.B
+import com.android.tools.r8.kotlin.metadata.extension_property_lib.asI
+
+fun main() {
+ val b = B()
+ b.doStuff()
+ b.asI.doStuff()
+}
\ No newline at end of file
diff --git a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_lib/B.kt
similarity index 63%
copy from src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt
copy to src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_lib/B.kt
index df51d42..4be711f 100644
--- a/src/test/java/com/android/tools/r8/kotlin/metadata/extension_lib/B.kt
+++ b/src/test/java/com/android/tools/r8/kotlin/metadata/extension_property_lib/B.kt
@@ -1,7 +1,7 @@
-// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8.kotlin.metadata.extension_lib
+package com.android.tools.r8.kotlin.metadata.extension_property_lib
interface I {
fun doStuff()
@@ -15,6 +15,5 @@
class B : Super()
-fun B.extension() {
- doStuff()
-}
\ No newline at end of file
+val B.asI : I
+ get() = this