diff options
author | wisberg <wisberg> | 2004-10-06 11:21:50 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2004-10-06 11:21:50 +0000 |
commit | 33ca99bf6bbbbc73f9fb31c355440f4447ba2c9f (patch) | |
tree | b6e2949806afb733c1e131037940e2cd4784a70d /tests | |
parent | 31169e73375b12f02dd94c1372464e2724035880 (diff) | |
download | aspectj-33ca99bf6bbbbc73f9fb31c355440f4447ba2c9f.tar.gz aspectj-33ca99bf6bbbbc73f9fb31c355440f4447ba2c9f.zip |
docs for aspectpath and forking
Diffstat (limited to 'tests')
-rw-r--r-- | tests/readme-writing-compiler-tests.html | 105 |
1 files changed, 84 insertions, 21 deletions
diff --git a/tests/readme-writing-compiler-tests.html b/tests/readme-writing-compiler-tests.html index 120f9dc2b..ba202b00c 100644 --- a/tests/readme-writing-compiler-tests.html +++ b/tests/readme-writing-compiler-tests.html @@ -1,7 +1,9 @@ <html> <!-- <![CDATA[ putDataHere ]]> --> +<head> <title>Writing tests for the AspectJ compiler </title> +</head> <body> <h2>Writing tests for the AspectJ compiler </h2> @@ -19,12 +21,13 @@ test code, discussing <li><a href="#simple">Simple test definitions</a></li> <li><a href="#sourceFiles">Test source files</a></li> <li><a href="#incremental">Incremental tests</a></li> - <li><a href="#verifying">Verifying test steps</a></li> + <li><a href="#verifying">Verifying test steps</a> <ul> <li><a href="#messages">Messages</a></li> <li><a href="#dirchanges">Changes in an output directory</a></li> - <li><a href="#tester">Runtime behavior</a></li> - </ul> + <li><a href="#tester">Testing runtime behavior</a></li> + </ul></li> + <li><a href="#forking">Forking at runtime</a></li> <li><a href="#compilerOptions">Compiler Options</a></li> <li><a href="#background">Harness background</a></li> </ul> @@ -33,7 +36,7 @@ information in <a href="#simple">Simple test definitions</a> and <a href="#sourceFiles">Test source files</a>. -<p>Related documents: +<p>Related documents:</p> <ul> <li>For information on running the harness, see <a href="readme-tests-module.html"> @@ -66,6 +69,7 @@ and expect an error on line 10 in a file <code>ajcSample.xml</code>: <code>pack/Aspect.java</code> and <code>pack2/Main.java</code> and run the main class: +</p> <pre> <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. <p>More complex compilations are discussed in <a href="#compilerOptions">Compiler Options</a> below. - +</p> <a name="sourceFiles"></a> <h4>Test source files</h4> @@ -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: +</p> <pre> ... <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 <code>-ajdeCompiler</code> to the harness or compile step as an argument. -<p> +<p/> To recap the attributes of note for setting up incremental tests: <ul> @@ -196,7 +201,7 @@ immediately preceding <compile> task in the options. </li> </ul> -<p> +<p/> 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: -<p> +<p/> <table border="1" cellpadding="1"> @@ -306,10 +311,12 @@ following things and comparing against expected behavior: </tr> <tr><td>Runtime behavior</td> <td>Use <code>Tester</code> in test source code - to signal events for comparison with expected events.</td> + to signal events for comparison with expected events. + To signal failure when running a forked test without Tester, + throw an exception.</td> </tr> </table> -<p> +<p/> <a name="messages"></a> <h5>Messages</h5> @@ -341,7 +348,7 @@ However, an IMessage also has a Throwable thrown, a String detail, and a List of ISourceLocation (essentially, "see also", to point to other relevant places in the code). The thrown element is not supported, but you can specify the others: - +</p> <pre> <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. - +</p> <p> 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 <code>^verbose<code> to +the compiler settings. Use the option <code>^verbose</code> to force the compiler's <code>-verbose</code> option off. +</p> <p> 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.) +</p> <a name="dirchanges"></a> <h5>Changes in an output directory</h5> @@ -402,9 +411,11 @@ the classes directory. The current harness defaults to using the classes directory, and when using the classes directory uses <code>.class</code> as a default suffix. +</p> <p> Here's an example specification: -<pre> +</p> + <pre> <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. <code>Tester</code> also has methods that operate like JUnit assertions as idioms to detect differences in expected and actual values, signalling appropriately. -<p> +</p> <code>Tester</code> is at <a href="../testing-client/src/org/aspectj/testing/Tester.java"> @@ -480,8 +491,60 @@ which is included on the classpath by the compile and run steps. <p>You can write runtime test cases without using Tester; simply throw some exception from the main thread to signal failure. +</p> + +<a name="forking"></a> +<h4>Forking and load-time weaving</h4> +<p>You can fork the tests that are run by setting global properties + or by setting attributes to run. One attribute, + <code>aspectpath</code>, forces the run to fork and uses + load-time weaving to weave aspects with the classpath. + </p> +<p>To fork for all tests, set the global system property + <code>javarun.fork</code> 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 all <code>run</code> steps to + fork into the specified Java 1.1 VM. +</p> +<pre> +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 ... + </pre> + +<p>You can fork a specific test by setting + the <code>fork</code> attribute (and optionally the + <code>vmargs</code> attribute): +</p> +<pre> + <ajc-test dir="new" title="show forking"> + <compile files="Main.java"/> + <run class="Main" fork="true" + vmargs="-Dname=value,-Dname2="value 2"/> + </ajc-test> +</pre> -<a name="compilerOptions"></a> +<p>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 <code>aspectpath</code> attribute to + <code>run</code>. + 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.</p> +<pre> + <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> +</pre> + + <a name="compilerOptions"></a> <h4>Compiler options</h4> 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 <code>-g:none</code>, but will fail for comma-delimited single-arg options like <code>-g:lines,vars</code> because the comma delimiters are ambiguous (yes, a design bug!). -<p> +<p/> The <code>compile</code> element has the following attributes which handle most of the other compiler arguments: <ul> @@ -515,7 +578,7 @@ which handle most of the other compiler arguments: Paths for these are all relative to the test base directory, and multiple entries are separated with commas. (Use only one entry for xlintfile.) -<p> +<p/> Here is a cooked example that uses all <code>compiler</code> attributes: <pre> <ajc-test dir="new" title="attributes test"> @@ -536,7 +599,7 @@ The following attributes of the compiler entity dictate harness behavior: <ul> <li><u>badInput</u>: To test invalid input, set the compiler <code>badInput</code> attribute -to "</code>true</code>". This prevents the harness from aborting a test +to "<code>true</code>". 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). </li> </ul> -<hr> +<hr/> <small>last updated March 8, 2004 </small> <!-- CVS variable --> </body> |