diff options
author | mattinger <[email protected]> | 2006-07-06 21:53:00 +0000 |
---|---|---|
committer | mattinger <[email protected]> | 2006-07-06 21:53:00 +0000 |
commit | 1159111b7a71b72eb04326df33211e1733f7e742 (patch) | |
tree | f0a80c384f633e521649654ab78e6239cf5e0d6f /test/src/net |
Initial addition into subversion with build script changes
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/ant-contrib@5 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'test/src/net')
22 files changed, 2268 insertions, 0 deletions
diff --git a/test/src/net/sf/antcontrib/BuildFileTestBase.java b/test/src/net/sf/antcontrib/BuildFileTestBase.java new file mode 100644 index 0000000..9764d23 --- /dev/null +++ b/test/src/net/sf/antcontrib/BuildFileTestBase.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.URL; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; + + +/** + * More methods for BuildFileTest. + * + * @author Dale Anson + */ +public abstract class BuildFileTestBase extends BuildFileTest { + + /** + * Constructor for the BuildFileTestBase object + * + * @param name string to pass up to TestCase constructor + */ + public BuildFileTestBase( String name ) { + super( name ); + } + + /** + * run a target, expect a build exception + * + * @param target target to run + */ + protected void expectBuildException( String target ) { + expectSpecificBuildException( target, "no specific reason", null ); + } + + /** + * Assert that the given message has NOT been logged with a priority >= INFO + * when running the given target. + * + * @param target Description of the Parameter + * @param log Description of the Parameter + */ + protected void expectLogNotContaining( String target, String log ) { + executeTarget( target ); + String realLog = getLog(); + assertTrue( "expecting log to NOT contain \"" + log + "\" log was \"" + + realLog + "\"", + realLog.indexOf( log ) < 0 ); + } + + /** + * set up to run the named project + * <p> + * Overrides BuildFileTest.configureProject to first + * attempt to make a File out of the filename parameter, if the resulting + * file does not exists, then attempt to locate the file in the classpath. + * This way, test xml files can be placed alongside of their corresponding + * class file and can be easily found. + * + * @param filename name of project file to run + * @exception BuildException Description of the Exception + */ + protected void configureProject( String filename ) throws BuildException { + // find the build file + File f = new File( filename ); + if ( !f.exists() ) { + URL url = getClass().getClassLoader().getResource( filename ); + if ( url == null ) + throw new BuildException( "Can't find " + filename ); + f = new File( url.getPath() ); + if ( !f.exists() ) + throw new BuildException( "Can't find " + filename ); + } + super.configureProject(f.getAbsolutePath()); + } + + /** + * run a target, expect an exception string containing the substring we look + * for (case sensitive match) + * + * @param target target to run + * @param cause information string to reader of report + * @param contains substring of the build exception to look for + */ + protected void expectBuildExceptionStackTraceContaining( String target, String cause, String contains ) { + try { + executeTarget( target ); + } + catch ( org.apache.tools.ant.BuildException ex ) { + //buildException = ex; // buildException has private access in super + StringWriter stacktrace = new StringWriter(); + PrintWriter writer = new PrintWriter( stacktrace, true ); + ex.printStackTrace( writer ); + String trace = stacktrace.toString(); + if ( ( null != contains ) && ( trace.indexOf( contains ) == -1 ) ) { + fail( "Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + trace + "' instead)" ); + } + return; + } + fail( "Should throw BuildException because: " + cause ); + } +} + diff --git a/test/src/net/sf/antcontrib/antclipse/AntclipseTest.java b/test/src/net/sf/antcontrib/antclipse/AntclipseTest.java new file mode 100644 index 0000000..973a8b9 --- /dev/null +++ b/test/src/net/sf/antcontrib/antclipse/AntclipseTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.antclipse; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Basic test for "antclipse" task. For the moment it just launches the test xml script. + * @author Adrian Spinei [email protected] + * @version $Revision: 1.2 $ + */ +public class AntclipseTest extends BuildFileTest +{ + + /** + * Simple overriden constructor + * @param arg0 + */ + public AntclipseTest(String arg0) + { + super(arg0); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + public void setUp() + { + configureProject("test/resources/antclipse/antclipsetest.xml"); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + public void tearDown() + { + //nothing to do + } + + /** + * Launches the "everything" task. Should not throw errors. + */ + public void testExecuteDefaultBuild() + { + executeTarget("everything"); + } + +} diff --git a/test/src/net/sf/antcontrib/antserver/AntServerTest.java b/test/src/net/sf/antcontrib/antserver/AntServerTest.java new file mode 100644 index 0000000..24cdca9 --- /dev/null +++ b/test/src/net/sf/antcontrib/antserver/AntServerTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.antserver; + +import net.sf.antcontrib.BuildFileTestBase; + + +/**************************************************************************** + * Place class description here. + * + * @author inger + * @author <additional author> + * + * @since + * + ****************************************************************************/ + + +public class AntServerTest + extends BuildFileTestBase +{ + public AntServerTest(String name) + { + super(name); + } + + + public void setUp() + { + configureProject("test/resources/antserver/antservertest.xml"); + } + + public void tearDown() + { + executeTarget("cleanup"); + } + + public void test1() + { + String expected[] = new String[] + { + "Test1 Successfully Called", + "[test1_remote]" + }; + + expectLogContaining("test1", expected); + } + + public void test2() + { + String expected[] = new String[] + { + "Test2 Successfully Called", + "[test2_remote]" + }; + + expectLogContaining("test2", expected); + } + + public void test3() + { + String expected[] = new String[] + { + "Test3 Successfully Called", + "[test3_remote]" + }; + + expectLogContaining("test3", expected); + } + + public void test4() + { + String expected[] = new String[] + { + "Test4 Successfully Called", + "[test4_remote]" + }; + + expectLogContaining("test4", expected); + } + + public void test5() + { + this.executeTarget("test5"); + } + + /** + * Assert that the given message has been logged with a priority + * >= INFO when running the given target. + */ + protected void expectLogContaining(String target, + String logs[]) + { + executeTarget(target); + String realLog = getLog(); + + int cnt = 0; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < logs.length; i++) + { + if (realLog.indexOf(logs[i]) >= 0) + cnt++; + if (i != 0) + sb.append(" and "); + sb.append("\"").append(logs[i]).append("\""); + } + + + assertTrue("expecting log to contain " + sb.toString() + + " log was \"" + realLog + "\"", + cnt == logs.length); + } + +} diff --git a/test/src/net/sf/antcontrib/design/VerifyDesignTest.java b/test/src/net/sf/antcontrib/design/VerifyDesignTest.java new file mode 100644 index 0000000..746448c --- /dev/null +++ b/test/src/net/sf/antcontrib/design/VerifyDesignTest.java @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2001-2005 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.design; + +import java.io.File; + +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.util.JavaEnvUtils; + +/** + * BIG NOTE*************************************************** + * Always expect specific exceptions. Most of these test cases when + * first submitted were not and therefore were not testing what they said + * they were testing. Exceptions were being caused by other things and the + * tests were still passing. Now all tests expect a specific exception + * so if any other is thrown we will fail the test case. + * ************************************************************ + * + * Testcase for <propertycopy>. + */ +public class VerifyDesignTest extends BuildFileTest { + + private final static String REASON = "Build should have failed with proper message and did not"; + private String baseDir = "test"+File.separator + +"resources"+File.separator + +"design"+File.separator; + private String c = File.separator; + + public VerifyDesignTest(String name) { + super(name); + } + + public void setUp() { + + configureProject("test/resources/design/verifydesign.xml"); +// project.log("ASFDSADF", Project.MSG_INFO); + } + + private static String s = ""; + + public static void log(String msg) { + s += msg+"\n"; + } + + public void tearDown() { + executeTarget("cleanup"); + + //System.out.println("test log=\n"+s); + } + + public void testArrayDepend() { + String class1 = "mod.arraydepend.ClassDependsOnArray"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testArrayDepend", Design.getErrorMessage(class1, class2)); + } + + public void testArrayDepend2() { + executeTarget("testArrayDepend2"); + } + + public void testArrayDepend3() { + String class1 = "mod.arraydepend3.ClassDependsOnArray"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testArrayDepend3", Design.getErrorMessage(class1, class2)); + } + + public void testBadXML() { + File designFile = new File("test/resources/design/designfiles/badxml.xml"); + String msg = "\nProblem parsing design file='" + + designFile.getAbsolutePath() + "'. \nline=3 column=1 Reason:\nElement type \"design\" must be followed by either attribute specifications, \">\" or \"/>\".\n"; + expectSpecificBuildException("testBadXML", REASON, msg); + } + + public void testCastDepend() { + String class1 = "mod.castdepend.ClassDependsOnCast"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testCastDepend", Design.getErrorMessage(class1, class2)); + } + + public void testCatchDepend() { + String class1 = "mod.catchdepend.ClassDependsOnCatch"; + String class2 = "mod.dummy.DummyRuntimeException"; + expectDesignCheckFailure("testCatchDepend", Design.getErrorMessage(class1, class2)); + } + + public void testClassFiles() { + String class1 = "mod.castdepend.ClassDependsOnCast"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testClassFiles", Design.getErrorMessage(class1, class2)); + } + + public void testDeclareJavaUtil() { + executeTarget("testDeclareJavaUtil"); + } + + public void testDeclareJavaUtilFail() { + String class1 = "mod.declarejavautil.ClassDependsOnJavaUtil"; + String class2 = "java.util.List"; + expectDesignCheckFailure("testDeclareJavaUtilFail", Design.getErrorMessage(class1, class2)); + } + + public void testDeclareJavax() { + String class1 = "mod.declarejavax.ClassDependsOnJavax"; + String class2 = "javax.swing.JButton"; + expectDesignCheckFailure("testDeclareJavax", Design.getErrorMessage(class1, class2)); + } + + public void testDeclareJavaxPass() { + executeTarget("testDeclareJavaxPass"); + } + + + //tests to write + + //depend on java.util should pass by default + //depend on java.util should fail after defining needDeclareTrue + //depend on javax.swing should pass after needDeclareFalse + + //depend on dummy should pass after needDeclareFalse + + public void testFieldDepend() { + String class1 = "mod.fielddepend.ClassDependsOnField"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testFieldDepend", Design.getErrorMessage(class1, class2)); + } + + public void testFieldRefDepend() { + if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) + || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) + || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { + return; + } + + String class1 = "mod.fieldrefdepend.ClassDependsOnReferenceInFieldDeclaration"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testFieldRefDepend", Design.getErrorMessage(class1, class2)); + } + + public void testInnerClassDepend() { + String class1 = "mod.innerclassdepend.InnerClassDependsOnSuper$Inner"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testInnerClassDepend", Design.getErrorMessage(class1, class2)); + } + + public void testInstanceOfDepend() { + String class1 = "mod.instanceofdepend.ClassDependsOnInstanceOf"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testInstanceOfDepend", Design.getErrorMessage(class1, class2)); + } + + public void testInterfaceDepend() { + String class1 = "mod.interfacedepend.ClassDependsOnInterfaceMod2"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testInterfaceDepend", Design.getErrorMessage(class1, class2)); + } + + public void testLocalVarDepend() { + String class1 = "mod.localvardepend.ClassDependsOnLocalVar"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testLocalVarDepend", Design.getErrorMessage(class1, class2)); + } + + public void testLocalVarRefDepend() { + if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) + || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) + || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { + return; + } + String class1 = "mod.localvarrefdepend.ClassDependsOnLocalVariableReference"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testLocalVarRefDepend", Design.getErrorMessage(class1, class2)); + } + + public void testMissingAttribute() { + File designFile = new File("test/resources/design/designfiles/missingattribute.xml"); + String msg = "\nProblem parsing design file='" + + designFile.getAbsolutePath() + "'. \nline=3 column=31 Reason:\nError in file=" + + designFile.getAbsolutePath() + ", package element must contain the 'name' attribute\n"; + expectSpecificBuildException("testMissingAttribute", REASON, msg); + } + + public void testMultipleErrors() { + File jarFile = new File(baseDir+File.separator+"build"+File.separator+"jar" + +File.separator+"test.jar"); + String class1 = "mod.arraydepend.ClassDependsOnArray"; + String class2 = "mod.dummy.DummyClass"; + //executeTarget("testMultipleErrors"); + String error1 = Design.getWrapperMsg(jarFile, Design.getErrorMessage(class1, class2)); + class1 = "mod.castdepend.ClassDependsOnCast"; + String error2 = Design.getWrapperMsg(jarFile, Design.getNoDefinitionError(class1)); + class1 = "mod.catchdepend.ClassDependsOnCatch"; + class2 = "mod.dummy.DummyRuntimeException"; + String error3 = Design.getWrapperMsg(jarFile, Design.getErrorMessage(class1, class2)); + String s = "\nEvaluating package=mod.arraydepend"+error1; + s += "\nEvaluating package=mod.castdepend"+error2; + s += "\nEvaluating package=mod.catchdepend"+error3; + s += "\nEvaluating package=mod.dummy"; + +// executeTarget("testMultipleErrors"); + expectDesignCheckFailure("testMultipleErrors", s); + } + + public void testNewDepend() { + String class1 = "mod.newdepend.ClassDependsOnNew"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testNewDepend", Design.getErrorMessage(class1, class2)); + } + + public void testNewDepend2() { + String class1 = "mod.newdepend2.ClassDependsOnNewInField"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testNewDepend2", Design.getErrorMessage(class1, class2)); + } + + public void testNoDebugOption() { + String class1 = "mod.nodebugoption.ClassDependsOnLocalVar"; + expectDesignCheckFailure("testNoDebugOption", VisitorImpl.getNoDebugMsg(class1)); + } + public void testNoJar() { + File jar = new File("test/resources/design/build/jar/test.jar"); + expectSpecificBuildException("testNoJar", REASON, VisitorImpl.getNoFileMsg(jar)); + } + + public void testParamDepend() { + String class1 = "mod.paramdepend.ClassDependsOnParameter"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testParamDepend", Design.getErrorMessage(class1, class2)); + } + + public void testPassLocalDepend() { + executeTarget("testPassLocalDepend"); + } + + public void testPathElementLocation() { + executeTarget("testPathElementLocation"); + } + + public void testPathElementPath() { + executeTarget("testPathElementPath"); + } + + public void testPutStatic() { + executeTarget("testPutStatic"); + } + + public void testRecursion() { + executeTarget("testRecursion"); + } + + public void testRecursion2() { + executeTarget("testRecursion2"); + } + + public void testRecursion3() { + executeTarget("testRecursion3"); + } + + public void testReturnValDepend() { + String class1 = "mod.returnvaldepend.ClassDependsOnReturnValue"; + String class2 = "mod.dummy.DummyInterface"; + expectDesignCheckFailure("testReturnValDepend", Design.getErrorMessage(class1, class2)); + } + + public void testSignatureExceptionDepend() { + String class1 = "mod.signatureexceptiondepend.ClassDependsOnExceptionInMethodSignature"; + String class2 = "mod.dummy.DummyException"; + expectDesignCheckFailure("testSignatureExceptionDepend", Design.getErrorMessage(class1, class2)); + } + + public void testStaticDepend() { + String class1 = "mod.staticdepend.ClassDependsOnStatic"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testStaticDepend", Design.getErrorMessage(class1, class2)); + } + + public void testStaticField2Depend() { + String class1 = "mod.staticfield2depend.ClassDependsOnStaticField"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testStaticField2Depend", Design.getErrorMessage(class1, class2)); + } + + public void testStaticFieldDepend() { + String class1 = "mod.staticfielddepend.ClassDependsOnStaticField"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testStaticFieldDepend", Design.getErrorMessage(class1, class2)); + } + + public void testStaticFinalDepend() { + //This is an impossible test since javac compiles String and primitive constants into the code + //losing any reference to the class that contains the constant...In this one instance, + //verifydesign can't verify that constant imports don't violate the design!!!! + //check out mod.staticfinaldepend.ClassDependsOnStaticField to see the code + //that will pass the design even if it is violating it. + // String class1 = "mod.staticfinaldepend.ClassDependsOnConstant"; + // String class2 = "mod.dummy.DummyClass"; + // expectDesignCheckFailure("testStaticFinalDepend", Design.getErrorMessage(class1, class2)); + } + + public void testSuperDepend() { + String s = File.separator; + File f = new File("test"+s+"resources"+s+"design"+s+"build"+s+"jar"+s+"test.jar"); + + // executeTarget("testSuperDepend"); + String class1 = "mod.superdepend.ClassDependsOnSuperMod2"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testSuperDepend", Design.getErrorMessage(class1, class2)); + + //jar file should have been deleted + assertTrue("jar file should not exist yet still does", !f.exists()); + } + + public void testWarSuccess() { + executeTarget("testWarSuccess"); + } + + public void testWarFailure() { + String class1 = "mod.warfailure.ClassDependsOnSuperMod2"; + String class2 = "mod.dummy.DummyClass"; + expectDesignCheckFailure("testWarFailure", Design.getErrorMessage(class1, class2)); + } + + public static void main(String[] args) { + TestSuite suite = new TestSuite(); + suite.addTest(new VerifyDesignTest("testArrayDepend2")); + TestRunner.run(suite); + } + + private void expectDesignCheckFailure(String target, String message) { + expectSpecificBuildException(target, "Design is broken", + "Design check failed due to previous " + + "errors"); + assertLogContaining(message); + } +} diff --git a/test/src/net/sf/antcontrib/logic/AntCallBackTest.java b/test/src/net/sf/antcontrib/logic/AntCallBackTest.java new file mode 100644 index 0000000..3635002 --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/AntCallBackTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import net.sf.antcontrib.BuildFileTestBase; + +/** + * Since AntCallBack is basically a copy and paste of antcall, the only testing + * done here is on the extra features provided by antcallback. It is assumed + * that changes to antcall will be propagated to antcallback and that antcall + * has it's own unit tests (which turns out to have been a bad assumption, + * I can't find any unit tests for antcall). + * + * @author danson + */ +public class AntCallBackTest extends BuildFileTestBase { + + /** + * Constructor for the AntCallBackTest object + * + * @param name Description of the Parameter + */ + public AntCallBackTest( String name ) { + super( name ); + } + + + /** The JUnit setup method */ + public void setUp() { + configureProject( "test/resources/logic/antcallbacktest.xml" ); + } + + + /** A unit test for JUnit */ + public void test1() { + expectPropertySet( "test1", "prop1", "prop1" ); + } + + + /** A unit test for JUnit */ + public void test2() { + expectPropertySet( "test2", "prop1", "prop1" ); + expectPropertySet( "test2", "prop2", "prop2" ); + expectPropertySet( "test2", "prop3", "prop3" ); + } + + + /** A unit test for JUnit */ + public void test3() { + expectPropertySet( "test3", "prop1", "prop1" ); + expectPropertySet( "test3", "prop2", "prop2" ); + expectPropertySet( "test3", "prop3", "prop3" ); + } + + + /** A unit test for JUnit */ + public void test4() { + expectPropertyUnset( "test4", "prop1" ); + expectPropertySet( "test4", "prop2", "prop2" ); + expectPropertySet( "test4", "prop3", "prop3" ); + } + + + /** A unit test for JUnit */ + public void test5() { + expectPropertySet( "test5", "prop1", "blah" ); + expectPropertySet( "test5", "prop2", "prop2" ); + expectPropertySet( "test5", "prop3", "prop3" ); + } +} + diff --git a/test/src/net/sf/antcontrib/logic/AssertTest.java b/test/src/net/sf/antcontrib/logic/AssertTest.java new file mode 100644 index 0000000..449068f --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/AssertTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import net.sf.antcontrib.BuildFileTestBase; + +/** + * Since AntCallBack is basically a copy and paste of antcall, the only testing + * done here is on the extra features provided by antcallback. It is assumed + * that changes to antcall will be propagated to antcallback and that antcall + * has it's own unit tests (which turns out to have been a bad assumption, + * I can't find any unit tests for antcall). + * + * @author danson + */ +public class AssertTest extends BuildFileTestBase { + + /** + * Constructor for the AntCallBackTest object + * + * @param name Description of the Parameter + */ + public AssertTest( String name ) { + super( name ); + } + + + /** The JUnit setup method */ + public void setUp() { + configureProject( "test/resources/logic/asserttest.xml" ); + } + + + /** A unit test for JUnit */ + public void test1() { + executeTarget( "test1" ); + } + + public void test2() { + expectBuildExceptionStackTraceContaining( "test2", "testing assert failure", "Property 'testprop' doesn't exist in this project." ); + } + + public void test3() { + expectBuildExceptionStackTraceContaining( "test3", "testing assert failure", "Expected 'false', but was 'true'." ); + } + + public void test4() { + executeTarget("test4"); + } + + public void test5() { + executeTarget("test5"); + } + + public void test6() { + executeTarget("test6"); + } + + public void test7(){ + expectBuildExceptionStackTraceContaining( "test7", "testing conditions", "Assertion failed boolean test." ); + } + + public void test8() { + executeTarget("test8"); + } + + public void test9() { + expectBuildExceptionStackTraceContaining( "test9", "testing conditions", "Assertion failed boolean test." ); + } +} + diff --git a/test/src/net/sf/antcontrib/logic/ForeachTaskTest.java b/test/src/net/sf/antcontrib/logic/ForeachTaskTest.java new file mode 100644 index 0000000..b02e453 --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/ForeachTaskTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <foreach>. + */ +public class ForeachTaskTest extends BuildFileTest { + + public ForeachTaskTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/foreach.xml"); + } + + public void tearDown() { + executeTarget("teardown"); + } + + public void testSimpleList() { + simpleTest("simpleList"); + } + + public void testDelimiter() { + simpleTest("delimiter"); + } + + public void testFileset() { + simpleTest("fileset"); + assertTrue(getLog().indexOf("The nested fileset element is deprectated," + + " use a nested path instead") > -1); + } + + public void testFilesetAndList() { + simpleTest("filesetAndList"); + assertTrue(getLog().indexOf("The nested fileset element is deprectated," + + " use a nested path instead") > -1); + } + + public void testNoList() { + expectSpecificBuildException("noList", "neither list nor fileset", + "You must have a list or path to iterate through"); + } + + public void testNoTarget() { + expectSpecificBuildException("noTarget", "no target", + "You must supply a target to perform"); + } + + public void testNoParam() { + expectSpecificBuildException("noParam", "no param", + "You must supply a property name to set on each iteration in param"); + } + + public void testNestedParam() { + executeTarget("nestedParam"); + assertTrue(getLog().indexOf("Called with param: rincewind") > -1); + } + + public void testNestedReference() { + executeTarget("nestedReference"); + assertTrue(getLog().indexOf("Called with param: twoflower") > -1); + } + + public void testPath() { + simpleTest("path"); + } + + public void testPathAndList() { + simpleTest("pathAndList"); + } + + private void simpleTest(String target) { + executeTarget(target); + int last = -1; + for (int i = 1; i < 4; i++) { + int thisIdx = getLog().indexOf("Called with param: " + i); + assertTrue(thisIdx > last); + last = thisIdx; + } + } +} diff --git a/test/src/net/sf/antcontrib/logic/IfTaskTest.java b/test/src/net/sf/antcontrib/logic/IfTaskTest.java new file mode 100644 index 0000000..bac8aff --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/IfTaskTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <if>. + */ +public class IfTaskTest extends BuildFileTest { + + public IfTaskTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/if.xml"); + } + + public void testNoCondition() { + expectSpecificBuildException("noCondition", "no condition", + "You must nest a condition into <if>"); + } + + public void testTwoConditions() { + expectSpecificBuildException("twoConditions", "two conditions", + "You must not nest more than one " + + "condition into <if>"); + } + + public void testNothingToDo() { + expectLog("nothingToDo", ""); + } + + public void testTwoThens() { + expectSpecificBuildException("twoThens", "two <then>s", + "You must not nest more than one " + + "<then> into <if>"); + } + + public void testTwoElses() { + expectSpecificBuildException("twoElses", "two <else>s", + "You must not nest more than one " + + "<else> into <if>"); + } + + public void testNormalOperation() { + executeTarget("normalOperation"); + assertTrue(getLog().indexOf("In then") > -1); + assertTrue(getLog().indexOf("some value") > -1); + assertEquals(-1, getLog().indexOf("${inner}")); + assertEquals(-1, getLog().indexOf("In else")); + } + + public void testNormalOperation2() { + executeTarget("normalOperation2"); + assertTrue(getLog().indexOf("In else") > -1); + assertEquals(-1, getLog().indexOf("In then")); + } + + public void testNoConditionInElseif() { + expectSpecificBuildException("noConditionInElseif", "no condition", + "You must nest a condition into <elseif>"); + } + + public void testTwoConditionInElseif() { + expectSpecificBuildException("twoConditionsInElseif", "two conditions", + "You must not nest more than one " + + "condition into <elseif>"); + } + + public void testNormalOperationElseif() { + executeTarget("normalOperationElseif"); + assertTrue(getLog().indexOf("In elseif") > -1); + assertEquals(-1, getLog().indexOf("In then")); + assertEquals(-1, getLog().indexOf("In else-branch")); + } + + public void testNormalOperationElseif2() { + executeTarget("normalOperationElseif2"); + assertTrue(getLog().indexOf("In else-branch") > -1); + assertEquals(-1, getLog().indexOf("In then")); + assertEquals(-1, getLog().indexOf("In elseif")); + } + +} diff --git a/test/src/net/sf/antcontrib/logic/OutOfDateTest.java b/test/src/net/sf/antcontrib/logic/OutOfDateTest.java new file mode 100644 index 0000000..ae52caa --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/OutOfDateTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.types.Path; + +/** + * Testcase for <outofdate>. + * + * @author Peter Reilly + */ +public class OutOfDateTest extends BuildFileTest { + + public OutOfDateTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/outofdate.xml"); + } + + public void tearDown() { + executeTarget("cleanup"); + } + + public void testSimple() { + executeTarget("simple"); + } + + public void testVerbose() { + executeTarget("verbose"); + assertTrue(getLog().indexOf("outofdate with regard to") > -1); + } + + public void testDelete() { + executeTarget("delete"); + } + + public void testDeleteAll() { + executeTarget("delete-all"); + } + + public void testDeleteQuiet() { + executeTarget("init"); + executeTarget("delete-quiet"); + assertTrue("No deleting message", getLog().indexOf("Deleting") == -1); + } + + public void testFileset() { + executeTarget("outofdate.init"); + executeTarget("outofdate.test"); + assertTrue(getLog().indexOf("outofdate triggered") > -1); + String outofdateSources = + getProject().getProperty("outofdate.sources"); + // switch \ to / if present + outofdateSources.replace('\\', '/'); + assertTrue("newer.text empty", outofdateSources.indexOf( + "newer.text") > -1); + assertTrue("file.notdone", outofdateSources.indexOf( + "outofdate/source/1/2/file.notdone") > -1); + assertTrue("file.done", outofdateSources.indexOf( + "outofdate/source/1/2/file.done") == -1); + assertTrue("done.y", outofdateSources.indexOf( + "outofdate/source/1/done.y") == -1); + assertTrue("partial.y", outofdateSources.indexOf( + "outofdate/source/1/partial.y") > -1); + String outofdateTargets = + getProject().getProperty("outofdate.targets"); + assertTrue(outofdateTargets.indexOf( + "outofdate.xml") > -1); + assertTrue(outofdateTargets.indexOf( + "outofdate/gen/1/2/file.notdone") > -1); + assertTrue(outofdateTargets.indexOf( + "outofdate/gen/1/partial.h") > -1); + assertTrue(outofdateTargets.indexOf( + "outofdate/gen/1/partial.c") == -1); + assertTrue(outofdateTargets.indexOf( + "outofdate/gen/1/done.h") == -1); + + Path sourcesPath = (Path) getProject().getReference( + "outofdate.sources.path"); + assertTrue(sourcesPath != null); + String[] sources = sourcesPath.list(); + assertTrue(sources.length == 3); + Path targetsPath = (Path) getProject().getReference( + "outofdate.targets.path"); + String[] targets = targetsPath.list(); + assertTrue(targetsPath != null); + assertTrue(targets.length == 3); + } + + public void testEmptySources() { + executeTarget("empty-sources"); + } + +} diff --git a/test/src/net/sf/antcontrib/logic/SwitchTest.java b/test/src/net/sf/antcontrib/logic/SwitchTest.java new file mode 100644 index 0000000..28ce036 --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/SwitchTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <switch>. + */ +public class SwitchTest extends BuildFileTest { + + public SwitchTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/switch.xml"); + } + + public void testNoValue() { + expectSpecificBuildException("noValue", "no value", + "Value is missing"); + } + + public void testNoChildren() { + expectSpecificBuildException("noChildren", "no children", + "No cases supplied"); + } + + public void testTwoDefaults() { + expectSpecificBuildException("twoDefaults", "two defaults", + "Cannot specify multiple default cases"); + } + + public void testNoMatch() { + expectSpecificBuildException("noMatch", "no match", + "No case matched the value foo" + + " and no default has been specified."); + } + + public void testCaseNoValue() { + expectSpecificBuildException("caseNoValue", "<case> no value", + "Value is required for case."); + } + + public void testDefault() { + executeTarget("testDefault"); + assertTrue(getLog().indexOf("In default") > -1); + assertTrue(getLog().indexOf("baz") > -1); + assertEquals(-1, getLog().indexOf("${inner}")); + assertEquals(-1, getLog().indexOf("In case")); + } + + public void testCase() { + executeTarget("testCase"); + assertTrue(getLog().indexOf("In case") > -1); + assertTrue(getLog().indexOf("baz") > -1); + assertEquals(-1, getLog().indexOf("${inner}")); + assertEquals(-1, getLog().indexOf("In default")); + } + + public void testCaseSensitive() { + executeTarget("testCaseSensitive"); + assertTrue(getLog().indexOf("In default") > -1); + assertEquals(-1, getLog().indexOf("In case")); + } + + public void testCaseInSensitive() { + executeTarget("testCaseInSensitive"); + assertTrue(getLog().indexOf("In case") > -1); + assertEquals(-1, getLog().indexOf("In default")); + } + +} diff --git a/test/src/net/sf/antcontrib/logic/ThrowTaskTest.java b/test/src/net/sf/antcontrib/logic/ThrowTaskTest.java new file mode 100644 index 0000000..1ad32e6 --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/ThrowTaskTest.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <throw>. + */ +public class ThrowTaskTest extends BuildFileTest { + + public ThrowTaskTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/throw.xml"); + } + + public void testRefid() { + String message = "exception created by testcase"; + getProject().addReference("testref", new BuildException(message)); + expectSpecificBuildException("useRefid", "this is what we've put in", + message); + } + +} diff --git a/test/src/net/sf/antcontrib/logic/TimestampSelectorTest.java b/test/src/net/sf/antcontrib/logic/TimestampSelectorTest.java new file mode 100644 index 0000000..601c8be --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/TimestampSelectorTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <foreach>. + */ +public class TimestampSelectorTest extends BuildFileTest { + + public TimestampSelectorTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/timestampselector.xml"); + } + + public void tearDown() { + executeTarget("teardown"); + } + + public void testFileStampFL() { + simpleTest("filestamp.fl", "file2.txt"); + } + + public void testFileStampPR() { + simpleTest("filestamp.pr", "file2.txt"); + } + + public void testDirStampDL() { + simpleTest("dirstamp.dl", "dir2"); + } + + public void testDirStampPR() { + simpleTest("dirstamp.pr", "dir2"); + } + + private void simpleTest(String target, String expected) + { + executeTarget(target); + assertTrue(getLog().indexOf(expected) > -1); + } +} diff --git a/test/src/net/sf/antcontrib/logic/TryCatchTaskTest.java b/test/src/net/sf/antcontrib/logic/TryCatchTaskTest.java new file mode 100644 index 0000000..feb8999 --- /dev/null +++ b/test/src/net/sf/antcontrib/logic/TryCatchTaskTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2001-2005 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.logic; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <trycatch>. + */ +public class TryCatchTaskTest extends BuildFileTest { + + public TryCatchTaskTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/trycatch.xml"); + } + + public void testFullTest() { + executeTarget("fullTest"); + assertEquals("Tada!", getProject().getProperty("foo")); + Object e = getProject().getReference("bar"); + assertNotNull(e); + assertTrue(e instanceof BuildException); + assertEquals("Tada!", ((BuildException) e).getMessage()); + } + + public void testTwoCatches() { + // two catch blocks were not supported prior to TryCatchTask.java v 1.4. + executeTarget("twoCatches"); + } + + public void testTwoFinallys() { + expectSpecificBuildException("twoFinallys", "two finally children", + "You must not specify more than one <finally>"); + } + + public void testTwoTrys() { + expectSpecificBuildException("twoTrys", "two try children", + "You must not specify more than one <try>"); + } + + public void testNoTry() { + expectSpecificBuildException("noTry", "no try child", + "A nested <try> element is required"); + } + + public void testNoException() { + executeTarget("noException"); + int message = getLog().indexOf("Tada!"); + int catchBlock = getLog().indexOf("In <catch>"); + int finallyBlock = getLog().indexOf("In <finally>"); + assertTrue(message > -1); + assertEquals(-1, catchBlock); + assertTrue(finallyBlock > message); + assertNull(getProject().getProperty("foo")); + assertNull(getProject().getReference("bar")); + } +} + diff --git a/test/src/net/sf/antcontrib/math/MathTest.java b/test/src/net/sf/antcontrib/math/MathTest.java new file mode 100644 index 0000000..aba9d17 --- /dev/null +++ b/test/src/net/sf/antcontrib/math/MathTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.math; + +import net.sf.antcontrib.BuildFileTestBase; + +/** + * + * @author danson + */ +public class MathTest extends BuildFileTestBase { + + /** + * Constructor for the MathTest object + * + * @param name Description of the Parameter + */ + public MathTest( String name ) { + super( name ); + } + + /** The JUnit setup method */ + public void setUp() { + configureProject( "test/resources/math/mathtest.xml" ); + } + + /** A unit test for JUnit */ + public void test1() { + expectPropertySet("test1", "result", "18"); + } +} + diff --git a/test/src/net/sf/antcontrib/platform/OsFamilyTest.java b/test/src/net/sf/antcontrib/platform/OsFamilyTest.java new file mode 100644 index 0000000..9dbd237 --- /dev/null +++ b/test/src/net/sf/antcontrib/platform/OsFamilyTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.platform; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <osfamily>. + */ +public class OsFamilyTest extends BuildFileTest { + + public OsFamilyTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/platform/osfamily.xml"); + } + + public void testConsistency() { + executeTarget("consistency"); + assertPropertyEquals("consistent", "true"); + } + + public void testMissingProperty() { + expectSpecificBuildException("missingProperty", "no attribute", + "The attribute 'property' is required " + + "for the OsFamily task."); + } + +} diff --git a/test/src/net/sf/antcontrib/platform/ShellScriptTest.java b/test/src/net/sf/antcontrib/platform/ShellScriptTest.java new file mode 100644 index 0000000..ba1a30e --- /dev/null +++ b/test/src/net/sf/antcontrib/platform/ShellScriptTest.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.platform; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <shellscript> + * + * @author Peter Reilly + */ +public class ShellScriptTest extends BuildFileTest { + public ShellScriptTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/platform/shellscript.xml"); + staticInitialize(); + } + + public void testShHello() { + if (! hasSh) + return; + executeTarget("sh.hello"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testBashHello() { + if (! hasBash) + return; + executeTarget("bash.hello"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testShInputString() { + if (! hasSh) + return; + executeTarget("sh.inputstring"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testShProperty() { + if (! hasSh) + return; + executeTarget("sh.property"); + assertTrue(getLog().indexOf("this is a property") > -1); + } + + + public void testPythonHello() { + if (! hasPython) + return; + executeTarget("python.hello"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testPerlHello() { + if (! hasPerl) + return; + executeTarget("perl.hello"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testNoShell() { + expectBuildExceptionContaining( + "noshell", "Execute failed", "a shell that should not exist"); + } + + public void testSed() { + if (! hasSed) + return; + executeTarget("sed.test"); + assertTrue(getLog().indexOf("BAR bar bar bar BAR bar") > -1); + } + + public void testSetProperty() { + if (! hasSh) + return; + executeTarget("sh.set.property"); + assertPropertyEquals("sh.set.property", "hello world"); + } + + public void testTmpSuffix() { + if (! hasSh) + return; + executeTarget("sh.tmp.suffix"); + assertTrue(getLog().indexOf(".bat") > -1); + } + + public void testCmd() { + if (! hasCmd) + return; + executeTarget("cmd.test"); + assertTrue(getLog().indexOf("hello world") > -1); + } + + public void testDir() { + if (! hasBash) + return; + executeTarget("dir.test"); + assertTrue( + getProject().getProperty("dir.test.property") + .indexOf("subdir") > -1); + } + + public void testCommand() { + expectBuildExceptionContaining( + "command.test", "Attribute failed", + "Attribute command is not supported"); + } + + private static boolean initialized = false; + private static boolean hasSh = false; + private static boolean hasBash = false; + private static boolean hasPython = false; + private static boolean hasPerl = false; + private static boolean hasSed = false; + private static boolean hasCmd = false; + private static Object staticMonitor = new Object(); + + /** + * check if the env contains the shells + * sh, bash, python and perl + * assume cmd.exe exists for windows + */ + private void staticInitialize() { + synchronized (staticMonitor) { + if (initialized) + return; + initialized = true; + hasSh = hasShell("hassh"); + hasBash = hasShell("hasbash"); + hasPerl = hasShell("hasperl"); + hasPython = hasShell("haspython"); + hasSed = hasShell("hassed"); + hasCmd = hasShell("hascmd"); + + } + } + + private boolean hasShell(String target) { + try { + executeTarget(target); + return true; + } + catch (Throwable t) { + return false; + } + } + +} diff --git a/test/src/net/sf/antcontrib/process/LimitTest.java b/test/src/net/sf/antcontrib/process/LimitTest.java new file mode 100644 index 0000000..2e84dbd --- /dev/null +++ b/test/src/net/sf/antcontrib/process/LimitTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.process; + +import net.sf.antcontrib.BuildFileTestBase; + +public class LimitTest extends BuildFileTestBase { + + public LimitTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/logic/limittest.xml"); + } + + public void test1() { + expectLogNotContaining("test1", "_failed_"); + } + + public void test2() { + expectLogContaining("test2", "_passed_"); + } +} diff --git a/test/src/net/sf/antcontrib/property/PathToFileSetTest.java b/test/src/net/sf/antcontrib/property/PathToFileSetTest.java new file mode 100644 index 0000000..da4a5d4 --- /dev/null +++ b/test/src/net/sf/antcontrib/property/PathToFileSetTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.property; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <pathtofileset>. + */ +public class PathToFileSetTest extends BuildFileTest { + + public PathToFileSetTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/property/pathtofileset.xml"); + } + + public void tearDown() { + executeTarget("cleanup"); + } + + public void testSimple() { + executeTarget("simple"); + assertPropertyContains("simple.0.property", "0.java"); + assertPropertyContains("simple.0.property", "1.java"); + assertPropertyNotContains("simple.0.property", "2.java"); + assertPropertyNotContains("simple.0.property", "3.java"); + assertPropertyNotContains("simple.1.property", "0.java"); + assertPropertyNotContains("simple.1.property", "1.java"); + assertPropertyContains("simple.1.property", "2.java"); + assertPropertyContains("simple.1.property", "3.java"); + } + + public void testSimpleException() { + expectBuildExceptionContaining("simple-exception", "expect not relative to", + "is not relative to"); + } + + private void assertPropertyContains(String property, String expected) { + String result = getProject().getProperty(property); + assertTrue("property " + property + " contains " + expected, + result.indexOf(expected) != -1); + } + + private void assertPropertyNotContains(String property, String expected) { + String result = getProject().getProperty(property); + assertTrue("property " + property + " contains " + expected, + result.indexOf(expected) == -1); + } + +} diff --git a/test/src/net/sf/antcontrib/property/PropertyCopyTest.java b/test/src/net/sf/antcontrib/property/PropertyCopyTest.java new file mode 100644 index 0000000..c2d23dc --- /dev/null +++ b/test/src/net/sf/antcontrib/property/PropertyCopyTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.property; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <propertycopy>. + */ +public class PropertyCopyTest extends BuildFileTest { + + public PropertyCopyTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/property/propertycopy.xml"); + } + + /** + * Runs a propertyCopy without a specified name attribute. + */ + public void testMissingName() { + expectSpecificBuildException("missingName", "missing name", + "You must specify a property to set."); + } + + public void testMissingFrom() { + expectSpecificBuildException("missingFrom", "missing from", + "Missing the 'from' attribute."); + } + + public void testNonSilent() { + expectSpecificBuildException("nonSilent", "from doesn't exist", + "Property 'bar' is not defined."); + } + + public void testSilent() { + executeTarget("silent"); + assertPropertyEquals("foo", null); + } + + public void testNormal() { + executeTarget("normal"); + assertPropertyEquals("displayName", "My Organiziation"); + } +} diff --git a/test/src/net/sf/antcontrib/property/PropertySelectorTest.java b/test/src/net/sf/antcontrib/property/PropertySelectorTest.java new file mode 100644 index 0000000..16ad269 --- /dev/null +++ b/test/src/net/sf/antcontrib/property/PropertySelectorTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2001-2005 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.property; + +import org.apache.tools.ant.BuildFileTest; + +/** + * Testcase for <propertyselector>. + */ +public class PropertySelectorTest extends BuildFileTest { + + public PropertySelectorTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/property/propertyselector.xml"); + } + + public void testDefaultGrouping() { + simpleTest("select.test.grouping.0", + "module.Module1.id", "module.Module2.id"); + } + + public void testDefaultGrouping1() { + simpleTest("select.test.grouping.1", + "Module1", "Module2"); + } + + private void simpleTest(String target, String expected1, String expected2) + { + executeTarget(target); + String order1 = expected1 + "," + expected2; + String order2 = expected2 + "," + expected1; + int index1 = getLog().indexOf(order1); + int index2 = getLog().indexOf(order2); + assertTrue("Neither '" + order1 + "' nor '" + order2 + + "' was found in '" + getLog() + "'", + index1 > -1 || index2 > -1); + } + +} diff --git a/test/src/net/sf/antcontrib/property/VariableTest.java b/test/src/net/sf/antcontrib/property/VariableTest.java new file mode 100644 index 0000000..d54c111 --- /dev/null +++ b/test/src/net/sf/antcontrib/property/VariableTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.property; + +import net.sf.antcontrib.BuildFileTestBase; + + +public class VariableTest extends BuildFileTestBase { + + public VariableTest(String name) { + super(name); + } + + public void setUp() { + configureProject("test/resources/property/variabletest.xml"); + } + + public void test1() { + expectPropertySet("test1", "x", "6"); + } + + public void test2() { + expectPropertySet("test2", "x", "12"); + } + + public void test3() { + expectPropertySet("test3", "x", "6 + 12"); + } + + public void test4() { + expectPropertySet("test4", "x", "6"); + } + + public void test5() { + expectPropertySet("test5", "str", "I am a string."); + } + + public void test6() { + expectPropertySet("test6", "x", "Today is blue."); + } + + public void test7() { + expectPropertySet("test7", "x", "6"); + } + + /* TODO: depends on the Antelope <if>, need to adjust to use the ant-contrib <if> + public void test8() { + expectPropertySet("test8", "x", "12"); + expectLogContaining("test8", "12"); + } + */ + public void test9() { + expectPropertyUnset("test9", "i"); + } + + public void test10() { + expectPropertySet("test10", "x", "xxx"); + } +} diff --git a/test/src/net/sf/antcontrib/walls/CompileWithWallsTest.java b/test/src/net/sf/antcontrib/walls/CompileWithWallsTest.java new file mode 100644 index 0000000..fe6a203 --- /dev/null +++ b/test/src/net/sf/antcontrib/walls/CompileWithWallsTest.java @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved. + * + * Licensed 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 net.sf.antcontrib.walls; + +import java.io.File; + +import org.apache.tools.ant.BuildFileTest; + +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +/** + * BIG NOTE*************************************************** + * Always expect specific exceptions. Most of these test cases when + * first submitted were not and therefore were not testing what they said + * they were testing. Exceptions were being caused by other things and the + * tests were still passing. Now all tests expect a specific exception + * so if any other is thrown we will fail the test case. + * ************************************************************ + * + * Testcase for <propertycopy>. + */ +public class CompileWithWallsTest extends BuildFileTest { + + private String baseDir = "test"+File.separator + +"resources"+File.separator + +"walls"+File.separator; + private String c = File.separator; + + public CompileWithWallsTest(String name) { + super(name); + } + + public void setUp() { + + configureProject("test/resources/walls/compilewithwalls.xml"); +// project.addBuildListener(new LogListener()); + } +// protected class LogListener implements BuildListener { +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent) +// */ +// public void buildStarted(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent) +// */ +// public void buildFinished(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent) +// */ +// public void targetStarted(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent) +// */ +// public void targetFinished(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent) +// */ +// public void taskStarted(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent) +// */ +// public void taskFinished(BuildEvent event) { +// // TODO Auto-generated method stub +// +// } +// +// /* (non-Javadoc) +// * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent) +// */ +// public void messageLogged(BuildEvent event) { +// +// System.out.println(event.getException()); +// System.out.println("aaa"); +// } +// +// } + + public void tearDown() { + executeTarget("cleanup"); + +// System.out.println(getFullLog()); +// System.out.println("std out. from ant build begin--------------"); +// System.out.println(getOutput()); +// System.out.println("std.out. from ant build end----------------"); +// System.out.println("std err. from ant build begin--------------"); +// System.out.println(getError()); +// System.out.println("std.err. from ant build end----------------"); + } + + public void testTooManyNestedWallElements() { + expectSpecificBuildException("testTooManyNestedWallElements" + , "TooManyNestedWallElements" + , "compilewithwalls task only supports one nested walls element or one walls attribute"); + } + + public void testFakeTest() { + //this is being deprecated, tests no longer really needed. + } +// public void testTooManyNestedJavacElements() { +// expectSpecificBuildException("testTooManyNestedJavacElements" +// , "TooManyNestedJavacElements" +// , "compilewithwalls task only supports one nested javac element"); +// } +// +// public void testNoWallElement() { +// expectSpecificBuildException("testNoWallElement" +// , "NoWallElement" +// , "There must be a nested walls element"); +// } +// +// public void testNoJavacElement() { +// expectSpecificBuildException("testNoJavacElement" +// , "NoJavacElement" +// , "There must be a nested javac element"); +// } +// +// public void testMoreThanOneSrcDirInJavac() { +// executeTarget("testMoreThanOneSrcDirInJavac"); +// } +// +// public void testNoSrcDirInJavac() { +// expectSpecificBuildException("testNoSrcDirInJavac" +// , "NoSrcDirInJavac" +// , "Javac inside compilewithwalls must have a srcdir specified"); +// } +// +// public void testIntermediaryDirAndDestDirSame() { +// expectSpecificBuildException("testIntermediaryDirAndDestDirSame" +// , "IntermediaryDirAndDestDirSame" +// , "intermediaryBuildDir attribute cannot be specified\n" +// +"to be the same as destdir or inside desdir of the javac task.\n" +// +"This is an intermediary build directory only used by the\n" +// +"compilewithwalls task, not the class file output directory.\n" +// +"The class file output directory is specified in javac's destdir attribute"); +// } +// +// public void testIntermediaryDirInsideDestDir() { +// expectSpecificBuildException("testIntermediaryDirInsideDestDir" +// , "IntermediaryDirInsideDestDir" +// , "intermediaryBuildDir attribute cannot be specified\n" +// +"to be the same as destdir or inside desdir of the javac task.\n" +// +"This is an intermediary build directory only used by the\n" +// +"compilewithwalls task, not the class file output directory.\n" +// +"The class file output directory is specified in javac's destdir attribute"); +// } +// +// public void testPackageDoesntEndWithStar() { +// expectSpecificBuildException("testPackageDoesntEndWithStar" +// , "PackageDoesntEndWithStar" +// , "The package='biz.xsoftware' must end with " +// + ".* or .** such as biz.xsoftware.* or " +// + "biz.xsoftware.**" ); +// } +// +// public void testPackageDoesntHaveSlash() { +// expectSpecificBuildException("testPackageDoesntHaveSlash" +// , "PackageDoesntHaveSlash" +// ,"A package name cannot contain '\\' or '/' like package=" +// + "biz/xsoftware.*\nIt must look like biz.xsoftware.* for example"); +// } +// +// public void testDependsOnNonExistPackage() { +// expectSpecificBuildException("testDependsOnNonExistPackage" +// , "DependsOnNonExistPackage" +// , "package name=modA did not have modB" +// + " listed before it and cannot compile without it"); +// } +// +// public void testDependsOnPackageAfter() { +// expectSpecificBuildException("testDependsOnPackageAfter" +// , "DependsOnPackageAfter" +// , "package name=modA did not have modB" +// + " listed before it and cannot compile without it"); +// } +// +// public void testPackageABreakingWhenAIsCompiledFirst() { +// expectSpecificBuildException("testPackageABreakingWhenAIsCompiledFirst" +// , "PackageABreakingWhenAIsCompiledFirst" +// , "Compile failed; see the compiler error output for details."); +// } +// +// +// /** +// * This test case tests when modB depends on modA but it was +// * not specified in the walls so modA is not in modB's path. +// * The build should then fail until they change the build.xml +// * so modB depends on modA in the walls element. +// */ +// public void testPackageBBreakingWhenAIsCompiledFirst() { +// +// expectSpecificBuildException("testPackageBBreakingWhenAIsCompiledFirst" +// , "PackageBBreakingWhenAIsCompiledFirst" +// , "Compile failed; see the compiler error output for details."); +// +// //modA should have been compiled successfully, it is only modB that +// //fails. It is very important we make sure A got compiled otherwise +// //we are not testing the correct behavior and the test would be wrong. +// ensureClassFileExists("testB"+c+"mod"+c+"modA"+c+"ModuleA.class", true); +// ensureClassFileExists("testB"+c+"mod"+c+"modB"+c+"ModuleB.class", false); +// } +// +// public void testCompileOfAllUsingDepends() { +// ensureClassFileExists("testC"+c+"mod"+c+"Module.class", false); +// //make sure we are testing the correct thing and Module.java exists! +// ensureJavaFileExists("testC"+c+"mod"+c+"Module.java", true); +// +// executeTarget("testCompileOfAllUsingDepends"); +// +// //must test class files were actually created afterwards. +// //The build might pass with no class files if the task is +// //messed up. +// ensureClassFileExists("testC"+c+"mod"+c+"Module.class", true); +// +// } +////--------------------------------------------------------- +//// +//// The following tests are all just repeats of some of the above tests +//// except the below tests use External walls file and the above tests +//// don't. +//// +////--------------------------------------------------------- +// +// public void testDependsOnPackageAfterExternalWalls() { +// expectSpecificBuildException("testDependsOnPackageAfterExternalWalls" +// , "DependsOnPackageAfterExternalWalls" +// , "package name=modA did not have modB" +// + " listed before it and cannot compile without it"); +// } +// +// /** +// * This test case tests when modB depends on modA but it was +// * not specified in the walls so modA is not in modB's path. +// * The build should then fail until they change the build.xml +// * so modB depends on modA in the walls element. +// */ +// public void testPackageBBreakingWhenAIsCompiledFirstExternalWalls() { +// ensureClassFileExists("testB"+c+"mod"+c+"modA"+c+"ModuleA.class", false); +// ensureJavaFileExists("testB"+c+"mod"+c+"modB"+c+"ModuleB.java", true); +// +// expectSpecificBuildException("testPackageBBreakingWhenAIsCompiledFirst" +// , "PackageBBreakingWhenAIsCompiledFirst" +// , "Compile failed; see the compiler error output for details."); +// +// //modA should have been compiled successfully, it is only modB that +// //fails. It is very important we make sure A got compiled otherwise +// //we are not testing the correct behavior and the test would be wrong. +// ensureClassFileExists("testB"+c+"mod"+c+"modA"+c+"ModuleA.class", true); +// ensureClassFileExists("testB"+c+"mod"+c+"modB"+c+"ModuleB.class", false); +// } +// +// public void testCompileOfAllUsingDependsExternalWalls() { +// ensureClassFileExists("testC"+c+"mod"+c+"Module.class", false); +// ensureJavaFileExists("testC"+c+"mod"+c+"Module.java", true); +// executeTarget("testCompileOfAllUsingDependsExternalWalls"); +// //must test class files were actually created afterwards. +// //The build might pass with no class files if the task is +// //messed up. +// ensureClassFileExists("testC"+c+"mod"+c+"Module.class", true); +// } + + private void ensureJavaFileExists(String file, boolean shouldExist) { + + //must test that it is testing the correct directory. + //It wasn't before. + String javaFile = baseDir+file; + File f1 = new File(javaFile); + if(shouldExist) + assertTrue("The java file="+f1.getAbsolutePath()+" didn't exist, we can't run this test. It will pass with false results", + f1.exists()); + else + assertTrue("The java file="+f1.getAbsolutePath()+" exists and shouldn't, we can't run this test. It will pass with false results", + !f1.exists()); + } + + private void ensureClassFileExists(String file, boolean shouldExist) { + + String classFile = baseDir + +"compilewithwalls"+File.separator + +"classes"+File.separator + +file; + + File f1 = new File(classFile); + if(shouldExist) + assertTrue("The class file="+f1.getAbsolutePath()+" didn't get created, No build exception\nwas thrown, but the build failed because a class\nfile should have been created", + f1.exists()); + else + assertTrue("The class file="+f1.getAbsolutePath()+" exists and shouldn't\nTest may be inaccurate if this file already exists...correct the test", + !f1.exists()); + } + + public static void main(String[] args) { + TestSuite suite = new TestSuite(CompileWithWallsTest.class); + TestRunner.run(suite); + } +} |