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