Thread: [Nice-commit] Nice/src/nice/tools/ant TestListener.nice,NONE,1.1 NiceUnit.java,NONE,1.1
Brought to you by:
bonniot
From: <bo...@us...> - 2004-02-18 16:57:21
|
Update of /cvsroot/nice/Nice/src/nice/tools/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13574/src/nice/tools/ant Added Files: TestListener.nice NiceUnit.java Log Message: Ant support for NiceUnit. --- NEW FILE: TestListener.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package nice.tools.ant; import nice.tools.unit; import org.apache.tools.ant.*; /** Listener for NiceUnit that reports to Ant. @author Daniel Bonniot (bo...@us...) */ class TestListener implements nice.tools.unit.TestListener { org.apache.tools.ant.Task task; private int failures = 0; private int tests = 0; start(test) { task.log("Running " + test, Project.MSG_VERBOSE); } end(test) { tests++; task.log("Finished " + test, Project.MSG_DEBUG); } failure(test, cause) { failures++; task.log("Test failed:\n " + cause); let couldPrint = iterLocations (test, cause, (?String file, String method, int line) => println("Location: " + file + " method " + method + (line < 0 ? "" : " line " + line))); if (! couldPrint) cause.printStackTrace(); } void printSummary() { if (failures > 0) throw new BuildException(""failures" tests failed", task.getLocation); task.log("Unit testing done: "tests" tests successful", Project.MSG_INFO); } } --- NEW FILE: NiceUnit.java --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package nice.tools.ant; import org.apache.tools.ant.*; import org.apache.tools.ant.types.*; import java.io.File; import java.util.Vector; import bossa.modules.Compilation; /** <h2><a name="java">NiceUnit</a></h2> <h3>Description</h3> <p>Runs unit tests for a Nice package.</p> All arguments to the NiceUnit task have to be placed as attributes in the niceunit xml-element. <h3>Parameters</h3> <table border="1" cellpadding="2" cellspacing="0"> <tr> <td valign="top"><b>Attribute</b></td> <td valign="top"><b>Description</b></td> <td align="center" valign="top"><b>Required</b></td> </tr> <tr> <td valign="top">package</td> <td valign="top">The Nice package to test.</td> <td align="center" valign="top">Yes</td> </tr> <tr> <td valign="top">classpath</td> <td valign="top">Search path for compiled packages and libraries.</td> <td align="center" valign="top">No</td> </tr> </table> <h4>classpath</h4> <p><code>NiceUnit</code>'s <i>classpath</i> attribute is a PATH like structure and can also be set via a nested <i>classpath</i> element. This is very reasonable if you want to make your build script's pathes platform independent. </p> <h5>Example</h5> <pre> <niceunit package="test" > <classpath> <pathelement location="\test.jar"/> <pathelement path="${java.class.path}"/> </classpath> </niceunit> </pre> <p>It is possible to use the <i>classpath</i> attribute together with the <i>classpath<i> nested tag. In this case the result is a concatenated path.</p> <p>It is highly recommended to use the nested version!<p> <h3>Examples</h3> <pre> <taskdef name="niceunit" classname="nice.tools.ant.NiceUnit"/> <target name="nice-tests"> <niceunit package="test" /> </target> </pre> * @author Daniel Bonniot */ public class NiceUnit extends Task { /** Search path for compiled packages and libraries. */ private String classpath = ""; public void setClasspath(String classpath) { this.classpath = classpath; } /** Location of nice.jar */ private String runtime = null; public void setRuntime(String runtime) { this.runtime = runtime; } /** The package to test. */ private String pack; public void setPackage(String pack) { this.pack = pack; } private Path nestedClasspath = null; /** * Creates a nested classpath element */ public Path createClasspath() { nestedClasspath = new Path(project); return nestedClasspath.createPath(); } /** Executes niceunit. */ public void execute() throws BuildException { String oldUserDir = System.getProperty("user.dir"); try { System.setProperty("user.dir", project.getBaseDir().getAbsolutePath()); TestListener listener = new TestListener(this); String classpath = this.classpath + (nestedClasspath != null ? File.pathSeparator+nestedClasspath : ""); if (! nice.tools.unit.fun.runTests(pack, listener, classpath)) throw new BuildException("Package " + pack + " was not found"); dispatch.printSummary(listener); } finally { System.setProperty("user.dir", oldUserDir); } } } // Setting for Emacs // Local variables: // tab-width:2 // indent-tabs-mode:t // End: |