1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.File ; 21 22 import junit.framework.AssertionFailedError; 23 24 import org.apache.tools.ant.BuildEvent; 25 import org.apache.tools.ant.BuildFileTest; 26 import org.apache.tools.ant.BuildListener; 27 import org.apache.tools.ant.input.InputHandler; 28 import org.apache.tools.ant.types.Path; 29 30 32 public class SubAntTest extends BuildFileTest { 33 34 public SubAntTest(String name) { 35 super(name); 36 } 37 38 public void setUp() { 39 configureProject("src/etc/testcases/taskdefs/subant.xml"); 40 } 41 42 public void tearDown() { 43 executeTarget("cleanup"); 44 } 45 46 public void testnodirs() { 47 project.executeTarget("testnodirs"); 48 expectLog("testnodirs", "No sub-builds to iterate on"); 49 } 50 51 public void testgenericantfile() { 53 File dir1 = project.resolveFile("."); 54 File dir2 = project.resolveFile("subant/subant-test1"); 55 File dir3 = project.resolveFile("subant/subant-test2"); 56 57 testBaseDirs("testgenericantfile", 58 new String [] { dir1.getAbsolutePath(), 59 dir2.getAbsolutePath(), 60 dir3.getAbsolutePath() 61 62 }); 63 } 64 65 public void testantfile() { 66 File dir1 = project.resolveFile("."); 67 File dir2 = project.resolveFile("subant/subant-test1"); 70 File dir3 = project.resolveFile("subant"); 73 74 testBaseDirs("testantfile", 75 new String [] { dir1.getAbsolutePath(), 76 dir2.getAbsolutePath(), 77 dir3.getAbsolutePath() 78 79 }); 80 81 } 82 83 protected void testBaseDirs(String target, String [] dirs) { 84 SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs); 85 project.addBuildListener(bc); 86 executeTarget(target); 87 AssertionFailedError ae = bc.getError(); 88 if (ae != null) { 89 throw ae; 90 } 91 project.removeBuildListener(bc); 92 } 93 94 private class BasedirChecker implements BuildListener { 95 private String [] expectedBasedirs; 96 private int calls = 0; 97 private AssertionFailedError error; 98 99 BasedirChecker(String [] dirs) { 100 expectedBasedirs = dirs; 101 } 102 103 public void buildStarted(BuildEvent event) {} 104 public void buildFinished(BuildEvent event) {} 105 public void targetFinished(BuildEvent event){} 106 public void taskStarted(BuildEvent event) {} 107 public void taskFinished(BuildEvent event) {} 108 public void messageLogged(BuildEvent event) {} 109 110 public void targetStarted(BuildEvent event) { 111 if (event.getTarget().getName().equals("")) { 112 return; 113 } 114 if (error == null) { 115 try { 116 assertEquals(expectedBasedirs[calls++], 117 event.getProject().getBaseDir().getAbsolutePath()); 118 } catch (AssertionFailedError e) { 119 error = e; 120 } 121 } 122 } 123 124 AssertionFailedError getError() { 125 return error; 126 } 127 128 } 129 130 131 } 132 | Popular Tags |