From 478dfd74fc4b22512a33b9a77e9a2df5b7805707 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 28 Aug 2022 21:07:51 -0700 Subject: [PATCH] tests: teach fake editor to check that initial text is as expected --- testing/fake-editor.rs | 7 +++++++ tests/test_describe_command.rs | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/testing/fake-editor.rs b/testing/fake-editor.rs index 161af108c..937d61c5f 100644 --- a/testing/fake-editor.rs +++ b/testing/fake-editor.rs @@ -37,6 +37,13 @@ fn main() { match parts.as_slice() { [""] => {} ["fail"] => exit(1), + ["expect"] => { + let actual = String::from_utf8(std::fs::read(&args.file).unwrap()).unwrap(); + if actual != payload { + eprintln!("unexpected content: {}", actual); + exit(1) + } + } ["write"] => { std::fs::write(&args.file, payload).unwrap(); } diff --git a/tests/test_describe_command.rs b/tests/test_describe_command.rs index 782a00e56..5928f7c16 100644 --- a/tests/test_describe_command.rs +++ b/tests/test_describe_command.rs @@ -30,8 +30,11 @@ fn test_describe() { Working copy now at: 7e0db3b0ad17 description from CLI "###); - // Test making no changes - std::fs::write(&edit_script, "").unwrap(); + // Check that the text file gets initialized with the current description and make no changes + std::fs::write(&edit_script, r#"expect +description from CLI +JJ: Lines starting with "JJ: " (like this one) will be removed. +"#).unwrap(); let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]); insta::assert_snapshot!(stdout, @r###" Working copy now at: 45bfa10db64d description from CLI