From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20127 invoked by alias); 30 Apr 2008 22:47:39 -0000 Received: (qmail 20100 invoked by uid 367); 30 Apr 2008 22:47:38 -0000 Date: Wed, 30 Apr 2008 22:47:00 -0000 Message-ID: <20080430224738.20085.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Better handle TestRunner class.testName X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 56ff5da9054640e37a187ff37871dc6d02058a0d X-Git-Newrev: 6ffbfe68fd18e6921b5c603c20d1abfcaa2c4f89 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q2/txt/msg00169.txt.bz2 The branch, master has been updated via 6ffbfe68fd18e6921b5c603c20d1abfcaa2c4f89 (commit) from 56ff5da9054640e37a187ff37871dc6d02058a0d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 6ffbfe68fd18e6921b5c603c20d1abfcaa2c4f89 Author: Andrew Cagney Date: Wed Apr 30 18:46:32 2008 -0400 Better handle TestRunner class.testName frysk-sys/frysk/junit/ChangeLog 2008-04-30 Andrew Cagney * Runner.java: Simplify argument mathing; especially class.testName. ----------------------------------------------------------------------- Summary of changes: frysk-sys/frysk/junit/ChangeLog | 5 ++ frysk-sys/frysk/junit/Runner.java | 112 ++++++++++++++++++++---------------- 2 files changed, 67 insertions(+), 50 deletions(-) First 500 lines of diff: diff --git a/frysk-sys/frysk/junit/ChangeLog b/frysk-sys/frysk/junit/ChangeLog index ef99570..dd5ddd2 100644 --- a/frysk-sys/frysk/junit/ChangeLog +++ b/frysk-sys/frysk/junit/ChangeLog @@ -1,3 +1,8 @@ +2008-04-30 Andrew Cagney + + * Runner.java: Simplify argument mathing; especially + class.testName. + 2008-04-17 Andrew Cagney * TestCase.java: Use frysk.config.Prefix. diff --git a/frysk-sys/frysk/junit/Runner.java b/frysk-sys/frysk/junit/Runner.java index 49ade26..add01be 100755 --- a/frysk-sys/frysk/junit/Runner.java +++ b/frysk-sys/frysk/junit/Runner.java @@ -42,6 +42,7 @@ package frysk.junit; import frysk.config.FryskVersion; import frysk.config.Prefix; import frysk.config.Host; +import frysk.rsl.Log; import frysk.rsl.LogOption; import frysk.expunit.Expect; import gnu.classpath.tools.getopt.FileArgumentCallback; @@ -64,6 +65,8 @@ import junit.textui.TestRunner; */ public class Runner extends TestRunner { + private static final Log fine = Log.fine(Runner.class); + // Repeat once by default. private int repeatValue = 1; private Collection testCases = null; @@ -95,61 +98,70 @@ public class Runner extends TestRunner { TestSuite testSuite = new TestSuite (); - if (otherArgs.size() > 0) { - // Construct the testsuite from the list of names. - for (Iterator argIter = otherArgs.listIterator(0); - argIter.hasNext(); ) { - String arg = (String)argIter.next(); - if (arg.charAt(0) == '-') { - this.repeatValue = - Integer.parseInt(arg); - } else { - int lidot = arg.lastIndexOf('.'); - String testName = null; - String testClass = null; - if (arg.substring(lidot + 1).startsWith("test")) { - testClass = arg.substring(0, lidot); - testName = arg.substring(lidot + 1); - } else if (arg.matches("test.*\\(.*\\)")) { - String[] testTuple = arg.split("[\\(\\)]"); - testName = testTuple[0]; - testClass = testTuple[1]; - } else { - testClass = arg; - } + // Construct the testsuite from the list of names. + for (Iterator i = otherArgs.iterator(); i.hasNext(); ) { + String arg = (String) i.next(); + + // A -N argument specifying a repeat count. + if (arg.matches("^-[0-9]*$")) { + repeatValue = - Integer.parseInt(arg); + fine.log(this, "repeat", repeatValue); + continue; + } + + String testMethod; + String testClass; + if (arg.matches("^test.*\\(.*\\)$")) { + // testFoo(frysk.class) + String[] testTuple = arg.split("[\\(\\)]"); + testMethod = testTuple[0]; + testClass = testTuple[1]; + } else if (arg.matches(".*\\.test[A-Z][^.]*")) { + // frysk.class.testMethod + int lidot = arg.lastIndexOf('.'); + testClass = arg.substring(0, lidot); + testMethod = arg.substring(lidot + 1); + } else { + // frysk.class + testClass = arg; + testMethod = null; + } + fine.log(this, "testClass", testClass, "testMethod", testMethod); - for (Iterator classIter = testClasses.iterator(); - classIter.hasNext (); ) { - Class testKlass = (Class)classIter.next (); - if (testName == null) { - // class only - if (testKlass.getName().startsWith(testClass)) { - testSuite.addTest(new TestSuite(testKlass)); - } - } else { - // class.name or name(class) - if (testKlass.getName().equals(testClass)) { - try { - // Probe the class to see if the - // method exists. - testKlass.getMethod(testName, null); - TestCase test = (TestCase)testKlass.newInstance(); - test.setName(testName); - testSuite.addTest(test); - } catch (NoSuchMethodException e) { - System.out.println("Couldn't find test method: " + testClass + "." + testName); - } catch (InstantiationException e) { - System.out.println("Couldn't instantiate class with name: " - + testClass); - } catch (IllegalAccessException e) { - System.out.println("Couldn't access class with name: " - + testClass); - } - } + for (Iterator c = testClasses.iterator(); c.hasNext (); ) { + Class testKlass = (Class) c.next (); + if (testMethod == null) { + // class only + if (testKlass.getName().startsWith(testClass)) { + testSuite.addTest(new TestSuite(testKlass)); + fine.log(this, "adding", testKlass); + } + } else { + // class.name or name(class) + if (testKlass.getName().equals(testClass)) { + try { + // Probe the class to see if the method + // exists. + testKlass.getMethod(testMethod, null); + TestCase test = (TestCase)testKlass.newInstance(); + test.setName(testMethod); + testSuite.addTest(test); + fine.log(this, "adding", testKlass); + } catch (NoSuchMethodException e) { + System.out.println("Couldn't find test method: " + testClass + "." + testMethod); + } catch (InstantiationException e) { + System.out.println("Couldn't instantiate class with name: " + + testClass); + } catch (IllegalAccessException e) { + System.out.println("Couldn't access class with name: " + + testClass); } } } } - } else { + } + + if (otherArgs.size() == 0) { for (Iterator i = testClasses.iterator (); i.hasNext (); ) { Class testKlass = (Class) i.next (); // Only include tests that gets by both filters. hooks/post-receive -- frysk system monitor/debugger