blob: 1807c65f91363cb2780510d92832c6a3c60f9983 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* Copyright 2011 Red Hat, Inc.
* Based on code from JUnit
*
* This file is made available under the terms of the Common Public License
* v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.internal.JUnitSystem;
import org.junit.internal.RealSystem;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
public class CommandLine extends JUnitCore {
public static void main(String... args) {
runMainAndExit(new RealSystem(), args);
}
public static void runMainAndExit(JUnitSystem system, String... args) {
new CommandLine().runMain(system, args);
system.exit(0);
}
@Override
public Result runMain(JUnitSystem system, String... args) {
List<Class<?>> classes = new ArrayList<Class<?>>();
List<Failure> missingClasses = new ArrayList<Failure>();
for (String each : args) {
try {
if (each.contains("$")) continue;
if (each.toLowerCase().endsWith(".jnlp")) continue;
classes.add(Class.forName(each));
} catch (ClassNotFoundException e) {
system.out().println("ERROR: Could not find class: " + each);
}
}
RunListener jXmlOutput = new JunitLikeXmlOutputListener(system, new File("tests-output.xml"));
addListener(jXmlOutput);
RunListener listener = new LessVerboseTextListener(system);
addListener(listener);
Result result = run(classes.toArray(new Class[0]));
for (Failure each : missingClasses) {
result.getFailures().add(each);
}
return result;
}
}
|