tests: extract a function for getting log output in jj move test

This commit is contained in:
Martin von Zweigbergk 2022-04-22 10:26:17 -07:00 committed by Martin von Zweigbergk
parent 99d2ef8883
commit cf7bef88fe

View file

@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::path::Path;
use crate::common::TestEnvironment; use crate::common::TestEnvironment;
pub mod common; pub mod common;
@ -54,9 +56,7 @@ fn test_move() {
test_env.jj_cmd_success(&repo_path, &["branch", "f"]); test_env.jj_cmd_success(&repo_path, &["branch", "f"]);
std::fs::write(repo_path.join("file2"), "f\n").unwrap(); std::fs::write(repo_path.join("file2"), "f\n").unwrap();
// Test the setup // Test the setup
let template = r#"commit_id.short() " " branches"#; insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
@ 0d7353584003 f @ 0d7353584003 f
o e9515f21068c e o e9515f21068c e
o bdd835cae844 d o bdd835cae844 d
@ -73,8 +73,7 @@ fn test_move() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["move"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["move"]);
insta::assert_snapshot!(stderr, @"Error: Source and destination cannot be the same. insta::assert_snapshot!(stderr, @"Error: Source and destination cannot be the same.
"); ");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ 0d7353584003 f @ 0d7353584003 f
o e9515f21068c e o e9515f21068c e
o bdd835cae844 d o bdd835cae844 d
@ -91,8 +90,7 @@ fn test_move() {
Working copy now at: 1c03e3d3c63f Working copy now at: 1c03e3d3c63f
Added 0 files, modified 1 files, removed 0 files Added 0 files, modified 1 files, removed 0 files
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ 1c03e3d3c63f f @ 1c03e3d3c63f f
o e9515f21068c e o e9515f21068c e
o bdd835cae844 d o bdd835cae844 d
@ -115,8 +113,7 @@ fn test_move() {
let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "@--"]); let stdout = test_env.jj_cmd_success(&repo_path, &["move", "--from", "@--"]);
insta::assert_snapshot!(stdout, @"Working copy now at: c8d83075e8c2 insta::assert_snapshot!(stdout, @"Working copy now at: c8d83075e8c2
"); ");
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ c8d83075e8c2 f @ c8d83075e8c2 f
o 2c50bfc59c68 e o 2c50bfc59c68 e
| o caa4d0b23201 c | o caa4d0b23201 c
@ -132,8 +129,7 @@ fn test_move() {
"); ");
// The change has been removed from the source (the change pointed to by 'd' was // The change has been removed from the source (the change pointed to by 'd' was
// abandoned) // abandoned)
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ c8d83075e8c2 f @ c8d83075e8c2 f
o 2c50bfc59c68 e o 2c50bfc59c68 e
| o caa4d0b23201 c | o caa4d0b23201 c
@ -172,9 +168,7 @@ fn test_move_partial() {
test_env.jj_cmd_success(&repo_path, &["branch", "d"]); test_env.jj_cmd_success(&repo_path, &["branch", "d"]);
std::fs::write(repo_path.join("file3"), "d\n").unwrap(); std::fs::write(repo_path.join("file3"), "d\n").unwrap();
// Test the setup // Test the setup
let template = r#"commit_id.short() " " branches"#; insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
@ bdd835cae844 d @ bdd835cae844 d
| o 5028db694b6b c | o 5028db694b6b c
| o 55171e33db26 b | o 55171e33db26 b
@ -192,8 +186,7 @@ fn test_move_partial() {
Working copy now at: 71b69e433fbc Working copy now at: 71b69e433fbc
Added 0 files, modified 2 files, removed 0 files Added 0 files, modified 2 files, removed 0 files
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ 71b69e433fbc d @ 71b69e433fbc d
| o 55171e33db26 b c | o 55171e33db26 b c
|/ |/
@ -220,8 +213,7 @@ fn test_move_partial() {
Working copy now at: 63f1a6e96edb Working copy now at: 63f1a6e96edb
Added 0 files, modified 1 files, removed 0 files Added 0 files, modified 1 files, removed 0 files
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ 63f1a6e96edb d @ 63f1a6e96edb d
| o d027c6e3e6bc c | o d027c6e3e6bc c
| o 55171e33db26 b | o 55171e33db26 b
@ -251,8 +243,7 @@ fn test_move_partial() {
Working copy now at: 17c2e6632cc5 Working copy now at: 17c2e6632cc5
Added 0 files, modified 1 files, removed 0 files Added 0 files, modified 1 files, removed 0 files
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]); insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
insta::assert_snapshot!(stdout, @r###"
@ 17c2e6632cc5 d @ 17c2e6632cc5 d
| o 6a3ae047a03e c | o 6a3ae047a03e c
| o 55171e33db26 b | o 55171e33db26 b
@ -273,3 +264,7 @@ fn test_move_partial() {
insta::assert_snapshot!(stdout, @"d insta::assert_snapshot!(stdout, @"d
"); ");
} }
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
test_env.jj_cmd_success(cwd, &["log", "-T", r#"commit_id.short() " " branches"#])
}