< prev index next >

test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java

Print this page
rev 7753 : 8071909: Port testlibrary improvments in jdk/test to hotspot/test as required for DCMD test port
Reviewed-by:

*** 22,31 **** --- 22,33 ---- */ package com.oracle.java.testlibrary; import java.io.IOException; + import java.util.ArrayList; + import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public final class OutputAnalyzer {
*** 67,76 **** --- 69,130 ---- this.stderr = stderr; exitValue = -1; } /** + * Verify that the stdout contents of output buffer is empty + * + * @throws RuntimeException + * If stdout was not empty + */ + public void stdoutShouldBeEmpty() { + if (!getStdout().isEmpty()) { + reportDiagnosticSummary(); + throw new RuntimeException("stdout was not empty"); + } + } + + /** + * Verify that the stderr contents of output buffer is empty + * + * @throws RuntimeException + * If stderr was not empty + */ + public void stderrShouldBeEmpty() { + if (!getStderr().isEmpty()) { + reportDiagnosticSummary(); + throw new RuntimeException("stderr was not empty"); + } + } + + /** + * Verify that the stdout contents of output buffer is not empty + * + * @throws RuntimeException + * If stdout was empty + */ + public void stdoutShouldNotBeEmpty() { + if (getStdout().isEmpty()) { + reportDiagnosticSummary(); + throw new RuntimeException("stdout was empty"); + } + } + + /** + * Verify that the stderr contents of output buffer is not empty + * + * @throws RuntimeException + * If stderr was empty + */ + public void stderrShouldNotBeEmpty() { + if (getStderr().isEmpty()) { + reportDiagnosticSummary(); + throw new RuntimeException("stderr was empty"); + } + } + + /** * Verify that the stdout and stderr contents of output buffer contains the string * * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */
*** 363,368 **** --- 417,441 ---- * @return Process exit value */ public int getExitValue() { return exitValue; } + + /** + * Get the contents of the output buffer (stdout and stderr) as list of strings. + * Output will be split by system property 'line.separator'. + * + * @return Contents of the output buffer as list of strings + */ + public List<String> asLines() { + return asLines(getOutput()); + } + + private List<String> asLines(String buffer) { + List<String> l = new ArrayList<>(); + String[] a = buffer.split(Utils.NEW_LINE); + for (String string : a) { + l.add(string); + } + return l; + } }
< prev index next >