author | epavlova |
Wed, 09 Oct 2019 10:59:45 -0700 | |
changeset 58523 | fb3d408c7a7e |
parent 50908 | 7c51db95ccb6 |
permissions | -rw-r--r-- |
50908 | 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.mxtool.junit; |
|
24 |
||
25 |
import java.io.PrintStream; |
|
26 |
||
27 |
import org.junit.internal.JUnitSystem; |
|
28 |
import org.junit.internal.TextListener; |
|
29 |
import org.junit.runner.Description; |
|
30 |
import org.junit.runner.Result; |
|
31 |
import org.junit.runner.notification.Failure; |
|
32 |
import org.junit.runner.notification.RunListener; |
|
33 |
||
34 |
class TextRunListener implements MxRunListener { |
|
35 |
||
36 |
private final PrintStream fWriter; |
|
37 |
protected Failure lastFailure; |
|
38 |
||
39 |
TextRunListener(JUnitSystem system) { |
|
40 |
this(system.out()); |
|
41 |
} |
|
42 |
||
43 |
TextRunListener(PrintStream writer) { |
|
44 |
fWriter = writer; |
|
45 |
} |
|
46 |
||
47 |
public boolean beVerbose() { |
|
48 |
return false; |
|
49 |
} |
|
50 |
||
51 |
@Override |
|
52 |
public PrintStream getWriter() { |
|
53 |
return fWriter; |
|
54 |
} |
|
55 |
||
56 |
public Failure getLastFailure() { |
|
57 |
return lastFailure; |
|
58 |
} |
|
59 |
||
60 |
@Override |
|
61 |
public void testStarted(Description description) { |
|
62 |
getWriter().print('.'); |
|
63 |
} |
|
64 |
||
65 |
@Override |
|
66 |
public void testFailed(Failure failure) { |
|
67 |
getWriter().print('E'); |
|
68 |
lastFailure = failure; |
|
69 |
} |
|
70 |
||
71 |
@Override |
|
72 |
public void testIgnored(Description description) { |
|
73 |
getWriter().print('I'); |
|
74 |
} |
|
75 |
||
76 |
public static RunListener createRunListener(MxRunListener l) { |
|
58523
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
77 |
PrintStream theWriter = l.getWriter(); |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
78 |
return new TextListener(theWriter) { |
50908 | 79 |
private Class<?> lastClass; |
80 |
private int passedInLastClass; |
|
81 |
private int failedInLastClass; |
|
82 |
private boolean failed; |
|
83 |
||
84 |
@Override |
|
85 |
public void testStarted(Description description) { |
|
86 |
Class<?> currentClass = description.getTestClass(); |
|
87 |
if (currentClass != lastClass) { |
|
88 |
if (lastClass != null) { |
|
89 |
l.testClassFinished(lastClass, passedInLastClass, failedInLastClass); |
|
90 |
l.testClassFinishedDelimiter(); |
|
91 |
} |
|
92 |
lastClass = currentClass; |
|
93 |
passedInLastClass = 0; |
|
94 |
failedInLastClass = 0; |
|
95 |
l.testClassStarted(currentClass); |
|
96 |
l.testClassStartedDelimiter(); |
|
97 |
} |
|
98 |
failed = false; |
|
99 |
l.testStarted(description); |
|
100 |
l.testStartedDelimiter(); |
|
101 |
} |
|
102 |
||
103 |
@Override |
|
104 |
public void testFailure(Failure failure) { |
|
105 |
failed = true; |
|
106 |
failedInLastClass++; |
|
107 |
l.testFailed(failure); |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
public void testFinished(Description description) { |
|
112 |
// we have to do this because there is no callback for successful tests |
|
113 |
if (!failed) { |
|
114 |
l.testSucceeded(description); |
|
115 |
passedInLastClass++; |
|
116 |
} |
|
117 |
l.testFinished(description); |
|
118 |
l.testFinishedDelimiter(); |
|
119 |
} |
|
120 |
||
121 |
@Override |
|
122 |
public void testIgnored(Description description) { |
|
123 |
testStarted(description); |
|
124 |
l.testIgnored(description); |
|
125 |
l.testFinished(description); |
|
126 |
l.testFinishedDelimiter(); |
|
127 |
} |
|
128 |
||
129 |
@Override |
|
130 |
public void testRunStarted(Description description) { |
|
131 |
l.testRunStarted(description); |
|
132 |
} |
|
133 |
||
134 |
@Override |
|
135 |
public void testRunFinished(Result result) { |
|
136 |
if (lastClass != null) { |
|
137 |
l.testClassFinished(lastClass, passedInLastClass, failedInLastClass); |
|
138 |
} |
|
139 |
l.testRunFinished(result); |
|
140 |
super.testRunFinished(result); |
|
141 |
} |
|
142 |
||
143 |
@Override |
|
144 |
public void testAssumptionFailure(Failure failure) { |
|
145 |
l.testAssumptionFailure(failure); |
|
146 |
} |
|
58523
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
147 |
|
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
148 |
@Override |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
149 |
protected void printFailure(Failure each, String prefix) { |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
150 |
// Print out the test message in the same format used to run a single test: |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
151 |
// my.package.MyClass#methodName |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
152 |
String header = each.getDescription().getClassName() + "#" + each.getDescription().getMethodName(); |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
153 |
theWriter.println(prefix + ") " + header); |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
154 |
theWriter.print(each.getTrace()); |
fb3d408c7a7e
8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents:
50908
diff
changeset
|
155 |
} |
50908 | 156 |
}; |
157 |
} |
|
158 |
} |