20 lines
894 B
Python
20 lines
894 B
Python
# mutate.py <id>: apply one named variant to commit.test.mjs (exact text, must match once). Run from the tree root.
|
|
import sys
|
|
F = "packages/queue/tests/commit.test.mjs"
|
|
SPAWN = 'spawn("git", ["-C", r.root, "commit", "-e", "-q", ...form]'
|
|
# git exits with its own status at once; a background subshell keeps the
|
|
# stderr pipe open and writes git's message 0.5 s later.
|
|
DELAYED = 'spawn("sh", ["-c", \'git "$@" 2>"$0"; s=$?; (sleep 0.5; cat "$0" >&2) & exit $s\', join(r.ctl, "git-err"), "-C", r.root, "commit", "-e", "-q", ...form]'
|
|
CLOSE = 'child.on("close", resolve)'
|
|
M = {
|
|
"delay-close": [(SPAWN, DELAYED)],
|
|
"delay-exit": [(SPAWN, DELAYED), (CLOSE, 'child.on("exit", resolve)')],
|
|
}
|
|
s = open(F).read()
|
|
for old, new in M[sys.argv[1]]:
|
|
n = s.count(old)
|
|
if n != 1: sys.exit(f"{sys.argv[1]}: {n} matches")
|
|
s = s.replace(old, new)
|
|
open(F, "w").write(s)
|
|
print(sys.argv[1], "applied")
|