--- old/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java 2013-09-12 16:59:17.000000000 +0200 +++ new/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java 2013-09-12 16:59:17.000000000 +0200 @@ -211,13 +211,13 @@ if (matcher.find()) { reportDiagnosticSummary(); throw new RuntimeException("'" + pattern - + "' found in stdout \n"); + + "' 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 \n"); + + "' found in stderr: '" + matcher.group() + "' \n"); } } @@ -252,6 +252,37 @@ + "' found in stderr \n"); } } + + /** + * Get the captured group of the first string matching the pattern. + * stdout is searched before stderr. + * + * @param pattern 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 pattern, int group) { + Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout); + Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr); + if (stdoutMatcher.find()) { + return stdoutMatcher.group(group); + } + if (stderrMatcher.find()) { + return stderrMatcher.group(group); + } + return null; + } + + /** + * Get the first string matching the pattern. + * stdout is searched before stderr. + * + * @param pattern The multi-line pattern to match + * @return The matched string or null if no match was found + */ + public String firstMatch(String pattern) { + return firstMatch(pattern, 0); + } /** * Verify the exit value of the process