#!/usr/bin/env node
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
 * Copyright 2011 Mozilla Foundation and contributors
 * Licensed under the New BSD license. See LICENSE or:
 * http://opensource.org/licenses/BSD-3-Clause
 */
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var util = require('./source-map/util');

function run(tests) {
  var failures = [];
  var total = 0;
  var passed = 0;

  for (var i = 0; i < tests.length; i++) {
    for (var k in tests[i].testCase) {
      if (/^test/.test(k)) {
        total++;
        try {
          tests[i].testCase[k](assert, util);
          passed++;
          process.stdout.write('.');
        }
        catch (e) {
          failures.push({
            name: tests[i].name + ': ' + k,
            error: e
          });
          process.stdout.write('E');
        }
      }
    }
  }

  process.stdout.write('\n');
  console.log(passed + ' / ' + total + ' tests passed.');

  failures.forEach(function (f) {
    console.log('================================================================================');
    console.log(f.name);
    console.log('--------------------------------------------------------------------------------');
    console.log(f.error.stack);
  });

  return failures.length;
}

var code;

process.stdout.on('close', function () {
  process.exit(code);
});

function isTestFile(f) {
  return /^test\-.*?\.js/.test(f);
}

function toModule(f) {
  return './source-map/' + f.replace(/\.js$/, '');
}

var requires = fs.readdirSync(path.join(__dirname, 'source-map')).filter(isTestFile).map(toModule);

code = run(requires.map(require).map(function (mod, i) {
  return {
    name: requires[i],
    testCase: mod
  };
}));
process.exit(code);

@@ -645,206 +645,126 @@
     
-  process.stdout.write('.');%0A        %7D%0A        catch (e) %7B%0A          failures.push(%7B%0A            name: tests%5Bi%5D.name + ': ' + k,%0A            error: e%0A          %7D);%0A          process.stdout.write('E'
+%7D%0A        catch (e) %7B%0A          console.log('FAILED ' + tests%5Bi%5D.name + ': ' + k + '!');%0A          console.log(e.stack
 );%0A 
@@ -797,33 +797,22 @@
 %0A%0A  
-process.stdout.write('%5Cn'
+console.log(%22%22
 );%0A 
@@ -867,16 +867,35 @@
 ssed.');
+%0A  console.log(%22%22);
 %0A%0A  fail
@@ -926,267 +926,8 @@
 ) %7B%0A
-    console.log('================================================================================');%0A    console.log(f.name);%0A    console.log('--------------------------------------------------------------------------------');%0A    console.log(f.error.stack);%0A
   %7D)
@@ -1064,22 +1064,110 @@
 (f) %7B%0A  
-return
+var testToRun = process.argv%5B2%5D;%0A  return testToRun%0A    ? path.basename(testToRun) === f%0A    :
  /%5Etest%5C
@@ -1330,16 +1330,19 @@
 e-map'))
+%0A  
 .filter(
@@ -1352,16 +1352,19 @@
 estFile)
+%0A  
 .map(toM

Extend the test runner so that we can choose to run only a specific test file.