-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests_with_coverage.py
More file actions
42 lines (32 loc) · 1.3 KB
/
run_tests_with_coverage.py
File metadata and controls
42 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import re
import subprocess
def find_all_files(directory):
all_files = []
for root, dirs, files in os.walk(directory):
for file in files:
all_files.append(os.path.join(root, file))
return all_files
def find_cov_files(path):
with open(path, "r") as file:
content = file.read()
return re.findall(r"(?<=SF:)(.+)", content)
def is_file_ignored(path):
with open(path, "r") as file:
content = file.read()
return re.search(r"//\s*coverage:\s*ignore-file", content) is not None
if __name__ == "__main__":
cwd = os.path.abspath(os.getcwd())
command = ["fvm", "flutter", "test"] + find_all_files('test/') + ["--coverage"]
subprocess.run(command, cwd=cwd)
# Add uncovered files to report
project_files = find_all_files("lib/")
covered_files = find_cov_files("coverage/lcov.info")
for covered_file in covered_files:
project_files.remove(covered_file)
with open("coverage/lcov.info", "a") as file:
for uncovered_file in project_files:
if not is_file_ignored(uncovered_file):
file.write(f"SF:{uncovered_file}\nDA:1,0\nend_of_record\n")
subprocess.run(["genhtml", "coverage/lcov.info", "-o", "coverage/html"], cwd=cwd)
subprocess.run(["open", "coverage/html/index.html"], cwd=cwd)