diff options
| author | Stefan Bodewig <bodewig@apache.org> | 2020-09-25 21:12:37 +0200 |
|---|---|---|
| committer | Stefan Bodewig <bodewig@apache.org> | 2020-09-25 21:12:37 +0200 |
| commit | a83708498058dfe59a50d40a982050837b1d397d (patch) | |
| tree | 5602709fbac5ca4dc198d3e86a21829a0635ea97 /src/tests/junit | |
| parent | 2beb3977a8b81dae5b432a21b45b94da2bfb238e (diff) | |
| download | ant-a83708498058dfe59a50d40a982050837b1d397d.tar.gz | |
enable Nashorn compatibility when running GraalVM JS
and add a magic property to disable it again
Diffstat (limited to 'src/tests/junit')
4 files changed, 144 insertions, 0 deletions
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/AbstractNashornCompatTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/AbstractNashornCompatTest.java new file mode 100644 index 000000000..25123d20a --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/AbstractNashornCompatTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.script.graal; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.MagicNames; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + +public class AbstractNashornCompatTest { + + private final String magicPropertyValue; + + public AbstractNashornCompatTest(String magicPropertyValue) { + this.magicPropertyValue = magicPropertyValue; + } + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/graal.xml"); + buildRule.getProject().setProperty(MagicNames.DISABLE_NASHORN_COMPAT, magicPropertyValue); + } + + @Test + public void runSquaresTest() { + buildRule.executeTarget("run-squares-test"); + assertThat("Expecting the square of 7 to be logged", buildRule.getLog(), + containsString("49")); + } +} diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DefaultNashornCompatTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DefaultNashornCompatTest.java new file mode 100644 index 000000000..a5c1771b0 --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DefaultNashornCompatTest.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.script.graal; + +public class DefaultNashornCompatTest extends AbstractNashornCompatTest { + + public DefaultNashornCompatTest() { + super(null); + } +} diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DisableNashornCompatTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DisableNashornCompatTest.java new file mode 100644 index 000000000..808bdee54 --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/DisableNashornCompatTest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.script.graal; + +import org.apache.tools.ant.BuildException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class DisableNashornCompatTest extends AbstractNashornCompatTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + public DisableNashornCompatTest() { + super("true"); + } + + @Test + @Override + public void runSquaresTest() { + thrown.expect(BuildException.class); + thrown.expectMessage("TypeError"); + super.runSquaresTest(); + } +} diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/EnableNashornCompatTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/EnableNashornCompatTest.java new file mode 100644 index 000000000..2161b6f97 --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/graal/EnableNashornCompatTest.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.script.graal; + +public class EnableNashornCompatTest extends AbstractNashornCompatTest { + + public EnableNashornCompatTest() { + super("false"); + } +} |
