commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=988276&view=rev
Log:
Fixed paths in build.xml so that it works on windows and linux. Added and tested task rn-unit-tests-with-selenium.

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=988276&r1=988275&r2=988276&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:45:09 2010
@@ -6,13 +6,30 @@
 		</classpath>
 	</taskdef>
 
-	<!--
+	<property name="ie_browser_name" value="ie"/>
+
+	<property name="is_for_ie" value="is-for-ie"/>
+	<property name="is_not_for_ie" value="is-not-for-ie"/>
+
 	<property name="backends" value="switch,table,state"/>
-	-->
+	<!--
 	<property name="backends" value="switch"/>
-	<property name="browsers" value="firefox,ie,chrome"/>
-	<property name="for-ie" value="is-for-ie,is-not-for-ie"/>
+	-->
+	<property name="browsers" value="firefox,${ie_browser_name},chrome"/>
+	<property name="for-ie" value="${is_for_ie},${is_not_for_ie}"/>
+
+	<!-- selenium configuration options -->
+	<property name="selenium_host" value="localhost"/>
+	<property name="selenium_port" value="4444"/>
+	<property name="selenium_root_url" value="http://localhost:8081/"/>
+	<property name="selenium_timeout" value="10000"/>
+
+	<property name="selenium_firefox_id" value="*firefox"/>
+	<property name="selenium_ie_id" value="*iexplore"/>
+	<property name="selenium_chrome_id" value="*googlechrome"/>
+	<property name="selenium_safari_id" value="*safari"/>
 
+	<!-- classpath configuration stuff -->
 	<path id="rhino-classpath" location="lib/java/js.jar"/>
 
 	<path id="xslt-processor-classpath" location="lib/java/xalan.jar"/>
@@ -50,8 +67,8 @@
 		<pathelement location="test/kitchen_sink/KitchenSink_performance.xml"/>
 		<pathelement location="test/kitchen_sink/KitchenSink_executableContent.xml"/>
 		-->
-		<!--
 		<pathelement location="test/conditional_transition/TestConditionalTransition.xml"/>
+		<!--
 		<pathelement location="test/in_predicate/TestInPredicate.xml"/>
 		<pathelement location="test/event_system_properties/TestEventSystemProperties.xml"/>
 		<pathelement location="test/prefix_events/TestPrefixEvents.xml"/>
@@ -76,6 +93,7 @@
 				<classpath>
 				<fileset dir="lib/java/" includes="js.jar"/>
 				<fileset dir="lib/build-java/" includes="*.jar"></fileset>
+				<fileset dir="lib/test-java/" includes="*.jar"></fileset>
 				</classpath><![CDATA[
 					var shell = org.mozilla.javascript.tools.shell.Main;
 					var args = ["-e","var a='STRING';"];
@@ -227,13 +245,33 @@
 		<for param="test-path">
 			<path refid="scxml_tests_xml"/>
 			<sequential>
+				<!-- for generate-unit-tests-html task -->
+
+				<!-- compute unit test module location -->
+				<!-- to simplify, we expect it to be in a particular location -->
+
 				<dirname property="@{test-path}-dir" file="@{test-path}"/>
 
 				<!-- convert to relative path -->
+				<!-- remove basedir, then remove first slash if there is one, then do other manipulations
-->
 				<pathconvert property="@{test-path}-unit-test-js-module">
 					<path location="${@{test-path}-dir}"/>
-					<globmapper from="${basedir}/*" to="*/scripts/unitTest"/>
+					<chainedmapper>
+						<globmapper from="${basedir}*" to="*"/>
+						<scriptmapper language="javascript">
+							self.addMappedName(source[0] == project.getProperty("file.separator") ? 
+										source.slice(1):
+										source);
+						</scriptmapper>
+						<scriptmapper language="javascript">
+							self.addMappedName(source.replace("\\","/","g"));
+						</scriptmapper>
+						<globmapper from="*" to="*/scripts/unitTest"/>
+					</chainedmapper>
 				</pathconvert>
+
+				<echo>@{test-path}-unit-test-js-module</echo>
+				<echo>${@{test-path}-unit-test-js-module}</echo>
 			</sequential>
 		</for>
 
@@ -253,35 +291,56 @@
 									<path path="@{test-path}"/>
 									<chainedmapper>
 									  <flattenmapper/>
-									  <globmapper from="*.xml" to="build/generate-javascript/@{for-ie}/@{backend}/*.js"/>
+									  <globmapper from="*.xml" to="build${file.separator}generate-javascript${file.separator}@{for-ie}${file.separator}@{backend}${file.separator}*.js"
handledirsep="true"/>
 									</chainedmapper>
 								</pathconvert>
 
+								<echo>@{for-ie}-@{backend}-@{test-path}-target-test-path</echo>
+								<echo>${@{for-ie}-@{backend}-@{test-path}-target-test-path}</echo>
+
 								<dirname property="@{for-ie}-@{backend}-@{test-path}-target-test-path-dir" file="${@{for-ie}-@{backend}-@{test-path}-target-test-path}"/>
 
 								<!-- for generate-unit-tests-html task -->
 
-								<!-- compute unit test module location -->
-								<!-- to simplify, we expect it to be in a particular location -->
-
-								<!-- convert to relative path -->
-								<pathconvert property="@{for-ie}-@{backend}-@{test-path}-unit-test-js-module">
-									<path location="${@{test-path}-dir}"/>
-									<globmapper from="${basedir}/*" to="*/scripts/unitTest"/>
-								</pathconvert>
-
 								<!-- compute unit test html target location -->
 								<pathconvert property="@{for-ie}-@{backend}-@{test-path}-unit-test-html-location">
 									<path location="${@{for-ie}-@{backend}-@{test-path}-target-test-path}"/>
-									<globmapper from="${basedir}/build/generate-javascript/*.js" to="${basedir}/build/generate-unit-tests-html/*.html"/>
+									<chainedmapper>
+										<globmapper from="${basedir}*" to="*"/>
+										<scriptmapper language="javascript">
+											self.addMappedName(source[0] == project.getProperty("file.separator") ? 
+														source.slice(1):
+														source);
+										</scriptmapper>
+										<scriptmapper language="javascript">
+											self.addMappedName(source.replace("\\","/","g"));
+										</scriptmapper>
+										<globmapper from="build/generate-javascript/*.js" to="build/generate-unit-tests-html/*.html"
handledirsep="true"/>
+									</chainedmapper>
 								</pathconvert>
 
+								<echo>@{for-ie}-@{backend}-@{test-path}-unit-test-html-location</echo>
+								<echo>${@{for-ie}-@{backend}-@{test-path}-unit-test-html-location}</echo>
+
 								<!-- compute relative path to js from html unit test folder -->
 								<pathconvert property="@{for-ie}-@{backend}-@{test-path}-target-test-relative-path">
 									<path location="${@{for-ie}-@{backend}-@{test-path}-target-test-path}"/>
-									<globmapper from="${basedir}/build/*" to="../../../*"/>
+									<chainedmapper>
+										<globmapper from="${basedir}*" to="*"/>
+										<scriptmapper language="javascript">
+											self.addMappedName(source[0] == project.getProperty("file.separator") ? 
+														source.slice(1):
+														source);
+										</scriptmapper>
+										<scriptmapper language="javascript">
+											self.addMappedName(source.replace("\\","/","g"));
+										</scriptmapper>
+										<globmapper from="build/*" to="../../../*" handledirsep="true"/>
+									</chainedmapper>
 								</pathconvert>
 								
+								<echo>@{for-ie}-@{backend}-@{test-path}-target-test-relative-path</echo>
+								<echo>${@{for-ie}-@{backend}-@{test-path}-target-test-relative-path}</echo>
 
 								<!-- get the dirname of the html target so we can make the directory structure
-->
 								<dirname property="@{for-ie}-@{backend}-@{test-path}-unit-test-html-target-dir"
file="${@{for-ie}-@{backend}-@{test-path}-unit-test-html-location}"/>
@@ -334,7 +393,7 @@
 		</for>
 	</target>
 
-	<target name="generate-unit-tests-html" depends="setup-properties">
+	<target name="generate-unit-test-html" depends="setup-properties">
 		<mkdir dir="build/generate-unit-tests-html"/>
 
 		<for list="${for-ie}" param="for-ie">
@@ -345,14 +404,14 @@
 							<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>

+								<echo>${@{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>

 
 								<!-- execute some tasks -->
 								<mkdir dir="${@{for-ie}-@{backend}-@{test-path}-unit-test-html-target-dir}"/>
 
 								<generate-unit-test-html-template
 									generatedJsCodeRelativePath="${@{for-ie}-@{backend}-@{test-path}-target-test-relative-path}"
-									testScriptModulePath="${@{for-ie}-@{backend}-@{test-path}-unit-test-js-module}"
+									testScriptModulePath="${@{test-path}-unit-test-js-module}"
 									out-path="${@{for-ie}-@{backend}-@{test-path}-unit-test-html-location}"/>
 							</sequential>
 						</for>
@@ -362,7 +421,104 @@
 		</for>
 	</target>
 
-	<target name="run-unit-tests-with-selenium">
+	<target name="run-unit-tests-with-selenium" depends="generate-unit-test-html,generate-javascript">
+		<rhinoscript><![CDATA[
+			function unitTestWithSelenium(sel,url,timeout){
+				sel.open(url);
+
+				sel.waitForPageToLoad("5000");
+				
+				// wait for all the tests to finish
+				sel.waitForCondition("window.dohIsComplete", timeout );
+				
+				// get the results
+				var testCount = Number(sel.getEval("window.doh._testCount"));
+				var failCount = Number(sel.getEval("window.doh._failureCount"));
+				var errorCount = Number(sel.getEval("window.doh._errorCount"));
+				
+				return {
+					testCount:testCount,
+					failCount:failCount,
+					errorCount:errorCount,
+					testsPassed:(testCount - failCount - errorCount)
+				};
+			}
+
+			print("Running Selenium unit tests...");
+
+			var unitTestResults = [];
+
+			browsers.split(",").forEach(function(browserName){
+
+				print("Running test for " + browserName + "...");
+
+				var browserId = project.getProperty("selenium_" + browserName + "_id");
+
+				var bSel = new Packages.com.thoughtworks.selenium.DefaultSelenium(selenium_host, selenium_port,
browserId, selenium_root_url);
+
+				print("bSel",bSel);
+
+				bSel.start();
+
+				//list comprehension to get the cartesian product
+				var configurations = [{forIE:forIE,backend:backend,testPath:testPath}
+					for each (forIE in project.getProperty("for-ie").split(','))
+					for each (backend in backends.split(','))
+					for each (testPath in Array.prototype.slice.call(scxml_tests_xml.list()))];
+
+				//use pattern matching in the parameter
+				configurations.forEach(function({forIE:forIE,backend:backend,testPath:testPath}){
+		
+					print("forIE:"+forIE+","+"backend:"+backend+","+"testPath:"+testPath);
+
+					//get path to html test
+					//@{for-ie}-@{backend}-@{test-path}-unit-test-html-location
+					var unitTestHtmlLocationPropertyName=forIE + "-" + backend + "-" + testPath + "-unit-test-html-location";
+					var unitTestHtmlLocation = project.getProperty(unitTestHtmlLocationPropertyName);
+
+					print("unitTestHtmlLocation:"+unitTestHtmlLocation);
+					
+					//ensure we are not testing an ie html test
+					//on a non-ie browser
+					if(browserName==ie_browser_name && forIE==is_for_ie ||
+						browserName!=ie_browser_name && forIE==is_not_for_ie){
+
+						var unitTestResult = unitTestWithSelenium(bSel,unitTestHtmlLocation,selenium_timeout);

+
+						print("unitTestResult:" + unitTestResult); 
+
+						var unitTestResultObj = {
+							data : unitTestResult,
+							browser : browserName,
+							scxmlTest : testPath,
+							backend : backend
+						};
+
+						unitTestResults.push(unitTestResultObj);
+
+						//report errors and failures that may occur
+						if(unitTestResult.failCount || unitTestResult.errorCount){
+							print("UNIT TEST ERROR");
+							//TODO: add better error handling here that integrates with Ant
+						}
+
+					}
+				});
+
+				bSel.stop();
+			});
+
+			var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
+			var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
+			var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
+			var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
+
+			print("Test Results:");
+			print("Total Tests: " + totalTests);
+			print("Total Tests Failed: " + totalTestsFailed);
+			print("Total Tests Errored: " + totalTestsErrored);
+			print("Total Tests Passed: " + totalTestsPassed);
+		]]></rhinoscript>
 	</target>
 
 	<target name="run-unit-tests-with-rhino" depends="generate-javascript">



Mime
View raw message