Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 1 | // 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 | |
| 5 | package com.android.tools.r8.kotlin.metadata; |
| 6 | |
| 7 | import static com.android.tools.r8.ToolHelper.getKotlinAnnotationJar; |
| 8 | import static com.android.tools.r8.ToolHelper.getKotlinStdlibJar; |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 9 | |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 10 | import com.android.tools.r8.KotlinTestParameters; |
| 11 | import com.android.tools.r8.TestParameters; |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 12 | import com.android.tools.r8.utils.DescriptorUtils; |
| 13 | import com.android.tools.r8.utils.StringUtils; |
| 14 | import java.nio.file.Path; |
| 15 | import java.util.Collection; |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 16 | import org.junit.Test; |
| 17 | import org.junit.runner.RunWith; |
| 18 | import org.junit.runners.Parameterized; |
| 19 | |
| 20 | @RunWith(Parameterized.class) |
| 21 | public class MetadataRewriteCrossinlineBlockTest extends KotlinMetadataTestBase { |
| 22 | |
Morten Krogh-Jespersen | 3dfba42a | 2022-01-03 09:47:06 +0100 | [diff] [blame^] | 23 | 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-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 28 | 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-Jespersen | 3dfba42a | 2022-01-03 09:47:06 +0100 | [diff] [blame^] | 76 | Path output = |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 77 | 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-Jespersen | 3dfba42a | 2022-01-03 09:47:06 +0100 | [diff] [blame^] | 83 | .compile(); |
| 84 | testForJvm() |
| 85 | .addRunClasspathFiles(getKotlinStdlibJar(kotlinc), libJar) |
| 86 | .addClasspath(output) |
| 87 | .run(parameters.getRuntime(), PKG_APP + ".MainKt") |
| 88 | .assertSuccessWithOutput(EXPECTED); |
Morten Krogh-Jespersen | f558017 | 2022-01-03 09:44:35 +0100 | [diff] [blame] | 89 | } |
| 90 | } |