Skip to content

Commit

Permalink
Remove some TODO notes from Test.Asserter and add docs. Test.Builder …
Browse files Browse the repository at this point in the history
…takes a handle to use for output, defaulting to stdout
  • Loading branch information
Whiteknight committed May 17, 2011
1 parent 81b83bf commit 8e76cde
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
20 changes: 12 additions & 8 deletions src/test/Asserter.winxed
@@ -1,10 +1,16 @@
namespace Rosella { namespace Test
{
/* Test Asserter to provide an OO-like interface to the functions defined
in the Assert namespace
/* Test Asserter class
This class provides test assertions. Assertions check various things
during the test run and signal failure if the checks are not met.
By default an instance of Asserter is located in the
"assert"/"$!assert" attribute of the TestCase object during the test
run.

You can provide a custom subclass, a custom instance, or a replacement
object for this functionality by passing an object to
Rosella.Test.test with the name "asserter".
*/
// TODO: Add the ability for the user to provide a custom subclass for
// asserter instead.
class Asserter
{
// Routine to get a default message, if none is provided
Expand Down Expand Up @@ -288,7 +294,8 @@ namespace Rosella { namespace Test
}

// Run the test, show that the output (and maybe the error output) matches
// the values expected
// the values expected. Notice that the strings are matched exactly,
// including leading and trailing whitespace
function output_is(var block, string output,
string message [optional], int has_msg [opt_flag],
string erroutput [named,optional], int has_erroutput [opt_flag])
Expand All @@ -315,8 +322,6 @@ namespace Rosella { namespace Test
);
}

// TODO: We should trim leading/trailing whitespace

string out_str = stdout.readall();
if (out_str != output)
self.fail(sprintf("%s\nExpected: '%s'\nReceived: '%s'", [message, output, out_str]));
Expand All @@ -328,6 +333,5 @@ namespace Rosella { namespace Test
if (errout_str != erroutput)
self.fail(message);
}

}
}}
31 changes: 20 additions & 11 deletions src/test/Builder.winxed
Expand Up @@ -6,11 +6,19 @@ namespace Rosella { namespace Test
class Builder
{
var test_number;
var output;

// TODO: We should take a Handle here, and use that handle for output.
function Builder()
function Builder(var output [optional], int has_out [opt_flag])
{
self.test_number = 0;
if (!has_out)
output = getstdout();
self.output = output;
}

function _printf(string fmt, var args [slurpy])
{
self.output.print(sprintf(fmt, args));
}

function reset()
Expand All @@ -23,18 +31,18 @@ namespace Rosella { namespace Test
{
self.test_number = self.test_number + 1;
string output = self._get_result_text(self.test_number, pass, msg);
if (has_todo)
say(output + " # TODO " + todo);
else
say(output + " # TODO");
if (!has_todo)
todo = "";
self._printf("%s # TODO %s\n", output, todo);
}

function ok(int pass, string msg [optional], int has_msg [opt_flag])
{
self.test_number = self.test_number + 1;
if (!has_msg)
msg = null;
say(self._get_result_text(self.test_number, pass, msg));
string result_text = self._get_result_text(self.test_number, pass, msg);
self._printf("%s\n", result_text);
}

function _get_result_text(int number, int pass, string msg)
Expand All @@ -56,23 +64,24 @@ namespace Rosella { namespace Test
var errmsg = error.message;
var lines = split("\n", errmsg);
for (string line in lines)
say("# " + line);
self._printf("# %s\n", line);

var bt_list = error.backtrace_strings();
for (string bt in bt_list) {
var frames = split("\n", bt);
for (string frame in frames)
say("# " + frame);
self._printf("# %s\n", frame);
}


} else
say("# " + string(error));
self._printf("# %s\n", string(error));
}

function plan(int count)
{
// TODO: Error checking
say("1.." + count);
self._printf("1..%d\n", count);
}
}
}}

0 comments on commit 8e76cde

Please sign in to comment.