Skip to content

Commit

Permalink
Add functionality for vectorized tests. bubaflub++ for the idea/motiv…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
Whiteknight committed Jun 18, 2011
1 parent 8542d4f commit 4a74382
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
1 change: 1 addition & 0 deletions setup.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function setup_stable_libraries(var rosella)
"test/Result",
"test/Suite",
"test/SuiteFactory",
"test/suitefactory/Vector",
"test/Test",
"test/TestCase",
"test/TestContext",
Expand Down
23 changes: 18 additions & 5 deletions src/test/Test.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ namespace Rosella
// a thin facade over SuiteFactory and Suite with some defaults thrown
// in. Returns 1 if the test was a success, 0 otherwise.
function test(var test_type, var options [slurpy,named])
{
__default_options(options);
var suitefactory = new Rosella.Test.SuiteFactory(test_type, options);
var suite = suitefactory.create();
var result = suite.run();
return result.was_successful();
}

function test_vector(var func, var tests, var options [slurpy,named])
{
__default_options(options);
var suitefactory = new Rosella.Test.SuiteFactory.Vector(func, tests, options);
var suite = suitefactory.create();
var result = suite.run();
return result.was_successful();
}

function __default_options(var options)
{
if (!(exists options["suite_type"]))
options["suite_type"] = class Rosella.Test.Suite;
Expand All @@ -29,11 +47,6 @@ namespace Rosella
options["test_prefix"] = "";
if (!(exists options["asserter"]))
options["asserter"] = new Rosella.Test.Asserter;

var suitefactory = new Rosella.Test.SuiteFactory(test_type, options);
var suite = suitefactory.create();
var result = suite.run();
return result.was_successful();
}

// Unconditional fail. Throws a Rosella.Test.Failure
Expand Down
64 changes: 64 additions & 0 deletions src/test/suitefactory/Vector.winxed
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace Rosella { namespace Test { namespace SuiteFactory
{
class Vector : Rosella.Test.SuiteFactory
{
var data;
var func;

function Vector(var func, var data, var options)
{
self.SuiteFactory(null, options);
self.data = data;
self.func = func;
}

function get_test_methods()
{
int is_role = 0;
var data = self.data;
${ does is_role, data, "array" };
if (is_role)
return self.get_test_methods_from_array();
${ does is_role, data, "hash" };
if (is_role)
return self.get_test_methods_from_hash();
return self.get_test_method_from_scalar();
}

function __make_test_method(var n, var f, var d)
{
var func = f;
var data = d;
var name = n;
return function(var obj) {
obj.status.verify(name);
func(obj, data);
};
}

function get_test_methods_from_array()
{
var test_methods = {};
for (int i = 0; i < elements(self.data); i++) {
string name = "test " + string(i);
test_methods[name] = self.__make_test_method(name, self.func, self.data[i]);
}
return test_methods;
}

function get_test_methods_from_hash()
{
var test_methods = {};
for (string key in self.data)
test_methods[key] = self.__make_test_method(key, self.func, self.data[key]);
return test_methods;
}

function get_test_methods_from_scalar()
{
return {
"test" : self.__make_test_method("test", self.func, self.data)
};
}
}
}}}

0 comments on commit 4a74382

Please sign in to comment.