test/lib/jdk/test/lib/process/OutputAnalyzer.java
author iignatyev
Tue, 16 May 2017 09:04:54 -0700
changeset 45052 d7deaa5e4f97
parent 43172 8c1bd20e4f45
child 49212 48452579de86
permissions -rw-r--r--
8180195: remove jaxp testlibrary Reviewed-by: fyuan, joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     1
/*
40614
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     4
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     8
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    13
 * accompanied this code).
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    14
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    18
 *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    21
 * questions.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    22
 */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    23
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    24
package jdk.test.lib.process;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    25
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    26
import java.io.IOException;
45052
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
    27
import java.io.PrintStream;
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    28
import java.util.Arrays;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    29
import java.util.List;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    30
import java.util.regex.Matcher;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    31
import java.util.regex.Pattern;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    32
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    33
public final class OutputAnalyzer {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    34
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    35
  private final String stdout;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    36
  private final String stderr;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    37
  private final int exitValue;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    38
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    39
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    40
   * Create an OutputAnalyzer, a utility class for verifying output and exit
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    41
   * value from a Process
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    42
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    43
   * @param process Process to analyze
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    44
   * @throws IOException If an I/O error occurs.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    45
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    46
  public OutputAnalyzer(Process process) throws IOException {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    47
    OutputBuffer output = ProcessTools.getOutput(process);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    48
    exitValue = process.exitValue();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    49
    this.stdout = output.getStdout();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    50
    this.stderr = output.getStderr();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    51
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    52
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    53
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    54
   * Create an OutputAnalyzer, a utility class for verifying output
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    55
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    56
   * @param buf String buffer to analyze
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    57
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    58
  public OutputAnalyzer(String buf) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    59
    this(buf, buf);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    60
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    61
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    62
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    63
   * Create an OutputAnalyzer, a utility class for verifying output
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    64
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    65
   * @param stdout stdout buffer to analyze
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    66
   * @param stderr stderr buffer to analyze
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    67
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    68
  public OutputAnalyzer(String stdout, String stderr) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    69
    this.stdout = stdout;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    70
    this.stderr = stderr;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    71
    exitValue = -1;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    72
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    73
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    74
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    75
   * Verify that the stdout contents of output buffer is empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    76
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    77
   * @throws RuntimeException
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    78
   *             If stdout was not empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    79
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    80
  public void stdoutShouldBeEmpty() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    81
    if (!getStdout().isEmpty()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    82
      reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    83
      throw new RuntimeException("stdout was not empty");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    84
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    85
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    86
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    87
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    88
   * Verify that the stderr contents of output buffer is empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    89
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    90
   * @throws RuntimeException
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    91
   *             If stderr was not empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    92
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    93
  public void stderrShouldBeEmpty() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    94
    if (!getStderr().isEmpty()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    95
      reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    96
      throw new RuntimeException("stderr was not empty");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    97
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    98
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
    99
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   100
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   101
   * Verify that the stdout contents of output buffer is not empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   102
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   103
   * @throws RuntimeException
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   104
   *             If stdout was empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   105
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   106
  public void stdoutShouldNotBeEmpty() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   107
    if (getStdout().isEmpty()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   108
      reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   109
      throw new RuntimeException("stdout was empty");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   110
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   111
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   112
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   113
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   114
   * Verify that the stderr contents of output buffer is not empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   115
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   116
   * @throws RuntimeException
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   117
   *             If stderr was empty
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   118
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   119
  public void stderrShouldNotBeEmpty() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   120
    if (getStderr().isEmpty()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   121
      reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   122
      throw new RuntimeException("stderr was empty");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   123
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   124
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   125
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   126
    /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   127
   * Verify that the stdout and stderr contents of output buffer contains the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   128
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   129
   * @param expectedString String that buffer should contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   130
   * @throws RuntimeException If the string was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   131
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   132
  public OutputAnalyzer shouldContain(String expectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   133
    if (!stdout.contains(expectedString) && !stderr.contains(expectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   134
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   135
        throw new RuntimeException("'" + expectedString + "' missing from stdout/stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   136
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   137
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   138
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   139
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   140
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   141
   * Verify that the stdout contents of output buffer contains the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   142
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   143
   * @param expectedString String that buffer should contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   144
   * @throws RuntimeException If the string was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   145
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   146
  public OutputAnalyzer stdoutShouldContain(String expectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   147
    if (!stdout.contains(expectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   148
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   149
        throw new RuntimeException("'" + expectedString + "' missing from stdout \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   150
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   151
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   152
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   153
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   154
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   155
   * Verify that the stderr contents of output buffer contains the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   156
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   157
   * @param expectedString String that buffer should contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   158
   * @throws RuntimeException If the string was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   159
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   160
  public OutputAnalyzer stderrShouldContain(String expectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   161
    if (!stderr.contains(expectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   162
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   163
        throw new RuntimeException("'" + expectedString + "' missing from stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   164
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   165
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   166
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   167
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   168
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   169
   * Verify that the stdout and stderr contents of output buffer does not contain the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   170
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   171
   * @param expectedString String that the buffer should not contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   172
   * @throws RuntimeException If the string was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   173
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   174
  public OutputAnalyzer shouldNotContain(String notExpectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   175
    if (stdout.contains(notExpectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   176
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   177
        throw new RuntimeException("'" + notExpectedString + "' found in stdout \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   178
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   179
    if (stderr.contains(notExpectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   180
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   181
        throw new RuntimeException("'" + notExpectedString + "' found in stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   182
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   183
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   184
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   185
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   186
  /**
43172
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   187
   * Verify that the stdout and stderr contents of output buffer does not contain the string
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   188
   *
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   189
   * @throws RuntimeException If the string was found
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   190
   */
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   191
  public OutputAnalyzer shouldBeEmpty() {
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   192
    if (!stdout.isEmpty()) {
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   193
        reportDiagnosticSummary();
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   194
        throw new RuntimeException("stdout was not empty");
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   195
    }
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   196
    if (!stderr.isEmpty()) {
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   197
        reportDiagnosticSummary();
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   198
        throw new RuntimeException("stderr was not empty");
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   199
    }
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   200
    return this;
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   201
  }
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   202
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   203
  /**
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   204
   * Verify that the stdout contents of output buffer does not contain the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   205
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   206
   * @param expectedString String that the buffer should not contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   207
   * @throws RuntimeException If the string was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   208
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   209
  public OutputAnalyzer stdoutShouldNotContain(String notExpectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   210
    if (stdout.contains(notExpectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   211
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   212
        throw new RuntimeException("'" + notExpectedString + "' found in stdout \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   213
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   214
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   215
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   216
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   217
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   218
   * Verify that the stderr contents of output buffer does not contain the string
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   219
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   220
   * @param expectedString String that the buffer should not contain
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   221
   * @throws RuntimeException If the string was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   222
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   223
  public OutputAnalyzer stderrShouldNotContain(String notExpectedString) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   224
    if (stderr.contains(notExpectedString)) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   225
        reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   226
        throw new RuntimeException("'" + notExpectedString + "' found in stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   227
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   228
    return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   229
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   230
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   231
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   232
   * Verify that the stdout and stderr contents of output buffer matches
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   233
   * the pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   234
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   235
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   236
   * @throws RuntimeException If the pattern was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   237
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   238
  public OutputAnalyzer shouldMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   239
      Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   240
      Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   241
      if (!stdoutMatcher.find() && !stderrMatcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   242
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   243
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   244
                + "' missing from stdout/stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   245
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   246
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   247
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   248
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   249
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   250
   * Verify that the stdout contents of output buffer matches the
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   251
   * pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   252
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   253
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   254
   * @throws RuntimeException If the pattern was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   255
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   256
  public OutputAnalyzer stdoutShouldMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   257
      Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   258
      if (!matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   259
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   260
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   261
                + "' missing from stdout \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   262
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   263
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   264
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   265
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   266
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   267
   * Verify that the stderr contents of output buffer matches the
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   268
   * pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   269
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   270
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   271
   * @throws RuntimeException If the pattern was not found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   272
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   273
  public OutputAnalyzer stderrShouldMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   274
      Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   275
      if (!matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   276
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   277
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   278
                + "' missing from stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   279
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   280
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   281
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   282
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   283
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   284
   * Verify that the stdout and stderr contents of output buffer does not
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   285
   * match the pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   286
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   287
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   288
   * @throws RuntimeException If the pattern was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   289
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   290
  public OutputAnalyzer shouldNotMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   291
      Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   292
      if (matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   293
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   294
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   295
                  + "' found in stdout: '" + matcher.group() + "' \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   296
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   297
      matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   298
      if (matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   299
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   300
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   301
                  + "' found in stderr: '" + matcher.group() + "' \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   302
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   303
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   304
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   305
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   306
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   307
   * Verify that the stdout contents of output buffer does not match the
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   308
   * pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   309
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   310
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   311
   * @throws RuntimeException If the pattern was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   312
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   313
  public OutputAnalyzer stdoutShouldNotMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   314
      Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   315
      if (matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   316
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   317
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   318
                  + "' found in stdout \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   319
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   320
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   321
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   322
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   323
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   324
   * Verify that the stderr contents of output buffer does not match the
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   325
   * pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   326
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   327
   * @param pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   328
   * @throws RuntimeException If the pattern was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   329
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   330
  public OutputAnalyzer stderrShouldNotMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   331
      Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   332
      if (matcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   333
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   334
          throw new RuntimeException("'" + pattern
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   335
                  + "' found in stderr \n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   336
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   337
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   338
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   339
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   340
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   341
   * Get the captured group of the first string matching the pattern.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   342
   * stderr is searched before stdout.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   343
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   344
   * @param pattern The multi-line pattern to match
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   345
   * @param group The group to capture
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   346
   * @return The matched string or null if no match was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   347
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   348
  public String firstMatch(String pattern, int group) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   349
    Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   350
    Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   351
    if (stderrMatcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   352
      return stderrMatcher.group(group);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   353
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   354
    if (stdoutMatcher.find()) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   355
      return stdoutMatcher.group(group);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   356
    }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   357
    return null;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   358
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   359
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   360
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   361
   * Get the first string matching the pattern.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   362
   * stderr is searched before stdout.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   363
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   364
   * @param pattern The multi-line pattern to match
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   365
   * @return The matched string or null if no match was found
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   366
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   367
  public String firstMatch(String pattern) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   368
    return firstMatch(pattern, 0);
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   369
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   370
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   371
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   372
   * Verify the exit value of the process
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   373
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   374
   * @param expectedExitValue Expected exit value from process
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   375
   * @throws RuntimeException If the exit value from the process did not match the expected value
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   376
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   377
  public OutputAnalyzer shouldHaveExitValue(int expectedExitValue) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   378
      if (getExitValue() != expectedExitValue) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   379
          reportDiagnosticSummary();
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   380
          throw new RuntimeException("Expected to get exit value of ["
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   381
                  + expectedExitValue + "]\n");
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   382
      }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   383
      return this;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   384
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   385
43172
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   386
  /**
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   387
   * Verify the exit value of the process
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   388
   *
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   389
   * @param notExpectedExitValue Unexpected exit value from process
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   390
   * @throws RuntimeException If the exit value from the process did match the expected value
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   391
   */
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   392
  public OutputAnalyzer shouldNotHaveExitValue(int notExpectedExitValue) {
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   393
      if (getExitValue() == notExpectedExitValue) {
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   394
          reportDiagnosticSummary();
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   395
          throw new RuntimeException("Unexpected to get exit value of ["
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   396
                  + notExpectedExitValue + "]\n");
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   397
      }
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   398
      return this;
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   399
  }
8c1bd20e4f45 8071566: Improve testing for multi-version JAR file maker tool
anazarov
parents: 40614
diff changeset
   400
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   401
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   402
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   403
   * Report summary that will help to diagnose the problem
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   404
   * Currently includes:
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   405
   *  - standard input produced by the process under test
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   406
   *  - standard output
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   407
   *  - exit code
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   408
   *  Note: the command line is printed by the ProcessTools
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   409
   */
40614
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   410
  public void reportDiagnosticSummary() {
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   411
      String msg =
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   412
          " stdout: [" + stdout + "];\n" +
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   413
          " stderr: [" + stderr + "]\n" +
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   414
          " exitValue = " + getExitValue() + "\n";
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   415
40614
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   416
      System.err.println(msg);
b5d80754b40e 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 34597
diff changeset
   417
  }
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   418
45052
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   419
  /**
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   420
   * Print the stdout buffer to the given {@code PrintStream}.
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   421
   *
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   422
   * @return this OutputAnalyzer
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   423
   */
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   424
  public OutputAnalyzer outputTo(PrintStream out) {
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   425
      out.println(getStdout());
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   426
      return this;
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   427
  }
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   428
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   429
  /**
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   430
   * Print the stderr buffer to the given {@code PrintStream}.
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   431
   *
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   432
   * @return this OutputAnalyzer
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   433
   */
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   434
  public OutputAnalyzer errorTo(PrintStream out) {
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   435
      out.println(getStderr());
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   436
      return this;
d7deaa5e4f97 8180195: remove jaxp testlibrary
iignatyev
parents: 43172
diff changeset
   437
  }
34597
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   438
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   439
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   440
   * Get the contents of the output buffer (stdout and stderr)
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   441
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   442
   * @return Content of the output buffer
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   443
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   444
  public String getOutput() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   445
    return stdout + stderr;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   446
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   447
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   448
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   449
   * Get the contents of the stdout buffer
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   450
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   451
   * @return Content of the stdout buffer
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   452
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   453
  public String getStdout() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   454
    return stdout;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   455
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   456
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   457
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   458
   * Get the contents of the stderr buffer
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   459
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   460
   * @return Content of the stderr buffer
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   461
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   462
  public String getStderr() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   463
    return stderr;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   464
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   465
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   466
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   467
   * Get the process exit value
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   468
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   469
   * @return Process exit value
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   470
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   471
  public int getExitValue() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   472
    return exitValue;
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   473
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   474
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   475
  /**
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   476
   * Get the contents of the output buffer (stdout and stderr) as list of strings.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   477
   * Output will be split by newlines.
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   478
   *
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   479
   * @return Contents of the output buffer as list of strings
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   480
   */
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   481
  public List<String> asLines() {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   482
    return asLines(getOutput());
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   483
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   484
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   485
  private List<String> asLines(String buffer) {
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   486
    return Arrays.asList(buffer.split("(\\r\\n|\\n|\\r)"));
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   487
  }
e5f2344c6fab 8141526: Allow to collect stdout/stderr from the FinalizationRunner even before the process returns
jbachorik
parents:
diff changeset
   488
}