Skip to content

Commit b7ebec0

Browse files
committed
Fix 'exclude region' overlap error message.
Signed-off-by: Henry Cox <[email protected]>
1 parent d1f9d85 commit b7ebec0

File tree

3 files changed

+98
-27
lines changed

3 files changed

+98
-27
lines changed

lib/lcovutil.pm

+40-24
Original file line numberDiff line numberDiff line change
@@ -5600,18 +5600,26 @@ sub parseLines
56005600
my @excludes;
56015601
if (defined($lcovutil::cov_filter[$lcovutil::FILTER_EXCLUDE_REGION])) {
56025602
push(@excludes,
5603-
[$excl_start, $excl_stop, \$exclude_region, 3 | EXCLUDE_REGION]);
5603+
[$excl_start, $excl_stop,
5604+
\$exclude_region, 3 | EXCLUDE_REGION,
5605+
$lcovutil::EXCL_START, $lcovutil::EXCL_STOP
5606+
]);
56045607
} else {
56055608
$excl_line = undef;
56065609
}
56075610

56085611
if (defined($lcovutil::cov_filter[$lcovutil::FILTER_EXCLUDE_BRANCH])) {
56095612
push(@excludes,
56105613
[$excl_ex_start, $excl_ex_stop,
5611-
\$exclude_exception_region, 4 | EXCLUDE_BRANCH_REGION
5614+
\$exclude_exception_region, 4 | EXCLUDE_BRANCH_REGION,
5615+
$lcovutil::EXCL_BR_START, $lcovutil::EXCL_BR_STOP,
56125616
],
5613-
[$excl_br_start, $excl_br_stop,
5614-
\$exclude_br_region, 2 | EXCLUDE_BRANCH_REGION
5617+
[$excl_br_start,
5618+
$excl_br_stop,
5619+
\$exclude_br_region,
5620+
2 | EXCLUDE_BRANCH_REGION,
5621+
$lcovutil::EXCL_EXCEPTION_BR_START,
5622+
$lcovutil::EXCL_EXCEPTION_BR_STOP,
56155623
]);
56165624
} else {
56175625
$excl_br_line = undef;
@@ -5632,18 +5640,24 @@ sub parseLines
56325640
}
56335641

56345642
foreach my $d (@excludes) {
5643+
# note: $d->[4] is the 'start' string (not converted to perl regexp)
5644+
# $d->[5] is the 'stop' string
56355645
my ($start, $stop, $ref, $reason) = @$d;
56365646
if ($_ =~ $start) {
56375647
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5638-
"$filename: overlapping exclude directives. Found $start at line $line - but no matching $stop for $start at line "
5639-
. $ref->[0])
5648+
"$filename: overlapping exclude directives. Found " .
5649+
$d->[4] .
5650+
" at line $line - but no matching " . $d->[5] .
5651+
' for ' . $d->[4] . ' at line ' . $$ref->[0])
56405652
if $$ref;
56415653
$$ref = [$line, $reason];
56425654
last;
56435655
} elsif ($_ =~ $stop) {
56445656
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5645-
"$filename: found $stop directive at line $line without matching $start directive"
5646-
) unless $$ref;
5657+
"$filename: found " . $d->[5] .
5658+
" directive at line $line without matching " .
5659+
$d->[4] . ' directive')
5660+
unless $$ref;
56475661
$$ref = undef;
56485662
last;
56495663
}
@@ -5675,22 +5689,24 @@ sub parseLines
56755689
$exclude_exception_region ? $exclude_exception_region->[1] : 0
56765690
) | $exclude_branch_line | $exclude_exception_branch_line);
56775691
}
5678-
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5679-
"$filename: unmatched $lcovutil::EXCL_START at line " .
5680-
$exclude_region->[0] .
5681-
" - saw EOF while looking for matching $lcovutil::EXCL_STOP"
5682-
) if $exclude_region;
5683-
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5684-
"$filename: unmatched $lcovutil::EXCL_BR_START at line " .
5685-
$exclude_br_region->[0] .
5686-
" - saw EOF while looking for matching $lcovutil::EXCL_BR_STOP"
5687-
) if $exclude_br_region;
5688-
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5689-
"$filename: unmatched $lcovutil::EXCL_EXCEPTION_BR_START at line " .
5690-
$exclude_exception_region->[0] .
5691-
" - saw EOF while looking for matching $lcovutil::EXCL_EXCEPTION_BR_STOP"
5692-
) if $exclude_exception_region;
5693-
5692+
foreach my $t ([$exclude_region, $lcovutil::EXCL_START,
5693+
$lcovutil::EXCL_STOP
5694+
],
5695+
[$exclude_br_region, $lcovutil::EXCL_BR_START,
5696+
$lcovutil::EXCL_BR_STOP
5697+
],
5698+
[$exclude_exception_region,
5699+
$lcovutil::EXCL_EXCEPTION_BR_START,
5700+
$lcovutil::EXCL_EXCEPTION_BR_STOP
5701+
]
5702+
) {
5703+
my ($key, $start, $stop) = @$t;
5704+
lcovutil::ignorable_error($lcovutil::ERROR_MISMATCH,
5705+
"$filename: unmatched $start at line " .
5706+
$key->[0] .
5707+
" - saw EOF while looking for matching $stop"
5708+
) if ($key);
5709+
}
56945710
my $data = $self->[0];
56955711
$data->[FILENAME] = $filename;
56965712
$data->[SOURCE] = $sourceLines;

tests/lcov/extract/extract.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ int main(int argc, const char *argv[])
1616
printf("Hai\n");
1717
delete[] a;
1818

19+
// TEST_OVERLAP_START
20+
// TEST_OVERLAP_START
1921
std::string str("asdads");
2022
str = "cd";
23+
// TEST_OVERLAP_END
24+
25+
//TEST_DANGLING_START
26+
//TEST_UNMATCHED_END
2127

2228
std::cout << str << std::endl;
2329

tests/lcov/extract/extract.sh

+52-3
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fi
493493
494494
# workaround: depending on compiler verision, we see a coverpoint on the
495495
# close brace line (gcc/6 for example) or we don't (gcc/10 for example)
496-
BRACE_LINE='^DA:28'
496+
BRACE_LINE='^DA:34'
497497
MARKER_LINES=`grep -v $BRACE_LINE internal.info | grep -c "^DA:"`
498498
499499
# check 'no-markers': is the excluded line back?
@@ -513,6 +513,55 @@ if [ $NOMARKER_LINES != '13' ] ; then
513513
fi
514514
fi
515515
516+
# override excl region start/stop and look for error
517+
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr1.info --rc lcov_excl_start=TEST_OVERLAP_START --rc lcov_excl_stop=TEST_OVERLAP_END --msg-log
518+
if [ $? == 0 ] ; then
519+
echo "error expected overlap fail"
520+
if [ $KEEP_GOING == 0 ] ; then
521+
exit 1
522+
fi
523+
fi
524+
525+
grep -E 'overlapping exclude directives. Found TEST_OVERLAP_START at .+ but no matching TEST_OVERLAP_END for TEST_OVERLAP_START at line ' regionErr1.msg
526+
if [ 0 != $? ] ; then
527+
echo "error expected overlap message but didn't find"
528+
if [ $KEEP_GOING == 0 ] ; then
529+
exit 1
530+
fi
531+
fi
532+
533+
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr2.info --rc lcov_excl_start=TEST_DANGLING_START --rc lcov_excl_stop=TEST_DANGLING_END --msg-log
534+
if [ $? == 0 ] ; then
535+
echo "error expected dangling fail"
536+
if [ $KEEP_GOING == 0 ] ; then
537+
exit 1
538+
fi
539+
fi
540+
541+
grep -E 'unmatched TEST_DANGLING_START at line .+ saw EOF while looking for matching TEST_DANGLING_END' regionErr2.msg
542+
if [ 0 != $? ] ; then
543+
echo "error expected dangling message but didn't find"
544+
if [ $KEEP_GOING == 0 ] ; then
545+
exit 1
546+
fi
547+
fi
548+
549+
$COVER $CAPTURE . $LCOV_OPTS --no-external -o regionErr3.info --rc lcov_excl_start=TEST_UNMATCHED_START --rc lcov_excl_stop=TEST_UNMATCHED_END --msg-log
550+
if [ $? == 0 ] ; then
551+
echo "error expected unmatched fail"
552+
if [ $KEEP_GOING == 0 ] ; then
553+
exit 1
554+
fi
555+
fi
556+
557+
grep -E 'found TEST_UNMATCHED_END directive at line .+ without matching TEST_UNMATCHED_START' regionErr3.msg
558+
if [ 0 != $? ] ; then
559+
echo "error expected unmapted message but didn't find"
560+
if [ $KEEP_GOING == 0 ] ; then
561+
exit 1
562+
fi
563+
fi
564+
516565
# override excl_line start/stop - and make sure we didn't match
517566
$COVER $CAPTURE . $LCOV_OPTS --no-external -o excl.info --rc lcov_excl_start=nomatch_start --rc lcov_excl_stop=nomatch_end
518567
if [ $? != 0 ] ; then
@@ -573,7 +622,7 @@ if [ 0 != ${PIPESTATUS[0]} ] ; then
573622
fi
574623
fi
575624
576-
BRACE_LINE="DA:28"
625+
BRACE_LINE="DA:34"
577626
# a bit of a hack: gcc/10 doesn't put a DA entry on the closing brace
578627
COUNT=`grep -v $BRACE_LINE omit.info | grep -c ^DA:`
579628
if [ $COUNT != '11' ] ; then
@@ -650,7 +699,7 @@ if [ $? != 0 ] ; then
650699
exit 1
651700
fi
652701
fi
653-
#munge the checksum in the outpt file
702+
#munge the checksum in the output file
654703
perl -i -pe 's/DA:6,1.+/DA:6,1,abcde/g' < checksum.info > mismatch.info
655704
$COVER $LCOV_TOOL $LCOV_OPTS --summary mismatch.info --checksum
656705
if [ $? == 0 ] ; then

0 commit comments

Comments
 (0)