Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8273154: Provide a JavadocTester method for non-overlapping, unordered output matching #5743

Conversation

jonathan-gibbons
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons commented Sep 28, 2021

Please review a moderately simple improvement for JavadocTester and a related new test.

A new OutputChecker class is introduced that mostly supersedes the existing methods to check the output generated by javadoc and the standard doclet. A self-imposed restriction is that no existing tests are modified.

The new class can be used to check files generated by the doclet and the streams written by the tool. It can be configured to check for ordered output or not, overlapping output, and complete coverage, and can search for literal strings and regular expressions.

There is a corresponding new test which is a non-standard use of JavadocTester, since it is designed to test JavadocTester itself, and not javadoc or the doclet. (Quis custodiet ipsos custodes?) Various methods are overridden so that the operation of the underlying methods can be checked.

Although it is a goal to NOT modify the code of any existing tests, it turns out to be reasonable to adapt some of the existing check... methods to use the new OutputChecker. All javadoc tests pass, both locally and on all standard platforms. Many/most uses of the existing checkOutput method provide "ordered" strings, and are candidates to use the new ordered check. But enough uses are not ordered, so it is not reasonable to change the default at this time. It is noted as a TODO to examine the appropriate test cases, so that we can decide whether to fix those tests and change the default.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8273154: Provide a JavadocTester method for non-overlapping, unordered output matching

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5743/head:pull/5743
$ git checkout pull/5743

Update a local copy of the PR:
$ git checkout pull/5743
$ git pull https://git.openjdk.java.net/jdk pull/5743/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5743

View PR using the GUI difftool:
$ git pr show -t 5743

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5743.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 28, 2021

👋 Welcome back jjg! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 28, 2021
@openjdk
Copy link

openjdk bot commented Sep 28, 2021

@jonathan-gibbons The following label will be automatically applied to this pull request:

  • javadoc

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the javadoc javadoc-dev@openjdk.org label Sep 28, 2021
@jonathan-gibbons
Copy link
Contributor Author

Reviewing the JBS issue, I see I did not address the following, which had been my intent to do so. I will update the PR.

// TODO: perhaps this method could be added to JavadocTester 
private void checkOutputEither(Output out, String first, String... other) { 
    checking("checkOutputEither"); 
    String output = getOutput(out);

@mlbridge
Copy link

mlbridge bot commented Sep 28, 2021

Webrevs

@pavelrappo
Copy link
Member

pavelrappo commented Oct 1, 2021

Unrelated to this PR. Every time I see these lines in JavadocTester, I cannot help thinking that we could use more specific APIs:

    public static final String FS = System.getProperty("file.separator");
    public static final String PS = System.getProperty("path.separator");
    public static final String NL = System.getProperty("line.separator");
    public static final String thisRelease = System.getProperty("java.specification.version");

The above lines can be translated into:

    public static final String FS = java.io.File.separator;
    public static final String PS = java.io.File.pathSeparator;
    public static final String NL = System.lineSeparator();
    public static final String thisRelease = String.valueOf(Runtime.version().feature());

I note that neither PS nor thisRelease seem to be currently used.

Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing this, Jon. Do you think you could also address closely related JDK-8270836 in this PR? Meanwhile, I'll keep reviewing the code.

* Checks for the presence (or absence) of an item.
*
* @param finder a function to find the next occurrence of an item starting at a given position
* @param kind the kind of the item ({@code "text"} or {@code "pattern:} to include in messages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param kind the kind of the item ({@code "text"} or {@code "pattern:} to include in messages
* @param kind the kind of the item ({@code "text"} or {@code "pattern"}) to include in messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

* @param select if {@code true}, lines that match the pattern will be checked for uniqueness;
* if {@code false}, lines that do not match the pattern will be checked
*/
public OutputChecker checkUnique(String pattern, boolean select ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public OutputChecker checkUnique(String pattern, boolean select ) {
public OutputChecker checkUnique(String pattern, boolean select) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

public OutputChecker checkUnique(String pattern, boolean select ) {
checking("checkUnique");
Pattern filter = Pattern.compile(pattern);
Matcher m = filter.matcher("");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reusable matcher; nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure it makes much difference, compared to allocating new ones.

@jonathan-gibbons
Copy link
Contributor Author

Unrelated to this PR. Every time I see these lines in JavadocTester, I cannot help thinking that we could use more specific APIs:

    public static final String FS = System.getProperty("file.separator");
    public static final String PS = System.getProperty("path.separator");
    public static final String NL = System.getProperty("line.separator");
    public static final String thisRelease = System.getProperty("java.specification.version");

The above lines can be translated into:

    public static final String FS = java.io.File.separator;
    public static final String PS = java.io.File.pathSeparator;
    public static final String NL = System.lineSeparator();
    public static final String thisRelease = String.valueOf(Runtime.version().feature());

I note that neither PS nor thisRelease seem to be currently used.

I dislike importing File, to help catch accidental use of File when Path would be better.
You may be right that PS and thisRelease may not be used, but I'd prefer to leave them in, just in case.

.map(this::fix)
.toArray(String[]::new);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@openjdk
Copy link

openjdk bot commented Nov 9, 2021

⚠️ @jonathan-gibbons This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@@ -430,8 +431,8 @@ private String fix(String item) {
* @param items the strings
*/
private String[] fix(String... items) {
return List.of(items).stream()
return Stream.of(items)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While List.of(items).stream() is not equivalent to Stream.of(items), that fix method (as a whole) still behaves the same way. One difference between those two approaches of creating an ordered stream is their behavior in regard to the null item.

Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'm looking forward to using this in testing the snippets feature (JEP 413).

@openjdk
Copy link

openjdk bot commented Nov 10, 2021

@jonathan-gibbons This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8273154: Provide a JavadocTester method for non-overlapping, unordered output matching

Reviewed-by: prappo

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 30 new commits pushed to the master branch:

  • 55b36c6: 8276825: hotspot/runtime/SelectionResolution test errors
  • 0f23c6a: 8276926: Use String.valueOf() when initializing File.separator and File.pathSeparator
  • a0b8445: 8276846: JDK-8273416 is incomplete for UseSSE=1
  • a3f710e: 8276215: Intrinsics matchers should handle native method flags better
  • 0f463a7: 8276845: (fs) java/nio/file/spi/SetDefaultProvider.java fails on x86_32
  • e01d6d0: 8276679: Malformed Javadoc inline tags in JDK source in javax/swing
  • fd0a25e: 8276805: java/awt/print/PrinterJob/CheckPrivilege.java fails due to disabled SecurityManager
  • 403f318: 8276854: Windows GHA builds fail due to broken Cygwin
  • e91e9d8: 8276721: G1: Refine G1EvacFailureObjectsSet::iterate
  • 8822d41: 8274736: Concurrent read/close of SSLSockets causes SSLSessions to be invalidated unnecessarily
  • ... and 20 more: https://git.openjdk.java.net/jdk/compare/14d66bd438dfa1feeafaca39be8f79a91e2968e9...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 10, 2021
@jonathan-gibbons
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 10, 2021

Going to push as commit ce3ed65.
Since your change was applied there have been 32 commits pushed to the master branch:

  • f561d3c: 8276864: Update boot JDKs to 17.0.1 in GHA
  • 38ec3a1: 8276672: Cannot build hsdis on WSL
  • 55b36c6: 8276825: hotspot/runtime/SelectionResolution test errors
  • 0f23c6a: 8276926: Use String.valueOf() when initializing File.separator and File.pathSeparator
  • a0b8445: 8276846: JDK-8273416 is incomplete for UseSSE=1
  • a3f710e: 8276215: Intrinsics matchers should handle native method flags better
  • 0f463a7: 8276845: (fs) java/nio/file/spi/SetDefaultProvider.java fails on x86_32
  • e01d6d0: 8276679: Malformed Javadoc inline tags in JDK source in javax/swing
  • fd0a25e: 8276805: java/awt/print/PrinterJob/CheckPrivilege.java fails due to disabled SecurityManager
  • 403f318: 8276854: Windows GHA builds fail due to broken Cygwin
  • ... and 22 more: https://git.openjdk.java.net/jdk/compare/14d66bd438dfa1feeafaca39be8f79a91e2968e9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Nov 10, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 10, 2021
@openjdk
Copy link

openjdk bot commented Nov 10, 2021

@jonathan-gibbons Pushed as commit ce3ed65.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jonathan-gibbons jonathan-gibbons deleted the 8273154.JavadocTester-checker branch November 18, 2022 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated javadoc javadoc-dev@openjdk.org
2 participants