Permalink
Browse files

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 ca3ecf8caf778edaf8977b8345966bc24ee063ed @lambdalisue lambdalisue committed Sep 6, 2011
Showing with 138 additions and 1 deletion.
  1. BIN img/example_machineout.png
  2. +2 −1 lib/reporters/index.js
  3. +109 −0 lib/reporters/machineout.js
  4. +27 −0 share/nodeunit.vim
View
BIN img/example_machineout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 lib/reporters/index.js
@@ -3,7 +3,8 @@ module.exports = {
'default': require('./default'),
'skip_passed': require('./skip_passed'),
'minimal': require('./minimal'),
- 'html': require('./html')
+ 'html': require('./html'),
+ 'machineout': require('./machineout')
// browser test reporter is not listed because it cannot be used
// with the command line tool, only inside a browser.
};
View
109 lib/reporters/machineout.js
@@ -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);
+ }
+ });
+};
+
View
27 share/nodeunit.vim
@@ -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

0 comments on commit ca3ecf8

Please sign in to comment.