mirror of
https://github.com/nicolabs/ciform.git
synced 2026-04-11 08:36:19 +02:00
# /ciform/ant-jsunit -> /ant-jsunit-hieatt
This commit is contained in:
parent
1955729617
commit
12f8b67e36
40
ant-jsunit-hieatt/trunk/build.properties
Normal file
40
ant-jsunit-hieatt/trunk/build.properties
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
########################################
|
||||
#
|
||||
# This file is a convenient way to define some parameters
|
||||
# specific to the project, rather than from inside the build script.
|
||||
#
|
||||
# Depending on the ant targets that will be invoked,
|
||||
# some properties will be required, some others won't.
|
||||
#
|
||||
# Usually you should not need to override those properties.
|
||||
# If you really need to, you can create a new file called "local.properties"
|
||||
# in the same directory and put inside any property you want to fit your local configuration.
|
||||
#
|
||||
# If you don't wish to create such a file, you can pass the required properties
|
||||
# to ant as command line arguments using the -D option.
|
||||
#
|
||||
# Do NOT commit the "local.properties" file to the version control system
|
||||
# (CVS, SVN, ...) : it should stay as a local configuration only.
|
||||
# Do not modify or remove this file from the v.c.s. either ;-o
|
||||
#
|
||||
########################################
|
||||
|
||||
# Where the source files are : here Maven-style
|
||||
src.dir=${basedir}/src/main/java
|
||||
# Where to find resources required at execution time
|
||||
rc.dir=${basedir}/src/main/resources
|
||||
|
||||
# Where to find third party libraries
|
||||
lib.dir=lib
|
||||
|
||||
# A working directory to store temporary files
|
||||
build.dir=${basedir}/build
|
||||
|
||||
# Where to find the tests sources
|
||||
tests.dir=${basedir}/src/test/java
|
||||
|
||||
# Where to create the packages
|
||||
target.dir=${basedir}/target
|
||||
|
||||
# Where to copy the api documentation
|
||||
doc.dir=${target.dir}/api
|
||||
108
ant-jsunit-hieatt/trunk/build.xml
Normal file
108
ant-jsunit-hieatt/trunk/build.xml
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<!--
|
||||
Build script for the project "ant-jsunit-hieatt".
|
||||
|
||||
This script is an Ant script using Ivy extension to resolve dependencies.
|
||||
You will need both Ant (http://ant.apache.org/) and Ivy (http://ant.apache.org/ivy) to use it.
|
||||
-->
|
||||
<project name="ant-jsunit-hieatt" default="verify" xmlns:ivy="antlib:org.apache.ivy.ant">
|
||||
|
||||
|
||||
<!-- ==================== -->
|
||||
<!-- Settings -->
|
||||
<!-- ==================== -->
|
||||
|
||||
<!-- custom, user specific, properties -->
|
||||
<property file="local.properties"/>
|
||||
<!-- default properties -->
|
||||
<property file="build.properties"/>
|
||||
|
||||
|
||||
<!-- ==================== -->
|
||||
<!-- Public targets : they are greatly inspired from the Maven build lifecycle -->
|
||||
<!-- ==================== -->
|
||||
|
||||
|
||||
<target name="clean" description="Restores the initial state of the project, deleting any generated file.">
|
||||
<delete includeemptydirs="true" dir="${target.dir}"/>
|
||||
<delete includeemptydirs="true" dir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="validate" description="Validates the project is correct and all necessary information is available.">
|
||||
<!-- Retreives dependencies with ivy -->
|
||||
<ivy:retrieve/>
|
||||
<!-- Creates necessary directories -->
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<mkdir dir="${target.dir}" />
|
||||
</target>
|
||||
|
||||
|
||||
<target name="compile" depends="validate" description="Compiles the source code of the project.">
|
||||
|
||||
<javac srcdir="${src.dir}" destdir="${build.dir}" source="1.4">
|
||||
<src path="${src.dir}" />
|
||||
<src path="${tests.dir}" />
|
||||
<classpath>
|
||||
<fileset dir="${lib.dir}">
|
||||
<include name="*.jar"/>
|
||||
</fileset>
|
||||
</classpath>
|
||||
</javac>
|
||||
|
||||
<dirset dir="/home/cbonar/src/jsunit/java/bin"/>
|
||||
<dirset dir="${jsunit.dir}/java/config"/>
|
||||
|
||||
<copy todir="${build.dir}">
|
||||
<fileset dir="${rc.dir}" />
|
||||
</copy>
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
<!-- NOTE : These tests should not require the code be packaged or deployed. -->
|
||||
<target name="test" depends="compile" description="Tests the compiled source code using a suitable unit testing framework.">
|
||||
<!-- nothing to do -->
|
||||
</target>
|
||||
|
||||
|
||||
<target name="package" depends="test, doc" description="Takes the compiled code and package it in its distributable format.">
|
||||
|
||||
<jar destfile="${target.dir}/${ant.project.name}-${ivy.revision}.jar"
|
||||
basedir="${build.dir}">
|
||||
<include name="**/*"/>
|
||||
</jar>
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
<target name="integration-test" depends="package" description="Processes and deploys the package if necessary into an environment where integration tests can be run.">
|
||||
<!-- nothing to do -->
|
||||
</target>
|
||||
|
||||
|
||||
<target name="verify" depends="integration-test" description="Runs any checks to verify the package is valid and meets quality criteria.">
|
||||
<!-- nothing to do -->
|
||||
</target>
|
||||
|
||||
|
||||
<target name="install" depends="verify" description="Installs the package into the local repository, for use as a dependency in other projects locally.">
|
||||
<!-- nothing to do -->
|
||||
</target>
|
||||
|
||||
|
||||
<target name="deploy" depends="verify" description="Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.">
|
||||
<!-- nothing to do -->
|
||||
</target>
|
||||
|
||||
|
||||
<!-- ==================== -->
|
||||
<!-- Internal targets -->
|
||||
<!-- ==================== -->
|
||||
|
||||
|
||||
<!-- Generates developer documentation. -->
|
||||
<target name="doc" depends="validate">
|
||||
</target>
|
||||
|
||||
|
||||
</project>
|
||||
20
ant-jsunit-hieatt/trunk/ivy.xml
Normal file
20
ant-jsunit-hieatt/trunk/ivy.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<ivy-module version="2.0">
|
||||
<info organisation="nicommons" module="ant-jsunit-hieatt" revision="1.0" status="integration">
|
||||
<ivyauthor name="Nicolas BONARDELLE" url="http://nicobo.net/contact?subject=ant-jsunit-hieatt" />
|
||||
<repository name="plugnauth@sourceforge" url="http://plugnauth.sourceforge.net/ivy" ivys="true" artifacts="true" />
|
||||
<description homepage="http://plugnauth.sourceforge.net/ant-jsunit-hieatt">
|
||||
An ant task for Edward Hieatt's JsUnit.
|
||||
</description>
|
||||
</info>
|
||||
<publications>
|
||||
<!-- The source script as plain text, including all inner informations and comments. -->
|
||||
<artifact name="ant-jsunit-hieatt" type="javascript" ext="js" />
|
||||
<!-- An obfuscated, size-reduced version of the script. Use to speed up loading time in final environment. -->
|
||||
<artifact name="ant-jsunit-hieatt" type="javascript" ext="js" />
|
||||
</publications>
|
||||
<dependencies>
|
||||
<!-- Ant : not yet implemented -->
|
||||
<!-- JUnit : not yet implemented -->
|
||||
<!-- JsUnit : not yet implemented -->
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
BIN
ant-jsunit-hieatt/trunk/lib/ant-junit.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/ant-junit.jar
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/ant.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/ant.jar
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/apache-ant-1.7.1-src.zip
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/apache-ant-1.7.1-src.zip
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/ivy-2.0.0-beta2.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/ivy-2.0.0-beta2.jar
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/jdom.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/jdom.jar
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/jsunit.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/jsunit.jar
Normal file
Binary file not shown.
BIN
ant-jsunit-hieatt/trunk/lib/junit.jar
Normal file
BIN
ant-jsunit-hieatt/trunk/lib/junit.jar
Normal file
Binary file not shown.
|
|
@ -0,0 +1,70 @@
|
|||
package net.jsunit;
|
||||
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import net.jsunit.StandaloneTest;
|
||||
import net.jsunit.configuration.Configuration;
|
||||
import net.jsunit.configuration.ConfigurationSource;
|
||||
import net.jsunit.configuration.DelegatingConfigurationSource;
|
||||
import net.jsunit.model.Browser;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates a JsUnit test suite page giving resources and executes it against
|
||||
* JUnit.
|
||||
*
|
||||
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||
*/
|
||||
public class GeneratedStandaloneTest extends StandaloneTest
|
||||
{
|
||||
|
||||
//
|
||||
// INITIALISATION
|
||||
//
|
||||
|
||||
public GeneratedStandaloneTest( String name )
|
||||
{
|
||||
super( name );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GeneratedStandaloneTest( ConfigurationSource source )
|
||||
{
|
||||
super( "" );//new GeneratedConfigurationSource( source ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// JUNIT SPECIFICATIONS
|
||||
//
|
||||
|
||||
public static Test suite()
|
||||
{
|
||||
try
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
ConfigurationSource originalSource = Configuration.resolveSource();
|
||||
Configuration configuration = new Configuration( originalSource );
|
||||
for ( final Browser browser : configuration.getBrowsers() )
|
||||
{
|
||||
suite.addTest( new GeneratedStandaloneTest( new DelegatingConfigurationSource( originalSource ) {
|
||||
public String browserFileNames()
|
||||
{
|
||||
return browser.getFileName();
|
||||
}
|
||||
} ) );
|
||||
}
|
||||
return suite;
|
||||
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace( System.err );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package net.jsunit.ant;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A simple class to represent a JsUnit test.
|
||||
* </p>
|
||||
*
|
||||
* <p>It is composed of a set of <script> tags, represented by the included {@link FileSet}s.
|
||||
* </p>
|
||||
*
|
||||
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||
*/
|
||||
public class JsUnitTestTask extends JUnitTest
|
||||
{
|
||||
|
||||
/** Known type for Javascript tags */
|
||||
public static final String TYPE_JAVASCRIPT = "text/javascript";
|
||||
|
||||
//
|
||||
// INITIALISATION
|
||||
//
|
||||
|
||||
/** All resources to include in the test suite page */
|
||||
private List filesets = new Vector();
|
||||
|
||||
/** Defaults to {@link #TYPE_JAVASCRIPT} */
|
||||
private String type = TYPE_JAVASCRIPT;
|
||||
|
||||
|
||||
|
||||
public JsUnitTestTask( String name, boolean haltOnError,
|
||||
boolean haltOnFailure, boolean filtertrace, String type )
|
||||
{
|
||||
super( name, haltOnError, haltOnFailure, filtertrace );
|
||||
setType( type );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JsUnitTestTask( String name )
|
||||
{
|
||||
super( name );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JsUnitTestTask()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List getFilesets()
|
||||
{
|
||||
return filesets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setFilesets( List filesets )
|
||||
{
|
||||
this.filesets = filesets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// NEW ANT FIELDS
|
||||
//
|
||||
|
||||
/** The <tt>type</tt> attribute of the <script> tag to be generated. */
|
||||
public String getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addFileSet( FileSet fs )
|
||||
{
|
||||
getFilesets().add( fs );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,356 @@
|
|||
package net.jsunit.ant;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.jsunit.GeneratedStandaloneTest;
|
||||
import net.jsunit.StandaloneTest;
|
||||
import net.jsunit.configuration.ConfigurationProperty;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.taskdefs.optional.junit.JUnitTask;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This task permits convenient access to the {@link GeneratedStandaloneTest}
|
||||
* unit test.
|
||||
*
|
||||
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||
*/
|
||||
public class StandaloneTestTask extends JUnitTask
|
||||
{
|
||||
/** Name of the property pointing to the root directory of the JsUnit installation */
|
||||
public static final String PROP_JSUNITROOT = "jsunit.dir";
|
||||
/** Name of the property pointing to the JsUnit core library's file */
|
||||
public static final String PROP_COREJS = "jsunit.coreJs";
|
||||
/** Name of the property pointing to the JsUnit's <tt>testRunner.html</tt> file */
|
||||
public static final String PROP_TESTRUNNER = "jsunit.testRunner";
|
||||
|
||||
/** Inner {@link JsUnitTestTask} elements */
|
||||
private Collection scriptsList = new Vector();
|
||||
private boolean runTests = true;
|
||||
private boolean keepTestPage = false;
|
||||
private String jsUnitRoot;
|
||||
private String coreJs;
|
||||
private String testRunner;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// INITIALISATION
|
||||
//
|
||||
|
||||
public StandaloneTestTask() throws Exception
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Collection getScriptsList()
|
||||
{
|
||||
return scriptsList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void setScriptsList( Collection scriptsList )
|
||||
{
|
||||
this.scriptsList = scriptsList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ANT Task IMPLEMENTATION
|
||||
//
|
||||
|
||||
public void addConfiguredTest( JsUnitTestTask anInner )
|
||||
{
|
||||
// Simply saves the gathered inner elements
|
||||
getScriptsList().add( anInner );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getJsUnitRoot()
|
||||
{
|
||||
return jsUnitRoot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setJsUnitRoot( String jsUnitRoot )
|
||||
{
|
||||
this.jsUnitRoot = jsUnitRoot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isKeepTestPage()
|
||||
{
|
||||
return keepTestPage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setKeepTestPage( boolean keepTestPage )
|
||||
{
|
||||
this.keepTestPage = keepTestPage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isRunTests()
|
||||
{
|
||||
return runTests;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setRunTests( boolean runTests )
|
||||
{
|
||||
this.runTests = runTests;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getCoreJs()
|
||||
{
|
||||
return coreJs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setCoreJs( String coreJs )
|
||||
{
|
||||
this.coreJs = coreJs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getTestRunner()
|
||||
{
|
||||
return testRunner;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setTestRunner( String testRunner )
|
||||
{
|
||||
this.testRunner = testRunner;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void execute()
|
||||
{
|
||||
// A list of the URI of the files to include mapped to their type as key
|
||||
Map scriptsFiles = new Hashtable();
|
||||
|
||||
if ( getScriptsList() == null || getScriptsList().size() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "No <script/> element !" );
|
||||
}
|
||||
|
||||
// Several elements of this type can be nested inside.
|
||||
for ( Iterator itl = getScriptsList().iterator(); itl.hasNext(); )
|
||||
{
|
||||
JsUnitTestTask files = (JsUnitTestTask) itl.next();
|
||||
// Adds the inner list for this type of script, indexed on the
|
||||
// type's name
|
||||
if ( !scriptsFiles.containsKey( files.getType() ) )
|
||||
{
|
||||
scriptsFiles.put( files.getType(), new Vector() );
|
||||
}
|
||||
// Scans and adds all given input files to their respective type's
|
||||
// list
|
||||
for ( Iterator itr = files.getFilesets().iterator(); itr.hasNext(); )
|
||||
{
|
||||
FileSet fs = (FileSet) itr.next();
|
||||
DirectoryScanner ds = fs.getDirectoryScanner();
|
||||
for ( int f = 0; f < ds.getIncludedFiles().length; f++ )
|
||||
{
|
||||
File file = new File( ds.getBasedir(), ds.getIncludedFiles()[f] );
|
||||
((Collection) scriptsFiles.get( files.getType() )).add( file.toURI() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the parameters
|
||||
String project = getProject().getName();
|
||||
String jsUnitRoot = getJsUnitRoot() != null ? getJsUnitRoot() : getProject().getProperty( PROP_JSUNITROOT );
|
||||
String coreJs = getCoreJs() != null ? getCoreJs() : getProject().getProperty( PROP_COREJS );
|
||||
String testRunner = getTestRunner() != null ? getTestRunner() : getProject().getProperty( PROP_TESTRUNNER );
|
||||
|
||||
// Checks the parameters
|
||||
if ( jsUnitRoot != null )
|
||||
{
|
||||
if ( coreJs == null )
|
||||
{
|
||||
coreJs = new File( jsUnitRoot, "app/jsUnitCore.js" ).getAbsolutePath();
|
||||
}
|
||||
if ( testRunner == null )
|
||||
{
|
||||
testRunner = new File( jsUnitRoot, "testRunner.html" ).getAbsolutePath();
|
||||
}
|
||||
}
|
||||
if ( coreJs == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Missing property coreJs" );
|
||||
}
|
||||
if ( testRunner == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Missing property testRunner" );
|
||||
}
|
||||
|
||||
// Builds the test suite page
|
||||
File testPage = null;
|
||||
try
|
||||
{
|
||||
testPage = buildTestSuitePage( project, coreJs, scriptsFiles );
|
||||
String url = buildURL( testRunner, testPage );
|
||||
System.setProperty( ConfigurationProperty.URL.getName(), url );
|
||||
// TODO : allow fork and find a way to pass parameters without system properties
|
||||
setFork( false );
|
||||
}
|
||||
catch ( URISyntaxException urise )
|
||||
{
|
||||
throw new BuildException( urise );
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
{
|
||||
throw new BuildException( ioe );
|
||||
}
|
||||
|
||||
// Lets the superclass do the job (will start the included test)
|
||||
if ( isRunTests() )
|
||||
{
|
||||
// Adds all tests to the test suite (TODO : what implications with more than one test ?)
|
||||
for ( Iterator itt = getScriptsList().iterator(); itt.hasNext(); )
|
||||
{
|
||||
JsUnitTestTask test = (JsUnitTestTask) itt.next();
|
||||
test.setName( StandaloneTest.class.getName() );
|
||||
// TODO : allow fork and find a way to pass parameters without system properties
|
||||
test.setFork( false );
|
||||
addTest( test );
|
||||
}
|
||||
|
||||
// Really starts the test
|
||||
super.execute();
|
||||
}
|
||||
|
||||
if ( !isKeepTestPage() )
|
||||
{
|
||||
// After execution, removes temporary files if asked
|
||||
testPage.deleteOnExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// UTILITY METHODS
|
||||
//
|
||||
|
||||
/** The best effort to get a well formed URI */
|
||||
private static URI buildURI( String text ) throws URISyntaxException
|
||||
{
|
||||
try
|
||||
{
|
||||
return new URL( text ).toURI();
|
||||
}
|
||||
catch ( MalformedURLException murle )
|
||||
{
|
||||
return new File( text ).toURI();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Writes a complete JsUnit test suite page from the current environment
|
||||
* into a temporary file.
|
||||
*
|
||||
* @return The generated test page
|
||||
* @throws IllegalArgumentException
|
||||
* if a required property is missing
|
||||
*/
|
||||
private static File buildTestSuitePage( String project, String JsUnitCore,
|
||||
Map includes, String filename ) throws IOException,
|
||||
URISyntaxException
|
||||
{
|
||||
// Reads the template of the test suite page to generate into a local
|
||||
// buffer
|
||||
InputStream is = StandaloneTest.class.getResourceAsStream( "TestSuite.html" );
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for ( int c = is.read(); c > -1; c = is.read() )
|
||||
{
|
||||
buffer.append( (char) c );
|
||||
}
|
||||
is.close();
|
||||
|
||||
// Replaces the variable parts of the template
|
||||
String out = buffer.toString();
|
||||
out = out.replaceAll( "@project@", project );
|
||||
out = out.replace( "@jsUnitCore.js@", JsUnitCore );
|
||||
StringBuffer includesBuffer = new StringBuffer();
|
||||
// Currently only Javascript is supported
|
||||
Collection javascripts = (Collection) includes.get( JsUnitTestTask.TYPE_JAVASCRIPT );
|
||||
//for ( int i = 0; i < javascripts.length; i++ )
|
||||
for ( Iterator itj = javascripts.iterator(); itj.hasNext(); )
|
||||
{
|
||||
URI javascript = (URI) itj.next();
|
||||
includesBuffer.append( "<script type=\"text/javascript\" src=\"" );
|
||||
includesBuffer.append( javascript/*new File( javascripts[i] ).toURI()*/);
|
||||
includesBuffer.append( "\"></script>\n" );
|
||||
}
|
||||
out = out.replace( "@includes@", includesBuffer.toString() );
|
||||
|
||||
// writes the generated test suite to a temporary file
|
||||
File testSuitePage = filename != null ? new File( filename ) : File.createTempFile( "jsunit-", ".tmp" );
|
||||
FileWriter fw = new FileWriter( testSuitePage );
|
||||
fw.write( out );
|
||||
fw.close();
|
||||
|
||||
return testSuitePage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static File buildTestSuitePage( String project, String JsUnitCore,
|
||||
Map includes ) throws IOException, URISyntaxException
|
||||
{
|
||||
return buildTestSuitePage( project, JsUnitCore, includes, null );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before calling this method, make sure {@link #setTestSuitePage(File)} has been correctly set.
|
||||
* @throws IllegalStateException if a property is missing or is incorrect
|
||||
*/
|
||||
private String buildURL( String testRunner, File testPage )
|
||||
throws URISyntaxException, IOException
|
||||
{
|
||||
URI uri = buildURI( testRunner );
|
||||
return new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), "testPage="
|
||||
+ testPage.getPath(), uri.getFragment() ).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Test Page for @project@</title>
|
||||
|
||||
<!-- JsUnit requirement -->
|
||||
<script type="text/javascript" src="@jsUnitCore.js@"></script>
|
||||
|
||||
<!-- All other requirements, including unit tests and the functions to test -->
|
||||
@includes@
|
||||
|
||||
<!-- "Automagically" detects test functions -->
|
||||
<script type="text/javascript">
|
||||
function exposeTestFunctionNames()
|
||||
{
|
||||
var tests = new Array();
|
||||
for ( var o in window ) {
|
||||
if( o.match(/^test/) && typeof(window[o]) == "function" ) {
|
||||
tests.push(o);
|
||||
}
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!--
|
||||
A minimal body to inform readers of the way to use this file.
|
||||
-->
|
||||
<h1>Test Page for @project@</h1>
|
||||
<p>
|
||||
This page is a unit test.<br/>
|
||||
It must be open with <a href="http://www.jsunit.net/">JsUnit's</a> TestRunner</a>.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
package net.jsunit;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This configuration redefines {@link #url()} to point to a custom file
|
||||
* and gathers automatically some more properties.
|
||||
*
|
||||
* @author http://nicobo.net/contact?subject=jsunit+ant
|
||||
*/
|
||||
public class GeneratedConfigurationSource //extends DelegatingConfigurationSource
|
||||
{
|
||||
// //
|
||||
// // CONSTANTS
|
||||
// //
|
||||
//
|
||||
// /**
|
||||
// * Property name defining the Javascript files to include in the test suite
|
||||
// * page.
|
||||
// */
|
||||
// public static final String PROP_JAVASCRIPTS = "jsunit.in.javascripts";
|
||||
//
|
||||
// /**
|
||||
// * Associates a type of script to the corresponding property where their
|
||||
// * name is stored.
|
||||
// */
|
||||
// public static final String[][] TYPE_PROP = { { JsUnitTestTask.TYPE_JAVASCRIPT, PROP_JAVASCRIPTS } };
|
||||
//
|
||||
// //
|
||||
// // PRIVATE FIELDS
|
||||
// //
|
||||
//
|
||||
// /** The generated test suite page */
|
||||
// private File testSuitePage = null;
|
||||
// private String project;
|
||||
// private String coreJs;
|
||||
// private String testRunner;
|
||||
// private Map includes;
|
||||
//
|
||||
//
|
||||
//
|
||||
// //
|
||||
// // INITIALISATION
|
||||
// //
|
||||
//
|
||||
// public GeneratedConfigurationSource( /*ConfigurationSource source,*/
|
||||
// String project, String coreJs, String testRunner )
|
||||
// throws URISyntaxException
|
||||
// {
|
||||
// //super( source );
|
||||
//
|
||||
// // Checks for required parameters
|
||||
// if ( System.getProperty( PROP_JAVASCRIPTS ) == null )
|
||||
// {
|
||||
// throw new IllegalArgumentException( "Missing required property "
|
||||
// + PROP_JAVASCRIPTS );
|
||||
// }
|
||||
//
|
||||
// setProject( project );
|
||||
// setCoreJs( coreJs );
|
||||
// setTestRunner( testRunner );
|
||||
//
|
||||
// // Gathers all parameters
|
||||
// // TODO Allow generic URI to be included in the generated file
|
||||
// Map includes = new Hashtable();
|
||||
// for ( int s = 0; s < TYPE_PROP.length; s++ )
|
||||
// {
|
||||
// String[] files = System.getProperty( TYPE_PROP[s][1] ).split( File.pathSeparator );
|
||||
// // indexed on the property's type
|
||||
// includes.put( TYPE_PROP[s][0], files );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public GeneratedConfigurationSource( /*ConfigurationSource source */)
|
||||
// throws URISyntaxException
|
||||
// {
|
||||
// this( /*Configuration.resolveSource(),*/"a JsUnit test suite", getRequiredURISystemProperty( PROP_COREJS ), getRequiredURISystemProperty( PROP_TESTRUNNER ) );
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// // public GeneratedConfigurationSource() throws URISyntaxException
|
||||
// // {
|
||||
// // this( Configuration.resolveSource() );
|
||||
// // }
|
||||
//
|
||||
// //
|
||||
// // ACCESSORS
|
||||
// //
|
||||
//
|
||||
// public File getTestSuitePage()
|
||||
// {
|
||||
// return testSuitePage;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void setTestSuitePage( File testSuitePage )
|
||||
// {
|
||||
// this.testSuitePage = testSuitePage;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public String getProject()
|
||||
// {
|
||||
// return project;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void setProject( String project )
|
||||
// {
|
||||
// this.project = project;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public String getCoreJs()
|
||||
// {
|
||||
// return coreJs;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void setCoreJs( String coreJs )
|
||||
// {
|
||||
// this.coreJs = coreJs;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public String getTestRunner()
|
||||
// {
|
||||
// return testRunner;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void setTestRunner( String testRunner )
|
||||
// {
|
||||
// this.testRunner = testRunner;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public Map getIncludes()
|
||||
// {
|
||||
// return includes;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public void setIncludes( Map includes )
|
||||
// {
|
||||
// this.includes = includes;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// //
|
||||
// // UTILITY METHODS
|
||||
// //
|
||||
//
|
||||
// /** The best effort to get a well formed URI */
|
||||
// private static URI getURI( String text ) throws URISyntaxException
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// return new URL( text ).toURI();
|
||||
// }
|
||||
// catch ( MalformedURLException murle )
|
||||
// {
|
||||
// return new File( text ).toURI();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * @param key
|
||||
// * the name of the property to retrieve
|
||||
// * @return A well formed URI based on the value of the given property
|
||||
// * @throws IllegalArgumentException
|
||||
// * if the given property doesn't exist.
|
||||
// */
|
||||
// private static String getRequiredURISystemProperty( String key )
|
||||
// throws URISyntaxException
|
||||
// {
|
||||
// String val = System.getProperty( key );
|
||||
//
|
||||
// if ( val == null )
|
||||
// {
|
||||
// System.err.println( "Missing property : " + key );
|
||||
// throw new IllegalArgumentException( "Missing property : " + key );
|
||||
// }
|
||||
//
|
||||
// return getURI( val ).toString();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// //
|
||||
// // ConfigurationSource IMPLEMENTATION
|
||||
// //
|
||||
//
|
||||
// /**
|
||||
// * Before calling this method, make sure {@link #setTestSuitePage(File)} has been correctly set.
|
||||
// * @throws IllegalStateException if a property is missing or is incorrect
|
||||
// */
|
||||
// public String makeUrl() throws URISyntaxException, IOException
|
||||
// {
|
||||
// // try
|
||||
// // {
|
||||
// // returns the full URL to use with JsUnit
|
||||
// return getRequiredURISystemProperty( PROP_TESTRUNNER ) + "?testPage="
|
||||
// + getTestSuitePage().getCanonicalPath();
|
||||
//
|
||||
// // }
|
||||
// // // URISyntaxException, IOException
|
||||
// // catch ( Exception e )
|
||||
// // {
|
||||
// // e.printStackTrace( System.err );
|
||||
// // throw new IllegalStateException( e );
|
||||
// // }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package net.jsunit;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestResult;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
|
||||
|
||||
public class GeneratedStandaloneTestTest extends TestCase
|
||||
{
|
||||
|
||||
public void testTestStandaloneRun()
|
||||
{
|
||||
GeneratedStandaloneTest test = new GeneratedStandaloneTest( "A test for a test !" );
|
||||
TestResult result = TestRunner.run( test );
|
||||
assert (result.failureCount() == 0 && result.errorCount() == 0);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue