You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompilerDumpTestCase.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * Matthew Webster - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.ajdt.internal.compiler.batch;
  12. import java.io.File;
  13. import org.aspectj.bridge.IMessage;
  14. import org.aspectj.tools.ajc.AjcTestCase;
  15. import org.aspectj.tools.ajc.CompilationResult;
  16. import org.aspectj.weaver.Dump;
  17. import junit.framework.TestCase;
  18. public class CompilerDumpTestCase extends AjcTestCase {
  19. public static final String PROJECT_DIR = "DumpTestCase";
  20. private File baseDir;
  21. private File dumpFile;
  22. private IMessage.Kind savedDumpCondition;
  23. protected void setUp() throws Exception {
  24. super.setUp();
  25. baseDir = new File("../org.aspectj.ajdt.core/testdata",PROJECT_DIR);
  26. dumpFile = null;
  27. savedDumpCondition = Dump.getDumpOnExit();
  28. }
  29. protected void tearDown() throws Exception {
  30. super.tearDown();
  31. if (dumpFile != null && dumpFile.exists()) {
  32. boolean deleted = dumpFile.delete();
  33. assertTrue("Dump file '" + dumpFile.getPath() + "' could not be deleted",deleted);
  34. }
  35. Dump.setDumpOnExit(savedDumpCondition);
  36. }
  37. /**
  38. * Aim: Dump after successful compile to ensure it contains the command
  39. * line information.
  40. *
  41. * Inputs to the compiler:
  42. * HelloWorld.java Pointcuts.aj Aspect.aj
  43. *
  44. * Expected result = Compile succeeds.
  45. */
  46. public void testDump () {
  47. String[] args = new String[] { "src/HelloWorld.java", "src/Pointcuts.aj", "src/Aspect.aj" };
  48. CompilationResult result = ajc(baseDir,args);
  49. assertNoMessages(result);
  50. String fileName = Dump.dump("DumpTestCase.testDump()");
  51. dumpFile = new File(fileName);
  52. org.aspectj.weaver.DumpTestCase.assertContents(dumpFile,"Command Line","HelloWorld.java");
  53. }
  54. /**
  55. * Aim: Dump after successful compile to ensure it contains warning
  56. * messages.
  57. *
  58. * Inputs to the compiler:
  59. * HelloWorld.java Pointcuts.aj Aspect.aj DeclareWarning.aj
  60. *
  61. * Expected result = Compile succeeds.
  62. */
  63. public void testDumpWithWarnings () {
  64. String[] args = new String[] { "src/HelloWorld.java", "src/Pointcuts.aj", "src/DeclareWarning.aj" };
  65. CompilationResult result = ajc(baseDir,args);
  66. String fileName = Dump.dump("DumpTestCase.testDumpWithWarnings()");
  67. dumpFile = new File(fileName);
  68. org.aspectj.weaver.DumpTestCase.assertContents(dumpFile,"Compiler Messages","warning");
  69. }
  70. /**
  71. * Aim: Dump due to errors.
  72. *
  73. * Inputs to the compiler:
  74. * HelloWorld.java Pointcuts.aj Aspect.aj DeclareError.aj
  75. *
  76. * Expected result = Compile fails and dump file created.
  77. */
  78. public void testWithErrors () {
  79. Dump.setDumpOnExit(IMessage.ERROR);
  80. String previousFileName = Dump.getLastDumpFileName();
  81. String[] args = new String[] { "src/HelloWorld.java", "src/Pointcuts.aj", "src/DeclareError.aj" };
  82. CompilationResult result = ajc(baseDir,args);
  83. String fileName = Dump.getLastDumpFileName();
  84. assertTrue("Dump file should be created",!fileName.equals(previousFileName));
  85. dumpFile = new File(fileName);
  86. org.aspectj.weaver.DumpTestCase.assertContents(dumpFile,"Compiler Messages","error");
  87. }
  88. }