Is there a recommended way of generating jtreg java test source?

Martin Buchholz martinrb at google.com
Mon Oct 20 20:03:15 UTC 2014


So ... I looked at various testing tools in openjdk, and I think it would
be good if there was easy-to-use support this kind of thing available from
every jtreg test, but the design of such a general utility would be
difficult.

For my own use, I ended up using ToolProvider and JavaCompiler, and the
result was not bad, but it would be a little better if just the right
infrastructure was available.

On Wed, Oct 15, 2014 at 2:17 PM, Jonathan Gibbons <
jonathan.gibbons at oracle.com> wrote:

>
> On 10/15/2014 01:04 PM, Martin Buchholz wrote:
>
>> Occasionally, one would like to generate the java sources to be tested
>> instead of checking them in (e.g. the generated source files may be huge).
>> Is there a way to do that?
>>
>> Ideally, you would want to have some java code be @run to create the
>> source files, and those could then in turn be @compile'd and @run'd, but
>> that does not seem to be possible.
>>
>
> Martin,
>
> We routinely do this in the OpenJDK langtools/test test suite, where we
> have a style of testing that generates hundreds, sometimes thousands of
> classes on the fly, to provide the test cases for a feature.
>
> You can generate the Java source code in memory, and then use the Java
> Compiler API to compile it (javax.tools.JacaCompiler) either to class files
> in memory or to class files on disk, depending on your ultimate usage.
> Note if you compile to memory, you can execute the classes using an
> appropriate ClassLoader.
>
> But, this all has to be done within a test class -- there is no inherent
> support in jtreg to @compile and @run generated stuff.
>
> You can look at the file langtools/test/tools/lib/ToolBox.java for a
> utility class to facilitate creating in memory source objects, compiling
> them, and so on.  We wrote and used this class to replace many of the
> remaining shell tests in the langtools repo.
>
> -- Jon
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/jtreg-use/attachments/20141020/3f3ee42d/attachment.html>


More information about the jtreg-use mailing list