@@ -396,6 +396,107 @@ EOF
396396 rm -f " $temp_file "
397397}
398398
399+ function test_coverage_report_lcov_includes_branch_records_for_if_else() {
400+ BASHUNIT_COVERAGE=" true"
401+ bashunit::coverage::init
402+
403+ local temp_file
404+ temp_file=$( mktemp)
405+ cat > " $temp_file " << 'EOF '
406+ #!/usr/bin/env bash
407+ if [ "$1" = "x" ]; then
408+ echo "taken"
409+ else
410+ echo "not-taken"
411+ fi
412+ EOF
413+
414+ echo " $temp_file " > " $_BASHUNIT_COVERAGE_TRACKED_FILES "
415+ echo " ${temp_file} :3" >> " $_BASHUNIT_COVERAGE_DATA_FILE "
416+
417+ local report_file
418+ report_file=$( mktemp)
419+ bashunit::coverage::report_lcov " $report_file "
420+
421+ local content
422+ content=$( cat " $report_file " )
423+
424+ assert_contains " BRDA:2,0,0,1" " $content "
425+ assert_contains " BRDA:2,0,1,0" " $content "
426+ assert_contains " BRF:2" " $content "
427+ assert_contains " BRH:1" " $content "
428+
429+ rm -f " $temp_file " " $report_file "
430+ }
431+
432+ function test_coverage_report_lcov_includes_branch_records_for_case() {
433+ BASHUNIT_COVERAGE=" true"
434+ bashunit::coverage::init
435+
436+ local temp_file
437+ temp_file=$( mktemp)
438+ cat > " $temp_file " << 'EOF '
439+ #!/usr/bin/env bash
440+ case "$1" in
441+ a)
442+ echo "got a"
443+ ;;
444+ b)
445+ echo "got b"
446+ ;;
447+ *)
448+ echo "other"
449+ ;;
450+ esac
451+ EOF
452+
453+ echo " $temp_file " > " $_BASHUNIT_COVERAGE_TRACKED_FILES "
454+ echo " ${temp_file} :7" >> " $_BASHUNIT_COVERAGE_DATA_FILE "
455+
456+ local report_file
457+ report_file=$( mktemp)
458+ bashunit::coverage::report_lcov " $report_file "
459+
460+ local content
461+ content=$( cat " $report_file " )
462+
463+ # Three case arms: only the second was hit
464+ assert_contains " BRDA:2,0,0,0" " $content "
465+ assert_contains " BRDA:2,0,1,1" " $content "
466+ assert_contains " BRDA:2,0,2,0" " $content "
467+ assert_contains " BRF:3" " $content "
468+ assert_contains " BRH:1" " $content "
469+
470+ rm -f " $temp_file " " $report_file "
471+ }
472+
473+ function test_coverage_report_lcov_omits_branch_records_when_none_present() {
474+ BASHUNIT_COVERAGE=" true"
475+ bashunit::coverage::init
476+
477+ local temp_file
478+ temp_file=$( mktemp)
479+ cat > " $temp_file " << 'EOF '
480+ #!/usr/bin/env bash
481+ echo "no branches"
482+ EOF
483+
484+ echo " $temp_file " > " $_BASHUNIT_COVERAGE_TRACKED_FILES "
485+
486+ local report_file
487+ report_file=$( mktemp)
488+ bashunit::coverage::report_lcov " $report_file "
489+
490+ local content
491+ content=$( cat " $report_file " )
492+
493+ assert_not_contains " BRDA:" " $content "
494+ assert_contains " BRF:0" " $content "
495+ assert_contains " BRH:0" " $content "
496+
497+ rm -f " $temp_file " " $report_file "
498+ }
499+
399500function test_coverage_report_lcov_includes_function_records() {
400501 BASHUNIT_COVERAGE=" true"
401502 bashunit::coverage::init
0 commit comments