RFR: 7903981: Support easy way to use current class name for test actions [v7]

Jan Lahoda jlahoda at openjdk.org
Tue Apr 22 08:17:59 UTC 2025


On Tue, 22 Apr 2025 07:54:38 GMT, Christian Stein <cstein at openjdk.org> wrote:

>> Please review this change to allow an easier way to use current class name for test actions.
>> 
>> Test authors usually specify the name of a test class to be run by `jtreg` 1:1 in a `@run` action directive. This PR introduces the new test property `test.main.class` and tries to initialize it with the fully-qualified class name of the test class. It is composed of the package name and the truncated file name of `.java` source file passed to `jtreg`: `SomeTest.java` becomes `SomeTest`
>> 
>> Example for `Test.java` in the unnamed package:
>> - `@run main Test` - `@run main ${test.main.class}`
>> 
>> Example for `Test.java` declaring `package p;`:
>> - `@run main p.Test` - `@run main ${test.main.class}`
>> 
>> See also: [CODETOOLS-7902352: Support use of ${property.name} in action args](https://bugs.openjdk.org/browse/CODETOOLS-7902352)
>
> Christian Stein has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update test/smartActionArgs/SmartActionArgs.gmk
>   
>   Remove now redundant `-p` flag from `mkdir` call

src/share/classes/com/sun/javatest/regtest/exec/RegressionScript.java line 1191:

> 1189:         String fileName = file.getFileName().toString();
> 1190:         int fileNameLength = fileName.length(); // including ".java".length() = 5
> 1191:         if (fileNameLength <= 5 && !fileName.endsWith(".java")) {

This logic seems suspicious to me. If `fileNameLength` will be over `5` characters, the extension will be ignored. If the extension is `.java`, the length will be ignored. Should it be:
Suggestion:

        if (fileNameLength <= 5 || !fileName.endsWith(".java")) {

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

PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2053579187


More information about the jtreg-dev mailing list