Copy hello program to each of the tests using it
This ensures the test data is local to the test module using it
which is required in our new build configuration.
Change-Id: Ie5ff025396d02b58e1d71bec4491d128d9aaa884
diff --git a/src/test/bootstrap/com/android/tools/r8/bootstrap/BootstrapCurrentEqualityTest.java b/src/test/bootstrap/com/android/tools/r8/bootstrap/BootstrapCurrentEqualityTest.java
index 34c1623..a6c99f8 100644
--- a/src/test/bootstrap/com/android/tools/r8/bootstrap/BootstrapCurrentEqualityTest.java
+++ b/src/test/bootstrap/com/android/tools/r8/bootstrap/BootstrapCurrentEqualityTest.java
@@ -22,8 +22,6 @@
import com.android.tools.r8.TestRuntime.CfVm;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.ProcessResult;
-import com.android.tools.r8.dex.Marker.Backend;
-import com.android.tools.r8.examples.hello.HelloTestRunner;
import com.android.tools.r8.retrace.ProguardMapProducer;
import com.android.tools.r8.retrace.ProguardMappingSupplier;
import com.android.tools.r8.retrace.Retrace;
@@ -51,17 +49,24 @@
@RunWith(Parameterized.class)
public class BootstrapCurrentEqualityTest extends TestBase {
+ static class HelloWorldProgram {
+ public static void main(String[] args) {
+ System.out.println("Hello, world!");
+ }
+ }
+
private static final Path MAIN_KEEP =
Paths.get(ToolHelper.getProjectRoot(), "src", "main", "keep.txt");
- private static final String HELLO_NAME = HelloTestRunner.getHelloClass().getTypeName();
+ private static final Class<?> HELLO_CLASS = HelloWorldProgram.class;
+ private static final String HELLO_NAME = typeName(HELLO_CLASS);
private static final String[] KEEP_HELLO = {
"-keep class " + HELLO_NAME + " {",
" public static void main(...);",
"}",
"-allowaccessmodification"
};
- private static String HELLO_EXPECTED = HelloTestRunner.getExpectedOutput();
+ private static String HELLO_EXPECTED = StringUtils.lines("Hello, world!");
private static Pair<Path, Path> r8R8Debug;
private static Pair<Path, Path> r8R8Release;
@@ -203,7 +208,8 @@
@Test
public void test() throws Exception {
- Path program = HelloTestRunner.writeHelloProgramJar(temp);
+ Path program = testFolder.newFolder().toPath().resolve("hello.jar");
+ writeClassesToJar(program, HELLO_CLASS);
testForJvm(parameters)
.addProgramFiles(program)
.run(parameters.getRuntime(), HELLO_NAME)
diff --git a/src/test/bootstrap/com/android/tools/r8/bootstrap/HelloWorldCompiledOnArtTest.java b/src/test/bootstrap/com/android/tools/r8/bootstrap/HelloWorldCompiledOnArtTest.java
index 9541dd4..31a8108 100644
--- a/src/test/bootstrap/com/android/tools/r8/bootstrap/HelloWorldCompiledOnArtTest.java
+++ b/src/test/bootstrap/com/android/tools/r8/bootstrap/HelloWorldCompiledOnArtTest.java
@@ -19,8 +19,8 @@
import com.android.tools.r8.desugar.desugaredlibrary.test.CompilationSpecification;
import com.android.tools.r8.desugar.desugaredlibrary.test.DesugaredLibraryTestCompileResult;
import com.android.tools.r8.desugar.desugaredlibrary.test.LibraryDesugaringSpecification;
-import com.android.tools.r8.examples.hello.HelloTestRunner;
import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.nio.file.Path;
@@ -34,6 +34,16 @@
@RunWith(Parameterized.class)
public class HelloWorldCompiledOnArtTest extends DesugaredLibraryTestBase {
+ static class HelloWorldProgram {
+ public static void main(String[] args) {
+ System.out.println("Hello, world!");
+ }
+ }
+
+ private static final Class<?> HELLO_CLASS = HelloWorldProgram.class;
+ private static final String HELLO_NAME = typeName(HELLO_CLASS);
+ private static String HELLO_EXPECTED = StringUtils.lines("Hello, world!");
+
private final TestParameters parameters;
private final CompilationSpecification compilationSpecification;
private final LibraryDesugaringSpecification libraryDesugaringSpecification;
@@ -62,13 +72,17 @@
return Paths.get(string).toAbsolutePath().toString();
}
- private static final String HELLO_NAME = typeName(HelloTestRunner.getHelloClass());
+ private Path writeHelloProgramJar() throws IOException {
+ Path jar = temp.newFolder().toPath().resolve("hello.jar");
+ writeClassesToJar(jar, HELLO_CLASS);
+ return jar;
+ }
@Test
public void testHelloCompiledWithR8Dex() throws Exception {
Path keepRules =
writeTextToTempFile(keepMainProguardConfiguration(HELLO_NAME)).toAbsolutePath();
- Path helloInput = HelloTestRunner.writeHelloProgramJar(temp);
+ Path helloInput = writeHelloProgramJar().toAbsolutePath();
Path helloOutput = temp.newFolder("helloOutput").toPath().resolve("out.zip").toAbsolutePath();
compileR8ToDexWithD8()
.run(
@@ -88,7 +102,7 @@
@Test
public void testHelloCompiledWithD8Dex() throws Exception {
- Path helloInput = HelloTestRunner.writeHelloProgramJar(temp).toAbsolutePath();
+ Path helloInput = writeHelloProgramJar().toAbsolutePath();
Path helloOutput = temp.newFolder("helloOutput").toPath().resolve("out.zip").toAbsolutePath();
compileR8ToDexWithD8()
.run(
@@ -106,7 +120,7 @@
private void verifyResult(Path helloOutput) throws IOException {
ProcessResult processResult = ToolHelper.runArtRaw(helloOutput.toString(), HELLO_NAME);
- assertEquals(HelloTestRunner.getExpectedOutput(), processResult.stdout);
+ assertEquals(HELLO_EXPECTED, processResult.stdout);
}
private DesugaredLibraryTestCompileResult<?> compileR8ToDexWithD8() throws Exception {
diff --git a/src/test/bootstrap/com/android/tools/r8/bootstrap/Java17R8BootstrapTest.java b/src/test/bootstrap/com/android/tools/r8/bootstrap/Java17R8BootstrapTest.java
index 6ef44bf..d410299 100644
--- a/src/test/bootstrap/com/android/tools/r8/bootstrap/Java17R8BootstrapTest.java
+++ b/src/test/bootstrap/com/android/tools/r8/bootstrap/Java17R8BootstrapTest.java
@@ -13,8 +13,8 @@
import com.android.tools.r8.TestRuntime.CfVm;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.desugar.LibraryFilesHelper;
-import com.android.tools.r8.examples.hello.HelloTestRunner;
import com.google.common.collect.ImmutableList;
+import java.io.IOException;
import java.nio.file.Path;
import org.junit.Assume;
import org.junit.BeforeClass;
@@ -33,7 +33,13 @@
@RunWith(Parameterized.class)
public class Java17R8BootstrapTest extends TestBase {
- private static final Class<?> HELLO_CLASS = HelloTestRunner.getHelloClass();
+ static class HelloWorldProgram {
+ public static void main(String[] args) {
+ System.out.println("Hello, world!");
+ }
+ }
+
+ private static final Class<?> HELLO_CLASS = HelloWorldProgram.class;
private static final String[] HELLO_KEEP = {
"-keep class " + HELLO_CLASS.getTypeName() + " { public static void main(...);}"
};
@@ -77,6 +83,12 @@
return new Path[] {ToolHelper.R8_WITH_RELOCATED_DEPS_17_JAR, r8Lib17NoDesugar, r8Lib17Desugar};
}
+ private Path writeHelloProgramJar() throws IOException {
+ Path jar = temp.newFolder().toPath().resolve("hello.jar");
+ writeClassesToJar(jar, HELLO_CLASS);
+ return jar;
+ }
+
@Test
public void testHello() throws Exception {
Assume.assumeTrue(!ToolHelper.isWindows());
@@ -84,7 +96,7 @@
Assume.assumeTrue(supportsSealedClassesWhenGeneratingCf());
Path prevGeneratedJar = null;
String prevRunResult = null;
- Path helloJar = HelloTestRunner.writeHelloProgramJar(temp);
+ Path helloJar = writeHelloProgramJar();
for (Path jar : jarsToCompare()) {
Path generatedJar =
testForExternalR8(Backend.CF, parameters.getRuntime())
@@ -119,7 +131,7 @@
Assume.assumeTrue(JavaBootstrapUtils.exists(ToolHelper.R8_WITH_RELOCATED_DEPS_17_JAR));
Assume.assumeTrue(supportsSealedClassesWhenGeneratingCf());
Path prevGeneratedJar = null;
- Path helloJar = HelloTestRunner.writeHelloProgramJar(temp);
+ Path helloJar = writeHelloProgramJar();
for (Path jar : jarsToCompare()) {
Path generatedJar =
testForExternalR8(Backend.CF, parameters.getRuntime())
diff --git a/src/test/java/com/android/tools/r8/cf/bootstrap/BootstrapTest.java b/src/test/java/com/android/tools/r8/cf/bootstrap/BootstrapTest.java
index ee0ff21..c381b0d 100644
--- a/src/test/java/com/android/tools/r8/cf/bootstrap/BootstrapTest.java
+++ b/src/test/java/com/android/tools/r8/cf/bootstrap/BootstrapTest.java
@@ -12,8 +12,8 @@
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.ProcessResult;
-import com.android.tools.r8.examples.hello.HelloTestRunner;
import com.android.tools.r8.utils.FileUtils;
+import com.android.tools.r8.utils.StringUtils;
import com.google.common.base.Charsets;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -27,12 +27,18 @@
@RunWith(Parameterized.class)
public class BootstrapTest extends TestBase {
+ static class HelloWorldProgram {
+ public static void main(String[] args) {
+ System.out.println("Hello, world!");
+ }
+ }
+
+ private static final Class<?> HELLO_CLASS = HelloWorldProgram.class;
+ private static String HELLO_EXPECTED = StringUtils.lines("Hello, world!");
+
private static final Path R8_STABLE_JAR =
Paths.get(ToolHelper.THIRD_PARTY_DIR, "r8-releases", "3.2.54", "r8.jar");
- private static final Class<?> HELLO_CLASS = HelloTestRunner.getHelloClass();
- private static final String HELLO_EXPECTED = HelloTestRunner.getExpectedOutput();
-
private static class R8Result {
final ProcessResult processResult;
diff --git a/src/test/java/com/android/tools/r8/examples/hello/HelloTestRunner.java b/src/test/java/com/android/tools/r8/examples/hello/HelloTestRunner.java
index cb305d2..55baca1 100644
--- a/src/test/java/com/android/tools/r8/examples/hello/HelloTestRunner.java
+++ b/src/test/java/com/android/tools/r8/examples/hello/HelloTestRunner.java
@@ -7,10 +7,7 @@
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.examples.ExamplesTestBase;
import com.android.tools.r8.utils.StringUtils;
-import java.io.IOException;
-import java.nio.file.Path;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -22,34 +19,18 @@
return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
}
- // The "hello" program is reused in various tests via these static methods.
-
- public static Class<?> getHelloClass() {
- return Hello.class;
- }
-
- public static String getExpectedOutput() {
- return StringUtils.lines("Hello, world");
- }
-
- public static Path writeHelloProgramJar(TemporaryFolder temp) throws IOException {
- Path jar = temp.newFolder().toPath().resolve("hello.jar");
- writeClassesToJar(jar, Hello.class);
- return jar;
- }
-
public HelloTestRunner(TestParameters parameters) {
super(parameters);
}
@Override
public Class<?> getMainClass() {
- return getHelloClass();
+ return Hello.class;
}
@Override
public String getExpected() {
- return getExpectedOutput();
+ return StringUtils.lines("Hello, world");
}
@Test