15500
|
1 /*
|
|
2 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 * or visit www.oracle.com if you need additional information or have any
|
|
21 * questions.
|
|
22 */
|
|
23 package com.oracle.graal.test;
|
|
24
|
|
25 import java.io.*;
|
|
26
|
|
27 import org.junit.internal.*;
|
|
28 import org.junit.runner.*;
|
|
29 import org.junit.runner.notification.*;
|
|
30
|
|
31 public class GraalTextListener implements GraalJUnitRunListener {
|
|
32
|
|
33 private final PrintStream fWriter;
|
|
34
|
|
35 public GraalTextListener(JUnitSystem system) {
|
|
36 this(system.out());
|
|
37 }
|
|
38
|
|
39 public GraalTextListener(PrintStream writer) {
|
|
40 fWriter = writer;
|
|
41 }
|
|
42
|
|
43 @Override
|
|
44 public PrintStream getWriter() {
|
|
45 return fWriter;
|
|
46 }
|
|
47
|
|
48 @Override
|
|
49 public void testRunStarted(Description description) {
|
|
50 }
|
|
51
|
|
52 @Override
|
|
53 public void testRunFinished(Result result) {
|
|
54 }
|
|
55
|
|
56 @Override
|
|
57 public void testAssumptionFailure(Failure failure) {
|
|
58 }
|
|
59
|
|
60 @Override
|
|
61 public void testClassStarted(Class<?> clazz) {
|
|
62 }
|
|
63
|
|
64 @Override
|
|
65 public void testClassFinished(Class<?> clazz) {
|
|
66 }
|
|
67
|
|
68 @Override
|
|
69 public void testStarted(Description description) {
|
|
70 getWriter().print('.');
|
|
71 }
|
|
72
|
|
73 @Override
|
|
74 public void testFinished(Description description) {
|
|
75 }
|
|
76
|
|
77 @Override
|
|
78 public void testFailed(Failure failure) {
|
|
79 getWriter().print('E');
|
|
80 }
|
|
81
|
|
82 @Override
|
|
83 public void testSucceeded(Description description) {
|
|
84 }
|
|
85
|
|
86 @Override
|
|
87 public void testIgnored(Description description) {
|
|
88 getWriter().print('I');
|
|
89 }
|
|
90
|
|
91 @Override
|
|
92 public void testClassFinishedDelimiter() {
|
|
93 }
|
|
94
|
|
95 @Override
|
|
96 public void testClassStartedDelimiter() {
|
|
97 }
|
|
98
|
|
99 @Override
|
|
100 public void testStartedDelimiter() {
|
|
101 }
|
|
102
|
|
103 @Override
|
|
104 public void testFinishedDelimiter() {
|
|
105 }
|
|
106
|
|
107 public static RunListener createRunListener(GraalJUnitRunListener l) {
|
|
108 return new TextListener(l.getWriter()) {
|
|
109 private Class<?> lastClass;
|
|
110 private boolean failed;
|
|
111
|
|
112 @Override
|
|
113 public final void testStarted(Description description) {
|
|
114 Class<?> currentClass = description.getTestClass();
|
|
115 if (currentClass != lastClass) {
|
|
116 if (lastClass != null) {
|
|
117 l.testClassFinished(lastClass);
|
|
118 l.testClassFinishedDelimiter();
|
|
119 }
|
|
120 lastClass = currentClass;
|
|
121 l.testClassStarted(currentClass);
|
|
122 l.testClassStartedDelimiter();
|
|
123 }
|
|
124 failed = false;
|
|
125 l.testStarted(description);
|
|
126 l.testStartedDelimiter();
|
|
127 }
|
|
128
|
|
129 @Override
|
|
130 public final void testFailure(Failure failure) {
|
|
131 failed = true;
|
|
132 l.testFailed(failure);
|
|
133 }
|
|
134
|
|
135 @Override
|
|
136 public final void testFinished(Description description) {
|
|
137 // we have to do this because there is no callback for successful tests
|
|
138 if (!failed) {
|
|
139 l.testSucceeded(description);
|
|
140 }
|
|
141 l.testFinished(description);
|
|
142 l.testFinishedDelimiter();
|
|
143 }
|
|
144
|
|
145 @Override
|
|
146 public void testIgnored(Description description) {
|
|
147 l.testStarted(description);
|
|
148 l.testStartedDelimiter();
|
|
149 l.testIgnored(description);
|
|
150 l.testFinished(description);
|
|
151 l.testFinishedDelimiter();
|
|
152 }
|
|
153
|
|
154 @Override
|
|
155 public void testRunStarted(Description description) {
|
|
156 l.testRunStarted(description);
|
|
157 }
|
|
158
|
|
159 @Override
|
|
160 public void testRunFinished(Result result) {
|
|
161 if (lastClass != null) {
|
|
162 l.testClassFinished(lastClass);
|
|
163 }
|
|
164 l.testRunFinished(result);
|
|
165 super.testRunFinished(result);
|
|
166 }
|
|
167
|
|
168 @Override
|
|
169 public void testAssumptionFailure(Failure failure) {
|
|
170 l.testAssumptionFailure(failure);
|
|
171 }
|
|
172
|
|
173 };
|
|
174 }
|
|
175
|
|
176 }
|