aboutsummaryrefslogtreecommitdiff
path: root/javatests/com/google/turbine/lower
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/com/google/turbine/lower')
-rw-r--r--javatests/com/google/turbine/lower/IntegrationTestSupport.java23
-rw-r--r--javatests/com/google/turbine/lower/LowerIntegrationTest.java344
-rw-r--r--javatests/com/google/turbine/lower/LowerTest.java110
-rw-r--r--javatests/com/google/turbine/lower/ModuleIntegrationTest.java8
-rw-r--r--javatests/com/google/turbine/lower/testdata/annotation_clinit.test18
-rw-r--r--javatests/com/google/turbine/lower/testdata/unicode_pkg.test4
6 files changed, 256 insertions, 251 deletions
diff --git a/javatests/com/google/turbine/lower/IntegrationTestSupport.java b/javatests/com/google/turbine/lower/IntegrationTestSupport.java
index a03473d..744f341 100644
--- a/javatests/com/google/turbine/lower/IntegrationTestSupport.java
+++ b/javatests/com/google/turbine/lower/IntegrationTestSupport.java
@@ -17,8 +17,10 @@
package com.google.turbine.lower;
import static com.google.common.collect.ImmutableList.toImmutableList;
+import static com.google.common.io.MoreFiles.getFileExtension;
import static com.google.turbine.testing.TestClassPaths.TURBINE_BOOTCLASSPATH;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toList;
@@ -82,7 +84,7 @@ import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeAnnotationNode;
/** Support for bytecode diffing-integration tests. */
-public class IntegrationTestSupport {
+public final class IntegrationTestSupport {
/**
* Normalizes order of members, attributes, and constant pool entries, to allow diffing bytecode.
@@ -410,20 +412,21 @@ public class IntegrationTestSupport {
final Set<String> classes1 = classes;
new SignatureReader(signature)
.accept(
- new SignatureVisitor(Opcodes.ASM7) {
+ new SignatureVisitor(Opcodes.ASM9) {
private final Set<String> classes = classes1;
// class signatures may contain type arguments that contain class signatures
Deque<List<String>> pieces = new ArrayDeque<>();
@Override
public void visitInnerClassType(String name) {
- pieces.peek().add(name);
+ pieces.element().add(name);
}
@Override
public void visitClassType(String name) {
- pieces.push(new ArrayList<>());
- pieces.peek().add(name);
+ List<String> classType = new ArrayList<>();
+ classType.add(name);
+ pieces.push(classType);
}
@Override
@@ -510,7 +513,7 @@ public class IntegrationTestSupport {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
throws IOException {
- if (path.getFileName().toString().endsWith(".class")) {
+ if (getFileExtension(path).equals("class")) {
classes.add(path);
}
return FileVisitResult.CONTINUE;
@@ -551,7 +554,9 @@ public class IntegrationTestSupport {
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, ImmutableList.of(out));
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
fileManager.setLocationFromPaths(StandardLocation.locationFor("MODULE_PATH"), classpath);
- if (inputs.stream().filter(i -> i.getFileName().toString().equals("module-info.java")).count()
+ if (inputs.stream()
+ .filter(i -> requireNonNull(i.getFileName()).toString().equals("module-info.java"))
+ .count()
> 1) {
// multi-module mode
fileManager.setLocationFromPaths(
@@ -578,7 +583,7 @@ public class IntegrationTestSupport {
na = na.substring(1);
}
sb.append(String.format("=== %s ===\n", na));
- sb.append(AsmUtils.textify(compiled.get(key)));
+ sb.append(AsmUtils.textify(compiled.get(key), /* skipDebug= */ true));
}
return sb.toString();
}
@@ -634,4 +639,6 @@ public class IntegrationTestSupport {
return new TestInput(sources, classes);
}
}
+
+ private IntegrationTestSupport() {}
}
diff --git a/javatests/com/google/turbine/lower/LowerIntegrationTest.java b/javatests/com/google/turbine/lower/LowerIntegrationTest.java
index 85c3450..ab4e0ee 100644
--- a/javatests/com/google/turbine/lower/LowerIntegrationTest.java
+++ b/javatests/com/google/turbine/lower/LowerIntegrationTest.java
@@ -17,12 +17,11 @@
package com.google.turbine.lower;
import static com.google.common.truth.Truth.assertThat;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static com.google.turbine.testing.TestResources.getResource;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
import java.io.IOError;
import java.io.IOException;
import java.nio.file.Files;
@@ -45,26 +44,103 @@ public class LowerIntegrationTest {
@Parameters(name = "{index}: {0}")
public static Iterable<Object[]> parameters() {
String[] testCases = {
+ // keep-sorted start
+ "B33513475.test",
+ "B33513475b.test",
+ "B33513475c.test",
+ "B70953542.test",
+ "B8056066.test",
+ "B8056066b.test",
+ "B8075274.test",
+ "B8148131.test",
"abstractenum.test",
"access1.test",
+ "anno_const_coerce.test",
+ "anno_const_scope.test",
+ "anno_nested.test",
+ "anno_repeated.test",
+ "anno_self_const.test",
+ "anno_void.test",
+ "annoconstvis.test",
+ "annotation_bool_default.test",
+ "annotation_class_default.test",
+ "annotation_clinit.test",
+ "annotation_declaration.test",
+ "annotation_enum_default.test",
+ "annotation_scope.test",
+ "annotations_default.test",
+ "annouse.test",
+ "annouse10.test",
+ "annouse11.test",
+ "annouse12.test",
+ "annouse13.test",
+ "annouse14.test",
+ "annouse15.test",
+ "annouse16.test",
+ "annouse17.test",
+ "annouse2.test",
+ "annouse3.test",
+ "annouse4.test",
+ "annouse5.test",
+ "annouse6.test",
+ "annouse7.test",
+ "annouse8.test",
+ "annouse9.test",
+ "annovis.test",
"anonymous.test",
+ "array_class_literal.test",
+ "ascii_sub.test",
"asset.test",
- "outerparam.test",
"basic_field.test",
"basic_nested.test",
"bcp.test",
+ "bmethod.test",
+ "bounds.test",
+ "boxed_const.test",
"builder.test",
"byte.test",
"byte2.test",
+ "bytecode_boolean_const.test",
+ "bytenoncanon.test",
+ "c_array.test",
+ "canon.test",
+ "canon_class_header.test",
+ "canon_recursive.test",
+ "cast_tail.test",
"circ_cvar.test",
"clash.test",
+ "complex_param_anno.test",
+ "concat.test",
+ "const.test",
+ "const_all.test",
+ "const_arith.test",
+ "const_boxed.test",
+ "const_byte.test",
+ "const_char.test",
+ "const_conditional.test",
+ "const_conv.test",
+ "const_field.test",
+ "const_hiding.test",
+ "const_moreexpr.test",
+ "const_multi.test",
+ "const_nonfinal.test",
+ "const_octal_underscore.test",
+ "const_types.test",
+ "const_underscore.test",
+ "constlevel.test",
+ "constpack.test",
+ "ctor_anno.test",
"ctorvis.test",
"cvar_qualified.test",
"cycle.test",
"default_fbound.test",
"default_rawfbound.test",
"default_simple.test",
+ "deficient_types_classfile.test",
+ "dollar.test",
"enum1.test",
+ "enum_abstract.test",
+ "enum_final.test",
"enumctor.test",
"enumctor2.test",
"enumimpl.test",
@@ -78,6 +154,7 @@ public class LowerIntegrationTest {
"enumint_objectmethod2.test",
"enumint_objectmethod_raw.test",
"enuminthacks.test",
+ "enummemberanno.test",
"enumstat.test",
"erasurebound.test",
"existingctor.test",
@@ -87,230 +164,156 @@ public class LowerIntegrationTest {
"extendsandimplements.test",
"extrainnerclass.test",
"fbound.test",
+ "field_anno.test",
"firstcomparator.test",
+ "float_exponent.test",
"fuse.test",
"genericarrayfield.test",
"genericexn.test",
"genericexn2.test",
+ "genericnoncanon.test",
+ "genericnoncanon1.test",
+ "genericnoncanon10.test",
+ "genericnoncanon2.test",
+ "genericnoncanon3.test",
+ "genericnoncanon4.test",
+ "genericnoncanon5.test",
+ "genericnoncanon6.test",
+ "genericnoncanon8.test",
+ "genericnoncanon9.test",
+ "genericnoncanon_byte.test",
+ "genericnoncanon_method3.test",
"genericret.test",
+ "hex_int.test",
"hierarchy.test",
"ibound.test",
"icu.test",
"icu2.test",
+ "import_wild_order.test",
+ "importconst.test",
"importinner.test",
+ "inner_static.test",
+ "innerannodecl.test",
+ "innerclassanno.test",
"innerctor.test",
"innerenum.test",
"innerint.test",
"innerstaticgeneric.test",
+ "interface_field.test",
+ "interface_member_public.test",
+ "interface_method.test",
"interfacemem.test",
"interfaces.test",
+ // TODO(cushon): crashes ASM, see:
+ // https://gitlab.ow2.org/asm/asm/issues/317776
+ // "canon_array.test",
+ "java_lang_object.test",
+ "javadoc_deprecated.test",
"lexical.test",
"lexical2.test",
"lexical4.test",
"list.test",
+ "local.test",
+ "long_expression.test",
"loopthroughb.test",
"mapentry.test",
+ "marker.test",
"member.test",
+ "member_import_clash.test",
+ // TODO(cushon): support for source level 9 in integration tests
+ // "B74332665.test",
+ "memberimport.test",
"mods.test",
"morefields.test",
"moremethods.test",
"multifield.test",
"nested.test",
"nested2.test",
+ "nested_member_import.test",
+ "nested_member_import_noncanon.test",
+ "non_const.test",
+ "noncanon.test",
+ "noncanon_static_wild.test",
+ "nonconst_unary_expression.test",
"one.test",
"outer.test",
+ "outerparam.test",
+ "package_info.test",
+ "packagedecl.test",
"packageprivateprotectedinner.test",
"param_bound.test",
+ "prim_class.test",
+ "private_member.test",
"privateinner.test",
"proto.test",
"proto2.test",
"qual.test",
"raw.test",
"raw2.test",
+ "raw_canon.test",
+ "rawcanon.test",
"rawfbound.test",
+ "receiver_param.test",
"rek.test",
"samepkg.test",
"self.test",
"semi.test",
+ // https://bugs.openjdk.java.net/browse/JDK-8054064 ?
+ "shadow_inherited.test",
"simple.test",
"simplemethod.test",
+ "source_anno_retention.test",
+ "source_bootclasspath_order.test",
+ "static_final_boxed.test",
+ "static_member_type_import.test",
+ "static_member_type_import_recursive.test",
+ "static_type_import.test",
+ "strictfp.test",
"string.test",
"superabstract.test",
"supplierfunction.test",
"tbound.test",
+ "tyanno_inner.test",
+ "tyanno_varargs.test",
"typaram.test",
+ "typaram_lookup.test",
+ "typaram_lookup_enclosing.test",
+ "type_anno_ambiguous.test",
+ "type_anno_ambiguous_param.test",
+ "type_anno_ambiguous_qualified.test",
+ "type_anno_array_bound.test",
+ "type_anno_array_dims.test",
+ "type_anno_c_array.test",
+ "type_anno_cstyle_array_dims.test",
+ "type_anno_hello.test",
+ "type_anno_order.test",
+ "type_anno_parameter_index.test",
+ "type_anno_qual.test",
+ "type_anno_raw.test",
+ "type_anno_receiver.test",
+ "type_anno_retention.test",
+ "type_anno_return.test",
+ "tyvar_bound.test",
"tyvarfield.test",
+ "unary.test",
+ "underscore_literal.test",
+ "unicode.test",
+ "unicode_pkg.test",
"useextend.test",
"vanillaexception.test",
"varargs.test",
- "wild.test",
- "bytenoncanon.test",
- "canon.test",
- "genericnoncanon.test",
- "genericnoncanon1.test",
- "genericnoncanon10.test",
- "genericnoncanon2.test",
- "genericnoncanon3.test",
- "genericnoncanon4.test",
- "genericnoncanon5.test",
- "genericnoncanon6.test",
- "genericnoncanon8.test",
- "genericnoncanon9.test",
- "genericnoncanon_byte.test",
- "genericnoncanon_method3.test",
- "noncanon.test",
- "rawcanon.test",
- "wildboundcanon.test",
- "wildcanon.test",
- "annoconstvis.test",
- "const_byte.test",
- "const_char.test",
- "const_field.test",
- "const_types.test",
- "const_underscore.test",
- "constlevel.test",
- "constpack.test",
- "importconst.test",
- "const.test",
- "const_all.test",
- "const_arith.test",
- "const_conditional.test",
- "const_moreexpr.test",
- "const_multi.test",
- "field_anno.test",
- "annotation_bool_default.test",
- "annotation_class_default.test",
- "annotation_declaration.test",
- "annotation_enum_default.test",
- "annotations_default.test",
- "annouse.test",
- "annouse10.test",
- "annouse11.test",
- "annouse12.test",
- "annouse13.test",
- "annouse14.test",
- "annouse15.test",
- "annouse16.test",
- "annouse17.test",
- "annouse2.test",
- "annouse3.test",
- "annouse4.test",
- "annouse5.test",
- "annouse6.test",
- "annouse7.test",
- "annouse8.test",
- "annouse9.test",
- "annovis.test",
- "complex_param_anno.test",
- "enummemberanno.test",
- "innerannodecl.test",
- "source_anno_retention.test",
- "anno_nested.test",
- "nested_member_import.test",
- "nested_member_import_noncanon.test",
- "unary.test",
- "hex_int.test",
- "const_conv.test",
- "bmethod.test",
- "prim_class.test",
- "wild2.test",
- "wild3.test",
- "const_hiding.test",
- "interface_field.test",
- "concat.test",
- "static_type_import.test",
- "non_const.test",
- "bounds.test",
- "cast_tail.test",
- "marker.test",
- "interface_method.test",
- "raw_canon.test",
- "float_exponent.test",
- "boxed_const.test",
- "package_info.test",
- "import_wild_order.test",
- "canon_recursive.test",
- // TODO(cushon): crashes ASM, see:
- // https://gitlab.ow2.org/asm/asm/issues/317776
- // "canon_array.test",
- "java_lang_object.test",
+ "visible_nested.test",
"visible_package.test",
+ "visible_package_private_toplevel.test",
"visible_private.test",
- "visible_same_package.test",
- "private_member.test",
- "visible_nested.test",
"visible_qualified.test",
- "ascii_sub.test",
- "bytecode_boolean_const.test",
- "tyvar_bound.test",
- "type_anno_hello.test",
- "type_anno_array_dims.test",
- "nonconst_unary_expression.test",
- "type_anno_ambiguous.test",
- "type_anno_ambiguous_param.test",
- "unicode.test",
- "annotation_scope.test",
- "visible_package_private_toplevel.test",
- "receiver_param.test",
- "static_member_type_import.test",
- "type_anno_qual.test",
- "array_class_literal.test",
- "underscore_literal.test",
- "c_array.test",
- "type_anno_retention.test",
- "member_import_clash.test",
- "anno_repeated.test",
- "long_expression.test",
- "const_nonfinal.test",
- "enum_abstract.test",
- "deficient_types_classfile.test",
- "ctor_anno.test",
- "anno_const_coerce.test",
- "const_octal_underscore.test",
- "const_boxed.test",
- "interface_member_public.test",
- "javadoc_deprecated.test",
- "strictfp.test",
- "type_anno_raw.test",
- "inner_static.test",
- "innerclassanno.test",
- "type_anno_parameter_index.test",
- "anno_const_scope.test",
- "type_anno_ambiguous_qualified.test",
- "type_anno_array_bound.test",
- "type_anno_return.test",
- "type_anno_order.test",
- "canon_class_header.test",
- "type_anno_receiver.test",
- "enum_final.test",
- "dollar.test",
- "typaram_lookup.test",
- "typaram_lookup_enclosing.test",
- "B33513475.test",
- "B33513475b.test",
- "B33513475c.test",
- "noncanon_static_wild.test",
- "B8075274.test",
- "B8148131.test",
- "B8056066.test",
- "B8056066b.test",
- "source_bootclasspath_order.test",
- "anno_self_const.test",
- "type_anno_cstyle_array_dims.test",
- "packagedecl.test",
- "static_member_type_import_recursive.test",
- "B70953542.test",
- // TODO(cushon): support for source level 9 in integration tests
- // "B74332665.test",
- "memberimport.test",
- "type_anno_c_array.test",
- // https://bugs.openjdk.java.net/browse/JDK-8054064 ?
- "shadow_inherited.test",
- "static_final_boxed.test",
- "anno_void.test",
- "tyanno_varargs.test",
- "tyanno_inner.test",
- "local.test",
+ "visible_same_package.test",
+ "wild.test",
+ "wild2.test",
+ "wild3.test",
+ "wildboundcanon.test",
+ "wildcanon.test",
+ // keep-sorted end
};
List<Object[]> tests =
ImmutableList.copyOf(testCases).stream().map(x -> new Object[] {x}).collect(toList());
@@ -344,10 +347,7 @@ public class LowerIntegrationTest {
public void test() throws Exception {
IntegrationTestSupport.TestInput input =
- IntegrationTestSupport.TestInput.parse(
- new String(
- ByteStreams.toByteArray(getClass().getResourceAsStream("testdata/" + test)),
- UTF_8));
+ IntegrationTestSupport.TestInput.parse(getResource(getClass(), "testdata/" + test));
ImmutableList<Path> classpathJar = ImmutableList.of();
if (!input.classes.isEmpty()) {
diff --git a/javatests/com/google/turbine/lower/LowerTest.java b/javatests/com/google/turbine/lower/LowerTest.java
index 8151e81..d74e829 100644
--- a/javatests/com/google/turbine/lower/LowerTest.java
+++ b/javatests/com/google/turbine/lower/LowerTest.java
@@ -18,13 +18,13 @@ package com.google.turbine.lower;
import static com.google.common.truth.Truth.assertThat;
import static com.google.turbine.testing.TestClassPaths.TURBINE_BOOTCLASSPATH;
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.fail;
+import static com.google.turbine.testing.TestResources.getResource;
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertThrows;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.io.ByteStreams;
import com.google.turbine.binder.Binder;
import com.google.turbine.binder.Binder.BindingResult;
import com.google.turbine.binder.ClassPathBinder;
@@ -233,18 +233,10 @@ public class LowerTest {
TURBINE_BOOTCLASSPATH.env())
.bytes();
- assertThat(AsmUtils.textify(bytes.get("test/Test")))
- .isEqualTo(
- new String(
- ByteStreams.toByteArray(
- LowerTest.class.getResourceAsStream("testdata/golden/outer.txt")),
- UTF_8));
- assertThat(AsmUtils.textify(bytes.get("test/Test$Inner")))
- .isEqualTo(
- new String(
- ByteStreams.toByteArray(
- LowerTest.class.getResourceAsStream("testdata/golden/inner.txt")),
- UTF_8));
+ assertThat(AsmUtils.textify(bytes.get("test/Test"), /* skipDebug= */ false))
+ .isEqualTo(getResource(LowerTest.class, "testdata/golden/outer.txt"));
+ assertThat(AsmUtils.textify(bytes.get("test/Test$Inner"), /* skipDebug= */ false))
+ .isEqualTo(getResource(LowerTest.class, "testdata/golden/inner.txt"));
}
@Test
@@ -268,7 +260,7 @@ public class LowerTest {
List<String> attributes = new ArrayList<>();
new ClassReader(lowered.get("Test$Inner$InnerMost"))
.accept(
- new ClassVisitor(Opcodes.ASM7) {
+ new ClassVisitor(Opcodes.ASM9) {
@Override
public void visitInnerClass(
String name, String outerName, String innerName, int access) {
@@ -285,10 +277,7 @@ public class LowerTest {
public void wildArrayElement() throws Exception {
IntegrationTestSupport.TestInput input =
IntegrationTestSupport.TestInput.parse(
- new String(
- ByteStreams.toByteArray(
- getClass().getResourceAsStream("testdata/canon_array.test")),
- UTF_8));
+ getResource(getClass(), "testdata/canon_array.test"));
Map<String, byte[]> actual =
IntegrationTestSupport.runTurbine(input.sources, ImmutableList.of());
@@ -346,11 +335,11 @@ public class LowerTest {
TypePath[] path = new TypePath[1];
new ClassReader(lowered.get("Test"))
.accept(
- new ClassVisitor(Opcodes.ASM7) {
+ new ClassVisitor(Opcodes.ASM9) {
@Override
public FieldVisitor visitField(
int access, String name, String desc, String signature, Object value) {
- return new FieldVisitor(Opcodes.ASM7) {
+ return new FieldVisitor(Opcodes.ASM9) {
@Override
public AnnotationVisitor visitTypeAnnotation(
int typeRef, TypePath typePath, String desc, boolean visible) {
@@ -397,7 +386,7 @@ public class LowerTest {
Map<String, Object> values = new LinkedHashMap<>();
new ClassReader(actual.get("Test"))
.accept(
- new ClassVisitor(Opcodes.ASM7) {
+ new ClassVisitor(Opcodes.ASM9) {
@Override
public FieldVisitor visitField(
int access, String name, String desc, String signature, Object value) {
@@ -424,7 +413,7 @@ public class LowerTest {
int[] acc = {0};
new ClassReader(lowered.get("Test"))
.accept(
- new ClassVisitor(Opcodes.ASM7) {
+ new ClassVisitor(Opcodes.ASM9) {
@Override
public void visit(
int version,
@@ -522,16 +511,11 @@ public class LowerTest {
Path libJar = temporaryFolder.newFile("lib.jar").toPath();
try (OutputStream os = Files.newOutputStream(libJar);
JarOutputStream jos = new JarOutputStream(os)) {
- jos.putNextEntry(new JarEntry("A$M.class"));
- jos.write(lib.get("A$M"));
- jos.putNextEntry(new JarEntry("A$M$I.class"));
- jos.write(lib.get("A$M$I"));
- jos.putNextEntry(new JarEntry("B.class"));
- jos.write(lib.get("B"));
- jos.putNextEntry(new JarEntry("B$BM.class"));
- jos.write(lib.get("B$BM"));
- jos.putNextEntry(new JarEntry("B$BM$BI.class"));
- jos.write(lib.get("B$BM$BI"));
+ write(jos, lib, "A$M");
+ write(jos, lib, "A$M$I");
+ write(jos, lib, "B");
+ write(jos, lib, "B$BM");
+ write(jos, lib, "B$BM$BI");
}
ImmutableMap<String, String> sources =
@@ -544,14 +528,13 @@ public class LowerTest {
"}"))
.build();
- try {
- IntegrationTestSupport.runTurbine(sources, ImmutableList.of(libJar));
- fail();
- } catch (TurbineError error) {
- assertThat(error)
- .hasMessageThat()
- .contains("Test.java: error: could not locate class file for A");
- }
+ TurbineError error =
+ assertThrows(
+ TurbineError.class,
+ () -> IntegrationTestSupport.runTurbine(sources, ImmutableList.of(libJar)));
+ assertThat(error)
+ .hasMessageThat()
+ .contains("Test.java: error: could not locate class file for A");
}
@Test
@@ -579,16 +562,11 @@ public class LowerTest {
Path libJar = temporaryFolder.newFile("lib.jar").toPath();
try (OutputStream os = Files.newOutputStream(libJar);
JarOutputStream jos = new JarOutputStream(os)) {
- jos.putNextEntry(new JarEntry("A$M.class"));
- jos.write(lib.get("A$M"));
- jos.putNextEntry(new JarEntry("A$M$I.class"));
- jos.write(lib.get("A$M$I"));
- jos.putNextEntry(new JarEntry("B.class"));
- jos.write(lib.get("B"));
- jos.putNextEntry(new JarEntry("B$BM.class"));
- jos.write(lib.get("B$BM"));
- jos.putNextEntry(new JarEntry("B$BM$BI.class"));
- jos.write(lib.get("B$BM$BI"));
+ write(jos, lib, "A$M");
+ write(jos, lib, "A$M$I");
+ write(jos, lib, "B");
+ write(jos, lib, "B$BM");
+ write(jos, lib, "B$BM$BI");
}
ImmutableMap<String, String> sources =
@@ -603,18 +581,15 @@ public class LowerTest {
"}"))
.build();
- try {
- IntegrationTestSupport.runTurbine(sources, ImmutableList.of(libJar));
- fail();
- } catch (TurbineError error) {
- assertThat(error)
- .hasMessageThat()
- .contains(
- lines(
- "Test.java:3: error: could not locate class file for A",
- " I i;",
- " ^"));
- }
+ TurbineError error =
+ assertThrows(
+ TurbineError.class,
+ () -> IntegrationTestSupport.runTurbine(sources, ImmutableList.of(libJar)));
+ assertThat(error)
+ .hasMessageThat()
+ .contains(
+ lines(
+ "Test.java:3: error: could not locate class file for A", " I i;", " ^"));
}
// If an element incorrectly has multiple visibility modifiers, pick one, and rely on javac to
@@ -629,7 +604,7 @@ public class LowerTest {
int[] testAccess = {0};
new ClassReader(lowered.get("Test"))
.accept(
- new ClassVisitor(Opcodes.ASM7) {
+ new ClassVisitor(Opcodes.ASM9) {
@Override
public void visit(
int version,
@@ -649,4 +624,9 @@ public class LowerTest {
static String lines(String... lines) {
return Joiner.on(System.lineSeparator()).join(lines);
}
+
+ static void write(JarOutputStream jos, Map<String, byte[]> lib, String name) throws IOException {
+ jos.putNextEntry(new JarEntry(name + ".class"));
+ jos.write(requireNonNull(lib.get(name)));
+ }
}
diff --git a/javatests/com/google/turbine/lower/ModuleIntegrationTest.java b/javatests/com/google/turbine/lower/ModuleIntegrationTest.java
index 03c6fb7..f2c0bbf 100644
--- a/javatests/com/google/turbine/lower/ModuleIntegrationTest.java
+++ b/javatests/com/google/turbine/lower/ModuleIntegrationTest.java
@@ -18,12 +18,11 @@ package com.google.turbine.lower;
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_VERSION;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static com.google.turbine.testing.TestResources.getResource;
import static java.util.stream.Collectors.toList;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.ImmutableList;
-import com.google.common.io.ByteStreams;
import com.google.turbine.binder.CtSymClassBinder;
import com.google.turbine.binder.JimageClassBinder;
import java.nio.file.Files;
@@ -68,10 +67,7 @@ public class ModuleIntegrationTest {
}
IntegrationTestSupport.TestInput input =
- IntegrationTestSupport.TestInput.parse(
- new String(
- ByteStreams.toByteArray(getClass().getResourceAsStream("moduletestdata/" + test)),
- UTF_8));
+ IntegrationTestSupport.TestInput.parse(getResource(getClass(), "moduletestdata/" + test));
ImmutableList<Path> classpathJar = ImmutableList.of();
if (!input.classes.isEmpty()) {
diff --git a/javatests/com/google/turbine/lower/testdata/annotation_clinit.test b/javatests/com/google/turbine/lower/testdata/annotation_clinit.test
new file mode 100644
index 0000000..7419ed6
--- /dev/null
+++ b/javatests/com/google/turbine/lower/testdata/annotation_clinit.test
@@ -0,0 +1,18 @@
+%%% pkg/Anno.java %%%
+package pkg;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Anno {
+ String CONSTANT = Anno.class.toString();
+
+ String value() default "";
+}
+
+=== pkg/T.java ===
+package pkg;
+
+@Anno
+class T {}
diff --git a/javatests/com/google/turbine/lower/testdata/unicode_pkg.test b/javatests/com/google/turbine/lower/testdata/unicode_pkg.test
new file mode 100644
index 0000000..85d38d9
--- /dev/null
+++ b/javatests/com/google/turbine/lower/testdata/unicode_pkg.test
@@ -0,0 +1,4 @@
+=== Test.java ===
+package pkg𐀀.test;
+
+class Test {}