Add next invocation command to fake-editor

This adds a `next invocation` command to `fake-editor` that ignores the
rest of the script for *this* invocation, but overwrites the script
with whatever follows `next invocation`.

This is useful to test commands that invoke `fake-editor` several times,
especially the `jj split` command.
This commit is contained in:
Ilya Grigoriev 2022-11-22 21:15:20 -08:00
parent 0b528eb587
commit 2150166652

View file

@ -30,8 +30,16 @@ struct Args {
fn main() {
let args: Args = Args::parse();
let edit_script_path = PathBuf::from(std::env::var_os("EDIT_SCRIPT").unwrap());
let edit_script = String::from_utf8(std::fs::read(edit_script_path).unwrap()).unwrap();
for instruction in edit_script.split('\0') {
let edit_script = String::from_utf8(std::fs::read(edit_script_path.clone()).unwrap()).unwrap();
let mut instructions = edit_script.split('\0').collect_vec();
if let Some(pos) = instructions.iter().position(|&i| i == "next invocation\n") {
// Overwrite the edit script. The next time `fake-editor` is called, it will
// only see the part after the `next invocation` command.
std::fs::write(edit_script_path, instructions[pos + 1..].join("\0")).unwrap();
instructions.truncate(pos);
}
for instruction in instructions {
let (command, payload) = instruction.split_once('\n').unwrap_or((instruction, ""));
let parts = command.split(' ').collect_vec();
match parts.as_slice() {