var FAILED = "FAILED!: ";
var STATUS = "STATUS: ";
var BUGNUMBER = "BUGNUMBER: ";
var SECT_PREFIX = 'Section ';
var SECT_SUFFIX = ' of test -';
var VERBOSE = false;
var callStack = new Array();
function expectExitCode(n)
{
print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n + ' ---');
}
function inSection(x)
{
return SECT_PREFIX + x + SECT_SUFFIX;
}
function inRhino()
{
return (typeof defineClass == "function");
}
function reportFailure (msg)
{
var lines = msg.split ("\n");
var l;
var funcName = currentFunc();
var prefix = (funcName) ? "[reported from " + funcName + "] ": "";
for (var i=0; i<lines.length; i++)
print (FAILED + prefix + lines[i]);
}
function printStatus (msg)
{
var lines = msg.split ("\n");
var l;
for (var i=0; i<lines.length; i++)
print (STATUS + lines[i]);
}
function printBugNumber (num)
{
print (BUGNUMBER + num);
}
function reportCompare (expected, actual, description)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var output = "";
if ((VERBOSE) && (typeof description != "undefined"))
printStatus ("Comparing '" + description + "'");
if (expected_t != actual_t)
output += "Type mismatch, expected type " + expected_t +
", actual type " + actual_t + "\n";
else if (VERBOSE)
printStatus ("Expected type '" + actual_t + "' matched actual " +
"type '" + expected_t + "'");
if (expected != actual)
output += "Expected value '" + expected + "', Actual value '" + actual +
"'\n";
else if (VERBOSE)
printStatus ("Expected value '" + actual + "' matched actual " +
"value '" + expected + "'");
if (output != "")
{
if (typeof description != "undefined")
reportFailure (description);
reportFailure (output);
}
}
function enterFunc (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
callStack.push(funcName);
}
function exitFunc (funcName)
{
var lastFunc = callStack.pop();
if (funcName)
{
if (!funcName.match(/\(\)$/))
funcName += "()";
if (lastFunc != funcName)
reportFailure ("Test driver failure, expected to exit function '" +
funcName + "' but '" + lastFunc + "' came off " +
"the stack");
}
}
function currentFunc()
{
return callStack[callStack.length - 1];
}