blob: 66c21f672f3803384c68a05e7845993828d05648 [file] [log] [blame]
// Copyright (c) 2019, 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.naming.b131810441;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.naming.b131810441.sub.Outer;
import com.android.tools.r8.utils.BooleanUtils;
import com.android.tools.r8.utils.StringUtils;
import com.android.tools.r8.utils.codeinspector.ClassSubject;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
class TestMain {
public static void main(String... args) {
Outer o = Outer.create(8);
o.trigger();
}
}
@RunWith(Parameterized.class)
public class AnonymousClassRenamingTest extends TestBase {
private static final String EXPECTED_OUTPUT = StringUtils.lines("Outer#<init>(8)");
private final TestParameters parameters;
private final boolean enableMinification;
@Parameterized.Parameters(name = "{0} minification: {1}")
public static Collection<Object[]> data() {
return buildParameters(
getTestParameters().withAllRuntimes().build(),
BooleanUtils.values());
}
public AnonymousClassRenamingTest(TestParameters parameters, boolean enableMinification) {
this.parameters = parameters;
this.enableMinification = enableMinification;
}
@Test
public void b131810441() throws Exception {
testForR8Compat(parameters.getBackend())
.addProgramClasses(TestMain.class)
.addProgramClassesAndInnerClasses(Outer.class)
.addKeepMainRule(TestMain.class)
.addKeepAttributes("InnerClasses", "EnclosingMethod")
.enableInliningAnnotations()
.minification(enableMinification)
.setMinApi(parameters.getRuntime())
.run(parameters.getRuntime(), TestMain.class)
.assertSuccessWithOutput(EXPECTED_OUTPUT)
.inspect(inspector -> {
ClassSubject anonymous = inspector.clazz(Outer.class.getName() + "$1");
assertThat(anonymous, isPresent());
assertEquals(enableMinification, anonymous.isRenamed());
});
}
}