From: wisberg Related documents:
+ Related documents:Writing tests for the AspectJ compiler
@@ -19,12 +21,13 @@ test code, discussing
ajcSample.xml
:
pack/Aspect.java
and
pack2/Main.java
and
run the main class:
+
<ajc-test dir="new" title="simple run test"> <compile files="pack/Aspect.java,pack1/Main.java"/> @@ -78,7 +82,7 @@ the classes directory generated by the compile step.More complex compilations are discussed in Compiler Options below. - +
Test source files
@@ -144,6 +148,7 @@ but rebuilds from scratch. In that case, there is still the question of whether source files should be updated; if not, the tag can have the special value "same". For example, if the last example had two more lines: +... <inc-compile tag="30"/> @@ -158,7 +163,7 @@ and then running the main class. This option has no effect on the normal (ajc) compiler, and requires specifying-ajdeCompiler
to the harness or compile step as an argument. -+
To recap the attributes of note for setting up incremental tests:
+
Now, to get back to the question of what exactly is happening in an incremental test. To do so, compare the tags with the files specified in @@ -281,7 +286,7 @@ As seen above, two ways to verify that a compile was successful are to run the corresponding class or check the compiler messages. More generally, the harness can verify compile/run test steps by detecting the following things and comparing against expected behavior: -+
Runtime behavior | Use Tester in test source code
- to signal events for comparison with expected events. |
+ to signal events for comparison with expected events.
+ To signal failure when running a forked test without Tester,
+ throw an exception.
+
<ajc-test dir="new" title="simple error test"> <compile files="Main.java"> @@ -372,19 +379,21 @@ messages expected on a line, provide enough information to distinguish them. If you are using text or detail attributes, do not use one string that is a prefix of the other, since it will match either message, and the other message might not match. - +The "info" messages are special in that they are normally ignored. To specify expected "info" messages, you have to list all the messages the compiler will issue, which can vary depending on -the compiler settings. Use the option
^verbose
to +the compiler settings. Use the option
^verbose
to force the compiler's-verbose
option off. +By the same token, if you don't specify any extra source locations, then they will not be checked. If you think it is a bug if they are issued, then you have to specify one if them. (There is currently no way to specify that a message has no extra source locations.) +
Changes in an output directory
@@ -402,9 +411,11 @@ the classes directory. The current harness defaults to using the classes directory, and when using the classes directory uses.class
as a default suffix. +Here's an example specification: -
+ +<ajc-test dir="new/dirchanges-test" title="dir-changes test"> <compile staging="true" files="Main.java,DeleteMe.java,Unchanged.java"/> @@ -455,7 +466,7 @@ public class Main implements Runnable { } aspect A { - before () : target(Runnable) && execution(void run()) { + before () : target(Runnable) && execution(void run()) { Tester.event("before advice"); } } @@ -468,7 +479,7 @@ the harness will report a failure.Tester
also has methods that operate like JUnit assertions as idioms to detect differences in expected and actual values, signalling appropriately. -+
Tester
is at @@ -480,8 +491,60 @@ which is included on the classpath by the compile and run steps.You can write runtime test cases without using Tester; simply throw some exception from the main thread to signal failure. +
+ + +Forking and load-time weaving
+You can fork the tests that are run by setting global properties + or by setting attributes to run. One attribute, +
+aspectpath
, forces the run to fork and uses + load-time weaving to weave aspects with the classpath. +To fork for all tests, set the global system property +
+javarun.fork
to "true". You can also + set other properties to control how forking happens. + (By default, forking uses the java executable that was + used to run the harness.) + The following causes allrun
steps to + fork into the specified Java 1.1 VM. ++java -Djavarun.fork=true \ + -Djavarun.java=c:/home/jdk11/bin/java.exe \ + -Djavarun.java.home=c:/home/jdk11 \ + -Djavarun.bootclasspath=c:/home/jdk11/lib/classes.zip \ + -Djavarun.vmargs=-Dname=value,-Dname2="value 2" \ + org.aspectj.testing.drivers.Harness ... ++ +You can fork a specific test by setting + the
+fork
attribute (and optionally the +vmargs
attribute): ++ <ajc-test dir="new" title="show forking"> + <compile files="Main.java"/> + <run class="Main" fork="true" + vmargs="-Dname=value,-Dname2="value 2"/> + </ajc-test> +- +As a special case of forking, load-time weaving sets up + a Java 1.4 or later VM using our weaving class loader, + if you specify the
+aspectpath
attribute to +run
. + In the following example, the main class and the aspect + are compiled separately. The main class is then woven + and run using load-time weaving.+ <ajc-test dir="new" title="show LTW"> + <compile files="Aspect.java" outjar="out.jar"/> + <compile files="Main.java"/> + <run class="Main" aspectpath="out.jar"/> + </ajc-test> ++ +Compiler options
The harness does not support all of the AspectJ 1.1 compiler options. Flags are mainly supported through the a comma-delimited list in @@ -497,7 +560,7 @@ This should work even for complex single-arg options like-g:none
, but will fail for comma-delimited single-arg options like-g:lines,vars
because the comma delimiters are ambiguous (yes, a design bug!). -+
Thecompile
element has the following attributes which handle most of the other compiler arguments:
+
Here is a cooked example that uses allcompiler
attributes:
<ajc-test dir="new" title="attributes test"> @@ -536,7 +599,7 @@ The following attributes of the compiler entity dictate harness behavior:
badInput
attribute
-to "true". This prevents the harness from aborting a test
+to "true
". This prevents the harness from aborting a test
because a specified input file was not found. (However, there is no way
to specify bad input for a directory in the files attribute intended for
-inpath, because the harness selects readable directories.)
@@ -605,7 +668,7 @@ For more information, see the API documentation for the harness
the emacssym option off, even in tests that specify it).