]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/node_modules/coffeestack/node_modules/source-map/test/run-tests.js
64a7c3a3d200d2a7ad806a4d817443ba1e6ebf0e
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / grim / node_modules / coffeestack / node_modules / source-map / test / run-tests.js
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
13 function run(tests) {
14 var total = 0;
15 var passed = 0;
16
17 for (var i = 0; i < tests.length; i++) {
18 for (var k in tests[i].testCase) {
19 if (/^test/.test(k)) {
20 total++;
21 try {
22 tests[i].testCase[k](assert, util);
23 passed++;
24 }
25 catch (e) {
26 console.log('FAILED ' + tests[i].name + ': ' + k + '!');
27 console.log(e.stack);
28 }
29 }
30 }
31 }
32
33 console.log('');
34 console.log(passed + ' / ' + total + ' tests passed.');
35 console.log('');
36
37 return total - passed;
38 }
39
40 function isTestFile(f) {
41 var testToRun = process.argv[2];
42 return testToRun
43 ? path.basename(testToRun) === f
44 : /^test\-.*?\.js/.test(f);
45 }
46
47 function toModule(f) {
48 return './source-map/' + f.replace(/\.js$/, '');
49 }
50
51 var requires = fs.readdirSync(path.join(__dirname, 'source-map'))
52 .filter(isTestFile)
53 .map(toModule);
54
55 var code = run(requires.map(require).map(function (mod, i) {
56 return {
57 name: requires[i],
58 testCase: mod
59 };
60 }));
61
62 process.exit(code);