diff options
author | wisberg <wisberg> | 2003-10-31 20:53:05 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-10-31 20:53:05 +0000 |
commit | 798bb91837d56ff947005649534babd0aa116fbc (patch) | |
tree | caa7444a432ac8745590cfe682fbb5c607817af6 /weaver/testsrc | |
parent | ebc09b49bd6349ee6d4cd82f4e6a80927aa1e646 (diff) | |
download | aspectj-798bb91837d56ff947005649534babd0aa116fbc.tar.gz aspectj-798bb91837d56ff947005649534babd0aa116fbc.zip |
consolidate output dir for post-test clean-up
Diffstat (limited to 'weaver/testsrc')
6 files changed, 73 insertions, 12 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/BcweaverTests.java b/weaver/testsrc/org/aspectj/weaver/BcweaverTests.java index d0eff4d15..35e7c5473 100644 --- a/weaver/testsrc/org/aspectj/weaver/BcweaverTests.java +++ b/weaver/testsrc/org/aspectj/weaver/BcweaverTests.java @@ -13,11 +13,36 @@ package org.aspectj.weaver; +import java.io.File; + +import org.aspectj.util.FileUtil; + import junit.framework.*; public class BcweaverTests extends TestCase { public static final String TESTDATA_PATH = "../weaver/testdata"; + public static final String OUTDIR_PATH = "../weaver/out"; + + /** @return File outDir (writable) or null if unable to write */ + public static File getOutdir() { + File result = new File(OUTDIR_PATH); + if (result.mkdirs() + || (result.canWrite() && result.isDirectory())) { + return result; + } + return null; + } + + /** best efforts to delete the output directory and any contents */ + public static void removeOutDir() { + File outDir = getOutdir(); + if (null != outDir) { + FileUtil.deleteContents(outDir); + outDir.delete(); + } + } + public static Test suite() { TestSuite suite = new TestSuite(BcweaverTests.class.getName()); // abstract diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java index 9acc65bdb..6e3f6269e 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java @@ -17,14 +17,26 @@ import java.io.*; import java.lang.reflect.Modifier; import java.util.*; +import org.aspectj.util.FileUtil; import org.aspectj.weaver.*; public class MegaZipTestCase extends WeaveTestCase { + private File outDir; + public MegaZipTestCase(String arg0) { super(arg0); } + public void setUp() { + outDir = BcweaverTests.getOutdir(); + } + + public void tearDown() { + BcweaverTests.removeOutDir(); + outDir = null; + } + private BcelAdvice makeAroundMunger(final boolean matchOnlyPrintln) { BcelWorld world = new BcelWorld(); @@ -86,8 +98,8 @@ public class MegaZipTestCase extends WeaveTestCase { public void zipTest(String fileName) throws IOException { long startTime = System.currentTimeMillis(); - File inFile = new File("testdata", fileName); - File outFile = new File("out", fileName); + File inFile = new File(BcweaverTests.TESTDATA_PATH, fileName); + File outFile = new File(outDir, fileName); outFile.delete(); world = new BcelWorld("c:/apps/java-1.3.1_04/lib/tools.jar"); diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/TraceJarWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/TraceJarWeaveTestCase.java index a463db310..ac6a43a51 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/TraceJarWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/TraceJarWeaveTestCase.java @@ -29,8 +29,8 @@ public class TraceJarWeaveTestCase extends WeaveTestCase { world = new BcelWorld(getTraceJar()); BcelWeaver weaver = new BcelWeaver(world); weaver.addLibraryAspect("MyTrace"); - - UnwovenClassFile classFile = makeUnwovenClassFile(classDir, "DynamicHelloWorld", outDir); + UnwovenClassFile classFile + = makeUnwovenClassFile(classDir, "DynamicHelloWorld", outDirPath); weaver.addClassFile(classFile); weaver.prepareForWeave(); diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java index 0f39caaf7..ba29b43d5 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java @@ -28,13 +28,26 @@ public abstract class WeaveTestCase extends TestCase { public boolean regenerate = false; public boolean runTests = true; - + + File outDir; + String outDirPath; + public BcelWorld world = new BcelWorld(); public WeaveTestCase(String name) { super(name); } + public void setUp() { + outDir = BcweaverTests.getOutdir(); + outDirPath = outDir.getAbsolutePath(); + } + public void tearDown() { + BcweaverTests.removeOutDir(); + outDir = null; + outDirPath = null; + } + public static InstructionList getAdviceTag(BcelShadow shadow, String where) { String methodName = "ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier(); @@ -53,13 +66,12 @@ public abstract class WeaveTestCase extends TestCase { } static String classDir = "../weaver/bin"; - static String outDir = "out"; public void weaveTest(String name, String outName, List planners) throws IOException { BcelWeaver weaver = new BcelWeaver(world); - UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDir); + UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath); weaver.addClassFile(classFile); weaver.setShadowMungers(planners); @@ -83,11 +95,11 @@ public abstract class WeaveTestCase extends TestCase { gen = classType.getLazyClassGen(); //new LazyClassGen(classType); } try { - checkClass(gen, outDir, outName + ".txt"); + checkClass(gen, outDirPath, outName + ".txt"); if (runTests) { System.out.println( "*******RUNNING: " + outName + " " + name + " *******"); - TestUtil.runMain(makeClassPath(outDir), name); + TestUtil.runMain(makeClassPath(outDirPath), name); } } catch (Error e) { gen.print(System.err); @@ -130,7 +142,7 @@ public abstract class WeaveTestCase extends TestCase { if (regenerate) genClass(gen, outDir, expectedFile); else realCheckClass(gen, outDir, expectedFile); } - static final File TESTDATA_DIR = new File("../weaver/testdata"); + static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH); void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { //ClassGen b = getJavaClass(outDir, className); FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile)); diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java index cf78e88ca..428bdce9c 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java @@ -26,7 +26,8 @@ public class WorldTestCase extends AbstractWorldTestCase { super(name); } - private final BcelWorld world = new BcelWorld("testdata/tracing.jar"); + private final BcelWorld world + = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar"); protected World getWorld() { return world; diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java index f3f63142d..1aa65bcfb 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/ZipTestCase.java @@ -22,6 +22,8 @@ import junit.framework.TestCase; public class ZipTestCase extends TestCase { + File outDir; + /** * Constructor for ZipTestCase. * @param arg0 @@ -29,6 +31,15 @@ public class ZipTestCase extends TestCase { public ZipTestCase(String arg0) { super(arg0); } + + public void setUp() { + outDir = BcweaverTests.getOutdir(); + } + + public void tearDown() { + BcweaverTests.removeOutDir(); + outDir = null; + } public void zipTest(String fileName, String aspectjar) throws IOException { @@ -37,7 +48,7 @@ public class ZipTestCase extends TestCase { public void zipTest(String fileName, String aspectjar, boolean isInJar) throws IOException { File inFile = new File(fileName); - File outFile = new File("out", inFile.getName()); + File outFile = new File(outDir, inFile.getName()); BcelWorld world = new BcelWorld(); |