Browse files

[tap] added static analysis

  • Loading branch information...
1 parent 31ac961 commit 905a4304fdf17ec41fe4660acdb30414c2a6d05b @dscape committed Sep 10, 2011
Showing with 18 additions and 5 deletions.
  1. +9 −3 engines/tap.js
  2. +1 −1 test/run
  3. +1 −1 test/select.js
  4. +7 −0 test/tap.js
View
12 engines/tap.js
@@ -5,16 +5,22 @@ var _ = require('underscore')
;
module.exports = exports = function(name,tests,module,selected) {
- var f, ok, test_names, total;
+ var f, ok, test_names, total = 0;
if(selected) { test_names = selected.split(','); }
else { test_names =
_.filter(_.keys(tests), function(e) { return e.indexOf('_ok') === -1; });
}
- total = test_names.length;
test(name, function (t) {
+ test_names.forEach(function(name) { // quick'n'dirty static analysis
+ var f_body = tests[name+'_ok'].toString()
+ , var_name = /(\w)\s*=\s*this\.t/.exec(f_body)[1] + '\\.'
+ , count = f_body.match(new RegExp(var_name, ['g', 'm'])).length
+ ;
+ total += count;
+ });
t.plan(total);
test_names.forEach(function(name) {
- tests[name](function () { this.t = t; return tests[name+'_ok'] }());
+ tests[name](function () { this.t = t; return tests[name+'_ok']; }());
});
});
};
View
2 test/run
@@ -3,5 +3,5 @@
tests=$(dirname $0)
for s in $(ls -d $tests/);
do
- for f in $s*.js; do node $f good,also_good; done;
+ for f in $s*.js; do node $f; done;
done;
View
2 test/select.js
@@ -12,4 +12,4 @@ tests.also_good = tests.good;
tests.also_good_ok = tests.good_ok;
ensure((__filename + '_single_test'), tests, module, 'good');
-ensure((__filename + '_mult_test'), tests, module,process.argv[2]); // good,also_good
+ensure((__filename + '_mult_test'), tests, module,'good,also_good');
View
7 test/tap.js
@@ -8,6 +8,13 @@ tests.tap_ok = function (value) {
t.equal(value,'foo','foo works');
};
+tests.tap2 = function (cb) { cb('foo','bar'); };
+tests.tap2_ok = function (foo,bar) {
+ var t = this.t;
+ t.equal(foo,'foo','foo is foo');
+ t.equal(bar,'bar','bar is bar');
+};
+
tests.plan_works = function (cb) { cb('bar'); };
tests.plan_works_ok = function (value) {
var t = this.t;

0 comments on commit 905a430

Please sign in to comment.