Created
January 17, 2016 22:43
-
-
Save jubianchi/b592b94dec4664c6fdb5 to your computer and use it in GitHub Desktop.
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
var AtoumParser, Emitter, Test, fs, | |
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | |
hasProp = {}.hasOwnProperty; | |
fs = require('fs'); | |
Emitter = require('atom').Emitter; | |
Test = (function() { | |
function Test() {} | |
Test.prototype.id = null; | |
Test.prototype.status = null; | |
Test.prototype["class"] = null; | |
Test.prototype.method = null; | |
Test.prototype.skipped = false; | |
Test.prototype.diag = ''; | |
Test.prototype.file = null; | |
Test.prototype.line = null; | |
return Test; | |
})(); | |
module.exports = AtoumParser = (function(superClass) { | |
extend(AtoumParser, superClass); | |
function AtoumParser() { | |
AtoumParser.__super__.constructor.call(this); | |
this.reset(); | |
} | |
AtoumParser.prototype.dispose = function() { | |
this.flush(); | |
return AtoumParser.__super__.dispose.call(this); | |
}; | |
AtoumParser.prototype.runnerDidStart = function() { | |
return this.reset(); | |
}; | |
AtoumParser.prototype.runnerDidProduceOutput = function(data) { | |
return this.parse(data); | |
}; | |
AtoumParser.prototype.runnerDidStop = function(code) { | |
if (code === 255) { | |
return; | |
} | |
return this.flush(); | |
}; | |
AtoumParser.prototype.reset = function() { | |
return this.test = null; | |
}; | |
AtoumParser.prototype.parse = function(data) { | |
if (data == null) { | |
data = ''; | |
} | |
return data.split('\n').filter(function(line) { | |
return line.length > 0; | |
}).forEach((function(_this) { | |
return function(line) { | |
return _this.parseLine(line); | |
}; | |
})(this)); | |
}; | |
AtoumParser.prototype.flush = function() { | |
if (this.test !== null) { | |
this.emit('test', this.test); | |
} | |
return this.reset(); | |
}; | |
AtoumParser.prototype.parseLine = function(line) { | |
var matches; | |
matches = line.match(/^\d+..(\d+)$/); | |
if (matches) { | |
return this.emit('plan', parseInt(matches[1], 10)); | |
} else { | |
matches = line.match(/((?:not )?ok) (\d+)(?: (?:# SKIP|# TODO|-) (.+)::(.+)\(\))?$/); | |
if (matches) { | |
this.flush(); | |
this.test = new Test(); | |
this.test.id = matches[2]; | |
this.test.status = matches[1]; | |
this.test["class"] = matches[3]; | |
this.test.method = matches[4]; | |
if (line.match(/# SKIP/)) { | |
this.test.status = 'skip'; | |
} | |
if (line.match(/# TODO/)) { | |
return this.test.status = 'void'; | |
} | |
} else { | |
matches = line.match(/^# (.+)::(.+)\(\)$/); | |
if (matches) { | |
this.test["class"] = matches[1]; | |
return this.test.method = matches[2]; | |
} else { | |
matches = line.match(/^# (.+?)(?:\:(\d+))?$/); | |
if (matches) { | |
if (fs.existsSync(matches[1])) { | |
this.test.file = matches[1]; | |
if (matches[2]) { | |
return this.test.line = parseInt(matches[2], 10); | |
} | |
} else { | |
return this.test.diag += line.replace(/^#\s+/g, '') + '\n'; | |
} | |
} else { | |
if (this.test) { | |
return this.test.diag += line.replace(/^#\s+/g, '') + '\n'; | |
} | |
} | |
} | |
} | |
} | |
}; | |
return AtoumParser; | |
})(Emitter); | |
RunLink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment