diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-04-14 23:33:43 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-04-14 23:42:08 -0700 |
commit | b4ff36a41b242c0b379d3c27fb30818de54fe2d4 (patch) | |
tree | 32e388da2e4e00ad16682579431d96bd1f36cc49 /lib/module.js | |
parent | 80711b0ff90cede610365cba65e46c3128b57bfd (diff) | |
download | node-new-b4ff36a41b242c0b379d3c27fb30818de54fe2d4.tar.gz |
Add --cov code coverage option
Diffstat (limited to 'lib/module.js')
-rw-r--r-- | lib/module.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/module.js b/lib/module.js index d806a4ae82..308fd4e8e3 100644 --- a/lib/module.js +++ b/lib/module.js @@ -347,6 +347,22 @@ Module.prototype._compile = function(content, filename) { // remove shebang content = content.replace(/^\#\!.*/, ''); + // add coverage + if (process.cov) { + var lines = content.split('\n'); + + if (lines.length > 0) { + lines[0] = '__cov[__filename] = { 0: true}; ' + lines[0]; + } + + for (var i = 0; i < lines.length; i++) { + lines[i] = + lines[i].replace(/;$/, '; __cov[__filename][' + i + '] = true;'); + } + + content = lines.join('\n'); + } + function require(path) { return Module._load(path, self); } |