From: Dean H. <dea...@us...> - 2003-11-20 13:01:44
|
Update of /cvsroot/ant-contrib/ant-contrib/test/src/net/sf/antcontrib/walls In directory sc8-pr-cvs1:/tmp/cvs-serv2313/test/src/net/sf/antcontrib/walls Modified Files: CompileWithWallsTest.java Log Message: add walls attribute to compilewithwalls task with test cases. Index: CompileWithWallsTest.java =================================================================== RCS file: /cvsroot/ant-contrib/ant-contrib/test/src/net/sf/antcontrib/walls/CompileWithWallsTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CompileWithWallsTest.java 15 Nov 2003 14:40:41 -0000 1.4 --- CompileWithWallsTest.java 20 Nov 2003 13:00:27 -0000 1.5 *************** *** 50,53 **** --- 50,56 ---- import java.io.File; + import junit.framework.TestSuite; + import junit.textui.TestRunner; + import org.apache.tools.ant.BuildFileTest; *************** *** 68,72 **** +"resources"+File.separator +"walls"+File.separator; ! public CompileWithWallsTest(String name) { super(name); --- 71,76 ---- +"resources"+File.separator +"walls"+File.separator; ! private String c = File.separator; ! public CompileWithWallsTest(String name) { super(name); *************** *** 171,228 **** //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. ! String resourceDir = "testB"+File.separator; ! ! //must test that it is testing the correct directory. ! //It wasn't before. ! String javaFile = baseDir+resourceDir+"mod" ! +File.separator+"Module.java"; ! String classFile = baseDir ! +"compilewithwalls"+File.separator ! +"classes"+File.separator ! +resourceDir ! +"mod"+File.separator ! +"modA"+File.separator ! +"ModuleA.class"; ! //must test class files were actually created afterwards. //The build might pass with no class files if the task is //messed up. ! File f1 = new File(classFile); ! 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()); } ! public void testCompileOfAllUsingDepends() { ! String resourceDir = "testC"+File.separator; ! //must test that it is testing the correct directory. ! //It wasn't before. ! String javaFile = baseDir+resourceDir+"mod" ! +File.separator+"Module.java"; ! String classFile = baseDir ! +"compilewithwalls"+File.separator ! +"classes"+File.separator ! +resourceDir ! +"mod"+File.separator ! +"Module.class"; ! ! File f1 = new File(javaFile); ! assertTrue("The java file="+f1.getAbsolutePath()+" didn't exist, we can't run this test. It will pass with false results", ! f1.exists()); ! ! executeTarget("testCompileOfAllUsingDepends"); //must test class files were actually created afterwards. //The build might pass with no class files if the task is //messed up. ! f1 = new File(classFile); ! 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()); } ! // public void testCompileOfAllUsingExternalWalls() { ! // executeTarget("testCompileOfAllUsingExternalWalls"); ! // } ! } --- 175,275 ---- //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("testDependsOnPackageAfter" ! , "DependsOnPackageAfter" ! , "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 + assertFalse("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 ! assertFalse("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); ! } } |