Permalink
Browse files

added usage example, and fixed some calculation bugs

  • Loading branch information...
tmpvar committed Feb 21, 2010
1 parent 6b0958e commit 5795ed5ec759134894217d9983f5f77281b5292c
Showing with 21 additions and 13 deletions.
  1. +6 −0 README.md
  2. +15 −13 lib/runner.js
View
@@ -7,4 +7,10 @@ Provides an easy way to hook into mjsunit and start running tests immediately.
Usage Example
-------------
+ var suites = {
+ "core" : {
+ cases: require("./core").tests
+ }
+ };
+ require("mjsunit.runner/lib/runner").run(suites);
View
@@ -45,11 +45,13 @@ exports.run = function(testSuites) {
};
var runSuite = function(suiteName) {
- for (var test in tests[suiteName].cases)
+ testSuites[suiteName].total = 0;
+ testSuites[suiteName].errors = [];
+ for (var test in testSuites[suiteName].cases)
{
- if (tests[suiteName].cases.hasOwnProperty(test)) {
- tests[suiteName].total++;
- runTest(suiteName, tests[suiteName], test);
+ if (testSuites[suiteName].cases.hasOwnProperty(test)) {
+ testSuites[suiteName].total++;
+ runTest(suiteName, testSuites[suiteName], test);
}
}
}
@@ -74,9 +76,9 @@ exports.run = function(testSuites) {
} else {
- for (suiteName in tests)
+ for (suiteName in testSuites)
{
- if (tests.hasOwnProperty(suiteName)) {
+ if (testSuites.hasOwnProperty(suiteName)) {
runSuite(suiteName);
}
}
@@ -105,20 +107,20 @@ exports.run = function(testSuites) {
return name;
}
- for (var suiteName in tests)
+ for (var suiteName in testSuites)
{
- if (tests.hasOwnProperty(suiteName)) {
- numerator = tests[suiteName].total - tests[suiteName].errors.length;
- denominator = tests[suiteName].total;
- percent = Math.round((numerator / denominator)*100,2);
+ if (testSuites.hasOwnProperty(suiteName)) {
+ numerator = testSuites[suiteName].total - testSuites[suiteName].errors.length;
+ denominator = testSuites[suiteName].total;
+ percent = Math.round((numerator / denominator)*100,2) || 100;
sys.puts(padName(suiteName) + "\t" + numerator + "/" + denominator + "\t\t" + percent + "% passing");
}
}
sys.puts("--------------------------------------------");
numerator = total-errors.length;
denominator = total;
- percent = Math.round((numerator / denominator)*100,2);
- sys.puts("TOTALS:\t\t" + numerator + "/" + denominator + "\t" + percent + "% passing\r\n");
+ percent = Math.round((numerator / denominator)*100,2) || 100;
+ sys.puts("TOTALS:\t\t" + numerator + "/" + denominator + "\t\t" + percent + "% passing\r\n");
}
};

0 comments on commit 5795ed5

Please sign in to comment.