Jump to content

Erlang Programming/Debugging and Tracing

From Wikibooks, open books for an open world

Tools

[edit | edit source]
  • Debugging
    • dbg
    • debugger
  • Tracing
    • ttb
    • invision
    • et
  • Coverage
    • Cover

Coverage

[edit | edit source]

Coverage shows what functions are covered by a test. Sample program: test_rotate.erl

-module(test_rotate).
-export([test/0]).

test() ->
  assert( left_rotate([a,b,c]), [b,c,a] ).

assert(X, X) -> true.

left_rotate([]) -> [];
left_rotate([H|T]) -> T ++ [H].

Sample output:

33> cover:compile(test_rotate).
34> test_rotate:test().
true
35> cover:analyse_to_file(test_rotate, "cover.html", [html]).
   

Contents of cover.html shows that each clause was run once except for left_rotate([]). Each time the program is tested, the run count for each visited clause is increased by one. Cover sample output file:

File generated from test_rotate.erl by COVER 2008-04-23   
at 12:49:11
*********************************************
        |  -module(test_rotate).
        |  -export([test/0]).
        |   
        |  test() ->
     1..|    assert( left_rotate([a,b,c]), [b,c,a] ).
        |  
     1..|  assert(X, X) -> true.
        |  
     0..|  left_rotate([]) -> []; 
     1..|  left_rotate([H|T]) -> T ++ [H].
        |