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

Emanuel Peter epeter at openjdk.org
Sat May 31 11:25:23 UTC 2025


On Fri, 30 May 2025 06:07:00 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

>> Emanuel Peter has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - Merge branch 'JDK-8344942-TemplateFramework-v3' of https://github.com/eme64/jdk into JDK-8344942-TemplateFramework-v3
>>  - move verification
>
> test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 160:
> 
>> 158:  * Ideally, we would have used <a href="https://openjdk.org/jeps/430">string templates</a> to inject these Template arguments into the strings.
>> 159:  * But since string templates are not (yet) available, the Templates provide <strong>hashtag replacements</strong>
>> 160: 
> 
> These paragraphs should probably belong together? And maybe you want to wrap the long line above.
> Suggestion:

Nice catch! Artifact from applying previous suggestion. Fixed now :)

> test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 174:
> 
>> 172:  * <p>
>> 173:  * The dollar and hashtag names must have at least one character. The first character must be a letter
>> 174:  * or underscore (i.e. {@code a-zA-Z_}), the other characters can also be digits (i.e. {@code a-zA-Z0-9_}).
> 
> This does not seem to be enforced:
> 
>         var testTemplate = Template.make(() -> body(
>             """
>             public class Foo {
>                 public static void main() {
>                     int $1var = 34;
>                 }
>             }
>             """
>         ));
>         System.out.println(testTemplate.render());
> 
> Results in:
> 
> public class Foo {
>     public static void main() {
>         int $1var = 34;
>     }
> }
> 
> which compiles fine. I can also change it to `$$var` which renders to `$var_1` which also compiles fine.

Oh, I did not think about these edge cases! Nice catch.
The problem is with the regex. The regex only finds valid cases, so your cases are not found. I can change the regex to find also invalid cases, and then validate them. I'll have to add some more tests for this as well!

> test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestAdvanced.java line 61:
> 
>> 59: public class TestAdvanced {
>> 60:     private static final Random RANDOM = Utils.getRandomInstance();
>> 61: 
> 
> Unused
> Suggestion:

Fixed, also removed the include.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2117725006
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2117725778
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2117725151


More information about the hotspot-compiler-dev mailing list