run-tests.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env node
  2. /* -*- Mode: js; js-indent-level: 2; -*- */
  3. /*
  4. * Copyright 2011 Mozilla Foundation and contributors
  5. * Licensed under the New BSD license. See LICENSE or:
  6. * http://opensource.org/licenses/BSD-3-Clause
  7. */
  8. var assert = require('assert');
  9. var fs = require('fs');
  10. var path = require('path');
  11. var util = require('./source-map/util');
  12. function run(tests) {
  13. var total = 0;
  14. var passed = 0;
  15. for (var i = 0; i < tests.length; i++) {
  16. for (var k in tests[i].testCase) {
  17. if (/^test/.test(k)) {
  18. total++;
  19. try {
  20. tests[i].testCase[k](assert, util);
  21. passed++;
  22. }
  23. catch (e) {
  24. console.log('FAILED ' + tests[i].name + ': ' + k + '!');
  25. console.log(e.stack);
  26. }
  27. }
  28. }
  29. }
  30. console.log('');
  31. console.log(passed + ' / ' + total + ' tests passed.');
  32. console.log('');
  33. return total - passed;
  34. }
  35. function isTestFile(f) {
  36. var testToRun = process.argv[2];
  37. return testToRun
  38. ? path.basename(testToRun) === f
  39. : /^test\-.*?\.js/.test(f);
  40. }
  41. function toModule(f) {
  42. return './source-map/' + f.replace(/\.js$/, '');
  43. }
  44. var requires = fs.readdirSync(path.join(__dirname, 'source-map'))
  45. .filter(isTestFile)
  46. .map(toModule);
  47. var code = run(requires.map(require).map(function (mod, i) {
  48. return {
  49. name: requires[i],
  50. testCase: mod
  51. };
  52. }));
  53. process.exit(code);