diff options
Diffstat (limited to 'testing')
6 files changed, 98 insertions, 26 deletions
diff --git a/testing/pom.xml b/testing/pom.xml index ae7fd0d9a..a1ff20056 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.aspectj</groupId> <artifactId>aspectj-parent</artifactId> - <version>1.9.10-SNAPSHOT</version> + <version>1.9.19-SNAPSHOT</version> </parent> <artifactId>testing</artifactId> diff --git a/testing/src/test/java/org/aspectj/testing/OutputSpec.java b/testing/src/test/java/org/aspectj/testing/OutputSpec.java index 5a6594756..14fc3bb62 100644 --- a/testing/src/test/java/org/aspectj/testing/OutputSpec.java +++ b/testing/src/test/java/org/aspectj/testing/OutputSpec.java @@ -17,6 +17,8 @@ import java.util.List; import org.aspectj.tools.ajc.AjcTestCase; import org.aspectj.util.LangUtil; +import static java.lang.Double.parseDouble; + public class OutputSpec { private List<String> expectedOutputLines = new ArrayList<>(); @@ -28,28 +30,31 @@ public class OutputSpec { } /** - * For a test output line that has specified a vm version, check if it matches the vm we are running on. - * vm might be "1.2,1.3,1.4,1.5" or simply "9" or it may be a version with a '+' suffix indicating that - * level or later, e.g. "9+" should be ok on Java 10 - * @return true if the current vm version matches the spec + * For a test output line that has specified list of JVM version ranges, determine whether the JVM we are running on + * matches at least one of those ranges. + * + * @param vmVersionRanges might be a single version like "9", a list of versions like "1.2,1.3,1.4,1.5", an equivalent + * range of "1.2-1.5", an open range like "-1.8", "9-" (equivalent to "9+") or a more complex list of ranges + * like "-1.6,9-11,13-14,17-" or "8,11,16+". Empty ranges like in "", " ", "8,,14", ",5", "6-," will be + * ignored. I.e., they will not yield a positive match. Bogus ranges like "9-11-14" will be ignored, too. + * + * @return true if the current vmVersionRanges version matches the spec */ - private boolean matchesThisVm(String vm) { - // vm might be 1.2, 1.3, 1.4, 1.5 or 1.9 possibly with a '+' in there - // For now assume + is attached to there only being one version, like "9+" - // System.out.println("Checking "+vm+" for "+LangUtil.getVmVersionString()); - String v = LangUtil.getVmVersionString(); - if (v.endsWith(".0")) { - v = v.substring(0,v.length()-2); - } - if (vm.contains(v)) { - return true; - } - if (vm.endsWith("+")) { - double vmVersion = LangUtil.getVmVersion(); - double vmSpecified = Double.parseDouble(vm.substring(0,vm.length()-1)); - return vmVersion >= vmSpecified; - } - return false; + private boolean matchesThisVm(String vmVersionRanges) { + double currentVmVersion = LangUtil.getVmVersion(); + return Arrays.stream(vmVersionRanges.split(",")) + .map(String::trim) + .filter(range -> !range.isEmpty()) + .map(range -> range + .replaceFirst("^([0-9.]+)$", "$1-$1") // single version 'n' to range 'n-n' + .replaceFirst("^-", "0-") // left open range '-n' to '0-n' + .replaceFirst("[+-]$", "-99999") // right open range 'n-' or 'n+' to 'n-99999' + .split("-") // range 'n-m' to array ['n', 'm'] + ) + .filter(range -> range.length == 2) + .map(range -> new double[] { parseDouble(range[0]), parseDouble(range[1]) }) + //.filter(range -> { System.out.println(range[0] + " - " +range[1]); return true; }) + .anyMatch(range -> range[0] <= currentVmVersion && range[1] >= currentVmVersion); } public void matchAgainst(String output) { diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java index ba4d00605..fade6c92f 100644 --- a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2021 Contributors + * Copyright (c) 2022 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v 2.0 @@ -20,14 +20,13 @@ public abstract class XMLBasedAjcTestCaseForJava18Only extends XMLBasedAjcTestCa @Override public void setUp() throws Exception { // Activate this block after upgrading to JDT Core Java 19 - /* throw new IllegalStateException( "These tests need a Java 18 level AspectJ compiler " + "(e.g. because they use version-specific preview features). " + "This compiler does not support preview features of a previous version anymore." ); - */ // Activate this block before upgrading to JDT Core Java 19 + /* if (!LangUtil.is18VMOrGreater() || LangUtil.is19VMOrGreater()) { throw new IllegalStateException( "These tests should be run on Java 18 only " + @@ -35,6 +34,7 @@ public abstract class XMLBasedAjcTestCaseForJava18Only extends XMLBasedAjcTestCa ); } super.setUp(); + */ } } diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java index 9b9efdd34..20e26862f 100644 --- a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2021 Contributors + * Copyright (c) 2022 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v 2.0 diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java new file mode 100644 index 000000000..e0a99283d --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19Only.java @@ -0,0 +1,40 @@ +/* ******************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +package org.aspectj.testing; + +import org.aspectj.util.LangUtil; + +/** + * Makes sure tests are running on the right level of JDK. + * + * @author Alexander Kriegisch + */ +public abstract class XMLBasedAjcTestCaseForJava19Only extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + // Activate this block after upgrading to JDT Core Java 20 + /* + throw new IllegalStateException( + "These tests need a Java 19 level AspectJ compiler " + + "(e.g. because they use version-specific preview features). " + + "This compiler does not support preview features of a previous version anymore." + ); + */ + // Activate this block before upgrading to JDT Core Java 20 + if (!LangUtil.is19VMOrGreater() || LangUtil.is20VMOrGreater()) { + throw new IllegalStateException( + "These tests should be run on Java 19 only " + + "(e.g. because they use version-specific preview features)" + ); + } + super.setUp(); + } + +} diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19OrLater.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19OrLater.java new file mode 100644 index 000000000..95beffef5 --- /dev/null +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava19OrLater.java @@ -0,0 +1,27 @@ +/* ******************************************************************* + * Copyright (c) 2022 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v 2.0 + * which accompanies this distribution and is available at + * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt + * ******************************************************************/ +package org.aspectj.testing; + +import org.aspectj.util.LangUtil; + +/** + * Makes sure tests are running on the right level of JDK. + * + * @author Alexander Kriegisch + */ +public abstract class XMLBasedAjcTestCaseForJava19OrLater extends XMLBasedAjcTestCase { + + @Override + public void setUp() throws Exception { + if (!LangUtil.is19VMOrGreater()) + throw new IllegalStateException("These tests should be run on Java 19 or later"); + super.setUp(); + } + +} |