557629d2bf
gates / gates (push) Successful in 2m3s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""R-725: every console banner felhom-bootstrap.sh paints uses only glyphs the console font draws.
|
|
|
|
The box console loads a Latin-2 font (Lat2-Terminus16 and friends, set_console_font). A glyph outside it is
|
|
drawn as something else: the linked banner ended in "✔", and the household saw "a doboz össze van kötve. V".
|
|
This test reads every printf literal in the script and the banner goldens the ISO harness compares against,
|
|
and refuses any character outside ASCII + the Hungarian letters + the em dash (which the banners already use
|
|
and which renders). Pure file reads: runs on the BusyBox CI runner.
|
|
Run: python3 scripts/iso/test/test_console_glyphs.py"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ISO = os.path.dirname(HERE)
|
|
ALLOWED_NON_ASCII = set("áéíóöőúüűÁÉÍÓÖŐÚÜŰ—")
|
|
PRINTF = re.compile(r"""printf\s+(?:'([^']*)'|"([^"]*)")""")
|
|
|
|
|
|
def bad_glyphs(text):
|
|
return sorted({c for c in text if ord(c) > 127 and c not in ALLOWED_NON_ASCII})
|
|
|
|
|
|
def main():
|
|
failures, checked = [], 0
|
|
script = os.path.join(ISO, "felhom-bootstrap.sh")
|
|
with open(script, encoding="utf-8") as fh:
|
|
for n, line in enumerate(fh, 1):
|
|
for m in PRINTF.finditer(line):
|
|
checked += 1
|
|
bad = bad_glyphs(m.group(1) or m.group(2) or "")
|
|
if bad:
|
|
failures.append("felhom-bootstrap.sh:%d: %s" % (n, " ".join(bad)))
|
|
gdir = os.path.join(HERE, "golden")
|
|
goldens = sorted(f for f in os.listdir(gdir) if f.endswith(".txt"))
|
|
for g in goldens:
|
|
with open(os.path.join(gdir, g), encoding="utf-8") as fh:
|
|
bad = bad_glyphs(fh.read())
|
|
if bad:
|
|
failures.append("golden/%s: %s" % (g, " ".join(bad)))
|
|
# Scope is a fact: a reader that found no banners checked nothing.
|
|
if checked < 20 or not goldens:
|
|
print("FAIL: read only %d printf literals and %d goldens — the scope is wrong" % (checked, len(goldens)))
|
|
return 1
|
|
# Positive control: the checker convicts the glyph that started this row.
|
|
if bad_glyphs("a doboz össze van kötve. ✔") != ["✔"]:
|
|
print("FAIL: the checker does not convict the check-mark glyph")
|
|
return 1
|
|
if failures:
|
|
print("FAIL: console glyphs the Latin-2 font cannot draw (R-725):\n " + "\n ".join(failures))
|
|
return 1
|
|
print("OK: %d printf literals + %d goldens use only console-safe glyphs" % (checked, len(goldens)))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|