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