Skip to content

Commit

Permalink
Merge pull request #33 from DoclerLabs/develop
Browse files Browse the repository at this point in the history
prepare 0.34.0
  • Loading branch information
aliokan authored Jan 15, 2018
2 parents 0b2283a + 651f9c6 commit ab991a0
Show file tree
Hide file tree
Showing 14 changed files with 583 additions and 107 deletions.
6 changes: 4 additions & 2 deletions src/hex/unittest/description/ClassDescriptor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ typedef ClassDescriptor =
/**
* The instance of the test class.
*/
var instance : Dynamic;
@:optional
var instance : Dynamic;

/**
* The type of the test class.
*/
var type : Class<Dynamic>;
@:optional
var type : Dynamic;

/**
* The class name of the test class.
Expand Down
6 changes: 2 additions & 4 deletions src/hex/unittest/description/ClassDescriptorUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ using Lambda;
*/
class ClassDescriptorUtil
{

function new() throw new hex.error.PrivateConstructorException();
/** @private */ function new() throw new hex.error.PrivateConstructorException();

static public function hasNextClass( classDescriptor : ClassDescriptor ) : Bool
return classDescriptor.classIndex < classDescriptor.classDescriptors.length;
Expand All @@ -33,8 +32,7 @@ class ClassDescriptorUtil
{
var l = 0;
for ( descriptor in classDescriptor.classDescriptors ) l += length( descriptor );
l += classDescriptor.methodDescriptors.length;
return l;
return l + classDescriptor.methodDescriptors.length;
}

public static function toString( classDescriptor : ClassDescriptor ) : String
Expand Down
16 changes: 11 additions & 5 deletions src/hex/unittest/description/MethodDescriptor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ package hex.unittest.description;
*/
typedef MethodDescriptor =
{
var methodName : String;
var isAsync : Bool;
var isIgnored : Bool;
var description : String;
var dataProvider : Array<Dynamic>;
var methodName : String;
var isAsync : Bool;
var isIgnored : Bool;
var description : String;
var timeout : UInt;

@:optional
var dataProviderFieldName : String;

@:optional
var dataProviderIndex : UInt;
}
27 changes: 16 additions & 11 deletions src/hex/unittest/metadata/MetadataList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,47 @@ package hex.unittest.metadata;
class MetadataList
{
/**
* Metadata marking method to be called setUp all tests in a class.
* Metadata marking method to be called setUp all tests in a class
*/
public inline static var BEFORE_CLASS : String = "BeforeClass";

/**
* Metadata marking method to be called tearDown all tests in a class.
* Metadata marking method to be called tearDown all tests in a class
*/
public inline static var AFTER_CLASS : String = "AfterClass";

/**
* Metadata marking method to be called setUp each test in a class.
* Metadata marking method to be called setUp each test in a class
*/
public inline static var BEFORE : String = "Before";

/**
* Metadata marking method to be called tearDown each test in a class.
* Metadata marking method to be called tearDown each test in a class
*/
public inline static var AFTER : String = "After";

/**
* Metadata marking test method in class.
* Metadata marking test method in class
*/
public inline static var TEST : String = "Test";

/**
* Metadata marking asynchronous test method in class.
* Metadata marking asynchronous test method in class
*/
public inline static var ASYNC : String = "Async";

/**
* Metadata for specifying asynchronous test timeout in ms
*/
public inline static var TIMEOUT : String = "Timeout";

/**
* Metadata marking a test method to ignore.
* Metadata marking a test method to ignore
*/
public inline static var IGNORE : String = "Ignore";

/**
* Metadata marking a test method to ignore.
* Metadata marking a test method to ignore
*/
public inline static var SUITE : String = "Suite";

Expand All @@ -52,12 +57,12 @@ class MetadataList
public inline static var DATA_PROVIDER : String = "DataProvider";

/**
* Array of valid metadatas for instance methods.
* Array of valid metadatas for instance methods
*/
public static var INSTANCE_METADATA = [ BEFORE, AFTER, TEST, ASYNC ];
public static var INSTANCE_METADATA = [ BEFORE, AFTER, TEST, ASYNC, TIMEOUT ];

/**
* Array of valid metadatas for instance methods.
* Array of valid metadatas for static methods
*/
public static var STATIC_METADATA = [ BEFORE_CLASS, AFTER_CLASS ];
}
73 changes: 42 additions & 31 deletions src/hex/unittest/metadata/MetadataParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,11 @@ class MetadataParser

var isDataDriven = Reflect.hasField( funcMeta, MetadataList.DATA_PROVIDER );
var dataProvider:Array<Array<Dynamic>> = null;
var dataProviderFieldName = "";
if ( isDataDriven )
{
args = Reflect.field( funcMeta, MetadataList.DATA_PROVIDER );
var dataProviderName = ( args != null ) ? args [0] : "";

if ( !Reflect.hasField(testDescriptor.type, dataProviderName ) )
{
throw new Exception( "Class " + testDescriptor.className + " is missing dataProvider '" + dataProviderName + "' for method '" + fieldName + "'" );
}
else
{
dataProvider = Reflect.field( testDescriptor.type, dataProviderName);
}
dataProviderFieldName = ( args != null ) ? args [0] : "";
}

switch( tag )
Expand All @@ -221,30 +213,46 @@ class MetadataParser
break;

case MetadataList.TEST :
this._addTestToDescriptor(testDescriptor, fieldName, false, isIgnored, description, dataProvider);
this._addTestToDescriptor(testDescriptor, fieldName, false, isIgnored, description, 0, dataProviderFieldName );
break;

case MetadataList.ASYNC:
this._addTestToDescriptor(testDescriptor, fieldName, true, isIgnored, description, dataProvider);
var hasTimeout = Reflect.hasField( funcMeta, MetadataList.TIMEOUT );
var timeout = hasTimeout ? Reflect.field( funcMeta, MetadataList.TIMEOUT )[ 0 ] : 1500;
this._addTestToDescriptor( testDescriptor, fieldName, true, isIgnored, description, timeout, dataProviderFieldName );
}
}
}
}

function _addTestToDescriptor( testDescriptor : ClassDescriptor,
fieldName : String,
isAsync : Bool,
isIgnored : Bool,
description : String,
dataProvider : Array<Array<Dynamic>> ) : Void
function _addTestToDescriptor( testDescriptor : ClassDescriptor,
fieldName : String,
isAsync : Bool,
isIgnored : Bool,
description : String,
timeout : UInt,
dataProviderFieldName : String ) : Void
{
if ( dataProvider != null && dataProvider.length > 0 )
if ( dataProviderFieldName != '' )
{
for ( provider in dataProvider ) testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, provider ) );
var length = 0;
try
{
length = Reflect.field( testDescriptor.type, dataProviderFieldName ).length;
}
catch ( e : Dynamic )
{
throw new Exception( "Class " + testDescriptor.className + " is missing dataProvider '" + dataProviderFieldName + "' for method '" + fieldName + "'" );
}

for ( dataProviderIndex in 0...length )
{
testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, dataProviderFieldName, dataProviderIndex ) );
}
}
else
{
testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, [] ) );
testDescriptor.methodDescriptors.push( _getMethodDescriptor( fieldName, isAsync, isIgnored, description, dataProviderFieldName, 0 ) );
}
}

Expand All @@ -266,17 +274,20 @@ class MetadataParser
name: ""
}

static function _getMethodDescriptor( methodName : String,
isAsync : Bool,
isIgnored : Bool,
?description : String,
?dataProvider : Array<Dynamic> ) : MethodDescriptor
static function _getMethodDescriptor( methodName : String,
isAsync : Bool,
isIgnored : Bool,
?description : String,
dataProviderFieldName : String,
dataProviderIndex : UInt ) : MethodDescriptor
return
{
methodName: methodName,
isAsync: isAsync,
isIgnored: isIgnored,
description: description != null ? description : "",
dataProvider: dataProvider
methodName: methodName,
isAsync: isAsync,
isIgnored: isIgnored,
description: description != null ? description : "",
timeout: 1500,
dataProviderFieldName: dataProviderFieldName,
dataProviderIndex: dataProviderIndex
}
}
Loading

0 comments on commit ab991a0

Please sign in to comment.