Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9cabe2a authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '0000-a15-add-coverage-regexp' into 'main'

chore: add coverage regexp

See merge request !645
parents fa572478 04e5ae9d
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ test:
      when: always
  script:
    - ./gradlew test jacocoDebugReport -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl"
    - python3 scripts/print_instruction_coverage.py app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml
  coverage: '/INSTRUCTION_COVERAGE\\s+([0-9]{1,3}\\.?[0-9]*)%/'
  artifacts:
    when: always
    paths:
+19 −0
Original line number Diff line number Diff line
import sys
import xml.etree.ElementTree as ET


def main() -> None:
    report_path = sys.argv[1] if len(sys.argv) > 1 else "app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml"
    xml_root = ET.parse(report_path).getroot()
    instruction_counter = next(
        counter for counter in xml_root.findall("counter") if counter.attrib["type"] == "INSTRUCTION"
    )
    missed_count = int(instruction_counter.attrib["missed"])
    covered_count = int(instruction_counter.attrib["covered"])
    total_instructions = covered_count + missed_count
    coverage_pct = covered_count / total_instructions * 100 if total_instructions else 0
    print(f"INSTRUCTION_COVERAGE {coverage_pct:.2f}%")


if __name__ == "__main__":
    main()