From a7896b85118fea64a6bc87deffd14f2c8c0e8b12 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 25 Jun 2024 17:56:58 +0900 Subject: [PATCH] tests: add word-level hunks and capture some colorized diff outputs --- cli/tests/test_diff_command.rs | 67 +++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/cli/tests/test_diff_command.rs b/cli/tests/test_diff_command.rs index 1ad6b6648b..a146b7d75d 100644 --- a/cli/tests/test_diff_command.rs +++ b/cli/tests/test_diff_command.rs @@ -23,10 +23,10 @@ fn test_diff_basic() { let repo_path = test_env.env_root().join("repo"); std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); - std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); + std::fs::write(repo_path.join("file2"), "foo\nbaz qux\n").unwrap(); test_env.jj_cmd_ok(&repo_path, &["new"]); std::fs::remove_file(repo_path.join("file1")).unwrap(); - std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap(); + std::fs::write(repo_path.join("file2"), "foo\nbar\nbaz quux\n").unwrap(); std::fs::write(repo_path.join("file3"), "foo\n").unwrap(); let stdout = test_env.jj_cmd_success(&repo_path, &["diff"]); @@ -36,6 +36,7 @@ fn test_diff_basic() { Modified regular file file2: 1 1: foo 2: bar + 2 3: baz quxquux Added regular file file3: 1: foo "###); @@ -47,10 +48,23 @@ fn test_diff_basic() { Modified regular file file2: 1 1: foo 2: bar + 2 3: baz quxquux Added regular file file3: 1: foo "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--color=debug"]); + insta::assert_snapshot!(stdout, @r###" + <><><><><> + <><><><><><><> + <><><><> + <><><><><><><><><><><> + <><><><><><><> + <><><><><><><><><><><><><><> + <><><><><> + <><><><><><><> + "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); insta::assert_snapshot!(stdout, @r###" D file1 @@ -75,12 +89,14 @@ fn test_diff_basic() { @@ -1,1 +1,0 @@ -foo diff --git a/file2 b/file2 - index 257cc5642c...3bd1f0e297 100644 + index 523a4a9de8...485b56a572 100644 --- a/file2 +++ b/file2 - @@ -1,1 +1,2 @@ + @@ -1,2 +1,3 @@ foo + -baz qux +bar + +baz quux diff --git a/file3 b/file3 new file mode 100644 index 0000000000..257cc5642c @@ -100,11 +116,13 @@ fn test_diff_basic() { @@ -1,1 +1,0 @@ -foo diff --git a/file2 b/file2 - index 257cc5642c...3bd1f0e297 100644 + index 523a4a9de8...485b56a572 100644 --- a/file2 +++ b/file2 - @@ -2,0 +2,1 @@ + @@ -2,1 +2,2 @@ + -baz qux +bar + +baz quux diff --git a/file3 b/file3 new file mode 100644 index 0000000000..257cc5642c @@ -114,6 +132,33 @@ fn test_diff_basic() { +foo "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git", "--color=debug"]); + insta::assert_snapshot!(stdout, @r###" + <><><><><> + <><><> + <><><> + <><><> + <> + <><><><><><><><><> + <><> + <><><><><> + <><><><><><><> + <><><> + <><><> + <><><><><><><><><> + <><> + <><> + <><> + <><> + <><><><><> + <><><> + <><><> + <> + <><><> + <><><><><><><><><> + <><> + "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "--git"]); insta::assert_snapshot!(stdout, @r###" D file1 @@ -127,12 +172,14 @@ fn test_diff_basic() { @@ -1,1 +1,0 @@ -foo diff --git a/file2 b/file2 - index 257cc5642c...3bd1f0e297 100644 + index 523a4a9de8...485b56a572 100644 --- a/file2 +++ b/file2 - @@ -1,1 +1,2 @@ + @@ -1,2 +1,3 @@ foo + -baz qux +bar + +baz quux diff --git a/file3 b/file3 new file mode 100644 index 0000000000..257cc5642c @@ -145,9 +192,9 @@ fn test_diff_basic() { let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--stat"]); insta::assert_snapshot!(stdout, @r###" file1 | 1 - - file2 | 1 + + file2 | 3 ++- file3 | 1 + - 3 files changed, 2 insertions(+), 1 deletion(-) + 3 files changed, 3 insertions(+), 2 deletions(-) "###); // Filter by glob pattern