#!/bin/bash die() { echo "ABORT: $*"; exit 1; } TARGET=${CARGO_TARGET_DIR:-./target} # Check macro.rs COVERAGE tags perl -e ' die unless open IN, ") { if (/COVERAGE\!\((.*?)\)/) { die "Duplicate COVERAGE tag: $1" if exists $tags{$1}; $tags{$1} = 1; } } die unless close IN; print((0 + keys %tags) . " macro.rs COVERAGE tags\n"); die unless open IN, ") { if (/pub\s+fn\s+(\S*?)\(\)/) { delete $tags{$1}; } } exit 0 if 0 == keys %tags; print "Coverage tag without entry in macro_coverage.rs: $_" for keys %tags; exit 1; ' || die COVERAGE tag problem # Run test with all feature combinations rm -r kcov >/dev/null 2>&1 mkdir kcov || die "Can't creat kcov/" COUNT=1000 ./run-feature-combinations | while read FEATURES do ID=${COUNT#1} let COUNT=COUNT+1 echo === $ID $FEATURES # Depending on the Rust version, test executables may be # dumped in $TARGET/debug or $TARGET/debug/deps rm -r $(find $TARGET/debug -name "stakker-*") >/dev/null 2>&1 # Can't use --no-run because it excludes some of the tests. # Need "link-dead-code" to get all the source (including # source without coverage) to show up. Need "opt-level=0" or # otherwise "link-dead-code" fails with linking problems. RUSTFLAGS="-C link-dead-code -C codegen-units=1 -C opt-level=0" \ cargo test $FEATURES >kcov/test-$ID 2>&1 || die "cargo test failed; see kcov/test-$ID" rm kcov/test-$ID set "" set $(find $TARGET/debug -name "stakker-*" -type f -executable) #was: ls $TARGET/debug/stakker-* | egrep 'stakker-[A-Fa-f0-9]+$' [ -z "$1" ] && die "Can't find test binary in $TARGET/debug" [ ! -z "$2" ] && die "Found more than one test binary in $TARGET/debug" EXE="$1" TESTS=$(echo $(find src -name "*.rs" | fgrep /test | fgrep -v macro_coverage) | perl -pe 's/ /,/g') mkdir kcov/out-$ID kcov --verify \ --include-pattern=stakker/src \ --exclude-pattern=$TESTS \ kcov/out-$ID $EXE || die "kcov failed" done echo "=== MERGING reports to kcov/out/ ..." mkdir kcov/out kcov --merge kcov/out kcov/out-* # Check that no files have been excluded. Skip src/lib.rs, because # there is no executable code in it. ( find src -name "*.rs" | fgrep -v test | perl -pe 's|.*/||'; echo macro_coverage.rs; # Always include this ) | sort >kcov/list-source ls kcov/out/kcov-merged/*.rs.*.html | perl -pe 's/\.rs.*/.rs/; s|.*/||;' | sort >kcov/list-covered cmp kcov/list-source kcov/list-covered >/dev/null 2>&1 || { echo "WARNING: Some files not included in report:" $(comm -23 kcov/list-source kcov/list-covered) }