summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/test-surface.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/tools/test-surface.py b/tools/test-surface.py
index 16929bd..b21133a 100644
--- a/tools/test-surface.py
+++ b/tools/test-surface.py
@@ -280,7 +280,19 @@ def analyse():
dotted_only = bool(internal) and not bare
internal = [h for h, _ in internal]
- if gated:
+ # Feature-conditional visibility: the item is `pub` under `test-support`
+ # and `pub(crate)` otherwise, declared twice with the same body. It is
+ # not the same as being gated — production *does* use this item, just
+ # not from outside its module — and the table should say which is which.
+ narrowed = gated and any(
+ re.search(r"pub\(crate\)\s+(?:fn|const|static|type)\s+%s\b" % re.escape(name), t)
+ or re.search(r"pub\(crate\)\s+use\s+[^;]*::%s\b" % re.escape(name), t)
+ for t in (open(pp).read() for pp in paths)
+ )
+
+ if gated and narrowed:
+ disp = "narrowed"
+ elif gated:
disp = "already-gated"
elif string_only:
disp = "narrow"
@@ -294,7 +306,7 @@ def analyse():
rows.append(dict(
module=mod, name=name,
where=("%s:%d" % (occ[0][0], occ[0][1])) if occ else "?",
- gated=gated, string_only=string_only, tests=users,
+ gated=gated, narrowed=narrowed, string_only=string_only, tests=users,
internal=internal, dotted_only=dotted_only,
confirmed=("%s.%s" % (mod, name)) in CONFIRMED,
sites=[list(s) for s in sites],
@@ -310,12 +322,13 @@ def analyse():
def render(rows):
- order = ["gate", "move-test", "narrow", "residue", "already-gated"]
+ order = ["gate", "move-test", "narrow", "residue", "narrowed", "already-gated"]
title = {"gate": "Gate behind `test-support`",
"move-test": "Move the test into the module, then narrow",
"narrow": "Narrow — no test actually calls it",
"residue": "Residue — `pub` because Rust has no test-conditional visibility",
- "already-gated": "Already gated"}
+ "already-gated": "Already gated",
+ "narrowed": "Feature-conditional visibility — production uses it, only from inside its module"}
out = [open(DOC).read().split("## gate-marker")[0]] if False else []
L = []
A = L.append
@@ -395,6 +408,7 @@ if __name__ == "__main__":
counts["gate_pending"] = sum(1 for r in rows if r["disp"] == "gate" and not r["gated"])
counts["ungated"] = sum(1 for r in rows if not r["gated"])
counts["total"] = len(rows)
+ counts["release_exposed"] = sum(1 for r in rows if not r["gated"])
print(json.dumps({"rows": rows, "counts": counts}, indent=1))
elif a.write_budget:
rows = analyse()
@@ -408,7 +422,7 @@ if __name__ == "__main__":
budget = json.load(open(path))
budget["test_surface"] = {k: counts[k] for k in
("gate", "gate_pending", "move-test", "narrow",
- "residue", "already-gated", "total", "ungated")
+ "residue", "narrowed", "already-gated", "total", "ungated")
if counts[k]}
with open(path, "w") as handle:
json.dump(budget, handle, indent=2, sort_keys=True)