RFR: 8344942: Template-Based Testing Framework [v61]
Emanuel Peter
epeter at openjdk.org
Sat May 31 11:28:08 UTC 2025
On Sat, 31 May 2025 11:22:21 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> 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!
This is what I already had, but they only validate the `let` and `$` calls, not the string replacements that use the regex.

-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2117727666
More information about the hotspot-compiler-dev
mailing list