Added:
trunk/src/tests/utest/TestDispatcher.hx
trunk/src/utest.0.1.0.zip (contents, props changed)
trunk/src/utest/Dispatcher.hx
trunk/src/utest/ui/common/ResultStats.hx
Modified:
trunk/src/tests/iterations/Iteration1.hx
trunk/src/tests/iterations/Iteration2.hx
trunk/src/utest/Assert.hx
trunk/src/utest/Runner.hx
trunk/src/utest/TestFixture.hx
trunk/src/utest/TestHandler.hx
trunk/src/utest/TestResult.hx
trunk/src/utest/ui/common/ClassResult.hx
trunk/src/utest/ui/common/FixtureResult.hx
trunk/src/utest/ui/common/PackageResult.hx
trunk/src/utest/ui/common/ResultAggregator.hx
trunk/src/utest/ui/text/TraceReport.hx
Log:
utest now uses events in the form of Dispatcher (removing a handler is not
currently supported in Neko but either not necessary so far)
refactored relations between Result objects
Modified: trunk/src/tests/iterations/Iteration1.hx
==============================================================================
--- trunk/src/tests/iterations/Iteration1.hx (original)
+++ trunk/src/tests/iterations/Iteration1.hx Fri Sep 19 10:31:44 2008
@@ -128,9 +128,9 @@
var fixture = new TestFixture(new TestClass(), "test");
var handler = new TestHandler(fixture);
var flag = false;
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
flag = true;
- }
+ });
handler.execute();
trace(flag ? "OK #12" : "FAIL");
}
@@ -157,13 +157,13 @@
handler.addAsync(function() {
// do nothing
}, TIMEOUT);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace(flag1 ? "OK #15" : "FAIL");
flag2 = true;
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
trace("FAIL");
- }
+ });
trace(flag1 ? "FAIL" : "OK #16");
flag1 = true;
handler.execute();
@@ -183,12 +183,12 @@
trace(flag ? "FAIL" : "OK #18");
flag = true;
}, TIMEOUT*2);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace("TIMEOUT");
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
trace(flag ? "OK #19" : "FAIL");
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async(), DELAY);
#else
@@ -207,12 +207,12 @@
trace(s == expected ? "OK #20" : "FAIL");
value = s;
}, TIMEOUT*2);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace("TIMEOUT");
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
trace(value == expected ? "OK #21" : "FAIL");
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async(expected), DELAY);
#else
@@ -232,12 +232,12 @@
var async2 = handler.addAsync(function() {
value += "2";
}, TIMEOUT*2);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace("TIMEOUT");
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
trace(value == "12" ? "OK #22" : "FAIL");
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async2(), TIMEOUT*2);
async1();
@@ -256,12 +256,12 @@
var async = handler.addAsync(function() {
value++;
}, TIMEOUT*2);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace("TIMEOUT");
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
trace(value == 1 ? "OK #23" : "FAIL");
- }
+ });
async();
async();
handler.execute();
@@ -273,17 +273,17 @@
var handler = new TestHandler(fixture);
var value = 0;
var async = handler.addAsync(function() { }, TIMEOUT*2);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
trace("TIMEOUT");
- }
- handler.onTested = function(h) {
+ });
+ handler.onTested.add(function(h) {
switch(handler.results.pop()) {
case AsyncError(_):
trace("OK #24");
default:
trace("FAIL");
}
- }
+ });
async();
async();
handler.execute();
@@ -295,14 +295,14 @@
var handler = new TestHandler(fixture);
var value = 0;
var async = handler.addAsync(function() { }, TIMEOUT);
- handler.onTimeout = function(h) {
+ handler.onTimeout.add(function(h) {
switch(handler.results.pop()) {
case TimeoutError(i):
trace(i == 1 ? "OK #25" : "FAIL");
default:
trace("FAIL");
}
- }
+ });
handler.execute();
}
@@ -311,14 +311,14 @@
var fixture = new TestFixture(new TestClass(), "test");
var handler = new TestHandler(fixture);
var async = handler.addAsync(function() throw "error", TIMEOUT);
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
switch(handler.results.pop()) {
case AsyncError(_):
trace("OK #26");
default:
trace("FAIL");
}
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async(), DELAY);
#else
@@ -344,9 +344,9 @@
public function testOnComplete() {
var fixture = new TestFixture(new TestClass(), "test");
var handler = new TestHandler(fixture);
- handler.onComplete = function(h) {
+ handler.onComplete.add(function(h) {
trace("OK #28");
- }
+ });
handler.execute();
}
@@ -355,15 +355,15 @@
var fixture = new TestFixture(new TestClass(), "test");
var handler = new TestHandler(fixture);
var value = "";
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
value += "1";
- }
- handler.onTimeout = function(h) {
+ });
+ handler.onTimeout.add(function(h) {
value += "2";
- }
- handler.onComplete = function(h) {
+ });
+ handler.onComplete.add(function(h) {
trace(value == "1" ? "OK #29" : "FAIL");
- }
+ });
handler.execute();
}
@@ -373,15 +373,15 @@
var handler = new TestHandler(fixture);
var async = handler.addAsync(function() {}, TIMEOUT);
var value = "";
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
value += "1";
- }
- handler.onTimeout = function(h) {
+ });
+ handler.onTimeout.add(function(h) {
value += "2";
- }
- handler.onComplete = function(h) {
+ });
+ handler.onComplete.add(function(h) {
trace(value == "1" ? "OK #30" : "FAIL");
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async(), DELAY);
#else
@@ -396,15 +396,15 @@
var handler = new TestHandler(fixture);
handler.addAsync(function() {}, DELAY);
var value = "";
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
value += "1";
- }
- handler.onTimeout = function(h) {
+ });
+ handler.onTimeout.add(function(h) {
value += "2";
- }
- handler.onComplete = function(h) {
+ });
+ handler.onComplete.add(function(h) {
trace(value == "2" ? "OK #31" : "FAIL");
- }
+ });
handler.execute();
}
@@ -412,15 +412,15 @@
public function testTeardown() {
var fixture = new TestFixture(new TestClass(), "test", null, "teardown");
var handler = new TestHandler(fixture);
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
trace(fixture.target.doneteardown ? "FAIL" : "OK #32");
- }
- handler.onTimeout = function(h) {
+ });
+ handler.onTimeout.add(function(h) {
trace("FAIL");
- }
- handler.onComplete = function(h) {
+ });
+ handler.onComplete.add(function(h) {
trace(fixture.target.doneteardown ? "OK #33" : "FAIL");
- }
+ });
handler.execute();
}
@@ -429,15 +429,15 @@
var fixture = new TestFixture(new TestClass(), "test", null, "teardown");
var handler = new TestHandler(fixture);
var async = handler.addAsync(function(){}, TIMEOUT);
- handler.onTested = function(h) {
+ handler.onTested.add(function(h) {
trace(fixture.target.doneteardown ? "FAIL" : "OK #34");
- }
- handler.onTimeout = function(h) {
+ });
+ handler.onTimeout.add(function(h) {
trace("FAIL");
- }
- handler.onComplete = function(h) {
+ });
+ handler.onComplete.add(function(h) {
trace(fixture.target.doneteardown ? "OK #35" : "FAIL");
- }
+ });
#if (flash || js)
haxe.Timer.delay(function() async(), DELAY);
#else
@@ -446,38 +446,6 @@
handler.execute();
}
- // #28
- public function testExecutionTime() {
- var fixture = new TestFixture(new TestClass(), "test");
- var handler = new TestHandler(fixture);
- var start = haxe.Timer.stamp();
- handler.execute();
- var time = Std.int(1000*(haxe.Timer.stamp() - start));
- trace((!Math.isNaN(handler.executionTime))? "OK #36" : "FAIL");
- trace(handler.executionTime >= 0 ? "OK #37" : "FAIL");
- trace(handler.executionTime <= time ? "OK #38" : "FAIL");
- }
-
- // #29
- public function testExecutionTimeAsync() {
- var fixture = new TestFixture(new TestClass(), "test");
- var handler = new TestHandler(fixture);
- var async = handler.addAsync(function(){}, TIMEOUT);
- var start = haxe.Timer.stamp();
- handler.onComplete = function(h) {
- var time = Std.int(1000*(haxe.Timer.stamp() - start));
- trace((!Math.isNaN(handler.executionTime))? "OK #39" : "FAIL");
- trace(handler.executionTime >= 0 ? "OK #40" : "FAIL");
- trace(handler.executionTime <= time ? "OK #41" : "FAIL");
- }
-
-#if (flash || js)
- haxe.Timer.delay(function() async(), DELAY);
-#else
- async();
-#end
- handler.execute();
- }
public static function main() {
var t = new Iteration1();
@@ -508,7 +476,5 @@
t.testOnCompleteSequenceAsyncTimeout();
t.testTeardown();
t.testTeardownAsync();
- t.testExecutionTime();
- t.testExecutionTimeAsync();
}
}
Modified: trunk/src/tests/iterations/Iteration2.hx
==============================================================================
--- trunk/src/tests/iterations/Iteration2.hx (original)
+++ trunk/src/tests/iterations/Iteration2.hx Fri Sep 19 10:31:44 2008
@@ -11,9 +11,9 @@
public function testRunnerRun() {
var r = new Runner();
r.fixtures.add(new TestFixture(new TestClass(), "assertTrue"));
- r.onProgress = function(runner, result, done, totals) {
- trace(done == 1 ? "OK @1" : "FAIL");
- };
+ r.onProgress.add(function(e) {
+ trace(e.done == 1 ? "OK @1" : "FAIL");
+ });
r.run();
}
@@ -21,9 +21,9 @@
public function testAssertCreateAsync() {
var r = new Runner();
r.fixtures.add(new TestFixture(new TestClass(), "assertAsync"));
- r.onProgress = function(runner, result, done, totals) {
- trace(done == 1 ? "OK @2" : "FAIL");
- };
+ r.onProgress.add(function(e) {
+ trace(e.done == 1 ? "OK @2" : "FAIL");
+ });
r.run();
}
@@ -34,9 +34,9 @@
r.fixtures.add(new TestFixture(test, "test1"));
r.fixtures.add(new TestFixture(test, "test2"));
r.fixtures.add(new TestFixture(test, "test3"));
- r.onComplete = function(r){
+ r.onComplete.add(function(r){
trace(test.seq == "123" ? "OK @3" : "FAIL");
- }
+ });
r.run();
}
Added: trunk/src/tests/utest/TestDispatcher.hx
==============================================================================
--- (empty file)
+++ trunk/src/tests/utest/TestDispatcher.hx Fri Sep 19 10:31:44 2008
@@ -0,0 +1,79 @@
+package tests.utest;
+
+import utest.Assert;
+import utest.Dispatcher;
+
+class TestDispatcher {
+ public function new();
+
+ public function testBase() {
+ var dispatcher : Dispatcher<String> = new Dispatcher();
+ Assert.isFalse(dispatcher.has());
+ var h = dispatcher.add(function(x : String) {});
+ Assert.isTrue(dispatcher.has());
+ dispatcher.remove(h);
+ Assert.isFalse(dispatcher.has());
+ }
+
+ var v : String;
+ public function handler1(s : String) {
+ v += s+"e1";
+ }
+
+ public function handler2(s : String) {
+ v += s+"e2";
+ }
+
+ public function testHandlers() {
+ var dispatcher : Dispatcher<String> = new Dispatcher<String>();
+ v = "";
+ dispatcher.dispatch("d1");
+ Assert.equals("", v);
+
+ v = "";
+ dispatcher.add(handler1);
+ dispatcher.dispatch("d2");
+ Assert.equals("d2e1", v);
+
+ v = "";
+ dispatcher.add(handler2);
+ dispatcher.dispatch("d3");
+ Assert.equals("d3e1d3e2", v);
+
+ v = "";
+ dispatcher.add(handler1);
+ dispatcher.dispatch("d4");
+ Assert.equals("d4e1d4e2d4e1", v);
+
+ v = "";
+ dispatcher.remove(handler1);
+ dispatcher.dispatch("d5");
+ Assert.equals("d5e2d5e1", v);
+
+ v = "";
+ dispatcher.remove(handler1);
+ dispatcher.dispatch("d6");
+ Assert.equals("d6e2", v);
+
+ v = "";
+ dispatcher.remove(handler2);
+ dispatcher.dispatch("d7");
+ Assert.equals("", v);
+ }
+
+ public function stopper(s : String) {
+ v += s+"s";
+ Dispatcher.stop();
+ }
+
+ public function testStop() {
+ var dispatcher = new Dispatcher();
+ v = "";
+ dispatcher.add(handler1);
+ dispatcher.add(stopper);
+ dispatcher.add(handler2);
+ dispatcher.dispatch("d1");
+
+ Assert.equals("d1e1d1s", v);
+ }
+}
\ No newline at end of file
Added: trunk/src/utest.0.1.0.zip
==============================================================================
Binary file. No diff available.
Modified: trunk/src/utest/Assert.hx
==============================================================================
--- trunk/src/utest/Assert.hx (original)
+++ trunk/src/utest/Assert.hx Fri Sep 19 10:31:44 2008
@@ -17,7 +17,8 @@
isTrue(value == false, msg, pos);
}
- public static function isNull(value : Dynamic, msg = "expected null but
was not null", ?pos : PosInfos) {
+ public static function isNull(value : Dynamic, ?msg : String, ?pos :
PosInfos) {
+ if(msg == null) msg = "expected null but was " + Std.string(value);
isTrue(value == null, msg, pos);
}
@@ -38,6 +39,35 @@
public static function floatEquals(expected : Float, value :
Float, ?msg : String , ?pos : PosInfos) {
if(msg == null) msg = "expected " + expected + " but was " + value;
isTrue(Math.abs(value-expected) < 1e-5, msg, pos);
+ }
+
+ /**
+ * Check that value is an object and contains at least the same fields and
values found in expcted.
+ * The default behavior is to check nested objects in fields recursively.
+ */
+ public static function like(expected : Dynamic, value : Dynamic,
recursive = true, ?path = '', ?msg : String, ?pos : PosInfos) {
+ if(expected == null && value == null) {
+ isTrue(true, msg, pos);
+ return;
+ }
+ var fields = Reflect.fields(expected);
+ for(field in fields) {
+ if(!Reflect.hasField(value, field)) {
+ Assert.fail("value doesn't have the expected field '"+path+field+"'");
+ return;
+ }
+ var e = Reflect.field(expected, field);
+ var v = Reflect.field(value, field);
+ if(Reflect.isObject(e) && recursive) {
+ like(e, v, true, field+'.', msg, pos);
+ } else {
+ if(e != v) {
+ Assert.fail("the expected value for the field '"+path+field+"'
was '"+e+"' but it is '"+v+"'");
+ return;
+ }
+ }
+ }
+ Assert.isTrue(true, msg, pos);
}
public static function raises(method:Void -> Void,
type:Class<Dynamic>, ?msg : String , ?pos : PosInfos) {
Added: trunk/src/utest/Dispatcher.hx
==============================================================================
--- (empty file)
+++ trunk/src/utest/Dispatcher.hx Fri Sep 19 10:31:44 2008
@@ -0,0 +1,95 @@
+package utest;
+
+private enum EventException {
+ StopPropagation;
+}
+
+class Dispatcher<T> {
+
+ private var handlers : Array<T -> Void>;
+
+ public function new() {
+ handlers = new Array();
+ }
+
+ public function add(h : T -> Void) : T -> Void {
+ handlers.push(h);
+ return h;
+ }
+
+ public function remove(h : T -> Void) : T -> Void {
+ for(i in 0...handlers.length)
+ if(Reflect.compareMethods(handlers[i], h))
+ return handlers.splice(i, 1)[0];
+ return null;
+ }
+
+ public function clear() {
+ handlers = new Array();
+ }
+
+ public function dispatch(e) {
+ try {
+ // prevents problems with self removing events
+ var list = handlers.copy();
+ for( l in list )
+ l(e);
+ return true;
+ } catch( exc : EventException ) {
+ return false;
+ }
+ }
+
+ public function has() {
+ return handlers.length > 0;
+ }
+
+ public static function stop() {
+ throw StopPropagation;
+ }
+}
+
+class Notifier {
+
+ private var handlers : Array<Void -> Void>;
+
+ public function new() {
+ handlers = new Array();
+ }
+
+ public function add(h : Void -> Void) : Void -> Void {
+ handlers.push(h);
+ return h;
+ }
+
+ public function remove(h : Void -> Void) : Void -> Void {
+ for(i in 0...handlers.length)
+ if(Reflect.compareMethods(handlers[i], h))
+ return handlers.splice(i, 1)[0];
+ return null;
+ }
+
+ public function clear() {
+ handlers = new Array();
+ }
+
+ public function dispatch() {
+ try {
+ // prevents problems with self removing events
+ var list = handlers.copy();
+ for( l in list )
+ l();
+ return true;
+ } catch( exc : EventException ) {
+ return false;
+ }
+ }
+
+ public function has() {
+ return handlers.length > 0;
+ }
+
+ public static function stop() {
+ throw StopPropagation;
+ }
+}
\ No newline at end of file
Modified: trunk/src/utest/Runner.hx
==============================================================================
--- trunk/src/utest/Runner.hx (original)
+++ trunk/src/utest/Runner.hx Fri Sep 19 10:31:44 2008
@@ -1,10 +1,20 @@
package utest;
+import utest.Dispatcher;
+
class Runner {
public var fixtures(default, null) : List<TestFixture<Dynamic>>;
+
+ public var onProgress(default, null) : Dispatcher<{ result : TestResult,
done : Int, totals : Int }>;
+ public var onStart(default, null) : Dispatcher<Runner>;
+ public var onComplete(default, null) : Dispatcher<Runner>;
+
public function new() {
- fixtures = new List();
+ fixtures = new List();
+ onProgress = new Dispatcher();
+ onStart = new Dispatcher();
+ onComplete = new Dispatcher();
}
public function addCase(test : Dynamic, setup = "setup", teardown
= "teardown", prefix = "test", ?pattern : EReg) {
@@ -41,7 +51,7 @@
public function run() {
counter = 0;
testsToRun = fixtures.length;
- onStart(this);
+ onStart.dispatch(this);
runNext();
}
@@ -49,22 +59,18 @@
if(fixtures.length > 0)
runFixture(fixtures.pop());
else
- onComplete(this);
+ onComplete.dispatch(this);
}
- public dynamic function onProgress(runner : Runner, result : TestResult,
done : Int, totals : Int);
- public dynamic function onStart(r : Runner);
- public dynamic function onComplete(r : Runner);
-
var counter : Int;
function runFixture(fixture : TestFixture<Dynamic>) {
var handler = new TestHandler(fixture);
- handler.onComplete = testComplete;
+ handler.onComplete.add(testComplete);
handler.execute();
}
function testComplete(h : TestHandler<Dynamic>) {
- onProgress(this, TestResult.ofHandler(h), fixtures.length+1, testsToRun);
+ onProgress.dispatch({ result : TestResult.ofHandler(h), done :
fixtures.length+1, totals : testsToRun });
runNext();
}
}
Modified: trunk/src/utest/TestFixture.hx
==============================================================================
--- trunk/src/utest/TestFixture.hx (original)
+++ trunk/src/utest/TestFixture.hx Fri Sep 19 10:31:44 2008
@@ -7,17 +7,6 @@
public var teardown(default, null) : String;
public function new(target : T, method : String, ?setup :
String, ?teardown : String) {
this.target = target;
- /*
- if(!Reflect.isObject(target)) throw "target argument is not an object";
-
-
- checkMethod(method, "method");
-
- if(setup != null)
- checkMethod(setup, "setup");
- if(teardown != null)
- checkMethod(teardown, "teardown");
-*/
this.method = method;
this.setup = setup;
this.teardown = teardown;
Modified: trunk/src/utest/TestHandler.hx
==============================================================================
--- trunk/src/utest/TestHandler.hx (original)
+++ trunk/src/utest/TestHandler.hx Fri Sep 19 10:31:44 2008
@@ -6,22 +6,26 @@
private static inline var POLLING_TIME = 10;
public var results(default, null) : List<Assertation>;
public var fixture(default, null) : TestFixture<T>;
- public var executionTime(default, null) : Int;
var asyncStack : List<Dynamic>;
+
+ public var onTested(default, null) : Dispatcher<TestHandler<T>>;
+ public var onTimeout(default, null) : Dispatcher<TestHandler<T>>;
+ public var onComplete(default, null) : Dispatcher<TestHandler<T>>;
+
public function new(fixture : TestFixture<T>) {
if(fixture == null) throw "fixture argument is null";
this.fixture = fixture;
results = new List();
asyncStack = new List();
- executionTime = -1;
+ onTested = new Dispatcher();
+ onTimeout = new Dispatcher();
+ onComplete = new Dispatcher();
}
- var startTime : Null<Float>;
public function execute() {
try {
executeMethod(fixture.setup);
try {
- startTime = haxe.Timer.stamp();
executeMethod(fixture.method);
} catch(e : Dynamic) {
results.add(Error(e));
@@ -110,17 +114,15 @@
}
function tested() {
- if(startTime != null)
- executionTime = Std.int((haxe.Timer.stamp() - startTime)*1000);
if(results.length == 0)
results.add(Warning("no assertions"));
- onTested(this);
+ onTested.dispatch(this);
completed();
}
function timeout() {
results.add(TimeoutError(asyncStack.length));
- onTimeout(this);
+ onTimeout.dispatch(this);
completed();
}
@@ -131,10 +133,6 @@
results.add(TeardownError(e));
}
unbindHandler();
- onComplete(this);
+ onComplete.dispatch(this);
}
-
- public dynamic function onTested(handler : TestHandler<T>);
- public dynamic function onTimeout(handler : TestHandler<T>);
- public dynamic function onComplete(handler : TestHandler<T>);
}
Modified: trunk/src/utest/TestResult.hx
==============================================================================
--- trunk/src/utest/TestResult.hx (original)
+++ trunk/src/utest/TestResult.hx Fri Sep 19 10:31:44 2008
@@ -8,71 +8,7 @@
public var method : String;
public var setup : String;
public var teardown : String;
- public var executionTime : Int;
public var assertations : List<Assertation>;
-/*
- public function hasSetup() {
- return setup != null;
- }
-
- public function hasTeardown() {
- return setup != null;
- }
-
- public function count() {
- return assertations.length;
- }
-
- public function successes() {
- return countAssertions(Success(null));
- }
-
- public function failures() {
- return countAssertions(Failure(null, null));
- }
-
- public function errors() {
- return countAssertions(Error(null));
- }
-
- public function setupErrors() {
- return countAssertions(SetupError(null));
- }
-
- public function teardownErrors() {
- return countAssertions(TeardownError(null));
- }
-
- public function timeoutErrors() {
- return countAssertions(TimeoutError(-1));
- }
-
- public function asyncErrors() {
- return countAssertions(AsyncError(null));
- }
-
- public function warnings() {
- return countAssertions(Warning(null));
- }
-
- public function allErrors() {
- return errors() + setupErrors() + teardownErrors() + timeoutErrors() +
asyncErrors();
- }
-
- public function isOk() {
- return assertations.length == successes();
- }
-
- function countAssertions(type : Assertation) {
- var index = Type.enumIndex(type);
- var v = 0;
- for(assertation in assertations) {
- if(index == Type.enumIndex(assertation))
- v++;
- }
- return v;
- }
-*/
public function new();
@@ -84,7 +20,6 @@
r.method = handler.fixture.method;
r.setup = handler.fixture.setup;
r.teardown = handler.fixture.teardown;
- r.executionTime = handler.executionTime;
r.assertations = handler.results;
return r;
}
Modified: trunk/src/utest/ui/common/ClassResult.hx
==============================================================================
--- trunk/src/utest/ui/common/ClassResult.hx (original)
+++ trunk/src/utest/ui/common/ClassResult.hx Fri Sep 19 10:31:44 2008
@@ -3,7 +3,6 @@
import utest.TestResult;
class ClassResult {
- public var executionTime(default, null) : Int;
var fixtures : Hash<FixtureResult>;
public var className(default, null) : String;
public var setupName(default, null) : String;
@@ -12,19 +11,9 @@
public var hasTeardown(default, null) : Bool;
public var methods(default, null) : Int;
- public var assertations(default, null) : Int;
- public var successes(default, null) : Int;
- public var failures(default, null) : Int;
- public var errors(default, null) : Int;
- public var warnings(default, null) : Int;
-
- public var isOk(default, null) : Bool;
- public var hasFailures(default, null) : Bool;
- public var hasErrors(default, null) : Bool;
- public var hasWarnings(default, null) : Bool;
+ public var stats(default, null) : ResultStats;
public function new(className : String, setupName : String,
teardownName : String) {
- executionTime = 0;
fixtures = new Hash();
this.className = className;
this.setupName = setupName;
@@ -33,35 +22,16 @@
hasTeardown = teardownName != null;
methods = 0;
- assertations = 0;
- successes = 0;
- failures = 0;
- errors = 0;
- warnings = 0;
-
- isOk = true;
- hasFailures = false;
- hasErrors = false;
- hasWarnings = false;
+ stats = new ResultStats();
}
public function add(result : FixtureResult) {
if(fixtures.exists(result.methodName)) throw "invalid duplicated fixture
result";
+
+ stats.wire(result.stats);
+
methods++;
fixtures.set(result.methodName, result);
- executionTime += result.executionTime;
- assertations += result.assertations;
- successes += result.successes;
- failures += result.failures;
- errors += result.errors;
- warnings += result.warnings;
- isOk = isOk && result.isOk;
- if(result.hasFailures)
- hasFailures = true;
- if(result.hasErrors)
- hasErrors = true;
- if(result.hasWarnings)
- hasWarnings = true;
}
public function get(method : String) {
@@ -79,19 +49,19 @@
if(errorsHavePriority) {
var me = this;
names.sort(function(a, b) {
- var afix = me.get(a);
- var bfix = me.get(b);
- if(afix.hasErrors) {
- return (!bfix.hasErrors) ? -1 : (afix.errors == bfix.errors ?
Reflect.compare(a, b) : Reflect.compare(afix.errors, bfix.errors));
- } else if(bfix.hasErrors) {
+ var as = me.get(a).stats;
+ var bs = me.get(b).stats;
+ if(as.hasErrors) {
+ return (!bs.hasErrors) ? -1 : (as.errors == bs.errors ?
Reflect.compare(a, b) : Reflect.compare(as.errors, bs.errors));
+ } else if(bs.hasErrors) {
return 1;
- } else if(afix.hasFailures) {
- return (!bfix.hasFailures) ? -1 : (afix.failures == bfix.failures ?
Reflect.compare(a, b) : Reflect.compare(afix.failures, bfix.failures));
- } else if(bfix.hasFailures) {
+ } else if(as.hasFailures) {
+ return (!bs.hasFailures) ? -1 : (as.failures == bs.failures ?
Reflect.compare(a, b) : Reflect.compare(as.failures, bs.failures));
+ } else if(bs.hasFailures) {
return 1;
- } else if(afix.hasWarnings) {
- return (!bfix.hasWarnings) ? -1 : (afix.warnings == bfix.warnings ?
Reflect.compare(a, b) : Reflect.compare(afix.warnings, bfix.warnings));
- } else if(bfix.hasWarnings) {
+ } else if(as.hasWarnings) {
+ return (!bs.hasWarnings) ? -1 : (as.warnings == bs.warnings ?
Reflect.compare(a, b) : Reflect.compare(as.warnings, bs.warnings));
+ } else if(bs.hasWarnings) {
return 1;
} else {
return Reflect.compare(a, b);
Modified: trunk/src/utest/ui/common/FixtureResult.hx
==============================================================================
--- trunk/src/utest/ui/common/FixtureResult.hx (original)
+++ trunk/src/utest/ui/common/FixtureResult.hx Fri Sep 19 10:31:44 2008
@@ -3,48 +3,26 @@
import utest.Assertation;
class FixtureResult {
- public var executionTime(default, null) : Int;
public var methodName(default, null) : String;
-
- public var assertations(default, null) : Int;
- public var successes(default, null) : Int;
- public var failures(default, null) : Int;
- public var errors(default, null) : Int;
- public var warnings(default, null) : Int;
-
- public var isOk(default, null) : Bool;
- public var hasFailures(default, null) : Bool;
- public var hasErrors(default, null) : Bool;
- public var hasWarnings(default, null) : Bool;
-
public var hasTestError(default, null) : Bool;
public var hasSetupError(default, null) : Bool;
public var hasTeardownError(default, null) : Bool;
public var hasTimeoutError(default, null) : Bool;
public var hasAsyncError(default, null) : Bool;
+ public var stats(default, null) : ResultStats;
+
var list(default, null) : List<Assertation>;
- public function new(executionTime : Int, methodName : String) {
- this.executionTime = executionTime;
+ public function new(methodName : String) {
this.methodName = methodName;
this.list = new List();
-
- assertations = 0;
- successes = 0;
- failures = 0;
- errors = 0;
- warnings = 0;
-
- isOk = true;
- hasFailures = false;
- hasErrors = false;
- hasWarnings = false;
-
hasTestError = false;
hasSetupError = false;
hasTeardownError = false;
hasTimeoutError = false;
hasAsyncError = false;
+
+ stats = new ResultStats();
}
public function iterator() {
@@ -53,43 +31,27 @@
public function add(assertation : Assertation) {
list.add(assertation);
- assertations++;
switch(assertation) {
case Success(_):
- successes++;
+ stats.addSuccesses(1);
case Failure(_, _):
- failures++;
- hasFailures = true;
- isOk = false;
+ stats.addFailures(1);
case Error(_):
- errors++;
- hasErrors = true;
- hasTestError = true;
- isOk = false;
+ stats.addErrors(1);
case SetupError(_):
- errors++;
- hasErrors = true;
+ stats.addErrors(1);
hasSetupError = true;
- isOk = false;
case TeardownError(_):
- errors++;
- hasErrors = true;
+ stats.addErrors(1);
hasTeardownError = true;
- isOk = false;
case TimeoutError(_):
- errors++;
- hasErrors = true;
+ stats.addErrors(1);
hasTimeoutError = true;
- isOk = false;
case AsyncError(_):
- errors++;
- hasErrors = true;
+ stats.addErrors(1);
hasAsyncError = true;
- isOk = false;
case Warning(_):
- warnings++;
- hasWarnings = true;
- isOk = false;
+ stats.addWarnings(1);
}
}
}
Modified: trunk/src/utest/ui/common/PackageResult.hx
==============================================================================
--- trunk/src/utest/ui/common/PackageResult.hx (original)
+++ trunk/src/utest/ui/common/PackageResult.hx Fri Sep 19 10:31:44 2008
@@ -7,68 +7,30 @@
import utest.Assertation;
class PackageResult {
- public var executionTime(default, null) : Int;
public var packageName(default, null) : String;
var classes : Hash<ClassResult>;
var packages : Hash<PackageResult>;
- public var assertations(default, null) : Int;
- public var successes(default, null) : Int;
- public var failures(default, null) : Int;
- public var errors(default, null) : Int;
- public var warnings(default, null) : Int;
-
- public var isOk(default, null) : Bool;
- public var hasFailures(default, null) : Bool;
- public var hasErrors(default, null) : Bool;
- public var hasWarnings(default, null) : Bool;
+ public var stats(default, null) : ResultStats;
public function new(packageName : String) {
this.packageName = packageName;
-
- executionTime = 0;
classes = new Hash();
packages = new Hash();
-
- assertations = 0;
- successes = 0;
- failures = 0;
- errors = 0;
- warnings = 0;
-
- isOk = true;
- hasFailures = false;
- hasErrors = false;
- hasWarnings = false;
+ stats = new ResultStats();
}
public function addResult(result : TestResult, flattenPackage : Bool) {
var pack = getOrCreatePackage(result.pack, flattenPackage, this);
var cls = getOrCreateClass(pack, result.cls, result.setup,
result.teardown);
- var fix = createFixtureAndIncrement(result.method, result.executionTime,
result.assertations);
+ var fix = createFixture(result.method, result.assertations);
cls.add(fix);
}
- function createFixtureAndIncrement(method : String, executionTime : Int,
assertations : Iterable<Assertation>) {
- var f = new FixtureResult(executionTime, method);
+ function createFixture(method : String, assertations :
Iterable<Assertation>) {
+ var f = new FixtureResult(method);
for(assertation in assertations)
f.add(assertation);
-
- executionTime += f.executionTime;
- this.assertations += f.assertations;
- successes += f.successes;
- failures += f.failures;
- errors += f.errors;
- warnings += f.warnings;
-
- isOk = isOk && f.isOk;
- if(f.hasFailures)
- hasFailures = true;
- if(f.hasErrors)
- hasErrors = true;
- if(f.hasWarnings)
- hasWarnings = true;
-
return f;
}
@@ -98,40 +60,12 @@
public function addClass(result : ClassResult) {
classes.set(result.className, result);
-
- executionTime += result.executionTime;
- assertations += result.assertations;
- successes += result.successes;
- failures += result.failures;
- errors += result.errors;
- warnings += result.warnings;
-
- isOk = isOk && result.isOk;
- if(result.hasFailures)
- hasFailures = true;
- if(result.hasErrors)
- hasErrors = true;
- if(result.hasWarnings)
- hasWarnings = true;
+ stats.wire(result.stats);
}
public function addPackage(result : PackageResult) {
packages.set(result.packageName, result);
-
- executionTime += result.executionTime;
- assertations += result.assertations;
- successes += result.successes;
- failures += result.failures;
- errors += result.errors;
- warnings += result.warnings;
-
- isOk = isOk && result.isOk;
- if(result.hasFailures)
- hasFailures = true;
- if(result.hasErrors)
- hasErrors = true;
- if(result.hasWarnings)
- hasWarnings = true;
+ stats.wire(result.stats);
}
public function existsPackage(name : String) {
@@ -157,19 +91,19 @@
if(errorsHavePriority) {
var me = this;
names.sort(function(a, b) {
- var afix = me.getClass(a);
- var bfix = me.getClass(b);
- if(afix.hasErrors) {
- return (!bfix.hasErrors) ? -1 : (afix.errors == bfix.errors ?
Reflect.compare(a, b) : Reflect.compare(afix.errors, bfix.errors));
- } else if(bfix.hasErrors) {
+ var as = me.getClass(a).stats;
+ var bs = me.getClass(b).stats;
+ if(as.hasErrors) {
+ return (!bs.hasErrors) ? -1 : (as.errors == bs.errors ?
Reflect.compare(a, b) : Reflect.compare(as.errors, bs.errors));
+ } else if(bs.hasErrors) {
return 1;
- } else if(afix.hasFailures) {
- return (!bfix.hasFailures) ? -1 : (afix.failures == bfix.failures ?
Reflect.compare(a, b) : Reflect.compare(afix.failures, bfix.failures));
- } else if(bfix.hasFailures) {
+ } else if(as.hasFailures) {
+ return (!bs.hasFailures) ? -1 : (as.failures == bs.failures ?
Reflect.compare(a, b) : Reflect.compare(as.failures, bs.failures));
+ } else if(bs.hasFailures) {
return 1;
- } else if(afix.hasWarnings) {
- return (!bfix.hasWarnings) ? -1 : (afix.warnings == bfix.warnings ?
Reflect.compare(a, b) : Reflect.compare(afix.warnings, bfix.warnings));
- } else if(bfix.hasWarnings) {
+ } else if(as.hasWarnings) {
+ return (!bs.hasWarnings) ? -1 : (as.warnings == bs.warnings ?
Reflect.compare(a, b) : Reflect.compare(as.warnings, bs.warnings));
+ } else if(bs.hasWarnings) {
return 1;
} else {
return Reflect.compare(a, b);
@@ -190,19 +124,19 @@
if(errorsHavePriority) {
var me = this;
names.sort(function(a, b) {
- var afix = me.getPackage(a);
- var bfix = me.getPackage(b);
- if(afix.hasErrors) {
- return (!bfix.hasErrors) ? -1 : (afix.errors == bfix.errors ?
Reflect.compare(a, b) : Reflect.compare(afix.errors, bfix.errors));
- } else if(bfix.hasErrors) {
+ var as = me.getPackage(a).stats;
+ var bs = me.getPackage(b).stats;
+ if(as.hasErrors) {
+ return (!bs.hasErrors) ? -1 : (as.errors == bs.errors ?
Reflect.compare(a, b) : Reflect.compare(as.errors, bs.errors));
+ } else if(bs.hasErrors) {
return 1;
- } else if(afix.hasFailures) {
- return (!bfix.hasFailures) ? -1 : (afix.failures == bfix.failures ?
Reflect.compare(a, b) : Reflect.compare(afix.failures, bfix.failures));
- } else if(bfix.hasFailures) {
+ } else if(as.hasFailures) {
+ return (!bs.hasFailures) ? -1 : (as.failures == bs.failures ?
Reflect.compare(a, b) : Reflect.compare(as.failures, bs.failures));
+ } else if(bs.hasFailures) {
return 1;
- } else if(afix.hasWarnings) {
- return (!bfix.hasWarnings) ? -1 : (afix.warnings == bfix.warnings ?
Reflect.compare(a, b) : Reflect.compare(afix.warnings, bfix.warnings));
- } else if(bfix.hasWarnings) {
+ } else if(as.hasWarnings) {
+ return (!bs.hasWarnings) ? -1 : (as.warnings == bs.warnings ?
Reflect.compare(a, b) : Reflect.compare(as.warnings, bs.warnings));
+ } else if(bs.hasWarnings) {
return 1;
} else {
return Reflect.compare(a, b);
Modified: trunk/src/utest/ui/common/ResultAggregator.hx
==============================================================================
--- trunk/src/utest/ui/common/ResultAggregator.hx (original)
+++ trunk/src/utest/ui/common/ResultAggregator.hx Fri Sep 19 10:31:44 2008
@@ -3,6 +3,7 @@
*/
package utest.ui.common;
+import utest.Dispatcher;
import utest.Runner;
import utest.TestResult;
@@ -10,18 +11,27 @@
var runner : Runner;
var flattenPackage : Bool;
public var root(default, null) : PackageResult;
+
+ public var onStart(default, null) : Notifier;
+ public var onComplete(default, null) : Dispatcher<PackageResult>;
+ public var onProgress(default, null) : Dispatcher<{ done : Int, totals :
Int }>;
+
public function new(runner : Runner, flattenPackage = false) {
if(runner == null) throw "runner argument is null";
this.flattenPackage = flattenPackage;
this.runner = runner;
- runner.onStart = start;
- runner.onProgress = progress;
- runner.onComplete = complete;
+ runner.onStart.add(start);
+ runner.onProgress.add(progress);
+ runner.onComplete.add(complete);
+
+ onStart = new Notifier();
+ onComplete = new Dispatcher();
+ onProgress = new Dispatcher();
}
function start(runner : Runner) {
root = new PackageResult(null);
- onStart();
+ onStart.dispatch();
}
function getOrCreatePackage(pack : String, flat : Bool, ?ref :
PackageResult) {
@@ -50,22 +60,18 @@
}
function createFixture(result : TestResult) {
- var f = new FixtureResult(result.executionTime, result.method);
+ var f = new FixtureResult(result.method);
for(assertation in result.assertations)
f.add(assertation);
return f;
}
- function progress(runner : Runner, result : TestResult, done : Int,
totals : Int) {
- root.addResult(result, flattenPackage);
- onProgress(done, totals);
+ function progress(e) {
+ root.addResult(e.result, flattenPackage);
+ onProgress.dispatch(e);
}
function complete(runner : Runner) {
- onComplete(root);
+ onComplete.dispatch(root);
}
-
- public dynamic function onStart();
- public dynamic function onComplete(pack : PackageResult);
- public dynamic function onProgress(done : Int, totals : Int);
}
Added: trunk/src/utest/ui/common/ResultStats.hx
==============================================================================
--- (empty file)
+++ trunk/src/utest/ui/common/ResultStats.hx Fri Sep 19 10:31:44 2008
@@ -0,0 +1,103 @@
+package utest.ui.common;
+
+import utest.Dispatcher;
+
+class ResultStats {
+ public var assertations(default, null) : Int;
+ public var successes(default, null) : Int;
+ public var failures(default, null) : Int;
+ public var errors(default, null) : Int;
+ public var warnings(default, null) : Int;
+ public var onAddSuccesses(default, null) : Dispatcher<Int>;
+ public var onAddFailures(default, null) : Dispatcher<Int>;
+ public var onAddErrors(default, null) : Dispatcher<Int>;
+ public var onAddWarnings(default, null) : Dispatcher<Int>;
+
+ public var isOk(default, null) : Bool;
+ public var hasFailures(default, null) : Bool;
+ public var hasErrors(default, null) : Bool;
+ public var hasWarnings(default, null) : Bool;
+
+ public function new() {
+ assertations = 0;
+ successes = 0;
+ failures = 0;
+ errors = 0;
+ warnings = 0;
+
+ isOk = true;
+ hasFailures = false;
+ hasErrors = false;
+ hasWarnings = false;
+
+ onAddSuccesses = new Dispatcher();
+ onAddFailures = new Dispatcher();
+ onAddErrors = new Dispatcher();
+ onAddWarnings = new Dispatcher();
+ }
+
+ public function addSuccesses(v : Int) {
+ if(v == 0) return;
+ assertations += v;
+ successes += v;
+ onAddSuccesses.dispatch(v);
+ }
+
+ public function addFailures(v : Int) {
+ if(v == 0) return;
+ assertations += v;
+ failures += v;
+ hasFailures = failures > 0;
+ isOk = !(hasFailures || hasErrors || hasWarnings);
+ onAddFailures.dispatch(v);
+ }
+
+ public function addErrors(v : Int) {
+ if(v == 0) return;
+ assertations += v;
+ errors += v;
+ hasErrors = errors > 0;
+ isOk = !(hasFailures || hasErrors || hasWarnings);
+ onAddErrors.dispatch(v);
+ }
+
+ public function addWarnings(v : Int) {
+ if(v == 0) return;
+ assertations += v;
+ warnings += v;
+ hasWarnings = warnings > 0;
+ isOk = !(hasFailures || hasErrors || hasWarnings);
+ onAddWarnings.dispatch(v);
+ }
+
+ public function sum(other : ResultStats) {
+ addSuccesses(other.successes);
+ addFailures(other.failures);
+ addErrors(other.errors);
+ addWarnings(other.warnings);
+ }
+
+ public function subtract(other : ResultStats) {
+ addSuccesses(-other.successes);
+ addFailures(-other.failures);
+ addErrors(-other.errors);
+ addWarnings(-other.warnings);
+ }
+
+ public function wire(dependant : ResultStats) {
+ dependant.onAddSuccesses.add(addSuccesses);
+ dependant.onAddFailures.add(addFailures);
+ dependant.onAddErrors.add(addErrors);
+ dependant.onAddWarnings.add(addWarnings);
+ sum(dependant);
+ }
+
+ public function unwire(dependant : ResultStats) {
+ dependant.onAddSuccesses.remove(addSuccesses);
+ dependant.onAddFailures.remove(addFailures);
+ dependant.onAddErrors.remove(addErrors);
+ dependant.onAddWarnings.remove(addWarnings);
+ subtract(dependant);
+ }
+
+}
\ No newline at end of file
Modified: trunk/src/utest/ui/text/TraceReport.hx
==============================================================================
--- trunk/src/utest/ui/text/TraceReport.hx (original)
+++ trunk/src/utest/ui/text/TraceReport.hx Fri Sep 19 10:31:44 2008
@@ -14,9 +14,7 @@
var indent : String;
public function new(runner : Runner) {
aggregator = new ResultAggregator(runner, true);
- aggregator.onComplete = complete;
- aggregator.onStart = start;
- aggregator.onProgress = progress;
+ aggregator.onComplete.add(complete);
#if php
if(php.Lib.isCli()) {
newline = "\n";
@@ -46,20 +44,15 @@
return s;
}
- function start() {
-
- }
-
function complete(result : PackageResult) {
var buf = new StringBuf();
- buf.add("results: " + (result.isOk ? "ALL TESTS OK" : "SOME TESTS
FAILURES")+newline+" "+newline);
+ buf.add("results: " + (result.stats.isOk ? "ALL TESTS OK" : "SOME TESTS
FAILURES")+newline+" "+newline);
- buf.add("assertations: " + result.assertations+newline);
- buf.add("successes: " + result.successes+newline);
- buf.add("errors: " + result.errors+newline);
- buf.add("failures: " + result.failures+newline);
- buf.add("warnings: " + result.warnings+newline);
- buf.add("total time: " + result.executionTime+newline);
+ buf.add("assertations: " + result.stats.assertations+newline);
+ buf.add("successes: " + result.stats.successes+newline);
+ buf.add("errors: " + result.stats.errors+newline);
+ buf.add("failures: " + result.stats.failures+newline);
+ buf.add("warnings: " + result.stats.warnings+newline);
buf.add(newline);
@@ -71,13 +64,13 @@
for(mname in cls.methodNames()) {
var fix = cls.get(mname);
buf.add(indents(1)+mname+": ");
- if(fix.isOk) {
+ if(fix.stats.isOk) {
buf.add("OK ");
- } else if(fix.hasErrors) {
+ } else if(fix.stats.hasErrors) {
buf.add("ERROR ");
- } else if(fix.hasFailures) {
+ } else if(fix.stats.hasFailures) {
buf.add("FAILURE ");
- } else if(fix.hasWarnings) {
+ } else if(fix.stats.hasWarnings) {
buf.add("WARNING ");
}
var messages = '';
@@ -114,8 +107,5 @@
}
}
trace(buf.toString());
- }
-
- function progress(done : Int, totals : Int) {
}
}