blob: 258230a2a11a6738d4519d3569e44c08fc46eac4 [file] [log] [blame]
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +01001// Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package com.android.tools.r8.kotlin.metadata;
6
7import static com.android.tools.r8.ToolHelper.getKotlinAnnotationJar;
8import static com.android.tools.r8.ToolHelper.getKotlinStdlibJar;
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +01009
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010010import com.android.tools.r8.KotlinTestParameters;
11import com.android.tools.r8.TestParameters;
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010012import com.android.tools.r8.utils.DescriptorUtils;
13import com.android.tools.r8.utils.StringUtils;
14import java.nio.file.Path;
15import java.util.Collection;
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010016import org.junit.Test;
17import org.junit.runner.RunWith;
18import org.junit.runners.Parameterized;
19
20@RunWith(Parameterized.class)
21public class MetadataRewriteCrossinlineBlockTest extends KotlinMetadataTestBase {
22
Morten Krogh-Jespersen3dfba42a2022-01-03 09:47:06 +010023 private final String EXPECTED =
24 StringUtils.lines(
25 "foo", "42", "42", "0", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42",
26 "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42", "42",
27 "42", "42", "42", "42");
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010028 private static final String PKG_LIB = PKG + ".crossinline_block_lib";
29 private static final String PKG_APP = PKG + ".crossinline_block_app";
30
31 @Parameterized.Parameters(name = "{0}, {1}")
32 public static Collection<Object[]> data() {
33 return buildParameters(
34 getTestParameters().withCfRuntimes().build(),
35 getKotlinTestParameters().withAllCompilersAndTargetVersions().build());
36 }
37
38 public MetadataRewriteCrossinlineBlockTest(
39 TestParameters parameters, KotlinTestParameters kotlinParameters) {
40 super(kotlinParameters);
41 this.parameters = parameters;
42 }
43
44 private static final KotlinCompileMemoizer libJars =
45 getCompileMemoizer(
46 getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_LIB), "lib"));
47 private final TestParameters parameters;
48
49 @Test
50 public void smokeTest() throws Exception {
51 Path libJar = libJars.getForConfiguration(kotlinc, targetVersion);
52 Path output =
53 kotlinc(parameters.getRuntime().asCf(), kotlinc, targetVersion)
54 .addClasspathFiles(libJar)
55 .addSourceFiles(
56 getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_APP), "main"))
57 .setOutputPath(temp.newFolder().toPath())
58 .compile();
59 testForJvm()
60 .addRunClasspathFiles(getKotlinStdlibJar(kotlinc), libJar)
61 .addClasspath(output)
62 .run(parameters.getRuntime(), PKG_APP + ".MainKt")
63 .assertSuccessWithOutput(EXPECTED);
64 }
65
66 @Test
67 public void testMetadataForLib() throws Exception {
68 Path libJar =
69 testForR8Compat(parameters.getBackend())
70 .addProgramFiles(libJars.getForConfiguration(kotlinc, targetVersion))
71 .addClasspathFiles(getKotlinStdlibJar(kotlinc), getKotlinAnnotationJar(kotlinc))
72 .addKeepAllClassesRule()
73 .addKeepAllAttributes()
74 .compile()
75 .writeToZip();
Morten Krogh-Jespersen3dfba42a2022-01-03 09:47:06 +010076 Path output =
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010077 kotlinc(parameters.getRuntime().asCf(), kotlinc, targetVersion)
78 .addClasspathFiles(libJar)
79 .addSourceFiles(
80 getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_APP), "main"))
81 .setOutputPath(temp.newFolder().toPath())
82 .enableAssertions()
Morten Krogh-Jespersen3dfba42a2022-01-03 09:47:06 +010083 .compile();
84 testForJvm()
85 .addRunClasspathFiles(getKotlinStdlibJar(kotlinc), libJar)
86 .addClasspath(output)
87 .run(parameters.getRuntime(), PKG_APP + ".MainKt")
88 .assertSuccessWithOutput(EXPECTED);
Morten Krogh-Jespersenf5580172022-01-03 09:44:35 +010089 }
90}