JS-Test-Simple
view release on metacpan or search on metacpan
lib/JS/Test/Builder.js view on Meta::CPAN
this.UseNums = true;
this.NoHeader = false;
this.NoEnding = false;
this.TestResults = [];
this.ToDo = [];
this.Buffer = [];
this.asyncs = [0];
this.asyncID = 0;
return this._setupOutput();
};
Test.Builder.prototype._print = function (msg) {
this.output().call(this, msg);
};
Test.Builder.prototype.warn = function (msg) {
this.warnOutput().apply(this, arguments);
};
Test.Builder.prototype.plan = function (arg) {
if (!arg) return;
if (this.HavePlan) Test.Builder.die("You tried to plan twice!");
if (!(arg instanceof Object))
Test.Builder.die("plan() doesn't understand " + arg);
for (var cmd in arg) {
if (cmd == 'tests') {
if (arg[cmd] == null) {
Test.Bulder.die(
"Got an undefined number of tests. Looks like you tried to "
+ "say how many tests you plan to run but made a mistake."
+ Test.Builder.LF
);
} else if (!arg[cmd]) {
Test.Builder.die(
"You said to run 0 tests! You've got to run something."
+ Test.Builder.LF
);
} else {
this.expectedTests(arg[cmd]);
}
} else if (cmd == 'skipAll') {
this.skipAll(arg[cmd]);
} else if (cmd == 'noPlan' && arg[cmd]) {
this.noPlan();
} else if ({}.hasOwnProperty) {
// see if the param belongs to Object.prototype.
if (arg.hasOwnProperty(cmd)) {
Test.Builder.die("plan() doesn't understand "
+ cmd + (arg[cmd] ? (" " + arg[cmd]) : ''));
}
} else {
// Ignore errors if hasOwnProperty() isn't available, as in
// Safari < 2.0.2 and Explorer 5.
}
}
};
Test.Builder.prototype.expectedTests = function (max) {
if (max) {
if (isNaN(max)) {
Test.Builder.die(
"Number of tests must be a postive integer. You gave it '"
+ max + "'." + Test.Builder.LF
);
}
this.ExpectedTests = max.valueOf();
this.HavePlan = true;
if (!this.noHeader()) this._print("1.." + max + Test.Builder.LF);
}
return this.ExpectedTests;
};
Test.Builder.prototype.noPlan = function () {
this.NoPlan = 1;
this.HavePlan = 1;
};
Test.Builder.prototype.hasPlan = function () {
if (this.ExpectedTests) return this.ExpectedTests;
if (this.NoPlan) return 'noPlan';
};
Test.Builder.prototype.skipAll = function (reason) {
var out = "1..0";
if (reason) out += " # Skip " + reason;
out += Test.Builder.LF;
this.SkipAll = 1;
if (!this.noHeader()) this.output()(out);
// Just throw and catch an exception.
Test.Builder.globalScope.onerror = function () { return true; }
throw new Error("__SKIP_ALL__");
};
Test.Builder.prototype.ok = function (test, desc) {
// test might contain an object that we don't want to accidentally
// store, so we turn it into a boolean.
test = !!test;
if (!this.HavePlan) {
Test.Builder.die(
"You tried to run a test without a plan! Gotta have a plan."
);
}
// Append any output to the previous test's results.
if (this.Buffer.length && this.TestResults.length) {
this.TestResults[this.TestResults.length - 1].appendOutput(
this.Buffer.splice(0, this.Buffer.length).join('')
);
}
// I don't think we need to worry about threading in JavaScript.
this.CurrTest++;
// In case desc is a string overloaded object, force it to stringify.
if (desc) desc = desc.toString();
var startsNumber
if (desc != null && /^[\d\s]+$/.test(desc)) {
( run in 0.679 second using v1.01-cache-2.11-cpan-39bf76dae61 )