JS-JSON
view release on metacpan or search on metacpan
tests/lib/Test/Builder.js view on Meta::CPAN
if (fn != null) {
var buffer = this.Buffer;
this.WarnOutput = function (msg) { buffer.push(msg); fn(msg) };
}
return this.WarnOutput;
};
Test.Builder.prototype._setupOutput = function () {
if (Test.PLATFORM == 'browser') {
var top = Test.Builder.globalScope;
var doc = top.document;
var writer = function (msg) {
// I'm sure that there must be a more efficient way to do this,
// but if I store the node in a variable outside of this function
// and refer to it via the closure, then things don't work right
// --the order of output can become all screwed up (see
// buffer.html). I have no idea why this is.
var body = doc.body || doc.getElementsByTagName("body")[0];
var node = doc.getElementById('test_output')
|| doc.getElementById('test');
if (!node) {
node = document.createElement('pre');
node.id = 'test_output';
body.appendChild(node);
}
// This approach is neater, but causes buffering problems when
// mixed with document.write. See tests/buffer.html.
//node.appendChild(document.createTextNode(msg));
//return;
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType == 3 /* Text Node */) {
// Append to the node and scroll down.
node.childNodes[i].appendData(msg);
top.scrollTo( 0, body.offsetHeight || body.scrollHeight );
return;
}
}
// If there was no text node, add one.
node.appendChild(doc.createTextNode(msg));
top.scrollTo(0, body.offsetHeight || body.scrollHeight);
return;
};
this.output(writer);
this.failureOutput(function (msg) {
writer('<span style="color: red; font-weight: bold">'
+ msg + '</span>')
});
this.todoOutput(writer);
this.endOutput(writer);
if (top.alert.apply) {
this.warnOutput(top.alert, top);
} else {
this.warnOutput(function (msg) { top.alert(msg); });
}
} else if (Test.PLATFORM == 'director') {
// Macromedia-Adobe:Director MX 2004 Support
// XXX Is _player a definitive enough object?
// There may be an even more explicitly Director object.
/*global trace */
this.output(trace);
this.failureOutput(trace);
this.todoOutput(trace);
this.warnOutput(trace);
} else if (Test.PLATFORM == 'wsh') {
// Windows Scripting Host Support
var printer = function (msg) {
WScript.StdOut.writeline(msg);
}
this.output(printer);
this.failureOutput(printer);
this.todoOutput(printer);
this.warnOutput(printer);
} else if (Test.PLATFORM == 'interp') {
// Command-line interpeter.
var out = function (toOut) { print( toOut.replace(/\n$/, '') ); };
this.output(out);
this.failureOutput(out);
this.todoOutput(out);
this.warnOutput(out);
}
return this;
};
Test.Builder.prototype.currentTest = function (num) {
if (num == null) return this.CurrTest;
if (!this.HavePlan)
Test.Builder.die("Can't change the current test number without a plan!");
this.CurrTest = num;
if (num >= this.TestResults.length ) {
var reason = 'incrementing test number';
for (var i = this.TestResults.length; i < num; i++) {
this.TestResults[i] = new Test.Builder.TestResult({
ok: true,
actualOK: null,
reason: reason,
type: 'unknown',
output: 'ok - ' + reason + Test.Builder.LF
});
}
} else if (num < this.TestResults.length) {
// IE requires the second argument to truncate the array.
this.TestResults.splice(num, this.TestResults.length);
}
return this.CurrTest;
};
Test.Builder.prototype.summary = function () {
var results = new Array(this.TestResults.length);
for (var i = 0; i < this.TestResults.length; i++) {
var result = this.TestResults[i];
results[i] = result ? null : result.getOK();
}
return results
( run in 0.360 second using v1.01-cache-2.11-cpan-39bf76dae61 )