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.

MainTest.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* *******************************************************************
  2. * Copyright (c) 2004 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Wes Isberg initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.tools.ajc;
  13. import org.aspectj.bridge.AbortException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. public class MainTest extends AjcTestCase {
  17. public void testBareMainUsage() {
  18. List<String> fails = new ArrayList<>();
  19. List<String> errors = new ArrayList<>();
  20. List<String> warnings = new ArrayList<>();
  21. List<String> infos = new ArrayList<>();
  22. List<String> usages = new ArrayList<>();
  23. Main.bareMain(new String[] { "-?" }, false, fails, errors, warnings, infos, usages);
  24. assertNotNull(
  25. "usage text not found in compiler output",
  26. usages.stream()
  27. .filter(message -> message.contains("AspectJ-specific options:"))
  28. .findFirst()
  29. .orElse(null)
  30. );
  31. }
  32. public void testBareMainUsageX() {
  33. List<String> fails = new ArrayList<>();
  34. List<String> errors = new ArrayList<>();
  35. List<String> warnings = new ArrayList<>();
  36. List<String> infos = new ArrayList<>();
  37. List<String> usages = new ArrayList<>();
  38. Main.bareMain(new String[] { "-X" }, false, fails, errors, warnings, infos, usages);
  39. assertNotNull(
  40. "usage text not found in compiler output",
  41. usages.stream()
  42. .filter(message -> message.contains("AspectJ-specific non-standard options:"))
  43. .findFirst()
  44. .orElse(null)
  45. );
  46. }
  47. public void testAjcUsageX() {
  48. CompilationResult compilationResult = ajc(null, new String[] { "-X" });
  49. MessageSpec messageSpec = new MessageSpec(
  50. null, null, null, null, null,
  51. newMessageList(new Message("AspectJ-specific non-standard options:"))
  52. );
  53. assertMessages(compilationResult, "Expecting xoptions usage message", messageSpec);
  54. }
  55. public void testMainMessageHolderFail() {
  56. try {
  57. new Main().runMain(new String[] {"-messageHolder","org.xyz.abc"},false);
  58. fail("ajc should have thrown abort exception");
  59. }
  60. catch (AbortException ex) {
  61. // good
  62. }
  63. }
  64. public void testMainMessageHolderOk() {
  65. Main main = new Main();
  66. main.runMain(new String[] {"-messageHolder","org.aspectj.tools.ajc.TestMessageHolder"},false);
  67. assertSame("ajc should be using our message handler",TestMessageHolder.class,main.getHolder().getClass());
  68. }
  69. }