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 867ad706c8c086e9fe0427b76e16002d08686958..4e1f2de35e08151d5014bd0a3b5af17de5334199 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 @@ -32580,7 +32580,7 @@ attr(,"class") [1] 17 -##com.oracle.truffle.r.test.builtins.TestBuiltin_list.testlist3# +##com.oracle.truffle.r.test.builtins.TestBuiltin_list.testlist3#GenericIgnoreIf.IgnoreIf# #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 new file mode 100644 index 0000000000000000000000000000000000000000..9c092552b6f7b5aca2521928646ccfa8260c724f --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/IgnoreIf.java @@ -0,0 +1,86 @@ +/* + * 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/TestBase.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/TestBase.java index 5e5b5104e24c3488e46b0cda06d6849aa26ff80e..36246c301b8cf35fb17f69b6a9fb5ea347a46c4a 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,8 +604,9 @@ 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 ^ (ProcessFailedTests && (!IgnoredUnknownOnlyTests || (IgnoredUnknownOnlyTests && ignored.contains(Ignored.Unknown))) && - !(ignored.contains(Ignored.Unstable) || ignored.contains(Ignored.SideEffects))); + isIgnored = (ignored.size() > 0 || IgnoreIf.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 0200332fdae65cbe35d5e3895b1de648f36e03a6..aafca73ba64f8d29ceb56c7b3c4e9a2536fed68d 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,6 +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.TestBase; // Checkstyle: stop line length check @@ -29,7 +30,8 @@ public class TestBuiltin_list extends TestBase { @Test public void testlist3() { - assertEval("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]]);"); + assertEval(IgnoreIf.systemPropertyContains("os.name", "sunos"), + "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]]);"); } @Test