Skip to content

Instantly share code, notes, and snippets.

@yumitsu
Created November 10, 2014 14:17
Show Gist options
  • Save yumitsu/5322ae95a25c4ca061e9 to your computer and use it in GitHub Desktop.
Save yumitsu/5322ae95a25c4ca061e9 to your computer and use it in GitHub Desktop.
Simple methods coverage task
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