aboutsummaryrefslogtreecommitdiff
path: root/tools/node_modules/source-map/test/run-tests.js
blob: 8bf2256ffb3a25d7547ecd90f5f42fba1abe8395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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);