< prev index next >
test/lib/jdk/test/lib/process/OutputAnalyzer.java
Print this page
rev 51638 : [mq]: 8210112
rev 51639 : [mq]: 8210112-1
*** 311,334 ****
* @param regexp
* @throws RuntimeException If the pattern was found
*/
public OutputAnalyzer shouldNotMatch(String regexp) {
String stdout = getStdout();
- String stderr = getStderr();
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(stdout);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stdout: '" + matcher.group() + "' \n");
}
matcher = pattern.matcher(stderr);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stderr: '" + matcher.group() + "' \n");
}
return this;
}
/**
* Verify that the stdout contents of output buffer does not match the
--- 311,336 ----
* @param regexp
* @throws RuntimeException If the pattern was found
*/
public OutputAnalyzer shouldNotMatch(String regexp) {
String stdout = getStdout();
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(stdout);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stdout: '" + matcher.group() + "' \n");
}
+
+ String stderr = getStderr();
matcher = pattern.matcher(stderr);
if (matcher.find()) {
reportDiagnosticSummary();
throw new RuntimeException("'" + regexp
+ "' found in stderr: '" + matcher.group() + "' \n");
}
+
return this;
}
/**
* Verify that the stdout contents of output buffer does not match the
*** 373,390 ****
* @param regexp The multi-line pattern to match
* @param group The group to capture
* @return The matched string or null if no match was found
*/
public String firstMatch(String regexp, int group) {
- String stdout = getStdout();
- String stderr = getStderr();
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
Matcher stderrMatcher = pattern.matcher(stderr);
- Matcher stdoutMatcher = pattern.matcher(stdout);
if (stderrMatcher.find()) {
return stderrMatcher.group(group);
}
if (stdoutMatcher.find()) {
return stdoutMatcher.group(group);
}
return null;
}
--- 375,392 ----
* @param regexp The multi-line pattern to match
* @param group The group to capture
* @return The matched string or null if no match was found
*/
public String firstMatch(String regexp, int group) {
Pattern pattern = Pattern.compile(regexp, Pattern.MULTILINE);
+ String stderr = getStderr();
Matcher stderrMatcher = pattern.matcher(stderr);
if (stderrMatcher.find()) {
return stderrMatcher.group(group);
}
+ String stdout = getStdout();
+ Matcher stdoutMatcher = pattern.matcher(stdout);
if (stdoutMatcher.find()) {
return stdoutMatcher.group(group);
}
return null;
}
*** 513,523 ****
public List<String> asLines() {
return asLines(getOutput());
}
private List<String> asLines(String buffer) {
! return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)"));
}
private static final String jvmwarningmsg = ".* VM warning:.*";
--- 515,525 ----
public List<String> asLines() {
return asLines(getOutput());
}
private List<String> asLines(String buffer) {
! return Arrays.asList(buffer.split("\\R"));
}
private static final String jvmwarningmsg = ".* VM warning:.*";
*** 569,604 ****
return Arrays.stream(getOutput().split("\\R"))
.filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
.collect(Collectors.toList());
}
-
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public int shouldMatchByLine(String pattern) {
return shouldMatchByLine(null, null, pattern);
}
/**
* @see #stdoutShouldMatchByLine(String, String, String)
*/
! public int stdoutShouldMatchByLine(String pattern) {
return stdoutShouldMatchByLine(null, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public int shouldMatchByLineFrom(String from, String pattern) {
return shouldMatchByLine(from, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public int shouldMatchByLineTo(String to, String pattern) {
return shouldMatchByLine(null, to, pattern);
}
/**
* Verify that the stdout and stderr contents of output buffer match the
--- 571,605 ----
return Arrays.stream(getOutput().split("\\R"))
.filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
.collect(Collectors.toList());
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public OutputAnalyzer shouldMatchByLine(String pattern) {
return shouldMatchByLine(null, null, pattern);
}
/**
* @see #stdoutShouldMatchByLine(String, String, String)
*/
! public OutputAnalyzer stdoutShouldMatchByLine(String pattern) {
return stdoutShouldMatchByLine(null, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public OutputAnalyzer shouldMatchByLineFrom(String from, String pattern) {
return shouldMatchByLine(from, null, pattern);
}
/**
* @see #shouldMatchByLine(String, String, String)
*/
! public OutputAnalyzer shouldMatchByLineTo(String to, String pattern) {
return shouldMatchByLine(null, to, pattern);
}
/**
* Verify that the stdout and stderr contents of output buffer match the
*** 611,623 ****
* @param to
* The line until where output will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
- * @return Count of lines which match the {@code pattern}
*/
! public int shouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getOutput(), from, to, pattern);
}
/**
* Verify that the stdout contents of output buffer matches the
--- 612,623 ----
* @param to
* The line until where output will be matched.
* Set {@code to} 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);
}
/**
* Verify that the stdout contents of output buffer matches the
*** 630,646 ****
* @param to
* The line until where stdout will be matched.
* Set {@code to} to null for matching until the last line.
* @param pattern
* Matching pattern
- * @return Count of lines which match the {@code pattern}
*/
! public int stdoutShouldMatchByLine(String from, String to, String pattern) {
return shouldMatchByLine(getStdout(), from, to, pattern);
}
! private int shouldMatchByLine(String buffer, String from, String to, String pattern) {
List<String> lines = asLines(buffer);
int fromIndex = 0;
if (from != null) {
fromIndex = indexOf(lines, from);
--- 630,645 ----
* @param to
* The line until where stdout will be matched.
* Set {@code to} 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);
}
! private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
List<String> lines = asLines(buffer);
int fromIndex = 0;
if (from != null) {
fromIndex = indexOf(lines, from);
*** 654,682 ****
Asserts.assertGreaterThan(toIndex, -1,
"The line/pattern '" + to + "' until where the output should match can not be found");
}
List<String> subList = lines.subList(fromIndex, toIndex);
! int matchedCount = 0;
! for (String line : subList) {
! Asserts.assertTrue(line.matches(pattern),
! "The line '" + line + "' does not match pattern '" + pattern + "'");
! matchedCount++;
! }
! return matchedCount;
}
/**
! * Check if there is a line matching {@code pattern} and return its index
*
! * @param pattern Matching pattern
* @return Index of first matching line
*/
! private int indexOf(List<String> lines, String pattern) {
for (int i = 0; i < lines.size(); i++) {
! if (lines.get(i).matches(pattern)) {
return i;
}
}
return -1;
}
--- 653,683 ----
Asserts.assertGreaterThan(toIndex, -1,
"The line/pattern '" + to + "' until where the output should match can not be found");
}
List<String> subList = lines.subList(fromIndex, toIndex);
! Asserts.assertFalse(subList.isEmpty(), "There is no lines to check");
!
! subList.stream()
! .filter(Pattern.compile(pattern).asPredicate().negate())
! .findAny()
! .ifPresent(line -> Asserts.assertTrue(false,
! "The line '" + line + "' does not match pattern '" + pattern + "'"));
! return this;
}
/**
! * Check if there is a line matching {@code regexp} and return its index
*
! * @param regexp Matching pattern
* @return Index of first matching line
*/
! private int indexOf(List<String> lines, String regexp) {
! Pattern pattern = Pattern.compile(regexp);
for (int i = 0; i < lines.size(); i++) {
! if (pattern.matcher(lines.get(i)).matches()) {
return i;
}
}
return -1;
}
< prev index next >