From ea82f25eb6a7d2f691a0990d9646f5495d699093 Mon Sep 17 00:00:00 2001 From: mwebster Date: Thu, 3 Aug 2006 08:32:31 +0000 Subject: [PATCH] Bug 150131 "org.aspectj.ajde.core testcases create "out" directory in project root" (use sandbox for compiling and running tests) --- .../compiler/batch/BasicCommandTestCase.java | 10 ++-- .../compiler/batch/BinaryFormsTestCase.java | 32 +++++++------ .../compiler/batch/CommandTestCase.java | 47 +++++++++++++------ .../compiler/batch/CompileAndRunTestCase.java | 46 +++++++++--------- .../compiler/batch/PerformanceTestCase.java | 9 ++-- .../batch/ProceedOnErrorTestCase.java | 11 +++-- .../core/builder/AjBuildManagerTest.java | 5 +- 7 files changed, 89 insertions(+), 71 deletions(-) diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java index 3f9cb379a..7a8bfa48f 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java @@ -95,7 +95,7 @@ public class BasicCommandTestCase extends CommandTestCase { List args = new ArrayList(); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-classpath"); args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin"); @@ -108,7 +108,7 @@ public class BasicCommandTestCase extends CommandTestCase { List args = new ArrayList(); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-classpath"); args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin;not_found_anywhere.jar"); @@ -128,7 +128,7 @@ public class BasicCommandTestCase extends CommandTestCase { List args = new ArrayList(); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-classpath"); args.add("../lib/junit/junit.jar;../testing-client/bin"); @@ -174,12 +174,12 @@ public class BasicCommandTestCase extends CommandTestCase { } public void testSizeChanges() { - File f1 = new File("out/SizeIssues.class"); + File f1 = new File(getSandboxName(),"SizeIssues.class"); List args = new ArrayList(); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-classpath"); args.add(getRuntimeClasspath() + File.pathSeparator + diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BinaryFormsTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BinaryFormsTestCase.java index ef7eda767..d69906cdf 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BinaryFormsTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BinaryFormsTestCase.java @@ -30,15 +30,17 @@ public class BinaryFormsTestCase extends CommandTestCase { public void testJar1() throws IOException { + String library = getSandboxName() + "/lib.jar"; + List args = new ArrayList(); args.add("-outjar"); - args.add("out/lib.jar"); + args.add(library); args.add("-classpath"); args.add(AjcTests.aspectjrtClasspath()); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-XnotReweavable"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/lib/ConcreteA.aj"); @@ -48,13 +50,13 @@ public class BinaryFormsTestCase extends CommandTestCase { args = new ArrayList(); args.add("-aspectpath"); - args.add("out/lib.jar"); + args.add(library); args.add("-classpath"); args.add(AjcTests.aspectjrtClasspath()); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-XnotReweavable"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/Client.java"); @@ -62,36 +64,36 @@ public class BinaryFormsTestCase extends CommandTestCase { CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); - TestUtil.runMain("out" + File.pathSeparator + "out/lib.jar", "client.Client"); - TestUtil.runMain("out" + File.pathSeparator + "out/lib.jar", "client.Client1"); + TestUtil.runMain(getSandboxName() + File.pathSeparator + library, "client.Client"); + TestUtil.runMain(getSandboxName() + File.pathSeparator + library, "client.Client1"); args = new ArrayList(); args.add("-aspectpath"); - args.add("out/lib.jar"); + args.add(library); args.add("-classpath"); args.add(AjcTests.aspectjrtClasspath()); args.add("-XnotReweavable"); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/MyAspect.aj"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/Client1.java"); CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS); - TestUtil.runMain("out" + File.pathSeparator + "out/lib.jar", "client.Client1"); + TestUtil.runMain(getSandboxName() + File.pathSeparator + library, "client.Client1"); args = new ArrayList(); args.add("-aspectpath"); - args.add("out/lib.jar"); + args.add(library); args.add("-classpath"); args.add(AjcTests.aspectjrtClasspath()); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-XnotReweavable"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/MyAspect1.aj"); @@ -101,10 +103,10 @@ public class BinaryFormsTestCase extends CommandTestCase { args = new ArrayList(); args.add("-classpath"); - args.add("out/lib.jar" + File.pathSeparator + AjcTests.aspectjrtClasspath()); + args.add(library + File.pathSeparator + AjcTests.aspectjrtClasspath()); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-XnotReweavable"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/Client1.java"); @@ -113,11 +115,11 @@ public class BinaryFormsTestCase extends CommandTestCase { args = new ArrayList(); args.add("-classpath"); - args.add(AjcTests.aspectjrtClasspath() + File.pathSeparator + "out/lib.jar"); + args.add(AjcTests.aspectjrtClasspath() + File.pathSeparator + library); args.add("-Xlint:error"); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/MyAspect.aj"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/binary/client/Client1.java"); diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java index 12dc26c1d..58c93b921 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java @@ -12,16 +12,6 @@ package org.aspectj.ajdt.internal.compiler.batch; -import org.aspectj.ajdt.ajc.*; -import org.aspectj.ajdt.ajc.AjdtCommand; -import org.aspectj.bridge.ICommand; -import org.aspectj.bridge.IMessage; -import org.aspectj.bridge.IMessageHandler; -import org.aspectj.bridge.IMessageHolder; -import org.aspectj.bridge.MessageHandler; -import org.aspectj.tools.ajc.AjcTests; -import org.aspectj.weaver.bcel.LazyClassGen; - import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -31,6 +21,18 @@ import java.util.List; import junit.framework.TestCase; +import org.aspectj.ajdt.ajc.AjdtAjcTests; +import org.aspectj.ajdt.ajc.AjdtCommand; +import org.aspectj.bridge.ICommand; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHandler; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.testing.util.TestUtil; +import org.aspectj.tools.ajc.Ajc; +import org.aspectj.tools.ajc.AjcTests; +import org.aspectj.weaver.bcel.LazyClassGen; + public abstract class CommandTestCase extends TestCase { /** @@ -44,17 +46,22 @@ public abstract class CommandTestCase extends TestCase { public static final int[] NO_ERRORS = new int[0]; public static final int[] TOP_ERROR = new int[0]; + private File sandbox; - public static void checkCompile(String source, int[] expectedErrors) { - checkCompile(source, new String[0], expectedErrors); + public void checkCompile(String source, int[] expectedErrors) { + checkCompile(source, new String[0], expectedErrors, getSandboxName()); } - public static void checkCompile(String source, String[] extraArgs, int[] expectedErrors) { + protected void runMain(String className) { + TestUtil.runMain(getSandboxName(), className); + } + + public static void checkCompile(String source, String[] extraArgs, int[] expectedErrors, String sandboxName) { List args = new ArrayList(); args.add("-verbose"); args.add("-d"); - args.add("out"); + args.add(sandboxName); args.add("-classpath"); @@ -77,7 +84,7 @@ public abstract class CommandTestCase extends TestCase { args.add("-verbose"); args.add("-d"); - args.add("out"); + args.add(getSandboxName()); args.add("-classpath"); args.add(getRuntimeClasspath()); @@ -170,6 +177,16 @@ public abstract class CommandTestCase extends TestCase { return AjcTests.aspectjrtClasspath(); } + protected String getSandboxName () { + return sandbox.getAbsolutePath(); + } + + protected void setUp() throws Exception { + super.setUp(); + + sandbox = Ajc.createEmptySandbox(); + } + } diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CompileAndRunTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CompileAndRunTestCase.java index 4c72a3718..2838763bf 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CompileAndRunTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CompileAndRunTestCase.java @@ -14,8 +14,6 @@ package org.aspectj.ajdt.internal.compiler.batch; import java.io.IOException; -import org.aspectj.testing.util.TestUtil; - public class CompileAndRunTestCase extends CommandTestCase { @@ -25,66 +23,66 @@ public class CompileAndRunTestCase extends CommandTestCase { public void testAround() throws IOException { checkCompile("src1/AroundA.java", NO_ERRORS); - TestUtil.runMain("out", "AroundAMain"); + runMain("AroundAMain"); } public void testInterType() throws IOException { checkCompile("src1/InterType.java", NO_ERRORS); - TestUtil.runMain("out", "InterType"); + runMain("InterType"); } public void testInterTypeMethods() throws IOException { checkCompile("src1/InterTypeMethods.java", NO_ERRORS); - TestUtil.runMain("out", "InterTypeMethods"); + runMain("InterTypeMethods"); } public void testIf() throws IOException { - CommandTestCase.checkCompile("src1/IfPcd.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "IfPcd"); + checkCompile("src1/IfPcd.java", CommandTestCase.NO_ERRORS); + runMain("IfPcd"); } public void testDeclareParentsFail() throws IOException { - CommandTestCase.checkCompile("src1/ParentsFail.java", new int[] {3, 11, 19}); + checkCompile("src1/ParentsFail.java", new int[] {3, 11, 19}); } public void testDeclareParents() throws IOException { - CommandTestCase.checkCompile("src1/Parents.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "Parents"); + checkCompile("src1/Parents.java", CommandTestCase.NO_ERRORS); + runMain("Parents"); } public void testPerCflow() throws IOException { - CommandTestCase.checkCompile("src1/PerCflow.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "PerCflow"); + checkCompile("src1/PerCflow.java", CommandTestCase.NO_ERRORS); + runMain("PerCflow"); } public void testPerObject() throws IOException { - CommandTestCase.checkCompile("src1/PerObject.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "PerObject"); + checkCompile("src1/PerObject.java", CommandTestCase.NO_ERRORS); + runMain("PerObject"); } public void testDeclareSoft() throws IOException { - CommandTestCase.checkCompile("src1/DeclareSoft.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "DeclareSoft"); + checkCompile("src1/DeclareSoft.java", CommandTestCase.NO_ERRORS); + runMain("DeclareSoft"); } public void testPrivileged() throws IOException { - CommandTestCase.checkCompile("src1/Privileged.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "Privileged"); + checkCompile("src1/Privileged.java", CommandTestCase.NO_ERRORS); + runMain("Privileged"); } public void testHandler() throws IOException { - CommandTestCase.checkCompile("src1/Handler.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "Handler"); + checkCompile("src1/Handler.java", CommandTestCase.NO_ERRORS); + runMain("Handler"); } public void testInterConstructors() throws IOException { - CommandTestCase.checkCompile("src1/InterTypeConstructors.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "InterTypeConstructors"); + checkCompile("src1/InterTypeConstructors.java", CommandTestCase.NO_ERRORS); + runMain("InterTypeConstructors"); } public void testAroundA1() throws IOException { - CommandTestCase.checkCompile("src1/AroundA1.java", CommandTestCase.NO_ERRORS); - TestUtil.runMain("out", "AroundA1"); + checkCompile("src1/AroundA1.java", CommandTestCase.NO_ERRORS); + runMain("AroundA1"); } } diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java index 98f69707e..1563a57bb 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/PerformanceTestCase.java @@ -14,8 +14,6 @@ package org.aspectj.ajdt.internal.compiler.batch; import java.io.IOException; -import org.aspectj.testing.util.TestUtil; - public class PerformanceTestCase extends CommandTestCase { @@ -28,7 +26,7 @@ public class PerformanceTestCase extends CommandTestCase { public void xxx_testLazyTjpOff() throws IOException { checkCompile("src1/LazyTjp.aj", NO_ERRORS); try { - TestUtil.runMain("out", "LazyTjp"); + runMain("LazyTjp"); fail("expected an exception when running without -XlazyTjp"); } catch (IllegalStateException e) { // expected exception thrown when no -XlazyTjp @@ -40,8 +38,9 @@ public class PerformanceTestCase extends CommandTestCase { // joinpoint method-execution(int LazyTjp.doit3(int)) because around advice is used [Xlint:canNotImplementLazyTjp]' // into an error so that we can use checkCompiles() ability to check errors occur. // Pass -proceedOnError to ensure even though we get that message, we still get the class file on disk - checkCompile("src1/LazyTjp.aj", new String[] {"-Xlint:error","-proceedOnError"}, new int[] {96}); - TestUtil.runMain("out", "LazyTjp"); + String sandboxName = getSandboxName(); + checkCompile("src1/LazyTjp.aj", new String[] {"-Xlint:error","-proceedOnError"}, new int[] {96}, sandboxName); + runMain("LazyTjp"); } } diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java index 3378130ea..570adf7aa 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/ProceedOnErrorTestCase.java @@ -30,11 +30,11 @@ public class ProceedOnErrorTestCase extends CommandTestCase { */ public void testNoProceedOnError() throws IOException { checkCompile("src1/C1.java", NO_ERRORS); - File f =new File("out"+File.separator+"C.class"); + File f =new File(getSandboxName(),"C.class"); long oldmodtime = f.lastModified(); pause(2); checkCompile("src1/C2.java", new int[]{1}); - f =new File("out"+File.separator+"C.class"); + f =new File(getSandboxName(),"C.class"); long newmodtime = f.lastModified(); // Without -proceedOnError supplied, we should *not* change the time stamp on the .class file assertTrue("The .class file should not have been modified as '-proceedOnError' was not supplied (old="+ @@ -44,11 +44,12 @@ public class ProceedOnErrorTestCase extends CommandTestCase { public void testProceedOnError() throws IOException { checkCompile("src1/C1.java", NO_ERRORS); - File f =new File("out"+File.separator+"C.class"); + File f =new File(getSandboxName(),"C.class"); long oldmodtime = f.lastModified(); pause(2); - checkCompile("src1/C2.java",new String[]{"-proceedOnError"}, new int[]{1}); - f =new File("out"+File.separator+"C.class"); + String sandboxName = getSandboxName(); + checkCompile("src1/C2.java",new String[]{"-proceedOnError"}, new int[]{1}, sandboxName); + f =new File(sandboxName,"C.class"); long newmodtime = f.lastModified(); // Without -proceedOnError supplied, we should *not* change the time stamp on the .class file assertTrue("The .class file should have been modified as '-proceedOnError' *was* supplied (old="+ diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java index 10eb2d222..8de9bb93b 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java @@ -20,11 +20,11 @@ import java.io.PrintWriter; import junit.framework.TestCase; import org.aspectj.ajdt.ajc.*; -import org.aspectj.ajdt.ajc.BuildArgParser; import org.aspectj.asm.AsmManager; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageHandler; import org.aspectj.bridge.MessageWriter; +import org.aspectj.tools.ajc.Ajc; import org.aspectj.util.StreamPrintWriter; //import org.eclipse.core.runtime.CoreException; @@ -64,9 +64,10 @@ public class AjBuildManagerTest extends TestCase { AjBuildManager manager = new AjBuildManager(messageWriter); BuildArgParser parser = new BuildArgParser(messageWriter); String javaClassPath = System.getProperty("java.class.path"); + String sandboxName = Ajc.createEmptySandbox().getAbsolutePath(); AjBuildConfig buildConfig = parser.genBuildConfig(new String[] { - "-d", "out", + "-d", sandboxName, "-classpath", javaClassPath, AjdtAjcTests.TESTDATA_PATH -- 2.39.5