Skip to content

Commit 38c11fd

Browse files
author
Andrew Lu
committedFeb 6, 2024
8315415: OutputAnalyzer.shouldMatchByLine() fails in some cases
Backport-of: 7b1e2bfe0f805a69b59839b6bf8250b62ea356b8
1 parent 0dc17ca commit 38c11fd

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed
 

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

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -607,68 +607,68 @@ public OutputAnalyzer stdoutShouldMatchByLine(String pattern) {
607607
/**
608608
* @see #shouldMatchByLine(String, String, String)
609609
*/
610-
public OutputAnalyzer shouldMatchByLineFrom(String from, String pattern) {
611-
return shouldMatchByLine(from, null, pattern);
610+
public OutputAnalyzer shouldMatchByLineFrom(String fromPattern, String pattern) {
611+
return shouldMatchByLine(fromPattern, null, pattern);
612612
}
613613

614614
/**
615615
* @see #shouldMatchByLine(String, String, String)
616616
*/
617-
public OutputAnalyzer shouldMatchByLineTo(String to, String pattern) {
618-
return shouldMatchByLine(null, to, pattern);
617+
public OutputAnalyzer shouldMatchByLineTo(String toPattern, String pattern) {
618+
return shouldMatchByLine(null, toPattern, pattern);
619619
}
620620

621621
/**
622622
* Verify that the stdout and stderr contents of output buffer match the
623623
* {@code pattern} line by line. The whole output could be matched or
624624
* just a subset of it.
625625
*
626-
* @param from
627-
* The line (excluded) from where output will be matched.
628-
* Set {@code from} to null for matching from the first line.
629-
* @param to
630-
* The line (excluded) until where output will be matched.
631-
* Set {@code to} to null for matching until the last line.
626+
* @param fromPattern
627+
* The pattern of line (excluded) from where output will be matched.
628+
* Set {@code fromPattern} to null for matching from the first line.
629+
* @param toPattern
630+
* The pattern of line (excluded) until where output will be matched.
631+
* Set {@code toPattern} to null for matching until the last line.
632632
* @param pattern
633633
* Matching pattern
634634
*/
635-
public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
636-
return shouldMatchByLine(getOutput(), from, to, pattern);
635+
public OutputAnalyzer shouldMatchByLine(String fromPattern, String toPattern, String pattern) {
636+
return shouldMatchByLine(getOutput(), fromPattern, toPattern, pattern);
637637
}
638638

639639
/**
640640
* Verify that the stdout contents of output buffer matches the
641641
* {@code pattern} line by line. The whole stdout could be matched or
642642
* just a subset of it.
643643
*
644-
* @param from
645-
* The line (excluded) from where stdout will be matched.
646-
* Set {@code from} to null for matching from the first line.
647-
* @param to
648-
* The line (excluded) until where stdout will be matched.
649-
* Set {@code to} to null for matching until the last line.
644+
* @param fromPattern
645+
* The pattern of line (excluded) from where stdout will be matched.
646+
* Set {@code fromPattern} to null for matching from the first line.
647+
* @param toPattern
648+
* The pattern of line (excluded) until where stdout will be matched.
649+
* Set {@code toPattern} to null for matching until the last line.
650650
* @param pattern
651651
* Matching pattern
652652
*/
653-
public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
654-
return shouldMatchByLine(getStdout(), from, to, pattern);
653+
public OutputAnalyzer stdoutShouldMatchByLine(String fromPattern, String toPattern, String pattern) {
654+
return shouldMatchByLine(getStdout(), fromPattern, toPattern, pattern);
655655
}
656656

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

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.