diff options
author | Chris Bernard <cebernard@gmail.com> | 2010-05-15 15:09:45 -0400 |
---|---|---|
committer | Chris Bernard <cebernard@gmail.com> | 2010-05-15 15:09:45 -0400 |
commit | 4825353a237b8cfe0ba0e1a9e6001de756af1189 (patch) | |
tree | 570c144abf1bfda5e4ec57bb6c4f73c722d15d4b /test | |
parent | 35a928ecf2e0736dad345f644108141eabbbbee8 (diff) |
Fix incorrect coverage count when prod modules include EUnit header.
Modules that include the EUnit header get an implicit test/0 fun,
which cover considers a runnable line, but eunit:(TestRepresentation)
never calls. Result: prod modules with tests can never reach 100%
coverage. Ironic. In this case, fix it by decrementing the NotCovered
counter returned by cover:analyze/3.
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_eunit_tests.erl | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/test/rebar_eunit_tests.erl b/test/rebar_eunit_tests.erl index 4f035fb..2187091 100644 --- a/test/rebar_eunit_tests.erl +++ b/test/rebar_eunit_tests.erl @@ -88,14 +88,25 @@ cover_with_suite_test_() -> {"Only production modules get coverage reports", assert_files_not_in("the temporary eunit directory", [".eunit/myapp_mymod_tests.COVER.html", - ".eunit/mysuite"])}]}. + ".eunit/mysuite.COVER.html"])}]}. expected_cover_generated_files() -> [".eunit/index.html", ".eunit/myapp_app.COVER.html", ".eunit/myapp_mymod.COVER.html", ".eunit/myapp_sup.COVER.html"]. - + +cover_coverage_test_() -> + {"Coverage is accurately calculated", + setup, fun() -> setup_cover_project(), rebar("-v eunit") end, + fun teardown/1, + + [{"Modules that include the EUnit header can still have 100% coverage", + %% cover notices the implicit EUnit test/0 func that never gets + %% called during eunit:test(TestRepresentation), so NotCounted + %% needs to be decremented in this case. + assert_full_coverage("myapp_mymod")}]}. + %% ==================================================================== %% Environment and Setup Tests %% ==================================================================== @@ -227,3 +238,12 @@ assert_files_not_in(Name, [File|T]) -> assert_files_not_in(Name, T)]; assert_files_not_in(_, []) -> []. +assert_full_coverage(Mod) -> + fun() -> + {ok, F} = file:read_file(".eunit/index.html"), + Result = [X || X <- string:tokens(binary_to_list(F), "\n"), + string:str(X, Mod) =/= 0, + string:str(X, "100%") =/= 0], + file:close(F), + ?assert(length(Result) == 1) + end. |