Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Thread.create issue with Haxe nightlies #188

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/massive/munit/Assert.hx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Assert
public static function isType(value:Dynamic, type:Dynamic, ?message:String, ?info:PosInfos)
{
assertionCount++;
if(Std.is(value, type)) return;
if(isOfType(value, type)) return;
if(message == null) message = "Value [" + value + "] was not of type: " + Type.getClassName(type);
fail(message, info);
}
Expand All @@ -166,7 +166,7 @@ class Assert
public static function isNotType(value:Dynamic, type:Dynamic, ?message:String, ?info:PosInfos)
{
assertionCount++;
if(!Std.is(value, type)) return;
if(!isOfType(value, type)) return;
if(message == null) message = "Value [" + value + "] was of type: " + Type.getClassName(type);
fail(message, info);
}
Expand Down Expand Up @@ -290,7 +290,7 @@ class Assert
}
catch (e:Dynamic)
{
if(Std.is(e, expectedType)) return e;
if(isOfType(e, expectedType)) return e;
Assert.fail('Expected exception of type ${Type.getClassName(expectedType)} but got ${Type.getClassName(Type.getClass(e))}: ${e}');
}
return null;
Expand Down Expand Up @@ -334,8 +334,8 @@ class Assert
case TFunction: Reflect.compareMethods(a, b);
case TClass(_):
if(a == b) return true;
if(Std.is(a, String) && Std.is(b, String)) return false; // previous comparison failed
if(Std.is(a, Array) && Std.is(b, Array)) {
if(isOfType(a, String) && isOfType(b, String)) return false; // previous comparison failed
if(isOfType(a, Array) && isOfType(b, Array)) {
var a:Array<Dynamic> = cast a;
var b:Array<Dynamic> = cast b;
if(a.length != b.length) return false;
Expand All @@ -344,7 +344,7 @@ class Assert
}
return true;
}
if(Std.is(a, Bytes) && Std.is(b, Bytes)) {
if(isOfType(a, Bytes) && isOfType(b, Bytes)) {
var a = cast(a, Bytes);
var b = cast(b, Bytes);
if(a.length != b.length) return false;
Expand All @@ -353,7 +353,7 @@ class Assert
}
return true;
}
if(Std.is(a, IMap) && Std.is(b, IMap)) {
if(isOfType(a, IMap) && isOfType(b, IMap)) {
var a:IMap<Dynamic, Dynamic> = cast a;
var b:IMap<Dynamic, Dynamic> = cast b;
var akeys = [for(it in a.keys()) it];
Expand All @@ -364,7 +364,7 @@ class Assert
}
return true;
}
if(Std.is(a, Date) && Std.is(b, Date)) {
if(isOfType(a, Date) && isOfType(b, Date)) {
var a = cast(a, Date).getTime();
var b = cast(b, Date).getTime();
return a == b;
Expand All @@ -381,7 +381,7 @@ class Assert
}
return true;
case TObject:
if(Std.is(a, Class) && Std.is(b, Class)) {
if(isOfType(a, Class) && isOfType(b, Class)) {
var a = Type.getClassName(a);
var b = Type.getClassName(b);
return a == b;
Expand Down Expand Up @@ -417,9 +417,9 @@ class Assert
}

static inline function empty(anObject:StringOrIterable):Bool {
if(Std.is(anObject, String)) {
if(isOfType(anObject, String)) {
return (anObject:String).length == 0;
} else if(Std.is(anObject, Array)) {
} else if(isOfType(anObject, Array)) {
var a:Array<Dynamic> = cast anObject;
return a.length == 0;
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/massive/munit/TestResult.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class TestResult

}

@:enum
abstract TestResultType(String) to String
enum abstract TestResultType(String) to String
{
var UNKNOWN = "UNKNOWN";
var PASS = "PASS";
Expand Down
18 changes: 12 additions & 6 deletions src/massive/munit/TestRunner.hx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ class TestRunner implements IAsyncDelegateObserver

#if (neko || cpp || java || hl || eval)
var self = this;
var runThread:Thread = Thread.create(function()
var createThread = Thread.create;
#if haxe4
#if (haxe >= version("4.2.0-rc.1"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if (haxe> = version (" 4.2.0-rc.1 ")) doesn't work without #if haxe4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works fine on Haxe 4, but not on Haxe 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think it wouldn't compile, but I would still do one assignment instead of two))

createThread = Thread.createWithEventLoop;
#end
#end
var runThread:Thread = createThread(function()
{
self.execute();
while (self.running)
Expand Down Expand Up @@ -235,7 +241,7 @@ class TestRunner implements IAsyncDelegateObserver
var time:Float = Timer.stamp() - startTime;
for (client in clients)
{
if(Std.is(client, IAdvancedTestResultClient))
if(isOfType(client, IAdvancedTestResultClient))
{
var cl:IAdvancedTestResultClient = cast client;
cl.setCurrentTestClass(null);
Expand All @@ -249,7 +255,7 @@ class TestRunner implements IAsyncDelegateObserver
{
for(c in clients)
{
if(Std.is(c, IAdvancedTestResultClient) && activeHelper.hasNext())
if(isOfType(c, IAdvancedTestResultClient) && activeHelper.hasNext())
{
var cl:IAdvancedTestResultClient = cast c;
cl.setCurrentTestClass(activeHelper.className);
Expand Down Expand Up @@ -310,11 +316,11 @@ class TestRunner implements IAsyncDelegateObserver
}

#if hamcrest
if (Std.is(e, org.hamcrest.AssertionException))
if (isOfType(e, org.hamcrest.AssertionException))
e = new AssertionException(e.message, e.info);
#end

if (Std.is(e, AssertionException))
if (isOfType(e, AssertionException))
{
result.executionTime = Timer.stamp() - testStartTime;
result.failure = e;
Expand All @@ -325,7 +331,7 @@ class TestRunner implements IAsyncDelegateObserver
else
{
result.executionTime = Timer.stamp() - testStartTime;
if (!Std.is(e, MUnitException))
if (!isOfType(e, MUnitException))
e = new UnhandledException(e, result.location);

result.error = e;
Expand Down
2 changes: 1 addition & 1 deletion src/massive/munit/UnhandledException.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UnhandledException extends MUnitException
{
var s = "";
#if flash
if (Std.is(source, flash.errors.Error) && flash.system.Capabilities.isDebugger)
if (isOfType(source, flash.errors.Error) && flash.system.Capabilities.isDebugger)
{
var lines = source.getStackTrace().split("\n");
lines.shift(); // remove repeated error name
Expand Down
2 changes: 1 addition & 1 deletion src/massive/munit/client/HTTPClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HTTPClient implements IAdvancedTestResultClient
*/
public function setCurrentTestClass(className:String)
{
if(Std.is(client, IAdvancedTestResultClient))
if(isOfType(client, IAdvancedTestResultClient))
{
cast(client, IAdvancedTestResultClient).setCurrentTestClass(className);
}
Expand Down
2 changes: 1 addition & 1 deletion src/massive/munit/client/PrintClientBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class ExternalPrintClientJS implements ExternalPrintClient
#end

var a:Array<Dynamic> = [];
if(Std.is(args, Array)) a = a.concat(cast(args, Array<Dynamic>));
if(isOfType(args, Array)) a = a.concat(cast(args, Array<Dynamic>));
else a.push(args);
var jsCode = convertToJavaScript(method, a);
#if js
Expand Down
11 changes: 11 additions & 0 deletions src/massive/munit/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package massive.munit;

#if haxe4
#if (haxe >= version("4.1.0"))
import Std.isOfType as isOfType;
#else
import Std.is as isOfType;
#end
#else
import Std.is as isOfType;
#end