Skip to content

Commit

Permalink
Add coverage check
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix authored and hurl-bot committed Dec 7, 2023
1 parent 4a94c88 commit ad39ccf
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ jobs:
if: always()
run: bin/check/rust_version.py 7

- name: Coverage
if: always()
run: bin/check/coverage.sh

- name: Rustfmt
if: always()
run: bin/check/rustfmt.sh
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.swp
*.swo
*.pyc
*.profraw
.mypy_cache/

target/
Expand Down
11 changes: 11 additions & 0 deletions bin/check/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -Eeuo pipefail
bin/install_prerequisites_ubuntu.sh
bin/install_grcov.sh
bin/test/test_prerequisites.sh
bin/coverage_run.sh
lines=$(bin/coverage_uncovered_lines.py packages/hurlfmt/src/format/json.rs)
if [ -n "$lines" ]; then
echo "$lines"
exit 1
fi
24 changes: 24 additions & 0 deletions bin/coverage_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -Eeuo pipefail

rm -rf target/profile
rm -rf target/coverage
cargo clean

RUSTFLAGS="-Cinstrument-coverage"
export RUSTFLAGS
LLVM_PROFILE_FILE="$(pwd)/target/profile/test-integ-%p-%m.profraw"
export LLVM_PROFILE_FILE

cargo build
PATH=$(pwd)/target/debug:$PATH
export PATH
bin/test/test_integ.sh
grcov target/profile \
--binary-path target/debug \
--source-dir . \
--output-types html \
--branch \
--ignore-not-existing \
--output-path target/coverage

42 changes: 42 additions & 0 deletions bin/coverage_uncovered_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import sys
from bs4 import BeautifulSoup

COVERAGE_DIR = "target/coverage"


def uncovered_lines(src_file):
html_file = COVERAGE_DIR + "/" + src_file + ".html"
sys.stderr.write(html_file + "\n")
html = open(html_file).read()
soup = BeautifulSoup(html, "html.parser")
elements = soup.select('div[role="row"]')
lines = []
for element in elements:
line = parse_row(element)
if line is not None:
lines.append(line)
return lines


def parse_row(element):
uncovered = element.select(".has-background-danger-light")
if len(uncovered) > 0:
line_number = element.select("div:first-child")[0]["id"]
line = uncovered[0].select("pre")[0].text
return line_number, line
return None


def main():
sys.stderr.write("Extracting uncovered lines\n")
for src_file in sys.argv[1:]:
lines = uncovered_lines(src_file)
if len(lines) > 0:
print(src_file)
for line_number, line in lines:
print("%s %s" % (line_number, line))


if __name__ == "__main__":
main()

0 comments on commit ad39ccf

Please sign in to comment.