blob: 5764120bc14284ef95624e9c6b39ddca480036de (
plain)
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
43
44
45
46
|
# Python coverage — Makefile fragment + setup recommendation
#
# This file is owned by the project, not the rulesets bundle. The bundle never
# edits your Makefile. Copy the two targets below into your own Makefile (and
# adjust the variables at the top), then delete this file or keep it as a note.
#
# What you get:
# make coverage runs the test suite under coverage.py, writes a JSON
# report, and prints coverage.py's own per-file table
# make coverage-summary prints a file-weighted project number and — the point
# — every source file on disk that no test imported,
# counted as 0%.
#
# Why the summary matters: a module no test imports never appears in coverage.py's
# output, so a line-weighted total silently skips it. The summary weights by file
# and counts a missing file as 0%, so untested modules stay visible. It does not
# reimplement the per-file table — `coverage report` already prints that.
#
# ---------------------------------------------------------------------------
# Prerequisite: coverage.py
#
# pip install coverage # or pytest-cov, if you prefer the pytest plugin
#
# The summary script itself needs nothing beyond the standard library — it parses
# the JSON report, it does not import coverage.
# ---------------------------------------------------------------------------
# Variables — adjust to your layout.
PYTHON ?= python3
SOURCE_DIR ?= src
COVERAGE_FILE ?= coverage.json
# The summary script ships with the bundle under .claude/scripts/ (gitignored).
COVERAGE_SUMMARY ?= .claude/scripts/coverage-summary.py
coverage:
@$(PYTHON) -m coverage run --source=$(SOURCE_DIR) -m pytest
@$(PYTHON) -m coverage json -o $(COVERAGE_FILE)
@$(PYTHON) -m coverage report
@$(MAKE) coverage-summary
coverage-summary:
@if [ ! -f $(COVERAGE_FILE) ]; then \
echo "[!] No coverage file at $(COVERAGE_FILE). Run 'make coverage' first."; \
exit 1; \
fi
@$(PYTHON) $(COVERAGE_SUMMARY) $(COVERAGE_FILE) $(SOURCE_DIR) $(CURDIR)
|