RFR: 8344942: Template-Based Testing Framework [v9]

Emanuel Peter epeter at openjdk.org
Wed May 7 20:49:59 UTC 2025


On Wed, 7 May 2025 20:35:05 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestTutorial.java line 131:
>> 
>>> 129:             "System.out.println(", arg, ");\n",  // capture arg via lambda argument
>>> 130:             "System.out.println(#arg);\n",       // capture arg via hashtag replacement
>>> 131:             "if (#arg != ", arg, ") { throw new RuntimeException(\"mismatch\"); }\n"
>> 
>> When should I use the lambda argument and when the hashtag replacement? Maybe add a comment here for some guidance or link to later tutorials where it becomes obvious.
>
> Honestly, I don't yet have a clear answer for this. Hmm.
> I'm not sure this is the best place to give this guidance.
> 
> I guess the difference is to use a separate "token" vs a hashtag replacement.
> - token: can paste anything. But it requires you to interrupt the string and add commas. That can be a little clunky. And: you can only do a recursive Template call with the token method.
> - hashtag: you need it captured as string, either by a template argument or `let`. Does not allow recursive template calls. But it looks a little nicer cosmetically.
> 
> Is this somewhat helpful? Maybe I can put that somewhere later in the tutorial? What do you think?

Maybe my guidance would be to prefer hashtag, if need be with a `let`. Especially if it is about inserting something on the same line.
If it is on a new line, then the token method looks nicer often. For example if you stream over a list.
And recursive Template calls just have to be "tokens".

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2078468295


More information about the hotspot-compiler-dev mailing list