Skip to content
Browse files

Merge branch 'antci' into cimerge

  • Loading branch information...
2 parents ccee463 + d29fff4 commit d3584c1ee85935fb5626d52988e22d049f5570b6 @robertpenner robertpenner committed Nov 7, 2010
View
1 .gitignore
@@ -6,6 +6,7 @@ asunit-3.0/obj
asunit-4.0/bin
asunit-4.0/bin-debug
asunit-4.0/obj
+asunit-4.0/report
html-template
.DS_Store
.actionScriptProperties
View
42 asunit-4.0/build.xml
@@ -14,7 +14,13 @@
<property name="libs.dir" location="${root.dir}/lib"/>
<property name="output.dir" location="${root.dir}/bin"/>
<property name="output.swc" location="${output.dir}/asunit.swc"/>
-
+ <property name="tests.swf" location="${root.dir}/AsUnitCIRunner.swf"/>
+ <property name="report.dir" location="${root.dir}/report"/>
+
+ <taskdef resource="flexUnitTasks.tasks" classpath="${libs.dir}/flexUnitTasks.jar" />
+
+ <!-- TARGETS -->
+
<target name="swc" depends="" description="Compile AS3 code into a SWC">
<echo>Using Flex SDK at: ${FLEX_HOME}</echo>
@@ -42,5 +48,39 @@
</java>
</target>
+
+ <target name="ci" depends="swc" description="Run continuous integration">
+ <echo>[test] Running Unit Tests</echo>
+ <delete dir="${report.dir}" quiet="true"/>
+ <mkdir dir="${report.dir}"/>
+
+ <!-- Compile SWF -->
+ <java jar="${FLEX_HOME}/lib/mxmlc.jar" dir="${FLEX_HOME}/frameworks" fork="true" failonerror="true">
+ <arg value="${test.dir}/AsUnitCIRunner.as"/>
+ <arg value="-incremental=true"/>
+ <arg value="-source-path+=${src.dir}"/>
+ <arg value="-output=${tests.swf}"/>
+ <arg value="-target-player=10"/>
+ <arg value="-default-size=1000,800"/>
+ <arg value="-default-background-color=0x000000"/>
+ <arg value="-static-link-runtime-shared-libraries=true"/>
+ <!-- Include classes from SWCs in this folder, but only the ones we use. -->
+ <arg value="-library-path+=${libs.dir}"/>
+ <arg value="-verbose-stacktraces=true"/>
+ <arg value="-headless-server=true"/>
+ <arg value="-keep-as3-metadata+=Test,Suite,Before,BeforeClass,After,AfterClass,RunWith,Ignore,Inject"/>
+ </java>
+
+ <!-- Execute TestRunner.swf as FlexUnit tests and publish reports -->
+ <flexunit swf="${tests.swf}" toDir="${report.dir}" haltonfailure="false" verbose="true" localTrusted="false" />
+
+ <!-- Generate readable JUnit-style reports -->
+ <junitreport todir="${report.dir}">
+ <fileset dir="${report.dir}">
+ <include name="TEST-*.xml" />
+ </fileset>
+ <report format="frames" todir="${report.dir}/html" />
+ </junitreport>
+ </target>
</project>
View
BIN asunit-4.0/lib/flexUnitTasks.jar
Binary file not shown.
View
22 asunit-4.0/src/asunit/core/FlexUnitCICore.as
@@ -0,0 +1,22 @@
+package asunit.core {
+
+ import asunit.printers.FlexUnitCIPrinter;
+ import asunit.printers.FlashDevelopPrinter;
+
+ import flash.system.fscommand;
+
+ public class FlexUnitCICore extends TextCore {
+
+ override protected function initializeObservers():void {
+ super.initializeObservers();
+ addObserver(new FlexUnitCIPrinter());
+ }
+
+ override protected function onRunCompleted():void {
+ super.onRunCompleted();
+ //fscommand('quit'); // fails silently if not in debug player
+ //System.exit(0); // generates SecurityError if not in debug player
+ }
+ }
+}
+
View
211 asunit-4.0/src/asunit/printers/FlexUnitCIPrinter.as
@@ -0,0 +1,211 @@
+package asunit.printers {
+ import asunit.framework.IResult;
+ import asunit.framework.IRunListener;
+ import asunit.framework.ITestFailure;
+ import asunit.framework.ITestSuccess;
+ import asunit.framework.ITestWarning;
+ import asunit.framework.Method;
+ import asunit.framework.TestObserver;
+
+ import flash.events.DataEvent;
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.IOErrorEvent;
+ import flash.events.SecurityErrorEvent;
+ import flash.events.TimerEvent;
+ import flash.net.XMLSocket;
+ import flash.system.fscommand;
+ import flash.utils.Timer;
+ import flash.utils.getQualifiedClassName;
+ import flash.utils.getTimer;
+
+ public class FlexUnitCIPrinter extends EventDispatcher implements IRunListener, TestObserver
+ {
+ protected static const DEFAULT_SERVER:String = "127.0.0.1";
+ protected static const DEFAULT_PORT:uint = 1024;
+
+ public var port:uint;
+ public var server:String; //this is local host. same machine
+
+ private static const SUCCESS:String = "success";
+ private static const ERROR:String = "error";
+ private static const FAILURE:String = "failure";
+ private static const IGNORE:String = "ignore";
+
+ private var _ready:Boolean = false;
+
+ private static const START_OF_TEST_RUN_ACK : String = "<startOfTestRunAck/>";
+ private static const END_OF_TEST_ACK : String ="<endOfTestRunAck/>";
+ private static const END_OF_TEST_RUN : String = "<endOfTestRun/>";
+
+ private var socket:XMLSocket;
+ private var connectTimeout:Timer;
+
+ protected var messageQueue:Array;
+
+ private var startTime : int;
+
+ public function FlexUnitCIPrinter()
+ {
+ this.port = port;
+ this.server = server;
+ messageQueue = [];
+
+ socket = new XMLSocket();
+ socket.addEventListener(Event.CONNECT, onConnect);
+ socket.addEventListener(DataEvent.DATA, onData);
+ socket.addEventListener(IOErrorEvent.IO_ERROR, onErrorEvent);
+ socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onErrorEvent);
+ socket.addEventListener(Event.CLOSE, onErrorEvent);
+
+ connectTimeout = new Timer(5000, 1);
+ connectTimeout.addEventListener(TimerEvent.TIMER_COMPLETE, onConnectTimeout);
+ connectTimeout.start();
+
+ connect();
+ }
+
+ protected function connect(ip:String = DEFAULT_SERVER, port:uint = DEFAULT_PORT):void {
+ try {
+ socket.connect(ip, port);
+ }
+ catch (e:Error) {
+ trace('## Error connecting to socket: ' + e.message);
+ }
+ }
+
+ private function onConnectTimeout(event:TimerEvent):void {
+ throw new Error('Timed out waiting to connect to socket.');
+ }
+
+ [Bindable(event="listenerReady")]
+ public function get ready():Boolean
+ {
+ return _ready;
+ }
+
+ public function onTestIgnored(method:Method):void {
+ var xmlMessageIgnore:String = "<testcase classname='" + getQualifiedClassName(method.scope)
+ + "' name='" + method.name + "' status='"+IGNORE+"'>"
+ + "<skipped />"
+ + "</testcase>";
+ sendMessage(xmlMessageIgnore);
+ }
+
+ protected static function xmlEscapeMessage(message:String):String {
+ if (!message) return '';
+
+ var escape:XML = <escape/>;
+ escape.setChildren( message );
+ return escape.children()[0].toXMLString();
+ }
+
+ public function onTestFailure(failure:ITestFailure):void {
+ sendMessage(getFailureMessage(failure));
+ }
+
+ protected function getFailureMessage(failure:ITestFailure):String {
+ var status:String = failure.isFailure ? FAILURE : ERROR;
+// var stackTrace:String = xmlEscapeMessage(failure.thrownException.getStackTrace());
+ var stackTrace:String = failure.thrownException.getStackTrace();
+ var xml:String =
+ "<testcase classname='" + getQualifiedClassName(failure.failedTest)
+ + "' name='" + failure.failedMethod
+ + "' time='0.000' status='" + status + "'>"
+
+ + "<error message='" + xmlEscapeMessage(failure.exceptionMessage)
+ + "' type='"+ getQualifiedClassName(failure.thrownException) +"' >"
+ + "<![CDATA[" + stackTrace + "]]>"
+ + "</error>"
+
+ + "</testcase>";
+
+ return xml;
+ }
+
+ protected function sendMessage(message:String):void {
+ if (!socket.connected) {
+ messageQueue.push(message);
+ return;
+ }
+ socket.send(message);
+ trace('+++++++++ sendMessage() - \n' + message + '\n');
+ }
+
+// protected function sendResults(msg:String):void
+// {
+// if(socket.connected)
+// {
+// socket.send( msg );
+// }
+//
+// trace(msg);
+// }
+
+ protected function onConnect(event:Event):void {
+ connectTimeout.stop();
+ sendQueuedMessages();
+ }
+
+ protected function sendQueuedMessages():void {
+ while (messageQueue.length) {
+ sendMessage(messageQueue.shift());
+ }
+ }
+
+ private function onData( event : DataEvent ) : void
+ {
+ trace('onData: ' + event.data);
+
+// // If we received an acknowledgement on startup, the java server is ready and we can start sending.
+// if ( data == START_OF_TEST_RUN_ACK ) {
+// setStatusReady();
+// } else
+
+ if (event.data == END_OF_TEST_ACK) {
+ // If we received an acknowledgement finish-up.
+ exit();
+ }
+ }
+
+ protected function onErrorEvent(event:Event):void {
+ trace('FlexUnitCIPrinter::onErrorEvent() - event: ' + event);
+ //throw new Error('FlashBuilderPrinter::onErrorEvent() - event: ' + event);
+ }
+
+ public function onRunStarted():void {
+ }
+
+ public function onTestStarted(test:Object):void {
+ startTime = getTimer();
+ }
+
+ public function onTestCompleted(test:Object):void {
+// testTimes.push({test:test, duration:duration});
+ }
+
+ public function onTestSuccess(success:ITestSuccess):void
+ {
+ //TODO: move test time into ITestSuccess
+ var duration:Number = (getTimer() - startTime) / 1000;
+ var xmlMessageSuccess:String = "<testcase classname='" + getQualifiedClassName(success.test)
+ + "' name='" + success.method + "' time='0.000' status='"+SUCCESS+"'/>";
+ sendMessage(xmlMessageSuccess);
+ }
+
+ public function onRunCompleted(result:IResult):void {
+ sendMessage(END_OF_TEST_RUN);
+ }
+
+ /**
+ * Exit the test runner by calling the ApplicationCloser.
+ */
+ protected function exit():void
+ {
+ socket.close();
+ fscommand("quit");
+ }
+
+ public function onWarning(warning : ITestWarning) : void {
+ }
+ }
View
18 asunit-4.0/test/AsUnitCIRunner.as
@@ -0,0 +1,18 @@
+package {
+
+ import asunit.core.FlexUnitCICore;
+ import asunit.core.TextCore;
+
+ import flash.display.MovieClip;
+
+ [SWF(width="1024", height="640", backgroundColor="#000000", frameRate="61")]
+ public class AsUnitCIRunner extends MovieClip {
+
+ private var core:TextCore;
+
+ public function AsUnitCIRunner() {
+ core = new FlexUnitCICore();
+ core.start(AllTests, null, this);
+ }
+ }
+}

0 comments on commit d3584c1

Please sign in to comment.
Something went wrong with that request. Please try again.