Skip to content

Commit

Permalink
8315415: OutputAnalyzer.shouldMatchByLine() fails in some cases
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes
  • Loading branch information
lmesnik committed Sep 19, 2023
1 parent da57d2a commit 7b1e2bf
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions test/lib/jdk/test/lib/process/OutputAnalyzer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -671,68 +671,68 @@ public OutputAnalyzer stdoutShouldMatchByLine(String pattern) {
/**
* @see #shouldMatchByLine(String, String, String)
*/
public OutputAnalyzer shouldMatchByLineFrom(String from, String pattern) {
return shouldMatchByLine(from, null, pattern);
public OutputAnalyzer shouldMatchByLineFrom(String fromPattern, String pattern) {
return shouldMatchByLine(fromPattern, null, pattern);
}

/**
* @see #shouldMatchByLine(String, String, String)
*/
public OutputAnalyzer shouldMatchByLineTo(String to, String pattern) {
return shouldMatchByLine(null, to, pattern);
public OutputAnalyzer shouldMatchByLineTo(String toPattern, String pattern) {
return shouldMatchByLine(null, toPattern, pattern);
}

/**
* Verify that the stdout and stderr contents of output buffer match the
* {@code pattern} line by line. The whole output could be matched or
* just a subset of it.
*
* @param from
* The line (excluded) from where output will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where output will be matched.
* Set {@code to} to null for matching until the last line.
* @param fromPattern
* The pattern of line (excluded) from where output will be matched.
* Set {@code fromPattern} to null for matching from the first line.
* @param toPattern
* The pattern of line (excluded) until where output will be matched.
* Set {@code toPattern} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern);
public OutputAnalyzer shouldMatchByLine(String fromPattern, String toPattern, String pattern) {
return shouldMatchByLine(getOutput(), fromPattern, toPattern, pattern);
}

/**
* Verify that the stdout contents of output buffer matches the
* {@code pattern} line by line. The whole stdout could be matched or
* just a subset of it.
*
* @param from
* The line (excluded) from where stdout will be matched.
* Set {@code from} to null for matching from the first line.
* @param to
* The line (excluded) until where stdout will be matched.
* Set {@code to} to null for matching until the last line.
* @param fromPattern
* The pattern of line (excluded) from where stdout will be matched.
* Set {@code fromPattern} to null for matching from the first line.
* @param toPattern
* The pattern of line (excluded) until where stdout will be matched.
* Set {@code toPattern} to null for matching until the last line.
* @param pattern
* Matching pattern
*/
public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getStdout(), from, to, pattern);
public OutputAnalyzer stdoutShouldMatchByLine(String fromPattern, String toPattern, String pattern) {
return shouldMatchByLine(getStdout(), fromPattern, toPattern, pattern);
}

private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
private OutputAnalyzer shouldMatchByLine(String buffer, String fromPattern, String toPattern, String pattern) {
List<String> lines = asLines(buffer);

int fromIndex = 0;
if (from != null) {
fromIndex = indexOf(lines, from, 0) + 1; // + 1 -> apply 'pattern' to lines after 'from' match
if (fromPattern != null) {
fromIndex = indexOf(lines, fromPattern, 0) + 1; // + 1 -> apply 'pattern' to lines after 'from' match
Asserts.assertGreaterThan(fromIndex, 0,
"The line/pattern '" + from + "' from where the output should match can not be found");
"The line matched with pattern '" + fromPattern + "' from where the output should match can not be found");
}

int toIndex = lines.size();
if (to != null) {
toIndex = indexOf(lines, to, fromIndex);
if (toPattern != null) {
toIndex = indexOf(lines, toPattern, fromIndex);
Asserts.assertGreaterThan(toIndex, fromIndex,
"The line/pattern '" + to + "' until where the output should match can not be found");
"The line matched with pattern '" + toPattern + "' until where the output should match can not be found");
}

List<String> subList = lines.subList(fromIndex, toIndex);
Expand Down

5 comments on commit 7b1e2bf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 7b1e2bf Oct 30, 2023

Choose a reason for hiding this comment

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

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 7b1e2bf Oct 30, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-7b1e2bfe in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7b1e2bfe from the openjdk/jdk repository.

The commit being backported was authored by Leonid Mesnik on 19 Sep 2023 and was reviewed by David Holmes.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git GoeLin-backport-7b1e2bfe:GoeLin-backport-7b1e2bfe
$ git checkout GoeLin-backport-7b1e2bfe
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git GoeLin-backport-7b1e2bfe

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 7b1e2bf Feb 2, 2024

Choose a reason for hiding this comment

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

@luchenlin Could not automatically backport 7b1e2bfe to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/lib/jdk/test/lib/process/OutputAnalyzer.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-7b1e2bfe

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 7b1e2bfe0f805a69b59839b6bf8250b62ea356b8

# Backport the commit
$ git cherry-pick --no-commit 7b1e2bfe0f805a69b59839b6bf8250b62ea356b8
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 7b1e2bfe0f805a69b59839b6bf8250b62ea356b8'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 7b1e2bfe0f805a69b59839b6bf8250b62ea356b8.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7b1e2bfe from the openjdk/jdk repository.

The commit being backported was authored by Leonid Mesnik on 19 Sep 2023 and was reviewed by David Holmes.

Thanks!

Please sign in to comment.