[utest commit] r16 - no log message

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 17, 2009, 2:40:38 PM4/17/09
to utes...@googlegroups.com
Author: franco.ponticelli
Date: Fri Apr 17 11:24:55 2009
New Revision: 16

Modified:
trunk/src/tests/utest/TestAssert.hx
trunk/src/tests/utest/TestDispatcher.hx
trunk/src/utest/Assert.hx
trunk/src/utest/Runner.hx
trunk/src/utest/TestHandler.hx

Log:


Modified: trunk/src/tests/utest/TestAssert.hx
==============================================================================
--- trunk/src/tests/utest/TestAssert.hx (original)
+++ trunk/src/tests/utest/TestAssert.hx Fri Apr 17 11:24:55 2009
@@ -2,10 +2,19 @@

import utest.Assert;
import utest.Assertation;
+import utest.Runner;
+import utest.ui.text.TraceReport;

class TestAssert {
public function new();

+ public static function main() {
+ var runner = new Runner();
+ runner.addCase(new TestAssert());
+ var report = new TraceReport(runner);
+ runner.run();
+ }
+
var resultsbypass : List<Assertation>;
var results : List<Assertation>;
public function bypass() {

Modified: trunk/src/tests/utest/TestDispatcher.hx
==============================================================================
--- trunk/src/tests/utest/TestDispatcher.hx (original)
+++ trunk/src/tests/utest/TestDispatcher.hx Fri Apr 17 11:24:55 2009
@@ -2,10 +2,19 @@

import utest.Assert;
import utest.Dispatcher;
+import utest.Runner;
+import utest.ui.text.TraceReport;

class TestDispatcher {
public function new();

+ public static function main() {
+ var runner = new Runner();
+ runner.addCase(new TestDispatcher());
+ var report = new TraceReport(runner);
+ runner.run();
+ }
+
public function testBase() {
var dispatcher : Dispatcher<String> = new Dispatcher();
Assert.isFalse(dispatcher.has());

Modified: trunk/src/utest/Assert.hx
==============================================================================
--- trunk/src/utest/Assert.hx (original)
+++ trunk/src/utest/Assert.hx Fri Apr 17 11:24:55 2009
@@ -256,11 +256,19 @@
}
}

- public static function allow<T>(possibilities : Array<T>, value :
T, ?msg : String , ?pos : PosInfos) {
+ public static function allows<T>(possibilities : Array<T>, value :
T, ?msg : String , ?pos : PosInfos) {
if(Lambda.has(possibilities, value)) {
isTrue(true, msg, pos);
} else {
fail(msg == null ? "value "+value+" not found in the expected
possibilities "+possibilities : msg, pos);
+ }
+ }
+
+ public static function contains<T>(match : T, values : Array<T>, ?msg :
String , ?pos : PosInfos) {
+ if(Lambda.has(values, match)) {
+ isTrue(true, msg, pos);
+ } else {
+ fail(msg == null ? "values "+values+" do not contain "+match: msg, pos);
}
}


Modified: trunk/src/utest/Runner.hx
==============================================================================
--- trunk/src/utest/Runner.hx (original)
+++ trunk/src/utest/Runner.hx Fri Apr 17 11:24:55 2009
@@ -2,15 +2,35 @@

import utest.Dispatcher;

-
+/**
+* The Runner class performs a set of tests. The tests can be added using
addCase or addFixtures.
+* Once all the tests are register they are axecuted on the run() call.
+* Note that Runner does not provide any visual output. To visualize the
test results use one of
+* the classes in the utest.ui package.
+*/
class Runner {
var fixtures(default, null) : Array<TestFixture<Dynamic>>;

+ /**
+ * Event object that monitors the progress of the runner.
+ */
public var onProgress(default, null) : Dispatcher<{ result : TestResult,
done : Int, totals : Int }>;
+ /**
+ * Event object that monitors when the runner starts.
+ */
public var onStart(default, null) : Dispatcher<Runner>;
+ /**
+ * Event object that monitors when the runner ends. This event takes into
account async calls
+ * performed during the tests.
+ */
public var onComplete(default, null) : Dispatcher<Runner>;
+ /**
+ * The number of fixtures registered.
+ */
public var length(default, null) : Int;
-
+ /**
+ * Instantiates a Runner onject.
+ */
public function new() {
fixtures = new Array();
onProgress = new Dispatcher();
@@ -19,6 +39,15 @@
length = 0;
}

+ /**
+ * Adds a new test case.
+ * @param test: must be a not null object
+ * @param setup: string name of the setup function (defaults to "setup")
+ * @param teardown: string name of the teardown function (defaults
to "teardown")
+ * @param prefix: prefix for methods that are tests (defaults to "test")
+ * @param pattern: a regular expression that discriminates the names of
test
+ * functions; when set, the prefix parameter is meaningless
+ */
public function addCase(test : Dynamic, setup = "setup", teardown
= "teardown", prefix = "test", ?pattern : EReg) {
if(!Reflect.isObject(test)) throw "can't add a null object as a test
case";
if(!isMethod(test, setup))
@@ -40,12 +69,12 @@
}
}
}
-
+
public function addFixture(fixture : TestFixture<Dynamic>) {
fixtures.push(fixture);
length++;
}
-
+
public function getFixture(index : Int) {
return fixtures[index];
}

Modified: trunk/src/utest/TestHandler.hx
==============================================================================
--- trunk/src/utest/TestHandler.hx (original)
+++ trunk/src/utest/TestHandler.hx Fri Apr 17 11:24:55 2009
@@ -71,6 +71,30 @@
Assert.createEvent = function(f, ?t){ return function(e){}};
}

+ /**
+ * Adds a function that is called asynchronously.
+ *
+ * Example:
+ * <pre>
+ * var fixture = new TestFixture(new TestClass(), "test");
+ * var handler = new TestHandler(fixture);
+ * var flag = false;
+ * var async = handler.addAsync(function() {
+ * flag = true;
+ * }, 50);
+ * handler.onTimeout.add(function(h) {
+ * trace("TIMEOUT");
+ * });
+ * handler.onTested.add(function(h) {
+ * trace(flag ? "OK" : "FAILED");
+ * });
+ * haxe.Timer.delay(function() async(), 10);
+ * handler.execute();
+ * </pre>
+ * @param f, the function that is called asynchrnously
+ * @param timeout, the maximum time to wait for f() (default is 250)
+ * @return returns a function closure that must be executed asynchrnously
+ */
public function addAsync(f : Void->Void, timeout = 250) {
asyncStack.add(f);
var handler = this;

Reply all
Reply to author
Forward
0 new messages