From 1799a612123f8949b4833717c1b7f8971e3a5190 Mon Sep 17 00:00:00 2001 From: Laurent Deketelaere Date: Mon, 13 Nov 2017 13:28:09 +0100 Subject: [PATCH 1/8] add MIT --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ca3677 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Francis Bourre + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 40f40df043ea5fb1c5adbf1e4a522a46349a17bf Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 10:33:04 +0100 Subject: [PATCH 2/8] Remove TestClassDescriptor and transfer its logic to an utility class (TestClassDescriptorUtil). Use typedef instead (ClassDescriptor) --- .../unittest/description/ClassDescriptor.hx | 53 ++++++ .../description/ClassDescriptorUtil.hx | 42 +++++ .../description/TestClassDescriptor.hx | 164 ------------------ .../description/TestMethodDescriptor.hx | 4 +- .../event/ITestClassResultListener.hx | 22 +-- src/hex/unittest/metadata/MetadataParser.hx | 76 +++++--- .../notifier/BrowserUnitTestNotifier.hx | 28 +-- src/hex/unittest/notifier/ConsoleNotifier.hx | 22 +-- src/hex/unittest/notifier/ExitingNotifier.hx | 22 +-- .../notifier/FlashUnitTestNotifier.hx | 24 +-- src/hex/unittest/notifier/TraceNotifier.hx | 22 +-- .../unittest/notifier/WebSocketNotifier.hx | 22 +-- .../notifier/junit/JUnitTestNotifier.hx | 24 +-- src/hex/unittest/runner/ExMachinaUnitCore.hx | 35 ++-- src/hex/unittest/runner/TestRunner.hx | 41 +++-- 15 files changed, 279 insertions(+), 322 deletions(-) create mode 100644 src/hex/unittest/description/ClassDescriptor.hx create mode 100644 src/hex/unittest/description/ClassDescriptorUtil.hx delete mode 100644 src/hex/unittest/description/TestClassDescriptor.hx diff --git a/src/hex/unittest/description/ClassDescriptor.hx b/src/hex/unittest/description/ClassDescriptor.hx new file mode 100644 index 0000000..0f38c62 --- /dev/null +++ b/src/hex/unittest/description/ClassDescriptor.hx @@ -0,0 +1,53 @@ +package hex.unittest.description; + +/** + * @author Francis Bourre + */ +typedef ClassDescriptor = +{ + /** + * The instance of the test class. + */ + var instance : Dynamic; + + /** + * The type of the test class. + */ + var type : Class; + + /** + * The class name of the test class. + */ + var className : String; + + /** + * Specifies is the class descripted is a suite. + */ + var isSuiteClass : Bool; + + /** + * The life cycle method to be called once, setUp tests in the class are executed. + */ + var beforeClassFieldName : String; + + /** + * The life cycle method to be called once, tearDown tests in the class are executed. + */ + var afterClassFieldName : String; + + /** + * The life cycle method to be called once, setUp each test in the class is executed. + */ + var setUpFieldName : String; + + /** + * The life cycle method to be called once, tearDown each test in the class is executed. + */ + var tearDownFieldName : String; + + var classDescriptors : Array; + var methodDescriptors : Array; + var classIndex : Int; + var methodIndex : Int; + var name : String; +} \ No newline at end of file diff --git a/src/hex/unittest/description/ClassDescriptorUtil.hx b/src/hex/unittest/description/ClassDescriptorUtil.hx new file mode 100644 index 0000000..a92913e --- /dev/null +++ b/src/hex/unittest/description/ClassDescriptorUtil.hx @@ -0,0 +1,42 @@ +package hex.unittest.description; + +using Lambda; + +/** + * ... + * @author Francis Bourre + */ +class ClassDescriptorUtil +{ + + function new() throw new hex.error.PrivateConstructorException(); + + static public function hasNextClass( classDescriptor : ClassDescriptor ) : Bool + return classDescriptor.classIndex < classDescriptor.classDescriptors.length; + + static public function nextClass( classDescriptor : ClassDescriptor ) : ClassDescriptor + return classDescriptor.classDescriptors[ classDescriptor.classIndex++ ]; + + static public function hasNextMethod( classDescriptor : ClassDescriptor ) : Bool + return classDescriptor.methodIndex < classDescriptor.methodDescriptors.length; + + static public function nextMethod( classDescriptor : ClassDescriptor ) : TestMethodDescriptor + return classDescriptor.methodDescriptors[ classDescriptor.methodIndex++ ]; + + static public function keepOnlyThisMethod( classDescriptor : ClassDescriptor, methodName : String ) : Void + classDescriptor.methodDescriptors = classDescriptor.methodDescriptors.filter( function( descriptor ) return descriptor.methodName == methodName ); + + static public function currentMethodDescriptor( classDescriptor : ClassDescriptor ) : TestMethodDescriptor + return classDescriptor.methodDescriptors[ classDescriptor.methodIndex == 0 ? 0 : classDescriptor.methodIndex - 1 ]; + + static public function length( classDescriptor : ClassDescriptor ) : UInt + { + var l = 0; + for ( descriptor in classDescriptor.classDescriptors ) l += length( descriptor ); + l += classDescriptor.methodDescriptors.length; + return l; + } + + public static function toString( classDescriptor : ClassDescriptor ) : String + return hex.util.Stringifier.stringify( classDescriptor ) + ':[$classDescriptor.instance, $classDescriptor.type, $classDescriptor.className]'; +} \ No newline at end of file diff --git a/src/hex/unittest/description/TestClassDescriptor.hx b/src/hex/unittest/description/TestClassDescriptor.hx deleted file mode 100644 index b61c984..0000000 --- a/src/hex/unittest/description/TestClassDescriptor.hx +++ /dev/null @@ -1,164 +0,0 @@ -package hex.unittest.description; - -import hex.error.NoSuchElementException; -import hex.util.Stringifier; - -/** - * ... - * @author Francis Bourre - */ -class TestClassDescriptor -{ - /** - * The instance of the test class. - */ - public var instance : Dynamic; - - /** - * The type of the test class. - */ - public var type : Class; - - /** - * The class name of the test class. - */ - public var className : String; - - /** - * Specifies is the class descripted is a suite. - */ - public var isSuiteClass : Bool; - - /** - * The life cycle method to be called once, setUp tests in the class are executed. - */ - public var beforeClassFieldName : String; - - /** - * The life cycle method to be called once, tearDown tests in the class are executed. - */ - public var afterClassFieldName : String; - - /** - * The life cycle method to be called once, setUp each test in the class is executed. - */ - public var setUpFieldName : String; - - /** - * The life cycle method to be called once, tearDown each test in the class is executed. - */ - public var tearDownFieldName : String; - - var _classDescriptors : Array; - var _methodDescriptors : Array; - var _classIndex : Int; - var _methodIndex : Int; - - var _name : String; - - public function new( type : Class ) - { - this.instance = Type.createEmptyInstance( type ); - this.type = type; - this.className = Type.getClassName( type ); - this._name = ""; - - this._classDescriptors = []; - this._methodDescriptors = []; - this._classIndex = 0; - this._methodIndex = 0; - } - - public function getTestLength() : UInt - { - var length : UInt = 0; - for ( classDescriptor in _classDescriptors ) - { - length += classDescriptor.getTestLength(); - } - length += this._methodDescriptors.length; - return length; - } - - public function getName() : String - { - return this._name; - } - - public function setName( name : String ) : Void - { - this._name = name; - } - - public function addTestMethodDescriptor( methodDescriptor : TestMethodDescriptor ) : Void - { - this._methodDescriptors.push( methodDescriptor ); - } - - public function addTestClassDescriptor( classDescriptor : TestClassDescriptor ) : Void - { - this._classDescriptors.push( classDescriptor ); - } - - public function hasNextClass() : Bool - { - return this._classIndex < this._classDescriptors.length; - } - - public function nextClass() : TestClassDescriptor - { - if ( this.hasNextClass() ) - { - return this._classDescriptors[ this._classIndex++ ]; - } - else - { - throw new NoSuchElementException( "nextClass() call on '" + this.toString() + "' failed." ); - } - } - - public function hasNextMethod() : Bool - { - return this._methodIndex < this._methodDescriptors.length; - } - - public function nextMethod() : TestMethodDescriptor - { - if ( this.hasNextMethod() ) - { - return this._methodDescriptors[ this._methodIndex++ ]; - } - else - { - throw new NoSuchElementException( "nextMethod call on '" + this.toString() + "' failed." ); - } - } - - public function keepOnlyThisMethod( methodName : String ) : Void - { - for ( descriptor in this._methodDescriptors ) - { - if ( descriptor.methodName == methodName ) - { - this._methodDescriptors = []; - this._methodDescriptors.push( descriptor ); - break; - } - } - } - - public function currentClassDescriptor() : TestClassDescriptor - { - return this._classDescriptors[ this._classIndex == 0 ? 0 : this._classIndex-1 ]; - } - - public function currentMethodDescriptor() : TestMethodDescriptor - { - return this._methodDescriptors[ this._methodIndex == 0 ? 0 : this._methodIndex-1 ]; - } - - public function toString() : String - { - return Stringifier.stringify( this ) + ':[$instance, $type, $className]'; - } -} diff --git a/src/hex/unittest/description/TestMethodDescriptor.hx b/src/hex/unittest/description/TestMethodDescriptor.hx index dbd9169..fc2459d 100644 --- a/src/hex/unittest/description/TestMethodDescriptor.hx +++ b/src/hex/unittest/description/TestMethodDescriptor.hx @@ -1,7 +1,5 @@ package hex.unittest.description; -import hex.util.Stringifier; - /** * ... * @author Francis Bourre @@ -29,6 +27,6 @@ class TestMethodDescriptor public function toString() : String { - return Stringifier.stringify( this ) + ':[$methodName, $isAsync, $isIgnored, $description, $dataProvider]'; + return hex.util.Stringifier.stringify( this ) + ':[$methodName, $isAsync, $isIgnored, $description, $dataProvider]'; } } diff --git a/src/hex/unittest/event/ITestClassResultListener.hx b/src/hex/unittest/event/ITestClassResultListener.hx index 6b0791d..914b220 100644 --- a/src/hex/unittest/event/ITestClassResultListener.hx +++ b/src/hex/unittest/event/ITestClassResultListener.hx @@ -1,7 +1,7 @@ package hex.unittest.event; import hex.error.Exception; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; /** * ... @@ -9,16 +9,16 @@ import hex.unittest.description.TestClassDescriptor; */ interface ITestClassResultListener { - function onStartRun( descriptor : TestClassDescriptor ) : Void; - function onEndRun( descriptor : TestClassDescriptor ) : Void; + function onStartRun( descriptor : ClassDescriptor ) : Void; + function onEndRun( descriptor : ClassDescriptor ) : Void; - function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void; - function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void; - function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void; - function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void; + function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void; + function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void; + function onTestClassStartRun( descriptor : ClassDescriptor ) : Void; + function onTestClassEndRun( descriptor : ClassDescriptor ) : Void; - function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void; - function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void; - function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void; - function onIgnore( descriptor : TestClassDescriptor ) : Void; + function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void; + function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void; + function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void; + function onIgnore( descriptor : ClassDescriptor ) : Void; } \ No newline at end of file diff --git a/src/hex/unittest/metadata/MetadataParser.hx b/src/hex/unittest/metadata/MetadataParser.hx index 4a46f77..efc943a 100644 --- a/src/hex/unittest/metadata/MetadataParser.hx +++ b/src/hex/unittest/metadata/MetadataParser.hx @@ -1,11 +1,13 @@ package hex.unittest.metadata; -import hex.error.Exception; -import hex.util.ClassUtil; import Reflect; -import hex.unittest.description.TestMethodDescriptor; -import hex.unittest.description.TestClassDescriptor; import haxe.rtti.Meta; +import hex.error.Exception; +import hex.unittest.description.ClassDescriptor; +import hex.unittest.description.TestMethodDescriptor; +import hex.util.ClassUtil; + +using hex.unittest.description.ClassDescriptorUtil; /** * ... @@ -18,22 +20,22 @@ class MetadataParser // } - public function parse( type : Class ) : TestClassDescriptor + public function parse( type : Class ) : ClassDescriptor { - var descriptor = new TestClassDescriptor( type ); + var descriptor = this._getClassDescriptor( type ); this._parse( descriptor ); return descriptor; } - public function parseMethod( type : Class, methodName : String ) : TestClassDescriptor + public function parseMethod( type : Class, methodName : String ) : ClassDescriptor { - var descriptor = new TestClassDescriptor( type ); + var descriptor = this._getClassDescriptor( type ); this._parse( descriptor ); descriptor.keepOnlyThisMethod( methodName ); return descriptor; } - function _parse( descriptor : TestClassDescriptor ) : Void + function _parse( descriptor : ClassDescriptor ) : Void { if ( !this._isSuite( descriptor ) ) { @@ -43,7 +45,7 @@ class MetadataParser } } - function _isSuite( descriptor : TestClassDescriptor ) : Bool + function _isSuite( descriptor : ClassDescriptor ) : Bool { var isSuiteClass : Bool = false; @@ -62,7 +64,7 @@ class MetadataParser if ( !isSuiteClass ) { var metadatas : Array = Reflect.field( metadataField, MetadataList.SUITE ); - descriptor.setName( metadatas[0] ); + descriptor.name = metadatas[ 0 ]; isSuiteClass = descriptor.isSuiteClass = true; descriptor.instance = Type.createInstance( descriptor.type, [] ); } @@ -70,8 +72,8 @@ class MetadataParser var suites : Array> = Reflect.field( descriptor.instance, fieldName ); for ( testClass in suites ) { - var classDescriptor = new TestClassDescriptor( testClass ); - descriptor.addTestClassDescriptor( classDescriptor ); + var classDescriptor = this._getClassDescriptor( testClass ); + descriptor.classDescriptors.push( classDescriptor ); this._parse( classDescriptor ); } } @@ -134,7 +136,7 @@ class MetadataParser return meta; } - function _scanTestClass( testDescriptor : TestClassDescriptor, fieldMeta : Dynamic ) : Void + function _scanTestClass( testDescriptor : ClassDescriptor, fieldMeta : Dynamic ) : Void { var fieldNames = Reflect.fields( fieldMeta ); for ( fieldName in fieldNames ) @@ -150,7 +152,7 @@ class MetadataParser this._searchForStaticMetadata( testDescriptor ); } - function _searchForStaticMetadata( testDescriptor : TestClassDescriptor ) : Void + function _searchForStaticMetadata( testDescriptor : ClassDescriptor ) : Void { var staticMetadata = Meta.getStatics( testDescriptor.type ); var fields = Reflect.fields( staticMetadata ); @@ -170,7 +172,7 @@ class MetadataParser } } - function _searchForInstanceMetadata( testDescriptor : TestClassDescriptor, fieldName : String, func : Dynamic, funcMeta : Dynamic ) : Void + function _searchForInstanceMetadata( testDescriptor : ClassDescriptor, fieldName : String, func : Dynamic, funcMeta : Dynamic ) : Void { for ( tag in MetadataList.INSTANCE_METADATA ) { @@ -191,11 +193,11 @@ class MetadataParser if ( isDataDriven ) { args = Reflect.field( funcMeta, MetadataList.DATA_PROVIDER ); - var dataProviderName = (args != null) ? args [0] : ""; + var dataProviderName = ( args != null ) ? args [0] : ""; - if (!Reflect.hasField(testDescriptor.type, dataProviderName)) + if ( !Reflect.hasField(testDescriptor.type, dataProviderName ) ) { - throw new Exception("Class " + testDescriptor.className + " is missing dataProvider '" + dataProviderName + "' for method '" + fieldName + "'"); + throw new Exception( "Class " + testDescriptor.className + " is missing dataProvider '" + dataProviderName + "' for method '" + fieldName + "'" ); } else { @@ -232,18 +234,40 @@ class MetadataParser } } - function _addTestToDescriptor(testDescriptor:TestClassDescriptor, fieldName:String, isAsync:Bool, isIgnored:Bool, description:String, dataProvider:Array>):Void + function _addTestToDescriptor( testDescriptor : ClassDescriptor, + fieldName : String, + isAsync : Bool, + isIgnored : Bool, + description : String, + dataProvider : Array> ) : Void { - if(dataProvider != null && dataProvider.length > 0) + if ( dataProvider != null && dataProvider.length > 0 ) { - for(provider in dataProvider) - { - testDescriptor.addTestMethodDescriptor( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, provider ) ); - } + for ( provider in dataProvider ) testDescriptor.methodDescriptors.push( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, provider ) ); } else { - testDescriptor.addTestMethodDescriptor( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, [] ) ); + testDescriptor.methodDescriptors.push( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, [] ) ); } } + + function _getClassDescriptor( type : Class ) : ClassDescriptor + { + return + { + instance: Type.createEmptyInstance( type ), + type: type, + className: Type.getClassName( type ), + isSuiteClass: false, + beforeClassFieldName: null, + afterClassFieldName: null, + setUpFieldName: null, + tearDownFieldName: null, + classDescriptors: [], + methodDescriptors: [], + classIndex: 0, + methodIndex: 0, + name: "" + } + } } \ No newline at end of file diff --git a/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx b/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx index 96dcc2c..2d8e7c0 100644 --- a/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx @@ -4,7 +4,7 @@ package hex.unittest.notifier; import hex.error.Exception; import hex.error.IllegalArgumentException; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.description.TestMethodDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; @@ -13,6 +13,8 @@ import js.html.Element; import js.html.HRElement; import js.html.SpanElement; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre @@ -82,7 +84,7 @@ class BrowserUnitTestNotifier implements ITestClassResultListener this._tabs--; } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this._assertionStartCount = Assert.getAssertionCount(); this._successfulCount = 0; @@ -93,7 +95,7 @@ class BrowserUnitTestNotifier implements ITestClassResultListener this.netTimeElapsed = 0; } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); @@ -127,29 +129,29 @@ class BrowserUnitTestNotifier implements ITestClassResultListener this.addRuler(); } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { - this._log( this.createElement( descriptor.getName() + ": '" + descriptor.className + "'", "white+bold+h4" ) ); + this._log( this.createElement( descriptor.name + ": '" + descriptor.className + "'", "white+bold+h4" ) ); this._addTab(); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( this.createElement( "Test class: '" + descriptor.className + "'", "darkwhite+h5+bold" ) ); this._addTab(); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { this._successfulCount++; var success = this.createElement( "✔ ", "green" ); @@ -159,7 +161,7 @@ class BrowserUnitTestNotifier implements ITestClassResultListener } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this._failedCount++; var methodDescriptor = descriptor.currentMethodDescriptor(); @@ -178,12 +180,12 @@ class BrowserUnitTestNotifier implements ITestClassResultListener this.setGlobalResultFailed( ); } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this.onFail( descriptor, timeElapsed, error ); } - public function onIgnore( descriptor : TestClassDescriptor ):Void + public function onIgnore( descriptor : ClassDescriptor ):Void { this._successfulCount++; var ignore = this.createElement( "- ", "yellow" ); @@ -192,7 +194,7 @@ class BrowserUnitTestNotifier implements ITestClassResultListener this.generateMessage( ignore, func, descriptor, 0 ); } - function generateMessage( icon:Element, func:Element, descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + function generateMessage( icon:Element, func:Element, descriptor : ClassDescriptor, timeElapsed : Float ) : Void { var description = descriptor.currentMethodDescriptor().description; var message = this.createElement( (description.length > 0 ? description : "") + " [" + timeElapsed + "ms]", "darkgrey" ); diff --git a/src/hex/unittest/notifier/ConsoleNotifier.hx b/src/hex/unittest/notifier/ConsoleNotifier.hx index 531b90f..58800ca 100644 --- a/src/hex/unittest/notifier/ConsoleNotifier.hx +++ b/src/hex/unittest/notifier/ConsoleNotifier.hx @@ -2,7 +2,7 @@ package hex.unittest.notifier; import hex.error.Exception; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; @@ -39,14 +39,14 @@ class ConsoleNotifier implements ITestClassResultListener this._tabs = this._tabs.substr( 0, this._tabs.length-1 ); } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this._tabs = ""; this._log( this.setColor( "<<< Start " + descriptor.className + " tests run >>>", "blue+bold+underline" ) ); this._addTab(); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); this._log( this.setColor( "<<< End tests run >>>", "blue+bold+underline" ) ); @@ -58,29 +58,29 @@ class ConsoleNotifier implements ITestClassResultListener } } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( this.setColor( "Suite class '" + descriptor.getName() + "'", "green+underline" ) ); this._addTab(); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( this.setColor( "Test class '" + descriptor.className + "'", "green" ) ); this._addTab(); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { if( !this._hideSuccessTest ) { @@ -92,7 +92,7 @@ class ConsoleNotifier implements ITestClassResultListener } } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var description = methodDescriptor.description; @@ -109,7 +109,7 @@ class ConsoleNotifier implements ITestClassResultListener } } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var description = methodDescriptor.description; @@ -120,7 +120,7 @@ class ConsoleNotifier implements ITestClassResultListener this._removeTab(); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var description = methodDescriptor.description; diff --git a/src/hex/unittest/notifier/ExitingNotifier.hx b/src/hex/unittest/notifier/ExitingNotifier.hx index 07910f9..5529524 100644 --- a/src/hex/unittest/notifier/ExitingNotifier.hx +++ b/src/hex/unittest/notifier/ExitingNotifier.hx @@ -2,16 +2,16 @@ package hex.unittest.notifier; import hex.error.Exception; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.event.ITestClassResultListener; class ExitingNotifier implements ITestClassResultListener { public function new() {} - public function onStartRun( descriptor : TestClassDescriptor ) : Void {} + public function onStartRun( descriptor : ClassDescriptor ) : Void {} - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { if ( Assert.getAssertionFailedCount() > 0 ) { @@ -29,19 +29,19 @@ class ExitingNotifier implements ITestClassResultListener #end } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void {} + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void {} - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void {} + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void {} - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void {} + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void {} - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void {} + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void {} - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void {} + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void {} - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void {} + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void {} - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void {} + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void {} - public function onIgnore( descriptor : TestClassDescriptor ) : Void {} + public function onIgnore( descriptor : ClassDescriptor ) : Void {} } diff --git a/src/hex/unittest/notifier/FlashUnitTestNotifier.hx b/src/hex/unittest/notifier/FlashUnitTestNotifier.hx index 8d63146..3e24251 100644 --- a/src/hex/unittest/notifier/FlashUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/FlashUnitTestNotifier.hx @@ -9,7 +9,7 @@ import flash.text.TextField; import flash.text.TextFormat; import hex.error.Exception; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; @@ -85,14 +85,14 @@ class FlashUnitTestNotifier implements ITestClassResultListener this._tabs--; } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this._tabs = 0; this._log( this.createElement( "[[[ Start " + descriptor.className + " tests run ]]]", "yellow+bold+h3" ) ); this._addTab(); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); @@ -124,29 +124,29 @@ class FlashUnitTestNotifier implements ITestClassResultListener this.addRuler(); } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( this.createElement( "Test suite: '" + descriptor.getName() + "'", "white+bold+h4" ) ); this._addTab(); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( this.createElement( "Test class: '" + descriptor.className + "'", "darkwhite+h5+bold" ) ); this._addTab(); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { var success = this.createElement( "✔ ", "green" ); var methodDescriptor = descriptor.currentMethodDescriptor(); @@ -155,7 +155,7 @@ class FlashUnitTestNotifier implements ITestClassResultListener } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var func = this.createElement( methodDescriptor.methodName + "() ", "red" ); @@ -173,12 +173,12 @@ class FlashUnitTestNotifier implements ITestClassResultListener this.setGlobalResultFailed( ); } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this.onFail( descriptor, timeElapsed, error ); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { var success = this.createElement( "- ", "yellow" ); var methodDescriptor = descriptor.currentMethodDescriptor(); @@ -186,7 +186,7 @@ class FlashUnitTestNotifier implements ITestClassResultListener this.generateMessage( success, func, descriptor, 0 ); } - function generateMessage( icon : String, func:String, descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + function generateMessage( icon : String, func:String, descriptor : ClassDescriptor, timeElapsed : Float ) : Void { var description = descriptor.currentMethodDescriptor().description; var message = this.createElement( ( description.length > 0 ? description : "" ) + " [" + timeElapsed + "ms]", "darkgrey" ); diff --git a/src/hex/unittest/notifier/TraceNotifier.hx b/src/hex/unittest/notifier/TraceNotifier.hx index fc26388..4741c25 100644 --- a/src/hex/unittest/notifier/TraceNotifier.hx +++ b/src/hex/unittest/notifier/TraceNotifier.hx @@ -9,7 +9,7 @@ import flash.events.UncaughtErrorEvent; import hex.error.Exception; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; @@ -82,14 +82,14 @@ class TraceNotifier implements ITestClassResultListener this._tabs = this._tabs.substr( 0, this._tabs.length - (TAB_CHARACTER.length) ); } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this._tabs = ""; this._log( "<<< Start " + descriptor.className + " tests run >>>" ); this._addTab(); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); this._log( "<<< End tests run >>>" ); @@ -101,29 +101,29 @@ class TraceNotifier implements ITestClassResultListener } } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( "Suite class '" + descriptor.getName() + "'" ); this._addTab(); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { this._log( "Test class '" + descriptor.className + "'" ); this._addTab(); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this._removeTab(); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { if( !this._hideSuccessTest ) { @@ -135,7 +135,7 @@ class TraceNotifier implements ITestClassResultListener } } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { if ( descriptor != null ) { @@ -161,7 +161,7 @@ class TraceNotifier implements ITestClassResultListener } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var description = methodDescriptor.description; @@ -171,7 +171,7 @@ class TraceNotifier implements ITestClassResultListener this._removeTab(); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); var description = methodDescriptor.description; diff --git a/src/hex/unittest/notifier/WebSocketNotifier.hx b/src/hex/unittest/notifier/WebSocketNotifier.hx index 491efef..2543297 100644 --- a/src/hex/unittest/notifier/WebSocketNotifier.hx +++ b/src/hex/unittest/notifier/WebSocketNotifier.hx @@ -7,7 +7,7 @@ import hex.error.Exception; import hex.event.ITrigger; import hex.event.ITriggerOwner; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.event.ITestClassResultListener; import js.html.CloseEvent; import js.html.Event; @@ -140,13 +140,13 @@ class WebSocketNotifier } } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this.netTimeElapsed = 0; this.sendMessage( "startRun", {} ); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { var data = { @@ -159,7 +159,7 @@ class WebSocketNotifier this.sendMessage( "endRun", data ); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); @@ -181,7 +181,7 @@ class WebSocketNotifier this.sendMessage( "testCaseRunSuccess", data ); } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var methodDescriptor = descriptor.currentMethodDescriptor(); @@ -207,17 +207,17 @@ class WebSocketNotifier this.sendMessage( "testCaseRunFailed", data ); } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this.onFail( descriptor, timeElapsed, error ); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { this.onSuccess( descriptor, 0 ); } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { var data = { @@ -228,12 +228,12 @@ class WebSocketNotifier this.sendMessage( "testSuiteStartRun", data ); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this.sendMessage( "testSuiteEndRun", {} ); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { var data = { @@ -243,7 +243,7 @@ class WebSocketNotifier this.sendMessage( "testClassStartRun", data ); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this.sendMessage( "testClassEndRun", {} ); } diff --git a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx index 2eeff48..d2defd0 100644 --- a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx @@ -1,7 +1,7 @@ package hex.unittest.notifier.junit; import hex.error.Exception; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.event.ITestClassResultListener; using StringTools; @@ -39,7 +39,7 @@ class JUnitTestNotifier implements ITestClassResultListener this._hostname = hostname; } - public function onStartRun( descriptor : TestClassDescriptor ) : Void + public function onStartRun( descriptor : ClassDescriptor ) : Void { this._testSuiteSummaries = new List(); this._testSuitesInExecution = new List(); @@ -48,7 +48,7 @@ class JUnitTestNotifier implements ITestClassResultListener this._testSuitesInExecution.push( this.getSuiteSummary("-", "") ); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { //pop the global suite this._testSuiteSummaries.add( this._testSuitesInExecution.pop() ); @@ -56,7 +56,7 @@ class JUnitTestNotifier implements ITestClassResultListener this._outputHandler.handleOutput( this.getOutput() ); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { var summary = this._testSuitesInExecution.first(); this.updateSummary( summary, timeElapsed ); @@ -65,7 +65,7 @@ class JUnitTestNotifier implements ITestClassResultListener summary.output += this.getTestCaseEnd(); } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var summary = this._testSuitesInExecution.first(); @@ -77,7 +77,7 @@ class JUnitTestNotifier implements ITestClassResultListener summary.output += this.getTestCaseEnd(); } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { var summary = this._testSuitesInExecution.first(); @@ -89,7 +89,7 @@ class JUnitTestNotifier implements ITestClassResultListener summary.output += this.getTestCaseEnd(); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { var summary = this._testSuitesInExecution.first(); @@ -101,21 +101,21 @@ class JUnitTestNotifier implements ITestClassResultListener summary.output += this.getTestCaseEnd(); } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { this._testSuitesInExecution.push( this.getSuiteSummary( descriptor.getName(), descriptor.className ) ); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this._testSuiteSummaries.add(_testSuitesInExecution.pop()); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { } @@ -154,7 +154,7 @@ class JUnitTestNotifier implements ITestClassResultListener summary.tests++; } - function getTestCaseStart( descriptor : TestClassDescriptor, timeElapsed : Float ) : String + function getTestCaseStart( descriptor : ClassDescriptor, timeElapsed : Float ) : String { var methodDescriptor = descriptor.currentMethodDescriptor(); return ""; diff --git a/src/hex/unittest/runner/ExMachinaUnitCore.hx b/src/hex/unittest/runner/ExMachinaUnitCore.hx index d97d1e9..9dbeed4 100644 --- a/src/hex/unittest/runner/ExMachinaUnitCore.hx +++ b/src/hex/unittest/runner/ExMachinaUnitCore.hx @@ -5,10 +5,12 @@ import hex.event.ITrigger; import hex.event.ITriggerOwner; import hex.util.Stringifier; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.event.ITestClassResultListener; import hex.unittest.metadata.MetadataParser; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre @@ -18,7 +20,7 @@ class ExMachinaUnitCore implements ITestClassResultListener { var _parser : MetadataParser; - var _classDescriptors : Array; + var _classDescriptors : Array; var _runner : TestRunner; var _currentClassDescriptor : Int; @@ -39,11 +41,8 @@ class ExMachinaUnitCore public function getTestLength() : UInt { - var length : UInt = 0; - for ( classDescriptor in this._classDescriptors ) - { - length += classDescriptor.getTestLength(); - } + var length = 0; + for ( classDescriptor in this._classDescriptors ) length += classDescriptor.length(); return length; } @@ -83,12 +82,12 @@ class ExMachinaUnitCore return this.dispatcher.disconnect( listener ); } - public function onStartRun( descriptor : TestClassDescriptor ): Void + public function onStartRun( descriptor : ClassDescriptor ): Void { this.dispatcher.onStartRun( descriptor ); } - public function onEndRun( descriptor : TestClassDescriptor ) : Void + public function onEndRun( descriptor : ClassDescriptor ) : Void { this.dispatcher.onEndRun( descriptor ); @@ -105,42 +104,42 @@ class ExMachinaUnitCore } } - public function onSuiteClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { this.dispatcher.onSuiteClassStartRun( descriptor ); } - public function onSuiteClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void { this.dispatcher.onSuiteClassEndRun( descriptor ); } - public function onTestClassStartRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassStartRun( descriptor : ClassDescriptor ) : Void { this.dispatcher.onTestClassStartRun( descriptor ); } - public function onTestClassEndRun( descriptor : TestClassDescriptor ) : Void + public function onTestClassEndRun( descriptor : ClassDescriptor ) : Void { this.dispatcher.onTestClassEndRun( descriptor ); } - public function onSuccess( descriptor : TestClassDescriptor, timeElapsed : Float ) : Void + public function onSuccess( descriptor : ClassDescriptor, timeElapsed : Float ) : Void { this.dispatcher.onSuccess( descriptor, timeElapsed ); } - public function onFail( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onFail( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this.dispatcher.onFail( descriptor, timeElapsed, error ); } - public function onTimeout( descriptor : TestClassDescriptor, timeElapsed : Float, error : Exception ) : Void + public function onTimeout( descriptor : ClassDescriptor, timeElapsed : Float, error : Exception ) : Void { this.dispatcher.onTimeout( descriptor, timeElapsed, error ); } - public function onIgnore( descriptor : TestClassDescriptor ) : Void + public function onIgnore( descriptor : ClassDescriptor ) : Void { this.dispatcher.onIgnore( descriptor ); } @@ -155,7 +154,7 @@ class ExMachinaUnitCore this._runner.run(); } - function _nextClassDescriptor() : TestClassDescriptor + function _nextClassDescriptor() : ClassDescriptor { return this._classDescriptors[ this._currentClassDescriptor++ ]; } diff --git a/src/hex/unittest/runner/TestRunner.hx b/src/hex/unittest/runner/TestRunner.hx index a9dadba..ec8e476 100644 --- a/src/hex/unittest/runner/TestRunner.hx +++ b/src/hex/unittest/runner/TestRunner.hx @@ -2,14 +2,17 @@ package hex.unittest.runner; import haxe.Timer; import haxe.ds.GenericStack; +import hex.collection.HashMap; import hex.error.Exception; import hex.event.ITrigger; import hex.event.ITriggerOwner; -import hex.unittest.description.TestClassDescriptor; +import hex.unittest.description.ClassDescriptor; import hex.unittest.error.TimeoutException; import hex.unittest.event.ITestClassResultListener; import hex.unittest.event.ITestResultListener; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre @@ -18,8 +21,8 @@ class TestRunner implements ITestRunner implements ITriggerOwner implements ITestResultListener { - var _classDescriptors : GenericStack; - var _executedDescriptors : Map; + var _classDescriptors : GenericStack; + var _executedDescriptors : HashMap; var _lastRender : Float = 0; public var dispatcher ( default, never ) : ITrigger; @@ -30,41 +33,41 @@ class TestRunner implements ITestRunner static public var RENDER_DELAY : Int = 0; #end - public function new( classDescriptor : TestClassDescriptor ) + public function new( classDescriptor : ClassDescriptor ) { - this._classDescriptors = new GenericStack(); - this._executedDescriptors = new Map(); + this._classDescriptors = new GenericStack(); + this._executedDescriptors = new HashMap(); this._classDescriptors.add( classDescriptor ); } public function run() : Void { - var classDescriptor : TestClassDescriptor = this._classDescriptors.first(); + var classDescriptor : ClassDescriptor = this._classDescriptors.first(); this.dispatcher.onStartRun( classDescriptor ); this._runClassDescriptor( this._classDescriptors.first() ); } - function _runClassDescriptor( classDescriptor : TestClassDescriptor ) : Void + function _runClassDescriptor( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor != null ) { if ( classDescriptor.isSuiteClass ) { - if ( !this._executedDescriptors.exists( classDescriptor ) ) + if ( !this._executedDescriptors.containsKey( classDescriptor ) ) { this.dispatcher.onSuiteClassStartRun( classDescriptor ); - this._executedDescriptors.set( classDescriptor, true ); + this._executedDescriptors.put( classDescriptor, true ); } this._runSuiteClass( classDescriptor ); } else { - if ( !this._executedDescriptors.exists( classDescriptor ) ) + if ( !this._executedDescriptors.containsKey( classDescriptor ) ) { this.dispatcher.onTestClassStartRun( classDescriptor ); classDescriptor.instance = Type.createEmptyInstance( classDescriptor.type ); - this._executedDescriptors.set( classDescriptor, true ); + this._executedDescriptors.put( classDescriptor, true ); } this._tryToRunBeforeClass( classDescriptor ); @@ -77,7 +80,7 @@ class TestRunner implements ITestRunner } } - function _runSuiteClass( classDescriptor : TestClassDescriptor ) : Void + function _runSuiteClass( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.hasNextClass() ) { @@ -93,7 +96,7 @@ class TestRunner implements ITestRunner } } - function _runTestClass( classDescriptor : TestClassDescriptor ) : Void + function _runTestClass( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.hasNextMethod() ) { @@ -111,7 +114,7 @@ class TestRunner implements ITestRunner } } - function _tryToRunSetUp( classDescriptor : TestClassDescriptor ) : Void + function _tryToRunSetUp( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.setUpFieldName != null ) { @@ -119,7 +122,7 @@ class TestRunner implements ITestRunner } } - function _tryToRunTearDown( classDescriptor : TestClassDescriptor ) : Void + function _tryToRunTearDown( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.tearDownFieldName != null ) { @@ -127,7 +130,7 @@ class TestRunner implements ITestRunner } } - function _tryToRunBeforeClass( classDescriptor : TestClassDescriptor ) : Void + function _tryToRunBeforeClass( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.beforeClassFieldName != null ) { @@ -135,7 +138,7 @@ class TestRunner implements ITestRunner } } - function _tryToRunAfterClass( classDescriptor : TestClassDescriptor ) : Void + function _tryToRunAfterClass( classDescriptor : ClassDescriptor ) : Void { if ( classDescriptor.afterClassFieldName != null ) { @@ -184,7 +187,7 @@ class TestRunner implements ITestRunner this._endTestMethodCall( classDescriptor ); } - function _endTestMethodCall( classDescriptor: TestClassDescriptor ) : Void + function _endTestMethodCall( classDescriptor: ClassDescriptor ) : Void { this._tryToRunTearDown( classDescriptor ); From 74e700afba7fb7d82d51662a865ca96e3433a2f9 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 10:44:43 +0100 Subject: [PATCH 3/8] Remove TestMethodDescriptor. Use typedef instead (MethodDescriptor). Add to existing notifiers missing ClassDescriptorUtil. --- .../unittest/description/ClassDescriptor.hx | 2 +- .../description/ClassDescriptorUtil.hx | 4 +-- .../unittest/description/MethodDescriptor.hx | 14 ++++++++ .../description/TestMethodDescriptor.hx | 32 ----------------- src/hex/unittest/metadata/MetadataParser.hx | 35 ++++++++++++------- .../notifier/BrowserUnitTestNotifier.hx | 4 +-- src/hex/unittest/notifier/ConsoleNotifier.hx | 2 ++ src/hex/unittest/notifier/TraceNotifier.hx | 2 ++ .../notifier/junit/JUnitTestNotifier.hx | 1 + src/hex/unittest/runner/MethodRunner.hx | 8 ++--- 10 files changed, 50 insertions(+), 54 deletions(-) create mode 100644 src/hex/unittest/description/MethodDescriptor.hx delete mode 100644 src/hex/unittest/description/TestMethodDescriptor.hx diff --git a/src/hex/unittest/description/ClassDescriptor.hx b/src/hex/unittest/description/ClassDescriptor.hx index 0f38c62..4e9f096 100644 --- a/src/hex/unittest/description/ClassDescriptor.hx +++ b/src/hex/unittest/description/ClassDescriptor.hx @@ -46,7 +46,7 @@ typedef ClassDescriptor = var tearDownFieldName : String; var classDescriptors : Array; - var methodDescriptors : Array; + var methodDescriptors : Array; var classIndex : Int; var methodIndex : Int; var name : String; diff --git a/src/hex/unittest/description/ClassDescriptorUtil.hx b/src/hex/unittest/description/ClassDescriptorUtil.hx index a92913e..ba96278 100644 --- a/src/hex/unittest/description/ClassDescriptorUtil.hx +++ b/src/hex/unittest/description/ClassDescriptorUtil.hx @@ -20,13 +20,13 @@ class ClassDescriptorUtil static public function hasNextMethod( classDescriptor : ClassDescriptor ) : Bool return classDescriptor.methodIndex < classDescriptor.methodDescriptors.length; - static public function nextMethod( classDescriptor : ClassDescriptor ) : TestMethodDescriptor + static public function nextMethod( classDescriptor : ClassDescriptor ) : MethodDescriptor return classDescriptor.methodDescriptors[ classDescriptor.methodIndex++ ]; static public function keepOnlyThisMethod( classDescriptor : ClassDescriptor, methodName : String ) : Void classDescriptor.methodDescriptors = classDescriptor.methodDescriptors.filter( function( descriptor ) return descriptor.methodName == methodName ); - static public function currentMethodDescriptor( classDescriptor : ClassDescriptor ) : TestMethodDescriptor + static public function currentMethodDescriptor( classDescriptor : ClassDescriptor ) : MethodDescriptor return classDescriptor.methodDescriptors[ classDescriptor.methodIndex == 0 ? 0 : classDescriptor.methodIndex - 1 ]; static public function length( classDescriptor : ClassDescriptor ) : UInt diff --git a/src/hex/unittest/description/MethodDescriptor.hx b/src/hex/unittest/description/MethodDescriptor.hx new file mode 100644 index 0000000..803da0a --- /dev/null +++ b/src/hex/unittest/description/MethodDescriptor.hx @@ -0,0 +1,14 @@ +package hex.unittest.description; + +/** + * ... + * @author Francis Bourre + */ +typedef MethodDescriptor = +{ + var methodName : String; + var isAsync : Bool; + var isIgnored : Bool; + var description : String; + var dataProvider : Array; +} \ No newline at end of file diff --git a/src/hex/unittest/description/TestMethodDescriptor.hx b/src/hex/unittest/description/TestMethodDescriptor.hx deleted file mode 100644 index fc2459d..0000000 --- a/src/hex/unittest/description/TestMethodDescriptor.hx +++ /dev/null @@ -1,32 +0,0 @@ -package hex.unittest.description; - -/** - * ... - * @author Francis Bourre - */ -class TestMethodDescriptor -{ - public var methodName : String; - public var isAsync : Bool; - public var isIgnored : Bool; - public var description : String; - public var dataProvider : Array; - - public function new ( methodName : String, - isAsync : Bool, - isIgnored : Bool, - ?description : String, - ?dataProvider : Array ) - { - this.methodName = methodName; - this.isAsync = isAsync; - this.isIgnored = isIgnored; - this.description = description != null ? description : ""; - this.dataProvider = dataProvider; - } - - public function toString() : String - { - return hex.util.Stringifier.stringify( this ) + ':[$methodName, $isAsync, $isIgnored, $description, $dataProvider]'; - } -} diff --git a/src/hex/unittest/metadata/MetadataParser.hx b/src/hex/unittest/metadata/MetadataParser.hx index efc943a..1e3d0ed 100644 --- a/src/hex/unittest/metadata/MetadataParser.hx +++ b/src/hex/unittest/metadata/MetadataParser.hx @@ -4,7 +4,7 @@ import Reflect; import haxe.rtti.Meta; import hex.error.Exception; import hex.unittest.description.ClassDescriptor; -import hex.unittest.description.TestMethodDescriptor; +import hex.unittest.description.MethodDescriptor; import hex.util.ClassUtil; using hex.unittest.description.ClassDescriptorUtil; @@ -15,21 +15,18 @@ using hex.unittest.description.ClassDescriptorUtil; */ class MetadataParser { - public function new() - { - // - } + public function new(){} public function parse( type : Class ) : ClassDescriptor { - var descriptor = this._getClassDescriptor( type ); + var descriptor = _getClassDescriptor( type ); this._parse( descriptor ); return descriptor; } public function parseMethod( type : Class, methodName : String ) : ClassDescriptor { - var descriptor = this._getClassDescriptor( type ); + var descriptor = _getClassDescriptor( type ); this._parse( descriptor ); descriptor.keepOnlyThisMethod( methodName ); return descriptor; @@ -72,7 +69,7 @@ class MetadataParser var suites : Array> = Reflect.field( descriptor.instance, fieldName ); for ( testClass in suites ) { - var classDescriptor = this._getClassDescriptor( testClass ); + var classDescriptor = _getClassDescriptor( testClass ); descriptor.classDescriptors.push( classDescriptor ); this._parse( classDescriptor ); } @@ -243,16 +240,15 @@ class MetadataParser { if ( dataProvider != null && dataProvider.length > 0 ) { - for ( provider in dataProvider ) testDescriptor.methodDescriptors.push( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, provider ) ); + for ( provider in dataProvider ) testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, provider ) ); } else { - testDescriptor.methodDescriptors.push( new TestMethodDescriptor( fieldName, isAsync, isIgnored, description, [] ) ); + testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, [] ) ); } } - function _getClassDescriptor( type : Class ) : ClassDescriptor - { + static function _getClassDescriptor( type : Class ) : ClassDescriptor return { instance: Type.createEmptyInstance( type ), @@ -269,5 +265,18 @@ class MetadataParser methodIndex: 0, name: "" } - } + + static function _getMethodDescriptor( methodName : String, + isAsync : Bool, + isIgnored : Bool, + ?description : String, + ?dataProvider : Array ) : MethodDescriptor + return + { + methodName: methodName, + isAsync: isAsync, + isIgnored: isIgnored, + description: description != null ? description : "", + dataProvider: dataProvider + } } \ No newline at end of file diff --git a/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx b/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx index 2d8e7c0..f041804 100644 --- a/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/BrowserUnitTestNotifier.hx @@ -5,7 +5,7 @@ import hex.error.Exception; import hex.error.IllegalArgumentException; import hex.unittest.assertion.Assert; import hex.unittest.description.ClassDescriptor; -import hex.unittest.description.TestMethodDescriptor; +import hex.unittest.description.MethodDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; import js.Browser; @@ -189,7 +189,7 @@ class BrowserUnitTestNotifier implements ITestClassResultListener { this._successfulCount++; var ignore = this.createElement( "- ", "yellow" ); - var methodDescriptor : TestMethodDescriptor = descriptor.currentMethodDescriptor(); + var methodDescriptor : MethodDescriptor = descriptor.currentMethodDescriptor(); var func = this.createElement( methodDescriptor.methodName + "() ", "lightgrey" ); this.generateMessage( ignore, func, descriptor, 0 ); } diff --git a/src/hex/unittest/notifier/ConsoleNotifier.hx b/src/hex/unittest/notifier/ConsoleNotifier.hx index 58800ca..d30b806 100644 --- a/src/hex/unittest/notifier/ConsoleNotifier.hx +++ b/src/hex/unittest/notifier/ConsoleNotifier.hx @@ -6,6 +6,8 @@ import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre diff --git a/src/hex/unittest/notifier/TraceNotifier.hx b/src/hex/unittest/notifier/TraceNotifier.hx index 4741c25..c4ee5fe 100644 --- a/src/hex/unittest/notifier/TraceNotifier.hx +++ b/src/hex/unittest/notifier/TraceNotifier.hx @@ -13,6 +13,8 @@ import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre diff --git a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx index d2defd0..640225a 100644 --- a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx @@ -5,6 +5,7 @@ import hex.unittest.description.ClassDescriptor; import hex.unittest.event.ITestClassResultListener; using StringTools; +using hex.unittest.description.ClassDescriptorUtil; /** * ... diff --git a/src/hex/unittest/runner/MethodRunner.hx b/src/hex/unittest/runner/MethodRunner.hx index 0547b42..188e8b5 100644 --- a/src/hex/unittest/runner/MethodRunner.hx +++ b/src/hex/unittest/runner/MethodRunner.hx @@ -7,7 +7,7 @@ import hex.error.IllegalStateException; import hex.event.ITrigger; import hex.event.ITriggerOwner; import hex.unittest.assertion.Assert; -import hex.unittest.description.TestMethodDescriptor; +import hex.unittest.description.MethodDescriptor; import hex.unittest.event.ITestResultListener; /** @@ -18,13 +18,13 @@ class MethodRunner implements ITriggerOwner { var _scope : Dynamic; var _methodReference : Dynamic; - var _methodDescriptor : TestMethodDescriptor; + var _methodDescriptor : MethodDescriptor; var _startTime : Float; var _endTime : Float; public var trigger ( default, never ) : ITrigger; - public function new( scope : Dynamic, methodDescriptor : TestMethodDescriptor ) + public function new( scope : Dynamic, methodDescriptor : MethodDescriptor ) { this._scope = scope; this._methodReference = Reflect.field( this._scope, methodDescriptor.methodName ); @@ -113,7 +113,7 @@ class MethodRunner implements ITriggerOwner return this.trigger.disconnect( listener ); } - public function getDescriptor() : TestMethodDescriptor + public function getDescriptor() : MethodDescriptor { return this._methodDescriptor; } From ff1f89b4ea79ec2355846e666d996fff68b1e52c Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 10:50:25 +0100 Subject: [PATCH 4/8] Fix: ClassDescriptor is a typedef and doesn't have any `getName` accessor --- src/hex/unittest/notifier/ConsoleNotifier.hx | 2 +- src/hex/unittest/notifier/TraceNotifier.hx | 2 +- src/hex/unittest/notifier/junit/JUnitTestNotifier.hx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hex/unittest/notifier/ConsoleNotifier.hx b/src/hex/unittest/notifier/ConsoleNotifier.hx index d30b806..15a21e2 100644 --- a/src/hex/unittest/notifier/ConsoleNotifier.hx +++ b/src/hex/unittest/notifier/ConsoleNotifier.hx @@ -62,7 +62,7 @@ class ConsoleNotifier implements ITestClassResultListener public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { - this._log( this.setColor( "Suite class '" + descriptor.getName() + "'", "green+underline" ) ); + this._log( this.setColor( "Suite class '" + descriptor.name + "'", "green+underline" ) ); this._addTab(); } diff --git a/src/hex/unittest/notifier/TraceNotifier.hx b/src/hex/unittest/notifier/TraceNotifier.hx index c4ee5fe..4a3f609 100644 --- a/src/hex/unittest/notifier/TraceNotifier.hx +++ b/src/hex/unittest/notifier/TraceNotifier.hx @@ -105,7 +105,7 @@ class TraceNotifier implements ITestClassResultListener public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { - this._log( "Suite class '" + descriptor.getName() + "'" ); + this._log( "Suite class '" + descriptor.name + "'" ); this._addTab(); } diff --git a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx index 640225a..d2b5598 100644 --- a/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/junit/JUnitTestNotifier.hx @@ -104,7 +104,7 @@ class JUnitTestNotifier implements ITestClassResultListener public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { - this._testSuitesInExecution.push( this.getSuiteSummary( descriptor.getName(), descriptor.className ) ); + this._testSuitesInExecution.push( this.getSuiteSummary( descriptor.name, descriptor.className ) ); } public function onSuiteClassEndRun( descriptor : ClassDescriptor ) : Void From 2d35a897d2a5e0e426e09be15a6ccaa7c8aac265 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 10:54:35 +0100 Subject: [PATCH 5/8] Fix: ClassDescriptor is a typedef and doesn't have any `getName` accessor --- src/hex/unittest/notifier/WebSocketNotifier.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hex/unittest/notifier/WebSocketNotifier.hx b/src/hex/unittest/notifier/WebSocketNotifier.hx index 2543297..b8e2b97 100644 --- a/src/hex/unittest/notifier/WebSocketNotifier.hx +++ b/src/hex/unittest/notifier/WebSocketNotifier.hx @@ -13,6 +13,8 @@ import js.html.CloseEvent; import js.html.Event; import js.html.WebSocket; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author ... @@ -222,7 +224,7 @@ class WebSocketNotifier var data = { className: descriptor.className, - suiteName: descriptor.getName() + suiteName: descriptor.name }; this.sendMessage( "testSuiteStartRun", data ); From 4d6f1feba82ce371c37ae11c389ca19b110e96a3 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 11:05:52 +0100 Subject: [PATCH 6/8] Replace GenericStack by an Array (GenericStack doesn't support typedefs on Flash target) --- src/hex/unittest/runner/TestRunner.hx | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/hex/unittest/runner/TestRunner.hx b/src/hex/unittest/runner/TestRunner.hx index ec8e476..f82e51e 100644 --- a/src/hex/unittest/runner/TestRunner.hx +++ b/src/hex/unittest/runner/TestRunner.hx @@ -1,7 +1,6 @@ package hex.unittest.runner; import haxe.Timer; -import haxe.ds.GenericStack; import hex.collection.HashMap; import hex.error.Exception; import hex.event.ITrigger; @@ -21,7 +20,7 @@ class TestRunner implements ITestRunner implements ITriggerOwner implements ITestResultListener { - var _classDescriptors : GenericStack; + var _classDescriptors : Array; var _executedDescriptors : HashMap; var _lastRender : Float = 0; @@ -35,16 +34,16 @@ class TestRunner implements ITestRunner public function new( classDescriptor : ClassDescriptor ) { - this._classDescriptors = new GenericStack(); + this._classDescriptors = []; this._executedDescriptors = new HashMap(); - this._classDescriptors.add( classDescriptor ); + this._classDescriptors.push( classDescriptor ); } public function run() : Void { - var classDescriptor : ClassDescriptor = this._classDescriptors.first(); + var classDescriptor : ClassDescriptor = this._classDescriptors[ 0 ]; this.dispatcher.onStartRun( classDescriptor ); - this._runClassDescriptor( this._classDescriptors.first() ); + this._runClassDescriptor( this._classDescriptors[ 0 ] ); } function _runClassDescriptor( classDescriptor : ClassDescriptor ) : Void @@ -85,14 +84,14 @@ class TestRunner implements ITestRunner if ( classDescriptor.hasNextClass() ) { classDescriptor = classDescriptor.nextClass(); - this._classDescriptors.add( classDescriptor ); + this._classDescriptors.push( classDescriptor ); this._runClassDescriptor( classDescriptor ); } else { this.dispatcher.onSuiteClassEndRun( classDescriptor ); - this._classDescriptors.pop(); - this._runClassDescriptor( this._classDescriptors.first() ); + this._classDescriptors.shift(); + this._runClassDescriptor( this._classDescriptors[ 0 ] ); } } @@ -109,8 +108,8 @@ class TestRunner implements ITestRunner { this.dispatcher.onTestClassEndRun( classDescriptor ); this._tryToRunAfterClass( classDescriptor ); - this._classDescriptors.pop(); - this._runClassDescriptor( this._classDescriptors.first() ); + this._classDescriptors.shift(); + this._runClassDescriptor( this._classDescriptors[ 0 ] ); } } @@ -161,28 +160,28 @@ class TestRunner implements ITestRunner **/ public function onSuccess( timeElapsed : Float ) : Void { - var classDescriptor = this._classDescriptors.first(); + var classDescriptor = this._classDescriptors[ 0 ]; this.dispatcher.onSuccess( classDescriptor, timeElapsed ); this._endTestMethodCall( classDescriptor ); } public function onFail( timeElapsed : Float, error : Exception ) : Void { - var classDescriptor = this._classDescriptors.first(); + var classDescriptor = this._classDescriptors[ 0 ]; this.dispatcher.onFail( classDescriptor, timeElapsed, error ); this._endTestMethodCall( classDescriptor ); } public function onTimeout( timeElapsed : Float ) : Void { - var classDescriptor = this._classDescriptors.first(); + var classDescriptor = this._classDescriptors[ 0 ]; this.dispatcher.onTimeout( classDescriptor, timeElapsed, new TimeoutException() ); this._endTestMethodCall( classDescriptor ); } public function onIgnore( timeElapsed : Float) : Void { - var classDescriptor = this._classDescriptors.first(); + var classDescriptor = this._classDescriptors[ 0 ]; this.dispatcher.onIgnore( classDescriptor ); this._endTestMethodCall( classDescriptor ); } From f4019c5512dc73aeb85dfd4e6ad13149f7446e78 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 15:23:55 +0100 Subject: [PATCH 7/8] Revert previous commit with GenericStack of Dynamic --- src/hex/unittest/runner/TestRunner.hx | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/hex/unittest/runner/TestRunner.hx b/src/hex/unittest/runner/TestRunner.hx index f82e51e..97efbd0 100644 --- a/src/hex/unittest/runner/TestRunner.hx +++ b/src/hex/unittest/runner/TestRunner.hx @@ -1,6 +1,7 @@ package hex.unittest.runner; import haxe.Timer; +import haxe.ds.GenericStack; import hex.collection.HashMap; import hex.error.Exception; import hex.event.ITrigger; @@ -20,7 +21,7 @@ class TestRunner implements ITestRunner implements ITriggerOwner implements ITestResultListener { - var _classDescriptors : Array; + var _classDescriptors : GenericStack; var _executedDescriptors : HashMap; var _lastRender : Float = 0; @@ -34,16 +35,16 @@ class TestRunner implements ITestRunner public function new( classDescriptor : ClassDescriptor ) { - this._classDescriptors = []; + this._classDescriptors = new GenericStack(); this._executedDescriptors = new HashMap(); - this._classDescriptors.push( classDescriptor ); + this._classDescriptors.add( classDescriptor ); } public function run() : Void { - var classDescriptor : ClassDescriptor = this._classDescriptors[ 0 ]; + var classDescriptor = this._classDescriptors.first(); this.dispatcher.onStartRun( classDescriptor ); - this._runClassDescriptor( this._classDescriptors[ 0 ] ); + this._runClassDescriptor( this._classDescriptors.first() ); } function _runClassDescriptor( classDescriptor : ClassDescriptor ) : Void @@ -84,14 +85,14 @@ class TestRunner implements ITestRunner if ( classDescriptor.hasNextClass() ) { classDescriptor = classDescriptor.nextClass(); - this._classDescriptors.push( classDescriptor ); + this._classDescriptors.add( classDescriptor ); this._runClassDescriptor( classDescriptor ); } else { this.dispatcher.onSuiteClassEndRun( classDescriptor ); - this._classDescriptors.shift(); - this._runClassDescriptor( this._classDescriptors[ 0 ] ); + this._classDescriptors.pop(); + this._runClassDescriptor( this._classDescriptors.first() ); } } @@ -108,8 +109,8 @@ class TestRunner implements ITestRunner { this.dispatcher.onTestClassEndRun( classDescriptor ); this._tryToRunAfterClass( classDescriptor ); - this._classDescriptors.shift(); - this._runClassDescriptor( this._classDescriptors[ 0 ] ); + this._classDescriptors.pop(); + this._runClassDescriptor( this._classDescriptors.first() ); } } @@ -160,28 +161,28 @@ class TestRunner implements ITestRunner **/ public function onSuccess( timeElapsed : Float ) : Void { - var classDescriptor = this._classDescriptors[ 0 ]; + var classDescriptor = this._classDescriptors.first(); this.dispatcher.onSuccess( classDescriptor, timeElapsed ); this._endTestMethodCall( classDescriptor ); } public function onFail( timeElapsed : Float, error : Exception ) : Void { - var classDescriptor = this._classDescriptors[ 0 ]; + var classDescriptor = this._classDescriptors.first(); this.dispatcher.onFail( classDescriptor, timeElapsed, error ); this._endTestMethodCall( classDescriptor ); } public function onTimeout( timeElapsed : Float ) : Void { - var classDescriptor = this._classDescriptors[ 0 ]; + var classDescriptor = this._classDescriptors.first(); this.dispatcher.onTimeout( classDescriptor, timeElapsed, new TimeoutException() ); this._endTestMethodCall( classDescriptor ); } public function onIgnore( timeElapsed : Float) : Void { - var classDescriptor = this._classDescriptors[ 0 ]; + var classDescriptor = this._classDescriptors.first(); this.dispatcher.onIgnore( classDescriptor ); this._endTestMethodCall( classDescriptor ); } @@ -201,4 +202,4 @@ class TestRunner implements ITestRunner Timer.delay( function( ) { _runTestClass( classDescriptor ); }, TestRunner.RENDER_DELAY ); } } -} +} \ No newline at end of file From 3c2f4e9c37ed338f7eb04043c3d4908ae714f217 Mon Sep 17 00:00:00 2001 From: Francis Bourre Date: Mon, 20 Nov 2017 15:37:29 +0100 Subject: [PATCH 8/8] Fix: FlashUnitTestNotifier is not updated with the new typedef descriptors --- src/hex/unittest/notifier/FlashUnitTestNotifier.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hex/unittest/notifier/FlashUnitTestNotifier.hx b/src/hex/unittest/notifier/FlashUnitTestNotifier.hx index 3e24251..cea11c7 100644 --- a/src/hex/unittest/notifier/FlashUnitTestNotifier.hx +++ b/src/hex/unittest/notifier/FlashUnitTestNotifier.hx @@ -13,6 +13,8 @@ import hex.unittest.description.ClassDescriptor; import hex.unittest.error.AssertException; import hex.unittest.event.ITestClassResultListener; +using hex.unittest.description.ClassDescriptorUtil; + /** * ... * @author Francis Bourre @@ -126,7 +128,7 @@ class FlashUnitTestNotifier implements ITestClassResultListener public function onSuiteClassStartRun( descriptor : ClassDescriptor ) : Void { - this._log( this.createElement( "Test suite: '" + descriptor.getName() + "'", "white+bold+h4" ) ); + this._log( this.createElement( "Test suite: '" + descriptor.name + "'", "white+bold+h4" ) ); this._addTab(); }