blob: 0fa90c169971419fd839a0a255daf91dcf5ed800 [file] [log] [blame]
// 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.sealed;
import static com.android.tools.r8.ToolHelper.getFilesInTestFolderRelativeToClass;
import static org.hamcrest.CoreMatchers.equalTo;
import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.KotlinTestBase;
import com.android.tools.r8.KotlinTestParameters;
import com.android.tools.r8.TestParameters;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class SealedClassTest extends KotlinTestBase {
private static final String MAIN = "com.android.tools.r8.kotlin.sealed.kt.FormatKt";
private static final String[] EXPECTED = new String[] {"ZIP"};
private final TestParameters parameters;
@Parameters(name = "{0}, {1}")
public static List<Object[]> data() {
return buildParameters(
getTestParameters().withAllRuntimesAndApiLevels().build(),
getKotlinTestParameters().withAllCompilersAndTargetVersions().build());
}
public SealedClassTest(TestParameters parameters, KotlinTestParameters kotlinParameters) {
super(kotlinParameters);
this.parameters = parameters;
}
private static final KotlinCompileMemoizer compilationResults =
getCompileMemoizer(getKotlinSources());
private static Collection<Path> getKotlinSources() {
try {
return getFilesInTestFolderRelativeToClass(SealedClassTest.class, "kt", ".kt");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Test
public void testRuntime() throws ExecutionException, CompilationFailedException, IOException {
testForRuntime(parameters)
.addProgramFiles(compilationResults.getForConfiguration(kotlinc, targetVersion))
.addRunClasspathFiles(buildOnDexRuntime(parameters, kotlinc.getKotlinStdlibJar()))
.run(parameters.getRuntime(), MAIN)
.assertSuccessWithOutputLines(EXPECTED);
}
@Test
public void testR8() throws ExecutionException, CompilationFailedException, IOException {
testForR8(parameters.getBackend())
.addProgramFiles(compilationResults.getForConfiguration(kotlinc, targetVersion))
.addProgramFiles(kotlinc.getKotlinStdlibJar())
.addProgramFiles(kotlinc.getKotlinAnnotationJar())
.setMinApi(parameters.getApiLevel())
.allowAccessModification()
.allowDiagnosticWarningMessages()
.addKeepMainRule(MAIN)
.compile()
.assertAllWarningMessagesMatch(equalTo("Resource 'META-INF/MANIFEST.MF' already exists."))
.run(parameters.getRuntime(), MAIN)
.assertSuccessWithOutputLines(EXPECTED);
}
}