Created
November 10, 2014 14:17
-
-
Save yumitsu/5322ae95a25c4ca061e9 to your computer and use it in GitHub Desktop.
Simple methods coverage task
This file contains hidden or 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
option '-f', '--file [FILE]', 'File to cover' | |
task 'coverage:methods', 'Returns methods defined in given file', (opts) -> | |
[fs, regex] = [ | |
require 'fs' | |
new RegExp '([\\w\\.\\_]+)?\\s*?\\=\\s*?function\\(', 'gm' | |
] | |
if not opts.file? | |
util.error 'no file specified', 'coverage' | |
return | |
file = opts.file | |
fs.exists file, (_e) -> | |
if _e | |
fs.readFile file, (e, c) -> | |
throw e if e | |
matches = while _m = regex.exec c | |
_m[1] | |
if matches.length isnt 0 | |
util.info 'found '+matches.length+' match(es)', 'coverage' | |
util.flatout matches | |
else | |
util.info 'no matches found', 'coverage' | |
else | |
util.error 'file not exists', 'coverage' | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment