From efd652d7eae77f1f959f0c591988f6f0eecf11d8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 12 Jan 2023 23:55:52 -0800 Subject: [PATCH] log: add test showing bugs in graph when the template uses color --- tests/test_log_command.rs | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index b73158774..4248f78c6 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -539,3 +539,47 @@ fn test_default_revset_per_repo() { .count() ); } + +#[test] +fn test_graph_template_color() { + // Test that color codes from a multi-line template don't span the graph lines. + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + test_env.jj_cmd_success( + &repo_path, + &["describe", "-m", "first line\nsecond line\nthird line"], + ); + test_env.jj_cmd_success(&repo_path, &["new", "-m", "single line"]); + + test_env.add_config( + br#"[colors] + description = "red" + "working_copy description" = "green" + "#, + ); + + // First test without color for comparison + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T=description"]); + insta::assert_snapshot!(stdout, @r###" + @ single line + o first line + | second line + | third line + o (no description set) + "###); + let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "log", "-T=description"]); + // TODO: The color codes shouldn't span the graph lines, and we shouldn't get an + // extra line at the end + insta::assert_snapshot!(stdout, @r###" + @ single line + |  + o first line + | second line + | third line + |  + o (no description set) +  + "###); +}