-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new reporter for machinally analysis
This **machineout** reporter will report any Fail or Error as format as below:: <Type>:<Method>:<File>:<Row>:<Column>:<Message> So you can analyse the message with simply splitting the line with ":" In python, the analyse method will be like below:: def analyse_nodeunit(s): type, method, file, row, column, message = s.split(":", 5) return type, method, file, row, column, message
- Loading branch information
1 parent
eb210ae
commit ca3ecf8
Showing
4 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*! | ||
* Nodeunit | ||
* | ||
* @author Alisue (lambdalisue@hashnote.net) | ||
* @url http://hashnote.net/ | ||
* | ||
* Copyright (c) 2011 Alisue | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
|
||
var nodeunit = require('../nodeunit'), | ||
utils = require('../utils'), | ||
fs = require('fs'), | ||
track = require('../track'), | ||
path = require('path'); | ||
AssertionError = require('../assert').AssertionError; | ||
|
||
/** | ||
* Reporter info string | ||
*/ | ||
|
||
exports.info = "Tests reporter for machinally analysis"; | ||
|
||
|
||
/** | ||
* Run all tests within each module, reporting the results to the command-line. | ||
* | ||
* @param {Array} files | ||
* @api public | ||
*/ | ||
|
||
exports.run = function (files, options) { | ||
// options doesn't effect | ||
|
||
var parseStack = function (stack, delimiter) { | ||
var parseTrace = function (trace) { | ||
var filename, row, column; | ||
pattern1 = /\s{4}at\s\S+\s\(([^:]+):(\d+):(\d+)\)/; | ||
pattern2 = /\s{4}at\s([^:]+):(\d+):(\d+)/; | ||
|
||
if (trace.match(pattern1) !== null) { | ||
filename = RegExp.$1; | ||
row = RegExp.$2; | ||
column = RegExp.$3; | ||
} else if (trace.match(pattern2) !== null) { | ||
filename = RegExp.$1; | ||
row = RegExp.$2; | ||
column = RegExp.$3; | ||
} else { | ||
throw new Error("Could not parse a line of stack trace: " + trace); | ||
} | ||
return {filename: filename, row: row, column: column}; | ||
}; | ||
if (delimiter === undefined) { | ||
delimiter = ':'; | ||
} | ||
traceback = stack.split('\n'); | ||
firstline = traceback.shift(); | ||
trace = parseTrace(traceback[0]); | ||
return {filename: trace.filename, row: trace.row, column: trace.column, message: firstline}; | ||
}; | ||
var createErrorMessage = function(type, name, filename, row, column, message){ | ||
return [type, name, filename, row, column, message].join(":"); | ||
}; | ||
var paths = files.map(function (p) { | ||
return path.join(process.cwd(), p); | ||
}); | ||
var tracker = track.createTracker(function (tracker) { | ||
if (tracker.unfinished()) { | ||
var names = tracker.names(); | ||
for (var i = 0; i < names.length; i += 1) { | ||
console.log(createErrorMessage( | ||
'Error', names[i], | ||
'', '', '', | ||
'Undone tests - To fix this, make sure all tests call test.done()' | ||
)); | ||
} | ||
process.reallyExit(tracker.unfinished()); | ||
} | ||
}); | ||
|
||
nodeunit.runFiles(paths, { | ||
testspec: options.testspec, | ||
moduleStart: function (name) {}, | ||
testDone: function (name, assertions) { | ||
tracker.remove(name); | ||
if (assertions.failures()) { | ||
assertions.forEach(function (a) { | ||
var stacks, message, filename, row, column; | ||
if (a.failed()) { | ||
stackinfo = parseStack(a.error.stack, ':'); | ||
console.log(createErrorMessage( | ||
'Fail', name, stackinfo.filename, | ||
stackinfo.row, stackinfo.column, stackinfo.message)); | ||
} | ||
}); | ||
} | ||
}, | ||
done: function (assertions, end) {}, | ||
testStart: function(name) { | ||
tracker.put(name); | ||
} | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
" Vim compiler file | ||
" Compiler: Unit testing for javascript using nodeunit | ||
" Maintainer: lambdalisue <lambdalisue@hashnote.net> | ||
" Last Change: 2011 Sep 06 | ||
" | ||
" How to install: | ||
" copy this vim script into $VIM/compiler/ directory | ||
" and add the line below to $VIM/ftplugin/javascript.vim (or coffee.vim) | ||
" | ||
" compiler nodeunit | ||
" | ||
" How to use: | ||
" Test with ':make' command of vim. See vim plugin called 'vim-makegreen' | ||
" | ||
if exists("current_compiler") | ||
finish | ||
endif | ||
let current_compiler = "nodeunit" | ||
|
||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal | ||
command -nargs=* CompilerSet setlocal <args> | ||
endif | ||
|
||
" Using folked version nodeunit found at | ||
" http://github.com/lambdalisue/nodeunit.git | ||
CompilerSet makeprg=echo\ $*\ >/dev/null;\ nodeunit\ --reporter\ machineout\ \"%\" | ||
CompilerSet efm=%s:%f:%l:%c:%m |