import sys, subprocess, json # usage: mutaten.py spec.json -- cmd... spec = [[file, old, new], ...] spec = json.load(open(sys.argv[1])); i = sys.argv.index('--'); cmd = sys.argv[i+1:] orig = {} try: for f, old, new in spec: s = orig.get(f) or open(f).read(); orig.setdefault(f, s) cur = open(f).read(); assert cur.count(old) == 1, (f, old[:60], cur.count(old)) open(f, 'w').write(cur.replace(old, new)) 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: for f, s in orig.items(): open(f, 'w').write(s)