hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java
changeset 16666 da191c7e38d2
parent 15441 b96e139eb20c
child 19141 1e8184e44a8c
equal deleted inserted replaced
16603:94855b102374 16666:da191c7e38d2
    22  */
    22  */
    23 
    23 
    24 package com.oracle.java.testlibrary;
    24 package com.oracle.java.testlibrary;
    25 
    25 
    26 import java.io.IOException;
    26 import java.io.IOException;
       
    27 import java.util.regex.Matcher;
       
    28 import java.util.regex.Pattern;
    27 
    29 
    28 public final class OutputAnalyzer {
    30 public final class OutputAnalyzer {
    29 
    31 
    30   private final String stdout;
    32   private final String stdout;
    31   private final String stderr;
    33   private final String stderr;
   140       throw new RuntimeException("'" + notExpectedString + "' found in stderr: [" + stderr + "]\n");
   142       throw new RuntimeException("'" + notExpectedString + "' found in stderr: [" + stderr + "]\n");
   141     }
   143     }
   142   }
   144   }
   143 
   145 
   144   /**
   146   /**
       
   147    * Verify that the stdout and stderr contents of output buffer matches
       
   148    * the pattern
       
   149    *
       
   150    * @param pattern
       
   151    * @throws RuntimeException If the pattern was not found
       
   152    */
       
   153   public void shouldMatch(String pattern) {
       
   154       Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
       
   155       Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
       
   156       if (!stdoutMatcher.find() && !stderrMatcher.find()) {
       
   157           throw new RuntimeException("'" + pattern
       
   158                   + "' missing from stdout/stderr: [" + stdout + stderr
       
   159                   + "]\n");
       
   160       }
       
   161   }
       
   162 
       
   163   /**
       
   164    * Verify that the stdout contents of output buffer matches the
       
   165    * pattern
       
   166    *
       
   167    * @param pattern
       
   168    * @throws RuntimeException If the pattern was not found
       
   169    */
       
   170   public void stdoutShouldMatch(String pattern) {
       
   171       Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
       
   172       if (!matcher.find()) {
       
   173           throw new RuntimeException("'" + pattern
       
   174                   + "' missing from stdout: [" + stdout + "]\n");
       
   175       }
       
   176   }
       
   177 
       
   178   /**
       
   179    * Verify that the stderr contents of output buffer matches the
       
   180    * pattern
       
   181    *
       
   182    * @param pattern
       
   183    * @throws RuntimeException If the pattern was not found
       
   184    */
       
   185   public void stderrShouldMatch(String pattern) {
       
   186       Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
       
   187       if (!matcher.find()) {
       
   188           throw new RuntimeException("'" + pattern
       
   189                   + "' missing from stderr: [" + stderr + "]\n");
       
   190       }
       
   191   }
       
   192 
       
   193   /**
       
   194    * Verify that the stdout and stderr contents of output buffer does not
       
   195    * match the pattern
       
   196    *
       
   197    * @param pattern
       
   198    * @throws RuntimeException If the pattern was found
       
   199    */
       
   200   public void shouldNotMatch(String pattern) {
       
   201       Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
       
   202       if (matcher.find()) {
       
   203           throw new RuntimeException("'" + pattern
       
   204                   + "' found in stdout: [" + stdout + "]\n");
       
   205       }
       
   206       matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
       
   207       if (matcher.find()) {
       
   208           throw new RuntimeException("'" + pattern
       
   209                   + "' found in stderr: [" + stderr + "]\n");
       
   210       }
       
   211   }
       
   212 
       
   213   /**
       
   214    * Verify that the stdout contents of output buffer does not match the
       
   215    * pattern
       
   216    *
       
   217    * @param pattern
       
   218    * @throws RuntimeException If the pattern was found
       
   219    */
       
   220   public void stdoutShouldNotMatch(String pattern) {
       
   221       Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
       
   222       if (matcher.find()) {
       
   223           throw new RuntimeException("'" + pattern
       
   224                   + "' found in stdout: [" + stdout + "]\n");
       
   225       }
       
   226   }
       
   227 
       
   228   /**
       
   229    * Verify that the stderr contents of output buffer does not match the
       
   230    * pattern
       
   231    *
       
   232    * @param pattern
       
   233    * @throws RuntimeException If the pattern was found
       
   234    */
       
   235   public void stderrShouldNotMatch(String pattern) {
       
   236       Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
       
   237       if (matcher.find()) {
       
   238           throw new RuntimeException("'" + pattern
       
   239                   + "' found in stderr: [" + stderr + "]\n");
       
   240       }
       
   241   }
       
   242 
       
   243   /**
   145    * Verifiy the exit value of the process
   244    * Verifiy the exit value of the process
   146    *
   245    *
   147    * @param expectedExitValue Expected exit value from process
   246    * @param expectedExitValue Expected exit value from process
   148    * @throws RuntimeException If the exit value from the process did not match the expected value
   247    * @throws RuntimeException If the exit value from the process did not match the expected value
   149    */
   248    */
   150   public void shouldHaveExitValue(int expectedExitValue) {
   249   public void shouldHaveExitValue(int expectedExitValue) {
   151     if (getExitValue() != expectedExitValue) {
   250       if (getExitValue() != expectedExitValue) {
   152       throw new RuntimeException("Exit value " + getExitValue() + " , expected to get " + expectedExitValue);
   251           throw new RuntimeException("Exit value " + getExitValue() + " , expected to get " + expectedExitValue);
   153     }
   252       }
   154   }
   253   }
   155 
   254 
   156   /**
   255   /**
   157    * Get the contents of the output buffer (stdout and stderr)
   256    * Get the contents of the output buffer (stdout and stderr)
   158    *
   257    *