From: <cr...@us...> - 2008-05-06 14:00:03
|
Revision: 4066 http://jnode.svn.sourceforge.net/jnode/?rev=4066&view=rev Author: crawley Date: 2008-05-06 06:59:51 -0700 (Tue, 06 May 2008) Log Message: ----------- Converted TestCommand (aka utest) Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.test.xml trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.test.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-06 11:33:20 UTC (rev 4065) +++ trunk/shell/descriptors/org.jnode.shell.command.test.xml 2008-05-06 13:59:51 UTC (rev 4066) @@ -23,6 +23,12 @@ <alias name="utest" class="org.jnode.shell.command.test.TestCommand"/> <alias name="suite" class="org.jnode.shell.command.test.SuiteCommand"/> </extension> + + <extension point="org.jnode.shell.syntaxes"> + <syntax alias="utest"> + <argument argLabel="className" description="run a JUnit testcase"/> + </syntax> + </extension> <extension point="org.jnode.security.permissions"> <permission class="java.util.PropertyPermission" name="user.home" actions="read"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-05-06 11:33:20 UTC (rev 4065) +++ trunk/shell/src/shell/org/jnode/shell/command/test/TestCommand.java 2008-05-06 13:59:51 UTC (rev 4066) @@ -24,54 +24,49 @@ import java.io.InputStream; import java.io.PrintStream; +import junit.framework.TestResult; import junit.framework.TestSuite; import junit.textui.TestRunner; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.ParsedArguments; -import org.jnode.shell.help.argument.ClassNameArgument; +import org.jnode.shell.AbstractCommand; +import org.jnode.shell.CommandLine; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; /** * @author epr + * @author cr...@jn... */ -public class TestCommand { +public class TestCommand extends AbstractCommand { - static final ClassNameArgument ARG_CLASS = new ClassNameArgument( - "classname", "the class representing the testcase"); + private final ClassNameArgument ARG_CLASS = new ClassNameArgument( + "className", Argument.MANDATORY, "the class representing the testcase"); - // static final Argument ARG_ARGS = new Argument("arg", "the argument(s) to - // pass to the testcase", Argument.MULTI); + public TestCommand() { + super("Run a JUnit testcase"); + registerArguments(ARG_CLASS); + } - public static Help.Info HELP_INFO = new Help.Info("utest", - "Run a JUnit testcase", new Parameter[] { new Parameter(ARG_CLASS, - Parameter.MANDATORY) - // new Parameter(ARG_ARGS, Parameter.OPTIONAL) - }); - public static void main(String[] args) throws Exception { - new TestCommand().execute(HELP_INFO.parse(args), System.in, System.out, - System.err); + new TestCommand().execute(args); } /** * Execute this command + * + * @throws ClassNotFoundException */ - public void execute(ParsedArguments cmdLine, InputStream in, - PrintStream out, PrintStream err) throws Exception { - - Class<?> clazz = ARG_CLASS.getClass(cmdLine); - - JNodeTestRunner.run(clazz); - } - - private static class JNodeTestRunner extends TestRunner { - - public static void run(Class<?> testClass) { - JNodeTestRunner runner = new JNodeTestRunner(); - TestSuite suite = new TestSuite(testClass); - runner.doRun(suite); + public void execute(CommandLine cmdLine, InputStream in, + PrintStream out, PrintStream err) { + try { + Class<?> clazz = ARG_CLASS.getValueAsClass(); + TestResult res = new TestRunner().doRun(new TestSuite(clazz)); + if (!res.wasSuccessful()) { + exit(1); + } + } catch (ClassNotFoundException ex) { + err.println("Class not found: " + ex.getMessage()); + exit(2); } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |