hotspot/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java
changeset 28820 1837a69c2a22
parent 26688 bb0cdd873e51
equal deleted inserted replaced
28819:70ac575cccce 28820:1837a69c2a22
    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.Arrays;
       
    28 import java.util.List;
    27 import java.util.regex.Matcher;
    29 import java.util.regex.Matcher;
    28 import java.util.regex.Pattern;
    30 import java.util.regex.Pattern;
    29 
    31 
    30 public final class OutputAnalyzer {
    32 public final class OutputAnalyzer {
    31 
    33 
    67     this.stderr = stderr;
    69     this.stderr = stderr;
    68     exitValue = -1;
    70     exitValue = -1;
    69   }
    71   }
    70 
    72 
    71   /**
    73   /**
       
    74    * Verify that the stdout contents of output buffer is empty
       
    75    *
       
    76    * @throws RuntimeException
       
    77    *             If stdout was not empty
       
    78    */
       
    79   public void stdoutShouldBeEmpty() {
       
    80     if (!getStdout().isEmpty()) {
       
    81       reportDiagnosticSummary();
       
    82       throw new RuntimeException("stdout was not empty");
       
    83     }
       
    84   }
       
    85 
       
    86   /**
       
    87    * Verify that the stderr contents of output buffer is empty
       
    88    *
       
    89    * @throws RuntimeException
       
    90    *             If stderr was not empty
       
    91    */
       
    92   public void stderrShouldBeEmpty() {
       
    93     if (!getStderr().isEmpty()) {
       
    94       reportDiagnosticSummary();
       
    95       throw new RuntimeException("stderr was not empty");
       
    96     }
       
    97   }
       
    98 
       
    99   /**
       
   100    * Verify that the stdout contents of output buffer is not empty
       
   101    *
       
   102    * @throws RuntimeException
       
   103    *             If stdout was empty
       
   104    */
       
   105   public void stdoutShouldNotBeEmpty() {
       
   106     if (getStdout().isEmpty()) {
       
   107       reportDiagnosticSummary();
       
   108       throw new RuntimeException("stdout was empty");
       
   109     }
       
   110   }
       
   111 
       
   112   /**
       
   113    * Verify that the stderr contents of output buffer is not empty
       
   114    *
       
   115    * @throws RuntimeException
       
   116    *             If stderr was empty
       
   117    */
       
   118   public void stderrShouldNotBeEmpty() {
       
   119     if (getStderr().isEmpty()) {
       
   120       reportDiagnosticSummary();
       
   121       throw new RuntimeException("stderr was empty");
       
   122     }
       
   123   }
       
   124 
       
   125     /**
    72    * Verify that the stdout and stderr contents of output buffer contains the string
   126    * Verify that the stdout and stderr contents of output buffer contains the string
    73    *
   127    *
    74    * @param expectedString String that buffer should contain
   128    * @param expectedString String that buffer should contain
    75    * @throws RuntimeException If the string was not found
   129    * @throws RuntimeException If the string was not found
    76    */
   130    */
   363    * @return Process exit value
   417    * @return Process exit value
   364    */
   418    */
   365   public int getExitValue() {
   419   public int getExitValue() {
   366     return exitValue;
   420     return exitValue;
   367   }
   421   }
       
   422 
       
   423   /**
       
   424    * Get the contents of the output buffer (stdout and stderr) as list of strings.
       
   425    * Output will be split by newlines.
       
   426    *
       
   427    * @return Contents of the output buffer as list of strings
       
   428    */
       
   429   public List<String> asLines() {
       
   430     return asLines(getOutput());
       
   431   }
       
   432 
       
   433   private List<String> asLines(String buffer) {
       
   434     return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)"));
       
   435   }
   368 }
   436 }