From 2150166652d90d0e9076a3576c32c0ed50917b0e Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Tue, 22 Nov 2022 21:15:20 -0800 Subject: [PATCH] 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. --- testing/fake-editor.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testing/fake-editor.rs b/testing/fake-editor.rs index 14f1e8cab..00d7321b6 100644 --- a/testing/fake-editor.rs +++ b/testing/fake-editor.rs @@ -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() {