From c84a35837e194f5ac8f38cee2998afb5ec631078 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Wed, 5 Oct 2022 17:37:21 +0200 Subject: [PATCH] OutputSpec.matchesThisVm better supports version ranges 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. Existing XML test specs using ' have been adjusted to use version ranges rather than long lists of consecutive versions. Furthermore, ranges with a trailing '+' like '14+' were replaced by using the new canonical format '14-', even though the parser still correctly recognises '14+'. Signed-off-by: Alexander Kriegisch --- .../java/org/aspectj/testing/OutputSpec.java | 47 ++++---- .../org/aspectj/systemtest/ajc150/ajc150.xml | 112 +++++++++--------- .../org/aspectj/systemtest/ajc151/ajc151.xml | 106 ++++++++--------- .../org/aspectj/systemtest/ajc154/ajc154.xml | 24 ++-- .../systemtest/ajc1611/newfeatures-tests.xml | 28 ++--- .../aspectj/systemtest/ajc1612/ajc1612.xml | 12 +- .../aspectj/systemtest/ajc169/intertype.xml | 56 ++++----- .../org/aspectj/systemtest/ajc170/ajc170.xml | 36 +++--- .../org/aspectj/systemtest/ajc173/ajc173.xml | 30 ++--- .../org/aspectj/systemtest/ajc174/ajc174.xml | 24 ++-- .../org/aspectj/systemtest/ajc188/ajc188.xml | 4 +- .../systemtest/ajc190/ajc190_from150.xml | 112 +++++++++--------- 12 files changed, 298 insertions(+), 293 deletions(-) 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 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/tests/src/test/resources/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc150/ajc150.xml index 7963070e0..63313f624 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2750,8 +2750,8 @@ - - + + @@ -3746,65 +3746,65 @@ - - - - - - - - - + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc151/ajc151.xml index 8d8cd66b8..3588f5950 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc151/ajc151.xml @@ -4,7 +4,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -92,22 +92,22 @@ - - - - + + + + - + - - - - + + + + @@ -120,23 +120,23 @@ - + - + - - + + - - + + @@ -153,7 +153,7 @@ - + @@ -167,19 +167,19 @@ - + - - + + - - + + - + @@ -191,32 +191,32 @@ - + - - + + - + - + - + - + @@ -227,7 +227,7 @@ - + @@ -239,7 +239,7 @@ - + @@ -248,12 +248,12 @@ - + - + @@ -264,7 +264,7 @@ - + @@ -272,18 +272,18 @@ - + - + - + @@ -292,11 +292,11 @@ - + - + @@ -307,7 +307,7 @@ - + @@ -317,7 +317,7 @@ - + @@ -345,7 +345,7 @@ - + @@ -379,7 +379,7 @@ - + @@ -390,10 +390,10 @@ - + - + @@ -403,8 +403,8 @@ - - + + @@ -415,4 +415,4 @@ - \ No newline at end of file + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc154/ajc154.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc154/ajc154.xml index a0d38cb6c..8ed8e3ffc 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc154/ajc154.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc154/ajc154.xml @@ -27,8 +27,8 @@ - - + + @@ -40,8 +40,8 @@ - - + + @@ -53,8 +53,8 @@ - - + + @@ -66,8 +66,8 @@ - - + + @@ -80,8 +80,8 @@ - - + + @@ -95,8 +95,8 @@ - - + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml index 914042633..86e135979 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml @@ -19,7 +19,7 @@ - + @@ -34,8 +34,8 @@ - - + + @@ -50,14 +50,14 @@ - + - + @@ -65,7 +65,7 @@ - + @@ -74,7 +74,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -103,18 +103,18 @@ - + - - + + - + @@ -122,7 +122,7 @@ - + @@ -135,5 +135,5 @@ - + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1612/ajc1612.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1612/ajc1612.xml index 838003df5..d7423a194 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1612/ajc1612.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1612/ajc1612.xml @@ -7,8 +7,8 @@ - - + + @@ -258,10 +258,10 @@ - - - - + + + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc169/intertype.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc169/intertype.xml index 5bb0155d3..e4dbec2fa 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc169/intertype.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc169/intertype.xml @@ -70,10 +70,10 @@ - - - - + + + + @@ -83,10 +83,10 @@ - - - - + + + + @@ -96,10 +96,10 @@ - - - - + + + + @@ -109,10 +109,10 @@ - - - - + + + + @@ -122,10 +122,10 @@ - - - - + + + + @@ -135,10 +135,10 @@ - - - - + + + + @@ -148,10 +148,10 @@ - - - - + + + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml index f3f18f6d9..5fe1c9ffa 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml @@ -182,16 +182,16 @@ - - - - - - + + + + + + - - + + @@ -202,16 +202,16 @@ - - + + - - + + - - + + @@ -223,8 +223,8 @@ - - + + @@ -235,8 +235,8 @@ - - + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc173/ajc173.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc173/ajc173.xml index 398fae62f..a60fca98c 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc173/ajc173.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc173/ajc173.xml @@ -5,40 +5,40 @@ - + - - + + - + - + - + - + - + - + - + @@ -49,7 +49,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -74,13 +74,13 @@ - + - - @@ -69,7 +69,7 @@ - + @@ -85,26 +85,26 @@ - + - - - + + - + @@ -116,7 +116,7 @@ - + @@ -134,7 +134,7 @@ - + @@ -153,7 +153,7 @@ - + @@ -171,7 +171,7 @@ - + @@ -190,7 +190,7 @@ - + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc188/ajc188.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc188/ajc188.xml index 7e7f9ba71..8aa734e3e 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc188/ajc188.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc188/ajc188.xml @@ -8,8 +8,8 @@ - - + + diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc190/ajc190_from150.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc190/ajc190_from150.xml index 885a0b74e..dede00f0a 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc190/ajc190_from150.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc190/ajc190_from150.xml @@ -2750,8 +2750,8 @@ - - + + @@ -3746,65 +3746,65 @@ - - - - - - - - - + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + -- 2.39.5