Skip to content

Commit

Permalink
use dump for the instrumentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug McInnes committed Mar 19, 2013
1 parent 1c9a6df commit f12e899
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bin/jcov
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ global_option '--no-color', 'Disable color output'
global_option '--no-coverage', 'Disable coverage output'
global_option '--report', 'Report test coverage'
global_option '--test REGEX', 'Limit the tests to only the ones that match the regular expression'
global_option '--dump' 'Dump instrumented Javascript for debugging purposes'
global_option '--dump', 'Dump instrumented Javascript for debugging purposes'
global_option '-c', '--config FILE', 'Specify a configuration file to use'

default_command :run
Expand Down
65 changes: 52 additions & 13 deletions features/instrumentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@ Feature: instrumentation
error_count = 0;
"""

Scenario: functions should be reported as covered
Scenario: it dumps instrumented file contents when a flag is set
Given a file named "public/javascripts/foo.js" with:
"""
var bar = 0;
"""
When I run `jcov --dump`
Then the output should contain:
"""
_coverage_tick('public/javascripts/foo.js', 1);var bar = 0;
"""

Scenario: functions should be covered
Given a file named "public/javascripts/foo.js" with:
"""
function foo() {
var bar = 0;
}
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (1/2) 50.0%
_coverage_tick('public/javascripts/foo.js', 1);function foo() {
_coverage_tick('public/javascripts/foo.js', 2); var bar = 0;
}
"""

Scenario: ignores comments
Expand All @@ -30,10 +43,13 @@ Feature: instrumentation
var bar = 0;
// three
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (1/1) 100.0%
// one
// two
_coverage_tick('public/javascripts/foo.js', 3);var bar = 0;
// three
"""

Scenario: it handles object definitions with function values
Expand All @@ -47,10 +63,16 @@ Feature: instrumentation
obj.foo();
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (3/3) 100.0%
_coverage_tick('public/javascripts/foo.js', 1);var obj = {
foo: function () {
_coverage_tick('public/javascripts/foo.js', 3); var test = 0;
}
};
_coverage_tick('public/javascripts/foo.js', 7);obj.foo();
"""

Scenario: it handles else if statements correctly
Expand All @@ -63,10 +85,15 @@ Feature: instrumentation
var two = 2;
}
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (2/3) 66.7%
_coverage_tick('public/javascripts/foo.js', 1);if (false) {
_coverage_tick('public/javascripts/foo.js', 2); var one = 1;
}
else if (true) {
_coverage_tick('public/javascripts/foo.js', 5); var two = 2;
}
"""

Scenario: it handles broken up if statements
Expand All @@ -78,10 +105,14 @@ Feature: instrumentation
var bar = 2;
}
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (3/3) 100.0%
_coverage_tick('public/javascripts/foo.js', 1);var foo = 3;
_coverage_tick('public/javascripts/foo.js', 2);if (foo > 1 &&
foo < 8) {
_coverage_tick('public/javascripts/foo.js', 4); var bar = 2;
}
"""

Scenario: it handles weirdly formatted case statements
Expand All @@ -97,8 +128,16 @@ Feature: instrumentation
wibble = 3;
}
"""
When I run `jcov`
When I run `jcov --dump`
Then the output should contain:
"""
Total Coverage: (3/5) 60.0%
_coverage_tick('public/javascripts/foo.js', 1);var foo = 'bar';
_coverage_tick('public/javascripts/foo.js', 2);switch (foo) {
case 'bar': wibble = 1;
_coverage_tick('public/javascripts/foo.js', 4); break;
case 'baz': wibble = 2;
_coverage_tick('public/javascripts/foo.js', 6); break;
default:
_coverage_tick('public/javascripts/foo.js', 8); wibble = 3;
}
"""

0 comments on commit f12e899

Please sign in to comment.