mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
tests: use insta to test editor contents
It's tedious to update editor expectation manually. Let's dump the actual content and test it after each command invocation.
This commit is contained in:
parent
1cb1a1f1dc
commit
5076622598
7 changed files with 112 additions and 101 deletions
|
@ -43,22 +43,19 @@ fn test_commit_with_editor() {
|
||||||
// set a new one
|
// set a new one
|
||||||
test_env.jj_cmd_success(&workspace_path, &["describe", "-m=initial"]);
|
test_env.jj_cmd_success(&workspace_path, &["describe", "-m=initial"]);
|
||||||
let edit_script = test_env.set_up_fake_editor();
|
let edit_script = test_env.set_up_fake_editor();
|
||||||
std::fs::write(
|
std::fs::write(edit_script, ["dump editor0", "write\nmodified"].join("\0")).unwrap();
|
||||||
edit_script,
|
|
||||||
"expect
|
|
||||||
initial
|
|
||||||
|
|
||||||
JJ: Lines starting with \"JJ: \" (like this one) will be removed.
|
|
||||||
\0write
|
|
||||||
modified",
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
test_env.jj_cmd_success(&workspace_path, &["commit"]);
|
test_env.jj_cmd_success(&workspace_path, &["commit"]);
|
||||||
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
|
insta::assert_snapshot!(get_log_output(&test_env, &workspace_path), @r###"
|
||||||
@ 3df78bc2b9b5 (no description set)
|
@ 3df78bc2b9b5 (no description set)
|
||||||
o 30a8c2b3d6eb modified
|
o 30a8c2b3d6eb modified
|
||||||
o 000000000000 (no description set)
|
o 000000000000 (no description set)
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
initial
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -38,19 +38,17 @@ fn test_describe() {
|
||||||
|
|
||||||
// Check that the text file gets initialized with the current description and
|
// Check that the text file gets initialized with the current description and
|
||||||
// make no changes
|
// make no changes
|
||||||
std::fs::write(
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
||||||
&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"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
Nothing changed.
|
Nothing changed.
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
description from CLI
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
|
||||||
// Set a description in editor
|
// Set a description in editor
|
||||||
std::fs::write(&edit_script, "write\ndescription from editor").unwrap();
|
std::fs::write(&edit_script, "write\ndescription from editor").unwrap();
|
||||||
|
|
|
@ -365,26 +365,24 @@ fn test_move_description() {
|
||||||
// If both descriptions were non-empty, we get asked for a combined description
|
// If both descriptions were non-empty, we get asked for a combined description
|
||||||
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
||||||
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
|
||||||
std::fs::write(
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
||||||
&edit_script,
|
|
||||||
r#"expect
|
|
||||||
JJ: Enter a description for the combined commit.
|
|
||||||
JJ: Description from the destination commit:
|
|
||||||
destination
|
|
||||||
|
|
||||||
JJ: Description from the source commit:
|
|
||||||
source
|
|
||||||
|
|
||||||
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
test_env.jj_cmd_success(&repo_path, &["move", "--to", "@-"]);
|
||||||
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
||||||
destination
|
destination
|
||||||
|
|
||||||
source
|
source
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
JJ: Enter a description for the combined commit.
|
||||||
|
JJ: Description from the destination commit:
|
||||||
|
destination
|
||||||
|
|
||||||
|
JJ: Description from the source commit:
|
||||||
|
source
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
|
||||||
// If the source's *content* doesn't become empty, then the source remains and
|
// If the source's *content* doesn't become empty, then the source remains and
|
||||||
// both descriptions are unchanged
|
// both descriptions are unchanged
|
||||||
|
|
|
@ -80,8 +80,15 @@ fn test_resolution() {
|
||||||
|
|
||||||
let editor_script = test_env.set_up_fake_editor();
|
let editor_script = test_env.set_up_fake_editor();
|
||||||
// Check that output file starts out empty and resolve the conflict
|
// Check that output file starts out empty and resolve the conflict
|
||||||
std::fs::write(&editor_script, "expect\n\0write\nresolution\n").unwrap();
|
std::fs::write(
|
||||||
|
&editor_script,
|
||||||
|
["dump editor0", "write\nresolution\n"].join("\0"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
test_env.jj_cmd_success(&repo_path, &["resolve"]);
|
test_env.jj_cmd_success(&repo_path, &["resolve"]);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
"###);
|
||||||
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
||||||
@r###"
|
@r###"
|
||||||
Resolved conflict in file:
|
Resolved conflict in file:
|
||||||
|
@ -105,17 +112,7 @@ fn test_resolution() {
|
||||||
@"");
|
@"");
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
&editor_script,
|
&editor_script,
|
||||||
"expect
|
["dump editor1", "write\nresolution\n"].join("\0"),
|
||||||
<<<<<<<
|
|
||||||
%%%%%%%
|
|
||||||
-base
|
|
||||||
+a
|
|
||||||
+++++++
|
|
||||||
b
|
|
||||||
>>>>>>>
|
|
||||||
\0write
|
|
||||||
resolution
|
|
||||||
",
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_env.jj_cmd_success(
|
test_env.jj_cmd_success(
|
||||||
|
@ -126,6 +123,16 @@ resolution
|
||||||
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
|
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###"
|
||||||
|
<<<<<<<
|
||||||
|
%%%%%%%
|
||||||
|
-base
|
||||||
|
+a
|
||||||
|
+++++++
|
||||||
|
b
|
||||||
|
>>>>>>>
|
||||||
|
"###);
|
||||||
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
||||||
@r###"
|
@r###"
|
||||||
Resolved conflict in file:
|
Resolved conflict in file:
|
||||||
|
@ -145,15 +152,9 @@ resolution
|
||||||
@"");
|
@"");
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
&editor_script,
|
&editor_script,
|
||||||
"expect
|
[
|
||||||
<<<<<<<
|
"dump editor2",
|
||||||
%%%%%%%
|
"write
|
||||||
-base
|
|
||||||
+a
|
|
||||||
+++++++
|
|
||||||
b
|
|
||||||
>>>>>>>
|
|
||||||
\0write
|
|
||||||
<<<<<<<
|
<<<<<<<
|
||||||
%%%%%%%
|
%%%%%%%
|
||||||
-some
|
-some
|
||||||
|
@ -162,6 +163,8 @@ b
|
||||||
conflict
|
conflict
|
||||||
>>>>>>>
|
>>>>>>>
|
||||||
",
|
",
|
||||||
|
]
|
||||||
|
.join("\0"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_env.jj_cmd_success(
|
test_env.jj_cmd_success(
|
||||||
|
@ -172,6 +175,16 @@ conflict
|
||||||
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
|
"merge-tools.fake-editor.merge-tool-edits-conflict-markers=true",
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor2")).unwrap(), @r###"
|
||||||
|
<<<<<<<
|
||||||
|
%%%%%%%
|
||||||
|
-base
|
||||||
|
+a
|
||||||
|
+++++++
|
||||||
|
b
|
||||||
|
>>>>>>>
|
||||||
|
"###);
|
||||||
// Note the "Modified" below
|
// Note the "Modified" below
|
||||||
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
||||||
@r###"
|
@r###"
|
||||||
|
@ -197,8 +210,9 @@ conflict
|
||||||
@"");
|
@"");
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
&editor_script,
|
&editor_script,
|
||||||
"expect
|
[
|
||||||
\0write
|
"dump editor3",
|
||||||
|
"write
|
||||||
<<<<<<<
|
<<<<<<<
|
||||||
%%%%%%%
|
%%%%%%%
|
||||||
-some
|
-some
|
||||||
|
@ -207,9 +221,14 @@ conflict
|
||||||
conflict
|
conflict
|
||||||
>>>>>>>
|
>>>>>>>
|
||||||
",
|
",
|
||||||
|
]
|
||||||
|
.join("\0"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
test_env.jj_cmd_success(&repo_path, &["resolve"]);
|
test_env.jj_cmd_success(&repo_path, &["resolve"]);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor3")).unwrap(), @r###"
|
||||||
|
"###);
|
||||||
// Note the "Resolved" below
|
// Note the "Resolved" below
|
||||||
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["diff"]),
|
||||||
@r###"
|
@r###"
|
||||||
|
|
|
@ -35,23 +35,7 @@ fn test_split_by_paths() {
|
||||||
let edit_script = test_env.set_up_fake_editor();
|
let edit_script = test_env.set_up_fake_editor();
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
edit_script,
|
edit_script,
|
||||||
"expect
|
["dump editor0", "next invocation\n", "dump editor1"].join("\0"),
|
||||||
JJ: Enter commit description for the first part (parent).
|
|
||||||
|
|
||||||
JJ: This part contains the following changes:
|
|
||||||
JJ: A file2
|
|
||||||
|
|
||||||
JJ: Lines starting with \"JJ: \" (like this one) will be removed.
|
|
||||||
\0next invocation
|
|
||||||
\0expect
|
|
||||||
JJ: Enter commit description for the second part (child).
|
|
||||||
|
|
||||||
JJ: This part contains the following changes:
|
|
||||||
JJ: A file1
|
|
||||||
JJ: A file3
|
|
||||||
|
|
||||||
JJ: Lines starting with \"JJ: \" (like this one) will be removed.
|
|
||||||
",
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["split", "file2"]);
|
||||||
|
@ -60,6 +44,25 @@ JJ: Lines starting with \"JJ: \" (like this one) will be removed.
|
||||||
Second part: 45833353d94e (no description set)
|
Second part: 45833353d94e (no description set)
|
||||||
Working copy now at: 45833353d94e (no description set)
|
Working copy now at: 45833353d94e (no description set)
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
JJ: Enter commit description for the first part (parent).
|
||||||
|
|
||||||
|
JJ: This part contains the following changes:
|
||||||
|
JJ: A file2
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor1")).unwrap(), @r###"
|
||||||
|
JJ: Enter commit description for the second part (child).
|
||||||
|
|
||||||
|
JJ: This part contains the following changes:
|
||||||
|
JJ: A file1
|
||||||
|
JJ: A file3
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.short()"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id.short()"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
|
|
@ -281,26 +281,24 @@ fn test_squash_description() {
|
||||||
// If both descriptions were non-empty, we get asked for a combined description
|
// If both descriptions were non-empty, we get asked for a combined description
|
||||||
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
||||||
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "source"]);
|
||||||
std::fs::write(
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
||||||
&edit_script,
|
|
||||||
r#"expect
|
|
||||||
JJ: Enter a description for the combined commit.
|
|
||||||
JJ: Description from the destination commit:
|
|
||||||
destination
|
|
||||||
|
|
||||||
JJ: Description from the source commit:
|
|
||||||
source
|
|
||||||
|
|
||||||
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
test_env.jj_cmd_success(&repo_path, &["squash"]);
|
test_env.jj_cmd_success(&repo_path, &["squash"]);
|
||||||
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@-"), @r###"
|
||||||
destination
|
destination
|
||||||
|
|
||||||
source
|
source
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
JJ: Enter a description for the combined commit.
|
||||||
|
JJ: Description from the destination commit:
|
||||||
|
destination
|
||||||
|
|
||||||
|
JJ: Description from the source commit:
|
||||||
|
source
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
|
||||||
// If the source's *content* doesn't become empty, then the source remains and
|
// If the source's *content* doesn't become empty, then the source remains and
|
||||||
// both descriptions are unchanged
|
// both descriptions are unchanged
|
||||||
|
|
|
@ -247,26 +247,24 @@ fn test_unsquash_description() {
|
||||||
// If both descriptions were non-empty, we get asked for a combined description
|
// If both descriptions were non-empty, we get asked for a combined description
|
||||||
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
||||||
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "source"]);
|
test_env.jj_cmd_success(&repo_path, &["describe", "@-", "-m", "source"]);
|
||||||
std::fs::write(
|
std::fs::write(&edit_script, "dump editor0").unwrap();
|
||||||
&edit_script,
|
|
||||||
r#"expect
|
|
||||||
JJ: Enter a description for the combined commit.
|
|
||||||
JJ: Description from the destination commit:
|
|
||||||
destination
|
|
||||||
|
|
||||||
JJ: Description from the source commit:
|
|
||||||
source
|
|
||||||
|
|
||||||
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
|
test_env.jj_cmd_success(&repo_path, &["unsquash"]);
|
||||||
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
insta::assert_snapshot!(get_description(&test_env, &repo_path, "@"), @r###"
|
||||||
destination
|
destination
|
||||||
|
|
||||||
source
|
source
|
||||||
"###);
|
"###);
|
||||||
|
insta::assert_snapshot!(
|
||||||
|
std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(), @r###"
|
||||||
|
JJ: Enter a description for the combined commit.
|
||||||
|
JJ: Description from the destination commit:
|
||||||
|
destination
|
||||||
|
|
||||||
|
JJ: Description from the source commit:
|
||||||
|
source
|
||||||
|
|
||||||
|
JJ: Lines starting with "JJ: " (like this one) will be removed.
|
||||||
|
"###);
|
||||||
|
|
||||||
// If the source's *content* doesn't become empty, then the source remains and
|
// If the source's *content* doesn't become empty, then the source remains and
|
||||||
// both descriptions are unchanged
|
// both descriptions are unchanged
|
||||||
|
|
Loading…
Reference in a new issue