commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r988274 - /commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
Date Mon, 23 Aug 2010 19:44:59 GMT
Author: jbeard
Date: Mon Aug 23 19:44:58 2010
New Revision: 988274

URL: http://svn.apache.org/viewvc?rev=988274&view=rev
Log:
Created task for unit testing under Rhino.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml?rev=988274&r1=988273&r2=988274&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml Mon Aug 23 19:44:58 2010
@@ -13,15 +13,22 @@
 	<property name="browsers" value="firefox,ie,chrome"/>
 	<property name="for-ie" value="is-for-ie,is-not-for-ie"/>
 
-	<path id="rhino-classpath">
-	</path>
+	<path id="rhino-classpath" location="lib/java/js.jar"/>
 
-	<path id="xslt-processor-classpath">
-		<pathelement location="lib/java/xalan.jar"/>
+	<path id="xslt-processor-classpath" location="lib/java/xalan.jar"/>
+
+	<path id="requirejs_bootstrap_paths">
+		<pathelement location="lib/js/requirejs/require.js"/> 
+		<pathelement location="lib/js/requirejs/require/rhino.js"/> 
+		<pathelement location="lib/js/requirejs/require/text.js"/> 
+		<pathelement location="lib/js/requirejs/require/xml.js"/> 
 	</path>
 
+	<property name="path_to_dojo_base" location="lib/test-js/dojo-release-1.4.2-src/dojo"/>
+	<property name="path_to_dojo" value="${path_to_dojo_base}/dojo.js"/>
+
 	<path id="scxml-js-compiler-classpath">
-		<pathelement location="lib/java/js.jar"/>
+		<path refid="rhino-classpath"/>
 		<pathelement location="lib/java/commons-cli.jar"/>
 		<pathelement location="lib/java/serializer.jar"/>
 		<pathelement location="lib/java/xalan.jar"/>
@@ -36,7 +43,7 @@
 		<include name="SwitchyardStatechartGenerator.xsl"/>
 	</fileset>
 
-	<path id="scxml-tests-xml">
+	<path id="scxml_tests_xml">
 		<pathelement location="test/kitchen_sink/KitchenSink.xml"/>
 		<!--
 		<pathelement location="test/kitchen_sink/KitchenSink_dataModule.xml"/>
@@ -60,6 +67,53 @@
 		<mkdir dir="build"/>
 	</target>
 
+	<macrodef name="rhinoscript">
+		<text name="text"/>
+
+		<sequential>
+			<!-- TODO: update classpath here -->
+			<script language="javascript" manager="bsf">
+				<classpath>
+				<fileset dir="lib/java/" includes="js.jar"/>
+				<fileset dir="lib/build-java/" includes="*.jar"></fileset>
+				</classpath><![CDATA[
+					var shell = org.mozilla.javascript.tools.shell.Main;
+					var args = ["-e","var a='STRING';"];
+					shell.exec(args);
+
+					var shellGlobal = shell.global;
+
+					//grab functions from shell global and place in current global
+					var load=shellGlobal.load;
+					var print=shellGlobal.print;
+					var defineClass=shellGlobal.defineClass;
+					var deserialize=shellGlobal.deserialize;
+					var doctest=shellGlobal.doctest;
+					var gc=shellGlobal.gc;
+					var help=shellGlobal.help;
+					var loadClass=shellGlobal.loadClass;
+					var quit=shellGlobal.quit;
+					var readFile=shellGlobal.readFile;
+					var readUrl=shellGlobal.readUrl;
+					var runCommand=shellGlobal.runCommand;
+					var seal=shellGlobal.seal;
+					var serialize=shellGlobal.serialize;
+					var spawn=shellGlobal.spawn;
+					var sync=shellGlobal.sync;
+					var toint32=shellGlobal.toint32;
+					var version=shellGlobal.version;
+					var environment=shellGlobal.environment;
+
+					var console ={
+						log : print,
+						debug : print
+					}
+	
+					@{text}
+			]]></script>
+		</sequential>
+	</macrodef>
+
 	<macrodef name="compile-with-scxml-js-ie">
 		<attribute name="backend"/>
 		<attribute name="test-path"/>
@@ -174,7 +228,7 @@
 				<for list="${backends}" param="backend">
 					<sequential>
 						<for param="test-path">
-							<path refid="scxml-tests-xml"/>
+							<path refid="scxml_tests_xml"/>
 							<sequential>
 
 								<!-- for generate-javascript task -->
@@ -236,7 +290,7 @@
 				<for list="${backends}" param="backend">
 					<sequential>
 						<for param="test-path">
-							<path refid="scxml-tests-xml"/>
+							<path refid="scxml_tests_xml"/>
 							<sequential>
 
 								<echo>${@{for-ie}-@{backend}-@{test-path}-target-test-path}, ${@{for-ie}-@{backend}-@{test-path}-target-test-path-dir}</echo>

@@ -274,7 +328,7 @@
 				<for list="${backends}" param="backend">
 					<sequential>
 						<for param="test-path">
-							<path refid="scxml-tests-xml"/>
+							<path refid="scxml_tests_xml"/>
 							<sequential>
 
 								<echo>${@{for-ie}-@{backend}-@{test-path}-unit-test-js-module},${@{for-ie}-@{backend}-@{test-path}-unit-test-html-location},${@{for-ie}-@{backend}-@{test-path}-unit-test-html-target-dir},${@{for-ie}-@{backend}-@{test-path}-target-test-relative-path}</echo>

@@ -297,6 +351,91 @@
 	<target name="run-unit-tests-with-selenium">
 	</target>
 
+	<target name="run-unit-tests-with-rhino" depends="setup-properties">
+		<rhinoscript>
+			//load requirejs
+			Array.prototype.slice.call(requirejs_bootstrap_paths.list()).forEach(function(requireJsPath){
+				load(requireJsPath);
+			});
+
+
+			//this is a bit weird, but we define this here in case we need to load dojo later using
the RequireJS loader
+			djConfig = {
+				"baseUrl" : path_to_dojo_base+"/"
+			}
+
+			//load testing library dependencies
+
+
+			function tailRecurse(list,stepCallback,baseCaseCallback){
+				var target = list.pop();
+				
+				if(target){
+					stepCallback(target, 
+						function(){tailRecurse(list,stepCallback,baseCaseCallback)});
+				}else{
+					if(baseCaseCallback) baseCaseCallback();
+				}
+			}
+
+
+			var forIE = "is-for-ie";
+			var scxmlXmlTestPathList = Array.prototype.slice.call(scxml_tests_xml.list());
+			var backendsList = backends.split(",");
+
+			var jsUnitTestPathPropertyNames = [{forIE:forIE, backend:backend,test_path:test_path}
+								for each (backend in backendsList)
+								for each (test_path in scxmlXmlTestPathList)];
+
+			require(
+				{baseUrl:basedir},
+				[path_to_dojo, 
+					"lib/test-js/env.js",
+					"test/testHelpers.js"],
+				function(){
+
+					dojo.require("doh.runner");	
+
+					//we use tailRecurse function because of asynchronous RequireJS call used to load the
unit test module
+					tailRecurse(jsUnitTestPathPropertyNames,
+						function(target,step){
+
+							//get the path to the generated javascript test
+							var jsTargetTestPathPropertyName =  target.forIE + "-" + target.backend + "-" + target.test_path
+ "-" + "target-test-path";
+							var jsTargetTestPath = project.getProperty(jsTargetTestPathPropertyName);
+						
+							//get the corresponding unit test
+							var jsUnitTestPathPropertyName = target.forIE + "-" + target.backend + "-" + target.test_path
+ "-" + "unit-test-js-module";
+							var jsUnitTestPath = project.getProperty(jsUnitTestPathPropertyName); 
+
+
+							print(jsTargetTestPath + "," + jsUnitTestPath) 
+
+							//load and register
+
+							require(
+								[jsUnitTestPath],
+								function(unitTestModule){
+									load(jsTargetTestPath);
+									unitTestModule.register(StatechartExecutionContext)
+									delete StatechartExecutionContext;
+									step();
+								}) 
+							
+						},
+						function(){
+							print("here");
+							//run with dojo
+							doh.run();
+						}
+					);
+
+				}
+			);
+
+		</rhinoscript>
+	</target>
+
 	<!-- build standalone executable -->
 	<target name="compile-single-js">
 		<java classname="org.mozilla.javascript.tools.shell.Main">



Mime
View raw message