diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-02-19 22:01:05 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2024-02-19 22:01:05 +0700 |
commit | 47db35bb48a1ef0919dff62521ca38cd7cf3ccec (patch) | |
tree | fce4041a52368870ec8beb8eb5b9a16f36b98ecc /tests/src/test/java/org/aspectj/systemtest/ajc1921 | |
parent | 4e4641f8cc06176377a1faf8378e93df9bf248e1 (diff) | |
download | aspectj-47db35bb48a1ef0919dff62521ca38cd7cf3ccec.tar.gz aspectj-47db35bb48a1ef0919dff62521ca38cd7cf3ccec.zip |
New abstract class JavaVersionSpecificXMLBasedAjcTestCase
Replaces now obsolete base classes
- XMLBasedAjcTestCaseForJava[n]OrLater,
- XMLBasedAjcTestCaseForJava[n]Only.
The new class is parametrised with minimum and maximum Java version and
hence can replace all the other classes. This does not only apply the
DRY principle, but also makes adding tests for new Java versions less
tedious.
By chance, I also noticed missing sanity tests for Java 12, which I
added as a little drive-by benefit.
Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests/src/test/java/org/aspectj/systemtest/ajc1921')
4 files changed, 36 insertions, 18 deletions
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 466135dc2..e221df46e 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Ajc1921TestsJava.java @@ -9,17 +9,23 @@ package org.aspectj.systemtest.ajc1921; import junit.framework.Test; import org.aspectj.apache.bcel.Constants; +import org.aspectj.testing.JavaVersionSpecificXMLBasedAjcTestCase; import org.aspectj.testing.XMLBasedAjcTestCase; -import org.aspectj.testing.XMLBasedAjcTestCaseForJava21OrLater; /** * @author Alexander Kriegisch */ -public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { +public class Ajc1921TestsJava extends JavaVersionSpecificXMLBasedAjcTestCase { + + private static final Constants.ClassFileVersion classFileVersion = Constants.ClassFileVersion.of(21); + + public Ajc1921TestsJava() { + super(21); + } public void testSwitchPatternMatchingPreview4Java() { runTest("switch pattern matching preview 4 java"); - checkVersion("SwitchPatternPreview4OK", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); + checkVersion("SwitchPatternPreview4OK", classFileVersion.MAJOR, classFileVersion.MINOR); } public void testSwitchPatternMatchingPreview4Error() { @@ -28,10 +34,10 @@ public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { public void testSwitchPatternMatchingPreview3Aspect() { runTest("switch pattern matching preview 3 aspect"); - checkVersion("SwitchPatternPreview3Aspect", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); - checkVersion("Application", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); - checkVersion("Shape", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); - checkVersion("S", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); + checkVersion("SwitchPatternPreview3Aspect", classFileVersion.MAJOR, classFileVersion.MINOR); + checkVersion("Application", classFileVersion.MAJOR, classFileVersion.MINOR); + checkVersion("Shape", classFileVersion.MAJOR, classFileVersion.MINOR); + checkVersion("S", classFileVersion.MAJOR, classFileVersion.MINOR); } public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() { @@ -54,8 +60,8 @@ public class Ajc1921TestsJava extends XMLBasedAjcTestCaseForJava21OrLater { public void testRecordPatternsPreview1Error() { // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/450 (fixed for preview 2 in Eclipse 2023-03, 4.27) runTest("record patterns error"); - checkVersion("RecordPatternsPreview1Error", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); - checkVersion("Box", Constants.ClassFileVersion.of(21).MAJOR, Constants.ClassFileVersion.of(21).MINOR); + checkVersion("RecordPatternsPreview1Error", classFileVersion.MAJOR, classFileVersion.MINOR); + checkVersion("Box", classFileVersion.MAJOR, classFileVersion.MINOR); } public void testRecordPatternsPreview1ExhaustivenessOK1() { diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java index 56e8b963a..a8166995b 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/AllTestsAspectJ1921.java @@ -9,6 +9,7 @@ package org.aspectj.systemtest.ajc1921; import junit.framework.Test; import junit.framework.TestSuite; +import org.aspectj.tools.ant.taskdefs.AjcTask; import org.aspectj.util.LangUtil; // AspectJ_JDK_Update @@ -28,18 +29,21 @@ import org.aspectj.util.LangUtil; */ public class AllTestsAspectJ1921 { + private static final int JAVA_VERSION = 21; + public static Test suite() { TestSuite suite = new TestSuite("AspectJ 1.9.21 tests"); suite.addTest(Bugs1921Tests.suite()); - if (LangUtil.isVMGreaterOrEqual(21)) { + if (LangUtil.isVMGreaterOrEqual(JAVA_VERSION)) { suite.addTest(SanityTestsJava21.suite()); suite.addTest(Ajc1921TestsJava.suite()); } - // AspectJ_JDK_Update + // Do not run tests using a previous compiler's preview features anymore. They would all fail. - // TODO: Comment out the following block when upgrading JDT Core to Java 22 - if (LangUtil.isVMGreaterOrEqual(21) && !LangUtil.isVMGreaterOrEqual(22)) { - suite.addTest(Java21PreviewFeaturesTests.suite()); + if (AjcTask.JAVA_VERSION_MAX == JAVA_VERSION) { + if (LangUtil.isVMGreaterOrEqual(JAVA_VERSION) && LangUtil.isVMLessOrEqual(JAVA_VERSION)) { + suite.addTest(Java21PreviewFeaturesTests.suite()); + } } return suite; } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java index 255583efd..2fd5e8ef8 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java @@ -9,13 +9,17 @@ package org.aspectj.systemtest.ajc1921; import junit.framework.Test; import org.aspectj.systemtest.ajc10x.Ajc10xTests; +import org.aspectj.testing.JavaVersionSpecificXMLBasedAjcTestCase; import org.aspectj.testing.XMLBasedAjcTestCase; -import org.aspectj.testing.XMLBasedAjcTestCaseForJava21Only; /** * @author Alexander Kriegisch */ -public class Java21PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava21Only { +public class Java21PreviewFeaturesTests extends JavaVersionSpecificXMLBasedAjcTestCase { + + public Java21PreviewFeaturesTests() { + super(21, 21); + } public void testStringPatterns() { runTest("string patterns"); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java index 2f4810e4e..0115abec8 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/SanityTestsJava21.java @@ -9,8 +9,8 @@ package org.aspectj.systemtest.ajc1921; import junit.framework.Test; import org.aspectj.apache.bcel.Constants; +import org.aspectj.testing.JavaVersionSpecificXMLBasedAjcTestCase; import org.aspectj.testing.XMLBasedAjcTestCase; -import org.aspectj.testing.XMLBasedAjcTestCaseForJava21OrLater; /* * Some very trivial tests that help verify things are OK. @@ -19,10 +19,14 @@ import org.aspectj.testing.XMLBasedAjcTestCaseForJava21OrLater; * * @author Alexander Kriegisch */ -public class SanityTestsJava21 extends XMLBasedAjcTestCaseForJava21OrLater { +public class SanityTestsJava21 extends JavaVersionSpecificXMLBasedAjcTestCase { public static final int bytecode_version_for_JDK_level = Constants.ClassFileVersion.of(21).MAJOR; + public SanityTestsJava21() { + super(21); + } + // Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug) public void testSimpleJava_A() { runTest("simple - a"); |