set -e
shopt -s globstar
SUFFIX=.original
if [ -e target ]; then
mv target coverage_save_target
fi
EXTRACT_SCRIPT='
p # print original, as sed is called quiet
/```rust$/,/```$/{ # work between ```rust and ```
\,//[/!],!s,^, , # indent uncommented lines
s, *//[/!], , # uncomment commented lines
s, *$,, # remove trailing spaces
s,^\( *\)# ,\1/* # */ , # comment hiding hash
s, ```rust$,{, # replace ```rust with {
s, rug::, /*& */ , # comment rug::
s, ::rug, /*& */ , # comment ::rug
s,fn main(),/* & */, # comment fn main()
s, ```,}, # replace ``` with }
H # append to hold
}
${ # at the end of the file
x # move the hold to pattern space
/./{ # if hold was not empty
s/^.// # remove leading newline
i\
// AUTOEXTRACTED DOCTESTS BELOW
i\
#[test]
i\
fn check_doctests() {
p # print the hold (wrapped by fn)
i\
}
}
}'
sed -i$SUFFIX -n -e "$EXTRACT_SCRIPT" src/**/*.rs
FILTER_SCRIPT='
# modify uncovered lines list
/Uncovered Lines/,/Tested\/Total Lines:/{
# make lines friendly with emacs compilation mode
s/^\(.*\): \(..*\)/\1:\2: Uncovered/
# if the line contains a comma split it, repeating prefix and suffix
s/\(^\)\(.*\):\([^,]*\), \(.*: Uncovered\)$/\1\2:\3: Uncovered\n\2:\4/
: repeat
# like above, but work on last line only
s/\(.*\n\)\(.*\):\([^,]*\), \(.*: Uncovered\)$/\1\2:\3: Uncovered\n\2:\4/
# if a line was split, repeat
t repeat
}
p # print the line(s) as sed is invoked with -e
'
(
printf '%s*- mode: compilation; default-directory: "%s" -*-\n' - "$PWD"
printf 'Compilation started at %s\n\n' "$(date)"
cargo tarpaulin -v --features serde --ignore-tests |&
sed -n -e "$FILTER_SCRIPT"
printf '\nCompilation finished at %s\n' "$(date)"
) > coverage.report
for f in src/**/*.rs$SUFFIX; do
mv "$f" "${f%$SUFFIX}"
done
if [ -e target ]; then
rm -r target
fi
if [ -e coverage_save_target ]; then
mv coverage_save_target target
fi