RFR: 8344942: Template-Based Testing Framework [v9]
Emanuel Peter
epeter at openjdk.org
Wed May 7 20:40:04 UTC 2025
On Wed, 7 May 2025 11:54:00 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:
>> Emanuel Peter has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 16 commits:
>>
>> - Merge branch 'master' into JDK-8344942-TemplateFramework-v3
>> - Whitespace
>> - Suggestions by Christian
>>
>> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
>> - typo
>> - For Christian: example and more intro
>> - fix hashtag
>> - manual merge
>> - Apply suggestions from code review
>>
>> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
>> - move library
>> - Merge branch 'master' into JDK-8344942-TemplateFramework-v3
>> - ... and 6 more: https://git.openjdk.org/jdk/compare/0844745e...fae7ced6
>
> 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?
> test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestTutorial.java line 143:
>
>> 141: public static void main() {
>> 142: """,
>> 143: templateHello.withArgs(),
>
> `withArgs()` looks strange when there are no args. Could we find a better name for it? But maybe I'm missing a pattern here.
Hmm, yeah, that is a slight concern. But it does return a `TemplateWithArgs`, which means a template that knows all the arguments already. This one happens to be a zero-arg version.
I suppose I could rename it to `withArgsNone()` or `withZeroArgs` or `withNoArgs` for the zero-args version? Would that be an improvement?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2078452435
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2078456128
More information about the hotspot-compiler-dev
mailing list