From 4a07d2f698b17c0d8821abd72eaf986d7696a6e2 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Thu, 21 Sep 2017 14:04:49 +0200 Subject: [PATCH] Change the new IgnoreIf trait to less generic IgnoreOS trait This is to support parsing the trait's value from the expected output file. --- .../truffle/r/test/ExpectedTestOutput.test | 2 +- .../com/oracle/truffle/r/test/IgnoreIf.java | 86 ------------------- .../com/oracle/truffle/r/test/IgnoreOS.java | 54 ++++++++++++ .../com/oracle/truffle/r/test/TestBase.java | 2 +- .../r/test/builtins/TestBuiltin_list.java | 4 +- .../r/test/generate/TestOutputManager.java | 4 + 6 files changed, 62 insertions(+), 90 deletions(-) delete mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreIf.java create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreOS.java diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 7048d69655..c2bfbac1b9 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -32636,7 +32636,7 @@ attr(,"class") [1] 17 -##com.oracle.truffle.r.test.builtins.TestBuiltin_list.testlist3#GenericIgnoreIf.IgnoreIf# +##com.oracle.truffle.r.test.builtins.TestBuiltin_list.testlist3#IgnoreOS.Solaris# #argv <- list(x = c(9.5367431640625e-07, 1.9073486328125e-06, 3.814697265625e-06, 7.62939453125e-06, 1.52587890625e-05, 3.0517578125e-05, 6.103515625e-05, 0.0001220703125, 0.000244140625, 0.00048828125, 0.0009765625, 0.001953125, 0.00390625, 0.0078125, 0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024), y = c(3.69420518444359e+25, 2.30887824027777e+24, 1.44304890017492e+23, 9.01905562612606e+21, 5.63690976641081e+20, 35230686042118275072, 2201917878145066496, 137619867512235136, 8601241751556820, 537577617482832, 33598603095309.8, 2099913194115.17, 131244699796.888, 8202825028.58974, 512684387.219832, 32044730.0464007, 2003284.70114408, 125327.674230857, 7863.68742857025, 499.272560819512, 33.2784230289721, 2.7659432263306, 0.488936768533843, -0.282943224311172, 7.32218543045282e-05, -0.00636442868227041, -0.0483709204009262, -0.0704795507649514, 0.0349437746169591, -0.0264830837608839, 0.0200901469411759), xlab = NULL, ylab = NULL);list(argv[[1]],argv[[2]],argv[[3]],argv[[4]]); [[1]] [1] 9.536743e-07 1.907349e-06 3.814697e-06 7.629395e-06 1.525879e-05 diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreIf.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreIf.java deleted file mode 100644 index 9c092552b6..0000000000 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreIf.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.test; - -import java.util.Arrays; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * This test trait allows ignoring tests in certain environments, such as certain operating systems - * etc. For instance, to ignore the following test on a Solaris OS, one can use the - * <code>systemPropertyContains</code> factory method to create the test trait. The resulting test - * trait will test whether the system property <code>os.name</code> contains string - * <code>sunos</code> and if so, the test will be ignored. - * - * <pre> - * assertEval(IgnoreIf.systemPropertyContains("os.name", "sunos"), "list(c(9.5367431640625e-07, 1.9073486328125e-06)"); - * </pre> - */ -public abstract class IgnoreIf implements TestTrait { - - public abstract boolean isIgnoring(); - - @Override - public String getName() { - return "IgnoreIf"; - } - - public static boolean containsIgnoring(TestTrait[] traits) { - IgnoreIf[] ignoreIfTraits = TestTrait.collect(traits, IgnoreIf.class); - return Arrays.stream(ignoreIfTraits).anyMatch(t -> t.isIgnoring()); - } - - public static IgnoreIf envVarIs(String var, String expectedValue) { - return new GenericIgnoreIf<>(() -> System.getenv(var), (value) -> expectedValue.equals(value)); - } - - public static IgnoreIf envVarContains(String var, String substring) { - return new GenericIgnoreIf<>(() -> System.getenv(var), (value) -> value != null && value.contains(substring)); - } - - public static IgnoreIf systemPropertyIs(String property, String expectedValue) { - return new GenericIgnoreIf<>(() -> System.getProperty(property), (value) -> expectedValue.equals(value)); - } - - public static IgnoreIf systemPropertyContains(String property, String substring) { - return new GenericIgnoreIf<>(() -> System.getProperty(property), (value) -> value != null && value.contains(substring)); - } - - public static final class GenericIgnoreIf<T> extends IgnoreIf { - private final Supplier<T> supplier; - private final Function<T, Boolean> pred; - - private GenericIgnoreIf(Supplier<T> supplier, Function<T, Boolean> pred) { - this.supplier = supplier; - this.pred = pred; - } - - @Override - public boolean isIgnoring() { - return pred.apply(supplier.get()); - } - - } - -} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreOS.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreOS.java new file mode 100644 index 0000000000..0be605720b --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreOS.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.test; + +import java.util.Arrays; + +/** + * This test trait allows ignoring tests on certain operating systems. + */ +public enum IgnoreOS implements TestTrait { + Solaris("sunos"), + Linux("linux"), + MacOS("darwin"); + + private String osName; + + IgnoreOS(String name) { + osName = name; + } + + public static boolean containsIgnoring(TestTrait[] traits) { + return Arrays.stream(TestTrait.collect(traits, IgnoreOS.class)).anyMatch(t -> t.isIgnoring()); + } + + private boolean isIgnoring() { + String current = System.getProperty("os.name"); + return current != null && current.contains(osName); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java index 36246c301b..8f82a29d1f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java @@ -604,7 +604,7 @@ public class TestBase { output.addAll(Arrays.asList(TestTrait.collect(traits, Output.class))); context.addAll(Arrays.asList(TestTrait.collect(traits, Context.class))); containsError = (!FULL_COMPARE_ERRORS && (output.contains(Output.IgnoreErrorContext) || output.contains(Output.ImprovedErrorContext) || output.contains(Output.IgnoreErrorMessage))); - isIgnored = (ignored.size() > 0 || IgnoreIf.containsIgnoring(traits)) ^ + isIgnored = (ignored.size() > 0 || IgnoreOS.containsIgnoring(traits)) ^ (ProcessFailedTests && (!IgnoredUnknownOnlyTests || (IgnoredUnknownOnlyTests && ignored.contains(Ignored.Unknown))) && !(ignored.contains(Ignored.Unstable) || ignored.contains(Ignored.SideEffects))); assert !output.contains(Output.IgnoreWhitespace) || output.size() == 1 : "IgnoreWhitespace trait does not work with any other Output trait"; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_list.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_list.java index aafca73ba6..9087339f29 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_list.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_list.java @@ -12,7 +12,7 @@ package com.oracle.truffle.r.test.builtins; import org.junit.Test; -import com.oracle.truffle.r.test.IgnoreIf; +import com.oracle.truffle.r.test.IgnoreOS; import com.oracle.truffle.r.test.TestBase; // Checkstyle: stop line length check @@ -30,7 +30,7 @@ public class TestBuiltin_list extends TestBase { @Test public void testlist3() { - assertEval(IgnoreIf.systemPropertyContains("os.name", "sunos"), + assertEval(IgnoreOS.Solaris, "argv <- list(x = c(9.5367431640625e-07, 1.9073486328125e-06, 3.814697265625e-06, 7.62939453125e-06, 1.52587890625e-05, 3.0517578125e-05, 6.103515625e-05, 0.0001220703125, 0.000244140625, 0.00048828125, 0.0009765625, 0.001953125, 0.00390625, 0.0078125, 0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024), y = c(3.69420518444359e+25, 2.30887824027777e+24, 1.44304890017492e+23, 9.01905562612606e+21, 5.63690976641081e+20, 35230686042118275072, 2201917878145066496, 137619867512235136, 8601241751556820, 537577617482832, 33598603095309.8, 2099913194115.17, 131244699796.888, 8202825028.58974, 512684387.219832, 32044730.0464007, 2003284.70114408, 125327.674230857, 7863.68742857025, 499.272560819512, 33.2784230289721, 2.7659432263306, 0.488936768533843, -0.282943224311172, 7.32218543045282e-05, -0.00636442868227041, -0.0483709204009262, -0.0704795507649514, 0.0349437746169591, -0.0264830837608839, 0.0200901469411759), xlab = NULL, ylab = NULL);list(argv[[1]],argv[[2]],argv[[3]],argv[[4]]);"); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/TestOutputManager.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/TestOutputManager.java index dc89e28859..fceba561b1 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/TestOutputManager.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/generate/TestOutputManager.java @@ -43,6 +43,7 @@ import java.util.SortedMap; import java.util.TreeMap; import com.oracle.truffle.r.runtime.RInternalError; +import com.oracle.truffle.r.test.IgnoreOS; import com.oracle.truffle.r.test.TestBase; import com.oracle.truffle.r.test.TestBase.Context; import com.oracle.truffle.r.test.TestBase.Ignored; @@ -271,6 +272,9 @@ public class TestOutputManager { case "WhiteList": trait = WhiteList.create(traitParts[1]); break; + case "IgnoreOS": + trait = IgnoreOS.valueOf(traitParts[1]); + break; default: System.err.println("unrecognized TestTrait: " + traitClass); } -- GitLab