1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var nodeunit = require('../nodeunit'),
|
16 | utils = require('../utils'),
|
17 | fs = require('fs'),
|
18 | track = require('../track'),
|
19 | path = require('path'),
|
20 | AssertionError = require('../assert').AssertionError;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exports.info = "Tests reporter for machinally analysis";
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | exports.run = function (files, options, callback) {
|
37 |
|
38 |
|
39 | var parseStack = function (stack, delimiter) {
|
40 | var parseTrace = function (trace) {
|
41 | var filename, row, column;
|
42 | pattern1 = /\s{4}at\s\S+\s\(([^:]+):(\d+):(\d+)\)/;
|
43 | pattern2 = /\s{4}at\s([^:]+):(\d+):(\d+)/;
|
44 |
|
45 | if (trace.match(pattern1) !== null) {
|
46 | filename = RegExp.$1;
|
47 | row = RegExp.$2;
|
48 | column = RegExp.$3;
|
49 | } else if (trace.match(pattern2) !== null) {
|
50 | filename = RegExp.$1;
|
51 | row = RegExp.$2;
|
52 | column = RegExp.$3;
|
53 | } else {
|
54 | throw new Error("Could not parse a line of stack trace: " + trace);
|
55 | }
|
56 | return {filename: filename, row: row, column: column};
|
57 | };
|
58 | if (delimiter === undefined) {
|
59 | delimiter = ':';
|
60 | }
|
61 | traceback = stack.split('\n');
|
62 | firstline = traceback.shift();
|
63 | trace = parseTrace(traceback[0]);
|
64 | return {filename: trace.filename, row: trace.row, column: trace.column, message: firstline};
|
65 | };
|
66 | var createErrorMessage = function(type, name, filename, row, column, message){
|
67 | return [type, name, filename, row, column, message].join(":");
|
68 | };
|
69 | var paths = files.map(function (p) {
|
70 | return path.resolve(p);
|
71 | });
|
72 | var tracker = track.createTracker(function (tracker) {
|
73 | if (tracker.unfinished()) {
|
74 | var names = tracker.names();
|
75 | for (var i = 0; i < names.length; i += 1) {
|
76 | console.log(createErrorMessage(
|
77 | 'Error', names[i],
|
78 | '', '', '',
|
79 | 'Undone tests - To fix this, make sure all tests call test.done()'
|
80 | ));
|
81 | }
|
82 | process.reallyExit(tracker.unfinished());
|
83 | }
|
84 | });
|
85 |
|
86 | nodeunit.runFiles(paths, {
|
87 | testspec: options.testspec,
|
88 | testFullSpec: options.testFullSpec,
|
89 | moduleStart: function (name) {},
|
90 | testDone: function (name, assertions) {
|
91 | tracker.remove(name);
|
92 | if (assertions.failures()) {
|
93 | assertions.forEach(function (a) {
|
94 | var stacks, message, filename, row, column;
|
95 | if (a.failed()) {
|
96 | stackinfo = parseStack(a.error.stack, ':');
|
97 | console.log(createErrorMessage(
|
98 | 'Fail', name, stackinfo.filename,
|
99 | stackinfo.row, stackinfo.column, stackinfo.message));
|
100 | }
|
101 | });
|
102 | }
|
103 | },
|
104 | done: function (assertions, end) {
|
105 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
|
106 | },
|
107 | testStart: function(name) {
|
108 | tracker.put(name);
|
109 | }
|
110 | });
|
111 | };
|
112 |
|