jdk/test/lib/testlibrary/OutputAnalyzerReportingTest.java
author jjg
Mon, 25 Nov 2013 17:42:28 -0800
changeset 21894 3535c1819067
parent 21662 b37eb0c9db8d
child 27189 b90845965ee9
permissions -rw-r--r--
8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21662
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     1
/*
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     4
 *
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     8
 *
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    13
 * accompanied this code).
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    14
 *
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    18
 *
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    21
 * questions.
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    22
 */
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    23
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    24
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    25
/*
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    26
 * @test
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    27
 * @summary Test the OutputAnalyzer reporting functionality,
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    28
 *     such as printing additional diagnostic info
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    29
 *     (exit code, stdout, stderr, command line, etc.)
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    30
 * @library /testlibrary
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    31
 */
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    32
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    33
import java.io.ByteArrayOutputStream;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    34
import java.io.PrintStream;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    35
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    36
import jdk.testlibrary.OutputAnalyzer;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    37
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    38
public class OutputAnalyzerReportingTest {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    39
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    41
        // Create the output analyzer under test
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    42
        String stdout = "aaaaaa";
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    43
        String stderr = "bbbbbb";
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    44
        OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    45
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    46
        // Expected summary values should be the same for all cases,
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    47
        // since the outputAnalyzer object is the same
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    48
        String expectedExitValue = "-1";
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    49
        String expectedSummary =
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    50
                " stdout: [" + stdout + "];\n" +
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    51
                " stderr: [" + stderr + "]\n" +
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    52
                " exitValue = " + expectedExitValue + "\n";
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    53
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    54
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    55
        DiagnosticSummaryTestRunner testRunner =
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    56
                new DiagnosticSummaryTestRunner();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    57
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    58
        // should have exit value
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    59
        testRunner.init(expectedSummary);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    60
        int unexpectedExitValue = 2;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    61
        try {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    62
            output.shouldHaveExitValue(unexpectedExitValue);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    63
        } catch (RuntimeException e) { }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    64
        testRunner.closeAndCheckResults();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    65
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    66
        // should not contain
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    67
        testRunner.init(expectedSummary);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    68
        try {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    69
            output.shouldNotContain(stdout);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    70
        } catch (RuntimeException e) { }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    71
        testRunner.closeAndCheckResults();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    72
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    73
        // should contain
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    74
        testRunner.init(expectedSummary);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    75
        try {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    76
            output.shouldContain("unexpected-stuff");
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    77
        } catch (RuntimeException e) { }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    78
        testRunner.closeAndCheckResults();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    79
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    80
        // should not match
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    81
        testRunner.init(expectedSummary);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    82
        try {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    83
            output.shouldNotMatch("[a]");
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    84
        } catch (RuntimeException e) { }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    85
        testRunner.closeAndCheckResults();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    86
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    87
        // should match
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    88
        testRunner.init(expectedSummary);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    89
        try {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    90
            output.shouldMatch("[qwerty]");
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    91
        } catch (RuntimeException e) { }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    92
        testRunner.closeAndCheckResults();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    93
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    94
    }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    95
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    96
    private static class DiagnosticSummaryTestRunner {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    97
        private ByteArrayOutputStream byteStream =
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    98
                new ByteArrayOutputStream(10000);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
    99
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   100
        private String expectedSummary = "";
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   101
        private PrintStream errStream;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   102
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   103
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   104
        public void init(String expectedSummary) {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   105
            this.expectedSummary = expectedSummary;
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   106
            byteStream.reset();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   107
            errStream = new PrintStream(byteStream);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   108
            System.setErr(errStream);
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   109
        }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   110
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   111
        public void closeAndCheckResults() {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   112
            // check results
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   113
            errStream.close();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   114
            String stdErrStr = byteStream.toString();
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   115
            if (!stdErrStr.contains(expectedSummary)) {
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   116
                throw new RuntimeException("The output does not contain "
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   117
                    + "the diagnostic message, or the message is incorrect");
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   118
            }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   119
        }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   120
    }
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   121
b37eb0c9db8d 8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff changeset
   122
}