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

Roger Riggs rriggs at openjdk.org
Tue Apr 8 18:55:35 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

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

> 1200:             String packageName = packageMatcher.find() ? packageMatcher.group(1) + "." : "";
> 1201:             return Optional.of(packageName + className);
> 1202:         } catch (IOException ignored) {

I think you can use "_" for the variable when its ignored, that seems to be the new convention (maybe only elsewhere) for unused variable.

test/smartActionArgs/optAuto/p/Test3.java line 35:

> 33: 
> 34: public class Test3 {
> 35:     private static final boolean expectDollar = false; // opt-auto, i.e. in

What is this for?

test/smartActionArgs/optAuto/p/Test3.java line 47:

> 45:                 case "--test.src":
> 46:                 case "--test.classes":
> 47:                 case "--test.class.path":

Command line options with "." look pretty odd, they can be mistaken for source files.
Typically, the embedded delimiter is "-" (hyphen).  Though jtreg may have its own convention.

The command line (@run) for the test only checks the first of these.

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

PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2033825894
PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2033839401
PR Review Comment: https://git.openjdk.org/jtreg/pull/257#discussion_r2033833844


More information about the jtreg-dev mailing list