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

Leonid Mesnik lmesnik at openjdk.org
Tue Apr 8 17:45:29 UTC 2025


On Tue, 8 Apr 2025 06:55:29 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:
> 
>   Base main entry-point name computation on file name

I think that fix looks good. 
The only question - does it enough information provided when jtreg can't execute expected test? Should be easy enough to correct the problem for jtreg test developer.
There are also small comments inline.

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

> 1182:                 .collect(Collectors.joining(File.pathSeparator));
> 1183:     }
> 1184: //    // where

please remove the commented code

src/share/doc/javatest/regtest/tag-spec.html line 1255:

> 1253: <td><code>test.main.class</code>
> 1254: <td><i>Not Available</i>
> 1255: <td>The computed name of the main entry-point of the current Java source file.

Might be add notes that 
1) packages are supported, based on package line
2) inner classes are not supported
3) the test fails during execution if ${test.main.class} is not found or doesn't have main() method. 
It is just a suggestion, please update as you think it would be better. No need to overload users with info.

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

Changes requested by lmesnik (no project role).

PR Review: https://git.openjdk.org/jtreg/pull/257#pullrequestreview-2750871570
PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2033717362
PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2033728610


More information about the jtreg-dev mailing list