blob: 3e20dcd95daab235663c673b974141c29bea9ab6 [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.shaking.keep;
import com.android.tools.r8.NoVerticalClassMerging;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
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 IndirectKeepStaticMethodTest extends TestBase {
private final TestParameters parameters;
@Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withAllRuntimesAndApiLevels().build();
}
public IndirectKeepStaticMethodTest(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void test() throws Exception {
testForR8(parameters.getBackend())
.addProgramClasses(A.class, B.class)
.addKeepRules("-keep class " + B.class.getTypeName() + " {", " static void m();", "}")
.enableNoVerticalClassMergingAnnotations()
.setMinApi(parameters.getApiLevel())
.compile()
.addRunClasspathFiles(buildOnDexRuntime(parameters, Main.class))
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("A");
}
static class Main {
public static void main(String[] args) {
B.m();
}
}
@NoVerticalClassMerging
static class A {
static void m() {
System.out.println("A");
}
}
static class B extends A {}
}