diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-11-05 10:03:23 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2023-11-05 10:03:23 +0700 |
commit | 70f3c09bcdd80f682b098f22da8b6285211e46da (patch) | |
tree | 1587bbbd3259fd6ff70030ca0a6b6d6ff337a470 | |
parent | f0c0088286c17f8a5bf6fa8a00b01a7f46568cf4 (diff) | |
download | aspectj-70f3c09bcdd80f682b098f22da8b6285211e46da.tar.gz aspectj-70f3c09bcdd80f682b098f22da8b6285211e46da.zip |
Enable some tests after J19 problems were fixed for J21
Two test classes which had redundant default clauses for switch with
record patterns were copied from the java19 to the java21 directory and
the redundant clauses deactivated, i.e. the test now run as originally
intended. For older JDK versions, the old tests still stay active in
order to document the old state of affairs.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
5 files changed, 52 insertions, 20 deletions
diff --git a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj index 4fad25327..37c73788f 100644 --- a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj +++ b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj @@ -13,7 +13,8 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect { switch (pair) { case Pair<I>(I i, C c) -> System.out.println("x"); case Pair<I>(I i, D d) -> System.out.println("y"); - // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed. + // Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj. default -> System.out.println("z"); } @@ -21,7 +22,8 @@ public aspect RecordPatternsPreview1ExhaustivenessAspect { case Pair<I>(C c, I i) -> System.out.println("a"); case Pair<I>(D d, C c) -> System.out.println("b"); case Pair<I>(D d1, D d2) -> System.out.println("c"); - // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed. + // Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj. default -> System.out.println("d"); } } diff --git a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java index e815c512d..1d1d9d4f3 100644 --- a/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java +++ b/tests/features1919/java19/RecordPatternsPreview1ExhaustivenessOK1.java @@ -10,7 +10,8 @@ public class RecordPatternsPreview1ExhaustivenessOK1 { switch (p2) { case Pair<I>(I i, C c) -> System.out.println("x"); case Pair<I>(I i, D d) -> System.out.println("y"); - // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed. + // Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java. default -> System.out.println("z"); } @@ -18,7 +19,8 @@ public class RecordPatternsPreview1ExhaustivenessOK1 { case Pair<I>(C c, I i) -> System.out.println("a"); case Pair<I>(D d, C c) -> System.out.println("b"); case Pair<I>(D d1, D d2) -> System.out.println("c"); - // TODO: remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed + // TODO: Remove redundant default clause when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed. + // Fixed since Java 21, see features1921/java21/RecordPatternsPreview1ExhaustivenessOK1.java. default -> System.out.println("d"); } } diff --git a/tests/features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj b/tests/features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj new file mode 100644 index 000000000..d87c99ffd --- /dev/null +++ b/tests/features1921/java21/RecordPatternsPreview1ExhaustivenessAspect.aj @@ -0,0 +1,35 @@ +public aspect RecordPatternsPreview1ExhaustivenessAspect { + static Pair<I> p2 = new Pair<>(new C(), new D()); + + public static void main(String[] args) { + doSomething(p2); + } + + public static void doSomething(Pair<I> pair) { + System.out.println(pair.toString().replaceAll("@[0-9a-f]+", "@000")); + } + + before(Pair<I> pair) : execution(* doSomething(Pair)) && args(pair) { + switch (pair) { + case Pair<I>(I i, C c) -> System.out.println("x"); + case Pair<I>(I i, D d) -> System.out.println("y"); + // Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. + // Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj. + // default -> System.out.println("z"); + } + + switch (pair) { + case Pair<I>(C c, I i) -> System.out.println("a"); + case Pair<I>(D d, C c) -> System.out.println("b"); + case Pair<I>(D d1, D d2) -> System.out.println("c"); + // Redundant default clause no longer necessary after fix of https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. + // Old version with default clause see features1919/java19/RecordPatternsPreview1ExhaustivenessAspect.aj. + // default -> System.out.println("d"); + } + } +} + +sealed interface I permits C, D { } +final class C implements I { } +final class D implements I { } +record Pair<T>(T x, T y) { } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java index 20efe1723..b0eaf3939 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java @@ -59,10 +59,8 @@ public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { } public void testRecordPatternsPreview1ExhaustivenessOK1() { - // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice, - // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 - // TODO: Remove redundant default clauses when fixed upstream - System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed"); + // Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected' twice, + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. Fixed in Java 21. runTest("record patterns exhaustiveness 1"); } @@ -71,10 +69,8 @@ public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { } public void testRecordPatternsPreview1ExhaustivenessAspect() { - // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected' twice, - // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 - // TODO: Remove redundant default clauses when fixed upstream - System.out.println("TODO: fully activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed"); + // Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected' twice, + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455. Fixed in Java 21. runTest("record patterns exhaustiveness aspect"); } @@ -84,11 +80,9 @@ public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { } public void testRecordPatternsPreview1ExhaustivenessOK2() { - // Falsely throws 'An enhanced switch statement should be exhaustive; a default label expected', - // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 - // TODO: activate when fixed - System.out.println("TODO: activate when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398 has been fixed"); - //runTest("record patterns exhaustiveness 2"); + // Used to falsely throw 'An enhanced switch statement should be exhaustive; a default label expected', + // see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/398. Fixed in Java 21. + runTest("record patterns exhaustiveness 2"); } public static Test suite() { diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml index 73f2bdf5b..ec4682216 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml @@ -139,7 +139,7 @@ </ajc-test> <!-- Java 21 final, Java 19, 20 preview --> - <ajc-test dir="features1919/java19" vm="21" title="record patterns exhaustiveness 1"> + <ajc-test dir="features1921/java21" vm="21" title="record patterns exhaustiveness 1"> <compile files="RecordPatternsPreview1ExhaustivenessOK1.java" options="-21"/> <run class="RecordPatternsPreview1ExhaustivenessOK1" vmargs=""> <stdout> @@ -150,9 +150,8 @@ </ajc-test> <!-- Java 21 final, Java 19, 20 preview --> - <ajc-test dir="features1919/java19" vm="21" title="record patterns exhaustiveness aspect"> + <ajc-test dir="features1921/java21" vm="21" title="record patterns exhaustiveness aspect"> <compile files="RecordPatternsPreview1ExhaustivenessAspect.aj" options="-21"/> - <!-- TODO: Remove redundant default clauses when https://github.com/eclipse-jdt/eclipse.jdt.core/issues/455 has been fixed --> <run class="RecordPatternsPreview1ExhaustivenessAspect" vmargs=""> <stdout> <line text="y"/> |