From 841ffee38d1268ff2ac0af231cf91a9cb874e8ec Mon Sep 17 00:00:00 2001 From: pdobacz <5735525+pdobacz@users.noreply.github.com> Date: Thu, 6 Nov 2025 12:42:23 +0100 Subject: [PATCH] tests: Add script to annotate `llvm-cov` report html --- coverage-annotator/.gitignore | 67 +++++++++++++++++ coverage-annotator/README.md | 17 +++++ coverage-annotator/pyproject.toml | 18 +++++ .../src/coverage_annotator/__init__.py | 0 .../add_annotations_to_coverage_html.py | 75 +++++++++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 coverage-annotator/.gitignore create mode 100644 coverage-annotator/README.md create mode 100644 coverage-annotator/pyproject.toml create mode 100644 coverage-annotator/src/coverage_annotator/__init__.py create mode 100644 coverage-annotator/src/coverage_annotator/add_annotations_to_coverage_html.py diff --git a/coverage-annotator/.gitignore b/coverage-annotator/.gitignore new file mode 100644 index 0000000000..0a5ff408f3 --- /dev/null +++ b/coverage-annotator/.gitignore @@ -0,0 +1,67 @@ +# ─── Python ──────────────────────────────────────────────────────────────── +__pycache__/ +*.py[cod] +*.pyo +*.pyd +*.pyw +*.so +*.egg +*.egg-info/ +.eggs/ +*.manifest +*.spec +*.log + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# ─── uv / Packaging ─────────────────────────────────────────────────────── +.uv/ +uv.lock +dist/ +build/ +*.whl +*.tar.gz + +# ─── Virtual Environments ───────────────────────────────────────────────── +.venv/ +venv/ +env/ +ENV/ + +# ─── Coverage / Testing ────────────────────────────────────────────────── +.coverage +coverage.xml +htmlcov/ +.pytest_cache/ +.cache/ +nosetests.xml +test-results.xml + +# ─── Editor / IDE files ────────────────────────────────────────────────── +.vscode/ +.idea/ +*.swp +*.swo +*.bak +*.orig + +# ─── macOS / Linux / Windows OS junk ───────────────────────────────────── +.DS_Store +Thumbs.db +ehthumbs.db +desktop.ini +Icon? +*.tmp + +# ─── Project-specific extras ───────────────────────────────────────────── +# Ignore generated annotated coverage output +coverage_with_annotations.html +*.html~ + +# Ignore local data or configs +local_settings.json +*.env +.env.* diff --git a/coverage-annotator/README.md b/coverage-annotator/README.md new file mode 100644 index 0000000000..4b22a3825f --- /dev/null +++ b/coverage-annotator/README.md @@ -0,0 +1,17 @@ +# Utility tool to annotate output report from `llvm-cov` + +Will annotate output report from `llvm-cov` (`index.html`), using comments included in a JSON file. + +## Usage + +```bash +uv run add-annotations coverage/html/index.html annotations.json coverage_with_annotations.html +``` + +Format of `annotations.json`, file paths must match exactly those in the report table: + +```json +{ + "include/evmmax/evmmax.hpp": "something something" +} +``` \ No newline at end of file diff --git a/coverage-annotator/pyproject.toml b/coverage-annotator/pyproject.toml new file mode 100644 index 0000000000..df16338ee7 --- /dev/null +++ b/coverage-annotator/pyproject.toml @@ -0,0 +1,18 @@ +[project] +name = "coverage-annotator" +version = "0.1.0" +description = "Add annotation column to HTML coverage reports using a JSON mapping" +authors = [{ name = "Your Name" }] +license = "MIT" +readme = "README.md" +requires-python = ">=3.9" + +dependencies = [ + "beautifulsoup4>=4.12", +] + +[project.scripts] +add-annotations = "coverage_annotator.add_annotations_to_coverage_html:main" + +[tool.uv] +package = true diff --git a/coverage-annotator/src/coverage_annotator/__init__.py b/coverage-annotator/src/coverage_annotator/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/coverage-annotator/src/coverage_annotator/add_annotations_to_coverage_html.py b/coverage-annotator/src/coverage_annotator/add_annotations_to_coverage_html.py new file mode 100644 index 0000000000..1f09ee80cb --- /dev/null +++ b/coverage-annotator/src/coverage_annotator/add_annotations_to_coverage_html.py @@ -0,0 +1,75 @@ +# evmone: Fast Ethereum Virtual Machine implementation +# Copyright 2025 The evmone Authors. +# SPDX-License-Identifier: Apache-2.0 + +import json +from bs4 import BeautifulSoup +import sys + +def add_annotations_to_coverage_html(html_path, json_path, output_path): + # Load annotations from JSON file + with open(json_path, 'r', encoding='utf-8') as jf: + annotations = json.load(jf) + + # Parse HTML + with open(html_path, 'r', encoding='utf-8') as hf: + soup = BeautifulSoup(hf, 'html.parser') + + # Find the coverage file table + # Commonly, the file list is inside a