blob: 63197d4f28d08f1fb3c45ec52a58d7f1eab5b647 [file] [log] [blame]
// Copyright (c) 2021, 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.ToolHelper.getKotlinAnnotationJar;
import static com.android.tools.r8.ToolHelper.getKotlinStdlibJar;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotEquals;
import com.android.tools.r8.KotlinCompilerTool.KotlinCompilerVersion;
import com.android.tools.r8.KotlinTestParameters;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.ToolHelper.ProcessResult;
import com.android.tools.r8.utils.DescriptorUtils;
import com.android.tools.r8.utils.StringUtils;
import java.nio.file.Path;
import java.util.Collection;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class MetadataRewriteCrossinlineBlockTest extends KotlinMetadataTestBase {
private final String EXPECTED = StringUtils.lines("foo");
private static final String PKG_LIB = PKG + ".crossinline_block_lib";
private static final String PKG_APP = PKG + ".crossinline_block_app";
@Parameterized.Parameters(name = "{0}, {1}")
public static Collection<Object[]> data() {
return buildParameters(
getTestParameters().withCfRuntimes().build(),
getKotlinTestParameters().withAllCompilersAndTargetVersions().build());
}
public MetadataRewriteCrossinlineBlockTest(
TestParameters parameters, KotlinTestParameters kotlinParameters) {
super(kotlinParameters);
this.parameters = parameters;
}
private static final KotlinCompileMemoizer libJars =
getCompileMemoizer(
getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_LIB), "lib"));
private final TestParameters parameters;
@Test
public void smokeTest() throws Exception {
Path libJar = libJars.getForConfiguration(kotlinc, targetVersion);
Path output =
kotlinc(parameters.getRuntime().asCf(), kotlinc, targetVersion)
.addClasspathFiles(libJar)
.addSourceFiles(
getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_APP), "main"))
.setOutputPath(temp.newFolder().toPath())
.compile();
testForJvm()
.addRunClasspathFiles(getKotlinStdlibJar(kotlinc), libJar)
.addClasspath(output)
.run(parameters.getRuntime(), PKG_APP + ".MainKt")
.assertSuccessWithOutput(EXPECTED);
}
@Test
public void testMetadataForLib() throws Exception {
Path libJar =
testForR8Compat(parameters.getBackend())
.addProgramFiles(libJars.getForConfiguration(kotlinc, targetVersion))
.addClasspathFiles(getKotlinStdlibJar(kotlinc), getKotlinAnnotationJar(kotlinc))
.addKeepAllClassesRule()
.addKeepAllAttributes()
.compile()
.writeToZip();
ProcessResult kotlinCompileResult =
kotlinc(parameters.getRuntime().asCf(), kotlinc, targetVersion)
.addClasspathFiles(libJar)
.addSourceFiles(
getKotlinFileInTest(DescriptorUtils.getBinaryNameFromJavaType(PKG_APP), "main"))
.setOutputPath(temp.newFolder().toPath())
.enableAssertions()
.compileRaw();
// TODO(b/211113454): This compilation should not fail.
assertNotEquals(0, kotlinCompileResult.exitCode);
if (kotlinc.is(KotlinCompilerVersion.KOTLINC_1_3_72)) {
assertThat(
kotlinCompileResult.stderr,
CoreMatchers.containsString(
"java.lang.AssertionError: 'checkParameterIsNotNull' should be invoked on local"));
} else {
assertThat(
kotlinCompileResult.stderr,
CoreMatchers.containsString(
"java.lang.AssertionError: 'checkNotNullParameter' should be invoked on local"));
}
}
}