Files
felhom.eu/documentation/audits/night-2026-10-28/tools/mutate.py
T

14 lines
559 B
Python

import sys, subprocess
# usage: mutate.py file old new -- test args...
f, old, new = sys.argv[1], sys.argv[2], sys.argv[3]
i = sys.argv.index('--'); cmd = sys.argv[i+1:]
s = open(f).read(); assert s.count(old) == 1, ("old not unique", s.count(old))
open(f, 'w').write(s.replace(old, new))
try:
r = subprocess.run(cmd, capture_output=True, text=True)
out = r.stdout + r.stderr
print("\n".join(l for l in out.splitlines() if l.startswith(('--- FAIL', 'ok', 'FAIL', ' ')) )[:3000])
print("RC", r.returncode)
finally:
open(f, 'w').write(s)