#!/usr/bin/env bash coverdata_dir=@abs_builddir@/logs coverdata_file=${coverdata_dir}/@PACKAGE_NAME@.coverdata coverdata_app=@PACKAGE_NAME@ analyze_coverdata=@abs_builddir@/analyze_coverdata.escript color_0="ff2200" color_5="ff3800" color_10="ff4e00" color_15="ff6400" color_20="ff7a00" color_25="ff9000" color_30="ffa500" color_35="ffbb00" color_40="ffd100" color_45="ffe700" color_50="fdfc00" color_55="ecff00" color_60="d6ff00" color_65="c0ff00" color_70="aaff00" color_75="94ff00" color_80="7eff00" color_85="69ff00" color_90="53ff00" color_95="3dff00" color_100="27ff00" output_analyze_coverdata () { pretty_name=$(echo $coverdata_app | tr "_" " ") # Generate covered modules data. We ignore stdout because cover # writes some useless logs. $analyze_coverdata $coverdata_file > /dev/null covered_mods=${coverdata_app}_covered_mods # Prepare index block. index=${coverdata_dir}/cover.html timestamp=$(date +'%Y-%m-%d at %H:%M:%S') cat << EOF > "$index" Testsuite coverage - ${pretty_name}

Testsuite coverage - ${pretty_name}

Date: ${timestamp}

${pretty_name} modules:

EOF # For each module of this test: # o Write its source code with cover results. # o Update index block. total_covered=0 total_not_covered=0 for module in $(cat ${coverdata_dir}/${covered_mods} | sort); do in=${coverdata_dir}/${coverdata_app}_${module}.out cvd=${coverdata_dir}/${coverdata_app}_${module}.covered not_cvd=${coverdata_dir}/${coverdata_app}_${module}.not_covered pct=${coverdata_dir}/${coverdata_app}_${module}.percent out=${coverdata_dir}/${module}.COVER.html link=${module}.COVER.html covered=$(cat $cvd) not_covered=$(cat $not_cvd) percent=$(cat $pct) color=$(echo $percent | sed -e 's/\..*$//') if [ $((color % 5)) -gt 0 ]; then color=$((color + (5 - color % 5))) fi color=$(eval echo \${color_$color}) headline=$(head -n 1 "$in") timestamp=${headline#*COVER } # Update source file to emphasize cover results. cat << EOF > "$out" Testsuite coverage / ${pretty_name} / ${module}

Testsuite coverage: ${pretty_name} / ${module}

${percent} %

Date: ${timestamp}

[index]

EOF

        line_nb=$(wc -l "$in")
        tail -n $((${line_nb% *} - 4)) "$in" | sed \
         -e 's,<,\<,g' -e 's,>,\>,g' \
         -e 's,^\([[:space:]]*0\.\.|.*\),\1,' \
         -e 's,^\([[:space:]]*[1-9][0-9]*\.\.|.*\),\1,' \
         -e 's,^\([[:space:]]*|[[:space:]][[:space:]]*%+ \$Id.*\),\1,' \
         -e 's,^\([[:space:]]*|[[:space:]][[:space:]]*%.*\),\1,' \
         -e 's,^\([[:space:]]*|[[:space:]]\{2\}[[:alpha:]][a-zA-Z0-9_]*\)\(.*\),\1\2,' \
         >> "$out"

        cat << EOF >> "$out"
EOF # Update index block. cat << EOF >> "$index" EOF # Update total results total_covered=$((total_covered + covered)) total_not_covered=$((total_not_covered + not_covered)) # Remove file generated by $analyze_coverdata. rm -f $in $cvd $not_cvd $pct done total_percent=$(echo "scale=1; ($total_covered * 100 / ( $total_covered + $total_not_covered))" | bc) color=$(echo $total_percent | sed -e 's/\..*$//') if [ $((color % 5)) -gt 0 ]; then color=$((color + (5 - color % 5))) fi color=$(eval echo \${color_$color}) # End index block. cat << EOF >> "$index"
Module Coverage (%) Coveraged (Lines) Not coveraged (Lines)
${module} ${percent} % ${covered} ${not_covered}
Total ${total_percent} % ${total_covered} ${total_not_covered}
EOF rm -f $covered_mods } output_analyze_coverdata