Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 82579 invoked from network); 23 Dec 2009 13:06:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Dec 2009 13:06:02 -0000 Received: (qmail 89417 invoked by uid 500); 23 Dec 2009 13:06:02 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 89344 invoked by uid 500); 23 Dec 2009 13:06:01 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 89335 invoked by uid 99); 23 Dec 2009 13:06:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Dec 2009 13:06:01 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Dec 2009 13:05:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BA7A123889ED; Wed, 23 Dec 2009 13:05:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r893502 [2/2] - in /ant/sandbox/groovyfront: ./ META-INF/ doc/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ant/ src/main/java/org/apache/ant/groovyfront/ src/main/resources/ src/main/r... Date: Wed, 23 Dec 2009 13:05:33 -0000 To: notifications@ant.apache.org From: hibou@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091223130534.BA7A123889ED@eris.apache.org> Added: ant/sandbox/groovyfront/src/test/antunit/antlibTest.groovy URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/antunit/antlibTest.groovy?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/antunit/antlibTest.groovy (added) +++ ant/sandbox/groovyfront/src/test/antunit/antlibTest.groovy Wed Dec 23 13:05:31 2009 @@ -0,0 +1,60 @@ +/* + * 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 + * + * http://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. + * + */ +import groovy.xml.NamespaceBuilder + +taskdef(uri: 'org.apache.ant.antunit', resource: 'org/apache/ant/antunit/antlib.xml') +def au = groovyns(prefix: 'au', uri: 'org.apache.ant.antunit') + +target(name: 'testWithNamespace') { + taskdef(uri: 'org.apache.ant.groovyfront.test', resource: 'org/apache/ant/groovyfront/antlib.xml') + au.assertFalse(message: 'property "myprop" is not expected to be set') { + isset(property: 'myprop') + } + def test = NamespaceBuilder.newInstance([ 'test': 'org.apache.ant.groovyfront.test' ], project.references['groovyfront.builder']) + test.'test:setprop'(n: 'myprop', v: 'foo') + au.assertPropertyEquals(name: 'myprop', value: 'foo') +} + +target(name: 'testGroovyns') { + taskdef(uri: 'org.apache.ant.groovyfront.test', resource: 'org/apache/ant/groovyfront/antlib.xml') + def test = groovyns(prefix: 'test', uri: 'org.apache.ant.groovyfront.test') + au.assertFalse(message: 'property "myprop" is not expected to be set') { + isset(property: 'myprop') + } + test.setprop(n: 'myprop', v: 'bar') + au.assertPropertyEquals(name: 'myprop', value: 'bar') +} + +target(name: 'testGroovynsNoPrefix') { + taskdef(uri: 'org.apache.ant.groovyfront.test', resource: 'org/apache/ant/groovyfront/antlib.xml') + def test = groovyns(uri: 'org.apache.ant.groovyfront.test') + au.assertFalse(message: 'property "myprop" is not expected to be set') { + isset(property: 'myprop') + } + test.setprop(n: 'myprop', v: 'bar') + au.assertPropertyEquals(name: 'myprop', value: 'bar') +} + +target(name: 'testNoNamespace') { + taskdef(resource: 'org/apache/ant/groovyfront/antlib.xml') + au.assertFalse(message: 'property "myprop" is not expected to be set') { + isset(property: 'myprop') + } + setprop(n: 'myprop', v: 'foo') + au.assertPropertyEquals(name: 'myprop', value: 'foo') +} Added: ant/sandbox/groovyfront/src/test/antunit/varMappingTest.groovy URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/antunit/varMappingTest.groovy?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/antunit/varMappingTest.groovy (added) +++ ant/sandbox/groovyfront/src/test/antunit/varMappingTest.groovy Wed Dec 23 13:05:31 2009 @@ -0,0 +1,211 @@ +/* + * 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 + * + * http://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. + * + */ + +taskdef(uri: 'org.apache.ant.antunit', resource: 'org/apache/ant/antunit/antlib.xml') +def au = groovyns(uri: 'org.apache.ant.antunit') + +target(name: 'setUp') { + foo = 'foo' +} + +target(name: 'tearDown') { + delete(file: '${foo}', quiet: 'true') + delete(file: 'file.txt', quiet: 'true') +} + +// a test that shows things run +target(name: 'testSimple') { + au.assertFileDoesntExist(file: '${foo}') + touch(file: '${foo}') + au.assertFileExists(file: '${foo}') +} + +target(name: 'testIfThenElse') { + touch(file: 'file.txt') + condition(property: 'fileExist', value: 'true', else: 'false') { + available(file: 'file.txt') + } + if (fileExist) { + au.assertPropertyEquals(name: 'fileExist', value: 'true') + } else { + au.testFail(message: 'the if branching of "fileExist" failed') + } + if (!fileExist) { + au.testFail(message: 'the else branching of "fileExist" failed') + } else { + au.assertPropertyEquals(name: 'fileExist', value: 'true') + } + + condition(property: 'fileExistNoAlternative') { + available(file: 'file.txt') + } + if (project.properties['fileExistNoAlternative'] != null && fileExistNoAlternative) { + au.assertPropertyEquals(name: 'fileExistNoAlternative', value: 'true') + } else { + au.testFail(message: 'the if branching of "fileExistNoAlternative" failed') + } + if (project.properties['fileExistNoAlternative'] == null || !fileExistNoAlternative) { + au.testFail(message: 'the else branching of "fileExistNoAlternative" failed') + } else { + au.assertPropertyEquals(name: 'fileExistNoAlternative', value: 'true') + } + + condition(property: 'fileNotExistNoAlternative') { + not { + available(file: 'file.txt') + } + } + if (project.properties['fileNotExistNoAlternative'] != null && fileNotExistNoAlternative) { + au.testFail(message: 'the else branching of "fileNotExistNoAlternative" failed') + } else { + au.assertTrue() { + not() { + isset(property: 'fileNotExistNoAlternative') + } + } + } + if (project.properties['fileNotExistNoAlternative'] == null || !fileNotExistNoAlternative) { + au.assertTrue() { + not() { + isset(property: 'fileNotExistNoAlternative') + } + } + } else { + au.testFail(message: 'the if branching of "fileNotExistNoAlternative" failed') + } +} + +target(name: 'testSetProperty') { + au.assertFalse(message: 'property "bar" is not expected to be set') { + isset(property: 'bar') + } + bar = '3' + au.assertPropertySet(name: 'bar') + au.assertPropertyEquals(name: 'bar', value: '3') + bar = '4' + au.assertPropertyEquals(name: 'bar', value: '3') +} + +target(name: 'testGString') { + propTestGString = 'foo' + // property resolved by Groovy + au.assertEquals(expected: 'foo', actual: "${propTestGString}") + // property resolved by Ant + au.assertEquals(expected: 'foo', actual: '${propTestGString}') + property(name: 'prop.with.dot', value: 'bar') + // property resolved by Ant (impossible with Groovy) + au.assertEquals(expected: 'bar', actual: '${prop.with.dot}') +} + +target(name: 'testSetPropertyNonString') { + propInt = 3 + au.assertPropertyEquals(name: 'propInt', value: '3') + propFloat = 1.2 + au.assertPropertyEquals(name: 'propFloat', value: '1.2') + propClosure = { 1 } + // the value should be the result of Object#toString() + au.assertPropertyContains(name: 'propClosure', value: 'varMappingTest$$_run_closure') +} + +target(name: 'testSetPropertyTask') { + echo = '3' + property(name: 'propEcho', value: '${echo}') + au.assertEquals(expected: '3', actual: '${propEcho}') + // check that echoing works + echo(message: '${echo}') + + condition = { true } + au.assertPropertyContains(name: 'condition', value: 'varMappingTest$$_run_closure') + // check that checking a condition still works + condition(property: 'propCondition') { + isset(property: 'propEcho') + } + au.assertEquals(expected: 'true', actual: '${propCondition}') + + // check that reading the property works + echo2 = echo + au.assertEquals(expected: '3', actual: '${echo2}') + condition2 = condition + au.assertPropertyContains(name: 'condition2', value: 'varMappingTest$$_run_closure') +} + +target(name: 'testSetPropertyProject') { + def fail = false + try { + project = '3' + } catch (Throwable t) { + fail = true + } + au.assertEquals(message: 'Setting "project" should fail', expected: 'true', actual: fail) +} + +target(name: 'testSetPropertyAndReference') { + au.assertTrue(message: 'property and reference "filesetRef" are not expected to be set') { + and() { + not() { + isset(property: 'filesetRef') + } + not() { + isreference(refid: 'filesetRef') + } + } + } + fileset(id: 'filesetRef', dir: '${basedir}') + au.assertTrue(message: 'reference "filesetRef" is expected to be set') { + isreference(refid: 'filesetRef') + } + filesetRef = '3' + au.assertPropertyEquals(name: 'filesetRef', value: '3') +} + +target(name: 'testLocalVariable') { + def add = { n -> n + 1 } + au.assertEquals(expected: '2', actual: add(1)) + + def setProp = { n, v -> + property(name: n, value: v) + } + au.assertFalse(message: 'property "propFunction" is not expected to be set') { + isset(property: 'propFunction') + } + setProp('propFunction', 'foo') + au.assertPropertyEquals(name: 'propFunction', value: 'foo') + + // reference shouldn't override tasks + project.addReference('zip', { n -> n }) + def fail = false + try { + zip(3) + } catch (Throwable t) { + fail = true + } + au.assertEquals(message: 'Calling zip should have failed', expected: 'true', actual: fail) + + // local variable override tasks + def zip = { n -> n } + au.assertEquals(expected: '3', actual: zip(3)) + + def echo = '3' + fail = false + try { + echo(message: 'some message') + } catch (Throwable t) { + fail = true + } + au.assertEquals(message: 'Calling echo should have failed', expected: 'true', actual: fail) +} Added: ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontAntlibTestSuite.java URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontAntlibTestSuite.java?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontAntlibTestSuite.java (added) +++ ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontAntlibTestSuite.java Wed Dec 23 13:05:31 2009 @@ -0,0 +1,34 @@ +/* + * 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 + * + * http://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.ant.groovyfront; + +import java.io.File; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.ant.antunit.junit3.AntUnitSuite; + +public class GroovyFrontAntlibTestSuite extends TestCase { + + public static TestSuite suite() { + File script = new File("src/test/antunit/antlibTest.groovy"); + return new AntUnitSuite(script, GroovyFrontAntlibTestSuite.class); + } + +} Added: ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontBuilderTest.java URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontBuilderTest.java?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontBuilderTest.java (added) +++ ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontBuilderTest.java Wed Dec 23 13:05:31 2009 @@ -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 + * + * http://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.ant.groovyfront; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.ant.groovyfront.GroovyFrontBuilder; +import org.apache.ant.groovyfront.GroovyFrontParsingContext; +import org.apache.ant.groovyfront.GroovyFrontProject; +import org.apache.tools.ant.Project; +import org.junit.Test; + +public class GroovyFrontBuilderTest { + + @Test + public void testIsTaskDefined() throws Exception { + GroovyFrontProject project = new GroovyFrontProject(new Project(), new GroovyFrontParsingContext(), "build.groovy"); + project.init(); + GroovyFrontBuilder groovyFront = new GroovyFrontBuilder(project); + assertTrue(groovyFront.isTaskDefined("echo")); + assertFalse(groovyFront.isTaskDefined("mytask")); + project.addTaskDefinition("mytask", MyTestTask.class); + assertTrue(groovyFront.isTaskDefined("mytask")); + } +} Added: ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java (added) +++ ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/GroovyFrontScriptTestSuite.java Wed Dec 23 13:05:31 2009 @@ -0,0 +1,34 @@ +/* + * 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 + * + * http://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.ant.groovyfront; + +import java.io.File; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.ant.antunit.junit3.AntUnitSuite; + +public class GroovyFrontScriptTestSuite extends TestCase { + + public static TestSuite suite() { + File script = new File("src/test/antunit/varMappingTest.groovy"); + return new AntUnitSuite(script, GroovyFrontScriptTestSuite.class); + } + +} Added: ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/MyTestTask.java URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/MyTestTask.java?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/MyTestTask.java (added) +++ ant/sandbox/groovyfront/src/test/java/org/apache/ant/groovyfront/MyTestTask.java Wed Dec 23 13:05:31 2009 @@ -0,0 +1,27 @@ +/* + * 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 + * + * http://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.ant.groovyfront; + +import org.apache.tools.ant.Task; + +public class MyTestTask extends Task { + + public MyTestTask() { + // nothing to initialize + } +} \ No newline at end of file Added: ant/sandbox/groovyfront/src/test/resources/org/apache/ant/groovyfront/antlib.xml URL: http://svn.apache.org/viewvc/ant/sandbox/groovyfront/src/test/resources/org/apache/ant/groovyfront/antlib.xml?rev=893502&view=auto ============================================================================== --- ant/sandbox/groovyfront/src/test/resources/org/apache/ant/groovyfront/antlib.xml (added) +++ ant/sandbox/groovyfront/src/test/resources/org/apache/ant/groovyfront/antlib.xml Wed Dec 23 13:05:31 2009 @@ -0,0 +1,30 @@ + + + + + + + + + + + + +