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

Print this page

        

*** 74,84 **** * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void shouldContain(String expectedString) { if (!stdout.contains(expectedString) && !stderr.contains(expectedString)) { ! throw new RuntimeException("'" + expectedString + "' missing from stdout/stderr: [" + stdout + stderr + "]\n"); } } /** * Verify that the stdout contents of output buffer contains the string --- 74,85 ---- * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void shouldContain(String expectedString) { if (!stdout.contains(expectedString) && !stderr.contains(expectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + expectedString + "' missing from stdout/stderr \n"); } } /** * Verify that the stdout contents of output buffer contains the string
*** 86,96 **** * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void stdoutShouldContain(String expectedString) { if (!stdout.contains(expectedString)) { ! throw new RuntimeException("'" + expectedString + "' missing from stdout: [" + stdout + "]\n"); } } /** * Verify that the stderr contents of output buffer contains the string --- 87,98 ---- * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void stdoutShouldContain(String expectedString) { if (!stdout.contains(expectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + expectedString + "' missing from stdout \n"); } } /** * Verify that the stderr contents of output buffer contains the string
*** 98,108 **** * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void stderrShouldContain(String expectedString) { if (!stderr.contains(expectedString)) { ! throw new RuntimeException("'" + expectedString + "' missing from stderr: [" + stderr + "]\n"); } } /** * Verify that the stdout and stderr contents of output buffer does not contain the string --- 100,111 ---- * @param expectedString String that buffer should contain * @throws RuntimeException If the string was not found */ public void stderrShouldContain(String expectedString) { if (!stderr.contains(expectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + expectedString + "' missing from stderr \n"); } } /** * Verify that the stdout and stderr contents of output buffer does not contain the string
*** 110,123 **** * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void shouldNotContain(String notExpectedString) { if (stdout.contains(notExpectedString)) { ! throw new RuntimeException("'" + notExpectedString + "' found in stdout: [" + stdout + "]\n"); } if (stderr.contains(notExpectedString)) { ! throw new RuntimeException("'" + notExpectedString + "' found in stderr: [" + stderr + "]\n"); } } /** * Verify that the stdout contents of output buffer does not contain the string --- 113,128 ---- * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void shouldNotContain(String notExpectedString) { if (stdout.contains(notExpectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + notExpectedString + "' found in stdout \n"); } if (stderr.contains(notExpectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + notExpectedString + "' found in stderr \n"); } } /** * Verify that the stdout contents of output buffer does not contain the string
*** 125,135 **** * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void stdoutShouldNotContain(String notExpectedString) { if (stdout.contains(notExpectedString)) { ! throw new RuntimeException("'" + notExpectedString + "' found in stdout: [" + stdout + "]\n"); } } /** * Verify that the stderr contents of output buffer does not contain the string --- 130,141 ---- * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void stdoutShouldNotContain(String notExpectedString) { if (stdout.contains(notExpectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + notExpectedString + "' found in stdout \n"); } } /** * Verify that the stderr contents of output buffer does not contain the string
*** 137,147 **** * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void stderrShouldNotContain(String notExpectedString) { if (stderr.contains(notExpectedString)) { ! throw new RuntimeException("'" + notExpectedString + "' found in stderr: [" + stderr + "]\n"); } } /** * Verify that the stdout and stderr contents of output buffer matches --- 143,154 ---- * @param expectedString String that the buffer should not contain * @throws RuntimeException If the string was found */ public void stderrShouldNotContain(String notExpectedString) { if (stderr.contains(notExpectedString)) { ! reportDiagnosticSummary(); ! throw new RuntimeException("'" + notExpectedString + "' found in stderr \n"); } } /** * Verify that the stdout and stderr contents of output buffer matches
*** 152,164 **** */ public void shouldMatch(String pattern) { Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (!stdoutMatcher.find() && !stderrMatcher.find()) { throw new RuntimeException("'" + pattern ! + "' missing from stdout/stderr: [" + stdout + stderr ! + "]\n"); } } /** * Verify that the stdout contents of output buffer matches the --- 159,171 ---- */ public void shouldMatch(String pattern) { Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (!stdoutMatcher.find() && !stderrMatcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' missing from stdout/stderr \n"); } } /** * Verify that the stdout contents of output buffer matches the
*** 168,179 **** * @throws RuntimeException If the pattern was not found */ public void stdoutShouldMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (!matcher.find()) { throw new RuntimeException("'" + pattern ! + "' missing from stdout: [" + stdout + "]\n"); } } /** * Verify that the stderr contents of output buffer matches the --- 175,187 ---- * @throws RuntimeException If the pattern was not found */ public void stdoutShouldMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (!matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' missing from stdout \n"); } } /** * Verify that the stderr contents of output buffer matches the
*** 183,194 **** * @throws RuntimeException If the pattern was not found */ public void stderrShouldMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (!matcher.find()) { throw new RuntimeException("'" + pattern ! + "' missing from stderr: [" + stderr + "]\n"); } } /** * Verify that the stdout and stderr contents of output buffer does not --- 191,203 ---- * @throws RuntimeException If the pattern was not found */ public void stderrShouldMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (!matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' missing from stderr \n"); } } /** * Verify that the stdout and stderr contents of output buffer does not
*** 198,214 **** * @throws RuntimeException If the pattern was found */ public void shouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (matcher.find()) { throw new RuntimeException("'" + pattern ! + "' found in stdout: [" + stdout + "]\n"); } matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (matcher.find()) { throw new RuntimeException("'" + pattern ! + "' found in stderr: [" + stderr + "]\n"); } } /** * Verify that the stdout contents of output buffer does not match the --- 207,225 ---- * @throws RuntimeException If the pattern was found */ public void shouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' found in stdout: '" + matcher.group() + "' \n"); } matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' found in stderr: '" + matcher.group() + "' \n"); } } /** * Verify that the stdout contents of output buffer does not match the
*** 218,229 **** * @throws RuntimeException If the pattern was found */ public void stdoutShouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (matcher.find()) { throw new RuntimeException("'" + pattern ! + "' found in stdout: [" + stdout + "]\n"); } } /** * Verify that the stderr contents of output buffer does not match the --- 229,241 ---- * @throws RuntimeException If the pattern was found */ public void stdoutShouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); if (matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' found in stdout \n"); } } /** * Verify that the stderr contents of output buffer does not match the
*** 233,244 **** * @throws RuntimeException If the pattern was found */ public void stderrShouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (matcher.find()) { throw new RuntimeException("'" + pattern ! + "' found in stderr: [" + stderr + "]\n"); } } /** * Get the captured group of the first string matching the pattern. --- 245,257 ---- * @throws RuntimeException If the pattern was found */ public void stderrShouldNotMatch(String pattern) { Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); if (matcher.find()) { + reportDiagnosticSummary(); throw new RuntimeException("'" + pattern ! + "' found in stderr \n"); } } /** * Get the captured group of the first string matching the pattern.
*** 277,291 **** * @param expectedExitValue Expected exit value from process * @throws RuntimeException If the exit value from the process did not match the expected value */ public void shouldHaveExitValue(int expectedExitValue) { if (getExitValue() != expectedExitValue) { ! throw new RuntimeException("Exit value " + getExitValue() + " , expected to get " + expectedExitValue); } } /** * Get the contents of the output buffer (stdout and stderr) * * @return Content of the output buffer */ public String getOutput() { --- 290,325 ---- * @param expectedExitValue Expected exit value from process * @throws RuntimeException If the exit value from the process did not match the expected value */ public void shouldHaveExitValue(int expectedExitValue) { if (getExitValue() != expectedExitValue) { ! reportDiagnosticSummary(); ! throw new RuntimeException("Expected to get exit value of [" ! + expectedExitValue + "]\n"); } } + /** + * Report summary that will help to diagnose the problem + * Currently includes: + * - standard input produced by the process under test + * - standard output + * - exit code + * Note: the command line is printed by the ProcessTools + */ + private void reportDiagnosticSummary() { + String msg = + " stdout: [" + stdout + "];\n" + + " stderr: [" + stderr + "]\n" + + " exitValue = " + getExitValue() + "\n"; + + System.err.println(msg); + } + + + /** * Get the contents of the output buffer (stdout and stderr) * * @return Content of the output buffer */ public String getOutput() {