mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 02:45:23 +00:00
Improve testsuite
o Covered modules are now explicitly listed in each testsuite. This permits to cover multiple modules by one testsuite. o An index.html file is generated. It lists all testsuites and their covered modules.
This commit is contained in:
parent
b4f76e7819
commit
3d715a24f7
@ -10,9 +10,11 @@ ERL_TESTS = t_yaml_parser
|
||||
|
||||
TESTS = dialyzer $(ERL_TESTS)
|
||||
|
||||
EXTRA_DIST = $(TPL_PL) $(TPL_ERL) $(ERL_FILES) eunit_lib.erl eunit_tty.erl cover_to_html.sh data
|
||||
EXTRA_DIST = $(TPL_PL) $(TPL_ERL) $(ERL_FILES) eunit_lib.erl \
|
||||
eunit_tty.erl cover_to_html.sh data
|
||||
|
||||
CLEANFILES = $(ERL_TESTS) $(TPL_FILES) eunit_lib.beam eunit_tty.beam erl_crash.dump cover_*.html
|
||||
CLEANFILES = $(ERL_TESTS) $(TPL_FILES) eunit_lib.beam eunit_tty.beam \
|
||||
erl_crash.dump cover_*.html
|
||||
|
||||
$(ERL_TESTS): $(ETEST) eunit_lib.erl eunit_tty.erl $(TPL_PL) $(TPL_ERL) data/$@/*.pattern
|
||||
@(test ! -e eunit_lib.beam \
|
||||
|
@ -1,13 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ -z "$1" -o -z "$2" ]; then
|
||||
echo "Syntax: $0 <test_name> <module>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cover_to_html () {
|
||||
module=$1
|
||||
test_name=$1
|
||||
pretty_name=`echo $test_name | tr "_" " "`
|
||||
module=$2
|
||||
|
||||
in=cover_${module}.out
|
||||
out=cover_${module}.html
|
||||
pct=cover_${module}.percent
|
||||
in=cover_${test_name}_${module}.out
|
||||
out=cover_${test_name}_${module}.html
|
||||
pct=cover_${test_name}_${module}.percent
|
||||
|
||||
percent=`cat $pct`
|
||||
percent=`cat $pct`
|
||||
|
||||
headline=`head -n 1 "$in"`
|
||||
timestamp=${headline#*COVER }
|
||||
@ -18,51 +25,51 @@ cover_to_html () {
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Testsuite coverity of "${module}"</title>
|
||||
<title>Testsuite coverity / ${pretty_name} / ${module}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
h1 {
|
||||
margin: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
#percent {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
margin: 0px;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
margin: 0px;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#timestamp {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 3em;
|
||||
color: #777;
|
||||
font-style: italic;
|
||||
border-bottom: solid 1px #000;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 3em;
|
||||
color: #777;
|
||||
font-style: italic;
|
||||
border-bottom: solid 1px #000;
|
||||
}
|
||||
.cvsid, .func {
|
||||
font-weight: bold;
|
||||
font-weight: bold;
|
||||
}
|
||||
.cvsid {
|
||||
color: #461b7e;
|
||||
color: #461b7e;
|
||||
}
|
||||
.cov {
|
||||
color: #007a00;
|
||||
color: #007a00;
|
||||
}
|
||||
.notcov {
|
||||
color: #f00;
|
||||
color: #f00;
|
||||
}
|
||||
.comment {
|
||||
color: #777;
|
||||
color: #777;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testsuite coverity of <span style="color: #9fc550;">${module}</span></h1>
|
||||
<h1>Testsuite coverity: <span style="text-transform: capitalize;">${pretty_name}</span> / <span style="color: #9fc550;">${module}</span></h1>
|
||||
<p id="percent">$percent %</p>
|
||||
<p id="timestamp">Date: ${timestamp}</p>
|
||||
<pre>
|
||||
@ -75,17 +82,96 @@ EOF
|
||||
-e 's,^\([[:space:]]*[1-9][0-9]*\.\.|.*\),<span class="cov">\1</span>,' \
|
||||
-e 's,^\([[:space:]]*|[[:space:]][[:space:]]*%+ \$Id.*\),<span class="cvsid">\1</span>,' \
|
||||
-e 's,^\([[:space:]]*|[[:space:]][[:space:]]*%.*\),<span class="comment">\1</span>,' \
|
||||
-e 's,^\([[:space:]]*|[[:space:]]\{2\}[[:alpha:]][[:alpha:]]*.*\),<span class="func">\1</span>,' \
|
||||
-e 's,^\([[:space:]]*|[[:space:]]\{2\}[[:alpha:]][a-zA-Z0-9_]*\)\(.*\),<span class="func">\1</span>\2,' \
|
||||
>> "$out"
|
||||
|
||||
cat << EOF >> "$out"
|
||||
</pre>
|
||||
</body>
|
||||
EOF
|
||||
|
||||
rm $in $pct
|
||||
}
|
||||
|
||||
for mod in $@; do
|
||||
cover_to_html $mod
|
||||
done
|
||||
update_index () {
|
||||
out=index.html
|
||||
|
||||
timestamp=`date +'Date: %Y-%m-%d at %H:%M:%S'`
|
||||
|
||||
cat << EOF > "$out"
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Testsuite coverity</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
h1 {
|
||||
margin: 0px;
|
||||
}
|
||||
#timestamp {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 3em;
|
||||
color: #777;
|
||||
font-style: italic;
|
||||
border-bottom: solid 1px #000;
|
||||
}
|
||||
table {
|
||||
border: 1px solid #999;
|
||||
border-collapse: collapse;
|
||||
background-color: #f9f9f9;;
|
||||
}
|
||||
th, td {
|
||||
padding: 4px;
|
||||
}
|
||||
th {
|
||||
border-bottom: 1px solid #999;
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Testsuite coverity</h1>
|
||||
<p id="timestamp">Date: ${timestamp}</p>
|
||||
EOF
|
||||
|
||||
for test_name in *.erl; do
|
||||
test_name=${test_name%.erl}
|
||||
pretty_name=`echo $test_name | tr "_" " "`
|
||||
cat << EOF >> "$out"
|
||||
<h2 style="text-transform: capitalize;">$pretty_name</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th style="width: 200px; text-align: left;">Module</th>
|
||||
<th style="width: 100px; text-align: right;">Coverage</th>
|
||||
</tr>
|
||||
EOF
|
||||
|
||||
for pct in cover_${test_name}_*.percent; do
|
||||
name=${pct%.percent}
|
||||
mod=${name#cover_${test_name}_}
|
||||
percent=`cat $pct`
|
||||
cat << EOF >> "$out"
|
||||
<tr>
|
||||
<td><a href="${name}.html">$mod</a></td>
|
||||
<td style="text-align: right;">$percent %</td>
|
||||
</tr>
|
||||
EOF
|
||||
done
|
||||
|
||||
cat << EOF >> "$out"
|
||||
</table>
|
||||
EOF
|
||||
done
|
||||
|
||||
cat << EOF >> "$out"
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
}
|
||||
|
||||
cover_to_html $1 $2
|
||||
update_index
|
||||
|
@ -1,6 +1,6 @@
|
||||
%% $Id: bones_version.erl 2899 2010-05-07 15:06:08Z jean.sebastien.pedron $
|
||||
|
||||
-module(${MODULE}).
|
||||
-module('${MODULE}').
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
@ -20,21 +20,34 @@ main_test_() ->
|
||||
|
||||
setup() ->
|
||||
%% Setup coverity checking.
|
||||
Dir = os:getenv("srcdir"),
|
||||
Include_Dir = filename:join([Dir, "..", "include"]),
|
||||
Src_Dir = filename:join([Dir, "..", "src"]),
|
||||
Dir = os:getenv("srcdir"),
|
||||
Include_Dir = filename:join([Dir, "..", "include"]),
|
||||
Src_Dir = filename:join([Dir, "..", "src"]),
|
||||
Cover_To_Html = filename:join([Dir, "cover_to_html.sh"]),
|
||||
Mods_List = filename:join([Dir, "data", ?MODULE_STRING,
|
||||
"COVERED-MODS"]),
|
||||
cover:start(),
|
||||
cover:compile_directory(Src_Dir, [{i, Include_Dir}]),
|
||||
Cover_To_Html.
|
||||
Covered_Mods = case file:consult(Mods_List) of
|
||||
{ok, [ML]} ->
|
||||
Fun = fun(M) ->
|
||||
F = filename:join([Src_Dir, M]) ++ ".erl",
|
||||
cover:compile_module(F, [{i, Include_Dir}])
|
||||
end,
|
||||
lists:foreach(Fun, ML),
|
||||
ML;
|
||||
_ ->
|
||||
[]
|
||||
end,
|
||||
{Covered_Mods, Cover_To_Html}.
|
||||
|
||||
cleanup(Cover_To_Html) ->
|
||||
Covered_Mod = list_to_atom(string:substr(atom_to_list(?MODULE), 3)),
|
||||
print_coverage(Cover_To_Html, [Covered_Mod]),
|
||||
cleanup({Covered_Mods, Cover_To_Html}) ->
|
||||
print_coverage(Cover_To_Html, Covered_Mods),
|
||||
cover:stop().
|
||||
|
||||
print_coverage(Cover_To_Html, Modules) ->
|
||||
io:format(standard_error, " Coverage:~n", []),
|
||||
Name = string:to_upper([hd(?MODULE_STRING)]) ++ tl(?MODULE_STRING),
|
||||
Name1 = string:join(string:tokens(Name, "_"), " "),
|
||||
io:format(standard_error, " ~s / Coverage:~n", [Name1]),
|
||||
print_coverage2(Cover_To_Html, Modules).
|
||||
|
||||
print_coverage2(Cover_To_Html, [Mod | Rest]) ->
|
||||
@ -42,7 +55,7 @@ print_coverage2(Cover_To_Html, [Mod | Rest]) ->
|
||||
Mod_S = atom_to_list(Mod),
|
||||
if
|
||||
Cov > 0 andalso Not_Cov > 0 ->
|
||||
file:write_file("cover_" ++ Mod_S ++ ".percent",
|
||||
file:write_file("cover_" ?MODULE_STRING "_" ++ Mod_S ++ ".percent",
|
||||
list_to_binary(io_lib:format("~.1f",
|
||||
[Cov * 100 / (Cov + Not_Cov)]))),
|
||||
io:format(standard_error, " - ~s: ~.1f%~n",
|
||||
@ -50,8 +63,9 @@ print_coverage2(Cover_To_Html, [Mod | Rest]) ->
|
||||
true ->
|
||||
io:format(standard_error, " - ~s: n/a~n~n", [Mod])
|
||||
end,
|
||||
cover:analyse_to_file(Mod, "cover_" ++ Mod_S ++ ".out", []),
|
||||
os:cmd(Cover_To_Html ++ " " ++ Mod_S),
|
||||
cover:analyse_to_file(Mod,
|
||||
"cover_" ?MODULE_STRING "_" ++ Mod_S ++ ".out", []),
|
||||
os:cmd(Cover_To_Html ++ " " ?MODULE_STRING " " ++ Mod_S),
|
||||
print_coverage2(Cover_To_Html, Rest);
|
||||
print_coverage2(_, []) ->
|
||||
ok.
|
||||
|
Loading…
Reference in New Issue
Block a user