Skip to content

Commit 2ec983b

Browse files
committed
Add check for case when branch filter is enabled but branch
coverage is not enabled. Result is not likely to be what user expected. Signed-off-by: Henry Cox <[email protected]>
1 parent 63c3dc9 commit 2ec983b

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/lcovutil.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,13 @@ sub parse_cov_filters(@)
21442144
$cov_filter[$FILTER_LINE_CLOSE_BRACE] = [0, 0];
21452145
$cov_filter[$FILTER_BLANK_LINE] = [0, 0];
21462146
}
2147+
if ((defined($cov_filter[$FILTER_BRANCH_NO_COND]) ||
2148+
defined($cov_filter[$FILTER_EXCLUDE_BRANCH])) &&
2149+
!$br_coverage
2150+
) {
2151+
lcovutil::ignorable_warning($ERROR_USAGE,
2152+
"branch filter enabled but branch coverage not enabled");
2153+
}
21472154
}
21482155

21492156
sub summarize_cov_filters

tests/gendiffcov/errs/msgtest.sh

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ LCOV_OPTS="$LCOV_BASE"
131131
DIFFCOV_OPTS="--filter line,branch,function --function-coverage --branch-coverage --highlight --demangle-cpp --prefix $PARENT_VERSION $PROFILE "
132132

133133
rm -f test.cpp *.gcno *.gcda a.out *.info *.log *.json diff.txt
134-
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed
134+
rm -rf select criteria annotate empty unused_src scriptErr scriptFixed epoch inconsistent
135135

136136
if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
137137
cover -delete
@@ -526,6 +526,57 @@ if [ 0 != $? ] ; then
526526
exit 1
527527
fi
528528
fi
529+
530+
# inconsistent setting of branch filtering without enabling branch coverage
531+
echo genhtml --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent --rc treat_warning_as_error=1
532+
$COVER $GENHTML_TOOL --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent --rc treat_warning_as_error=1 2>&1 | tee inconsistent.log
533+
if [ 0 == ${PIPESTATUS[0]} ] ; then
534+
echo "ERROR: genhtml inconsistent warning-as-error passed by accident"
535+
if [ 0 == $KEEP_GOING ] ; then
536+
exit 1
537+
fi
538+
fi
539+
grep 'ERROR: (usage) branch filter enabled but branch coverage not enabled' inconsistent.log
540+
if [ 0 != $? ] ; then
541+
echo "ERROR: missing inconsistency message"
542+
if [ 0 == $KEEP_GOING ] ; then
543+
exit 1
544+
fi
545+
fi
546+
547+
# when we treat warning as error, but ignore the message type
548+
echo genhtml --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent --rc treat_warning_as_error=1 --ignore usage
549+
$COVER $GENHTML_TOOL --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent --rc treat_warning_as_error=1 --ignore usage 2>&1 | tee inconsistent.log
550+
if [ 0 != ${PIPESTATUS[0]} ] ; then
551+
echo "ERROR: genhtml inconsistent warning-as-error passed by accident"
552+
if [ 0 == $KEEP_GOING ] ; then
553+
exit 1
554+
fi
555+
fi
556+
grep 'WARNING: (usage) branch filter enabled but branch coverage not enabled' inconsistent.log
557+
if [ 0 != $? ] ; then
558+
echo "ERROR: missing inconsistency message"
559+
if [ 0 == $KEEP_GOING ] ; then
560+
exit 1
561+
fi
562+
fi
563+
564+
echo genhtml --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent
565+
$COVER $GENHTML_TOOL --filter branch --prefix $PARENT_VERSION $PROFILE initial.info -o inconsistent 2>&1 | tee inconsistent2.log
566+
if [ 0 != ${PIPESTATUS[0]} ] ; then
567+
echo "ERROR: genhtml inconsistent warning-as-error failed"
568+
if [ 0 == $KEEP_GOING ] ; then
569+
exit 1
570+
fi
571+
fi
572+
grep 'WARNING: (usage) branch filter enabled but branch coverage not enabled' inconsistent2.log
573+
if [ 0 != $? ] ; then
574+
echo "ERROR: missing inconsistency message 2"
575+
if [ 0 == $KEEP_GOING ] ; then
576+
exit 1
577+
fi
578+
fi
579+
529580
530581
echo "Tests passed"
531582

0 commit comments

Comments
 (0)