just playing with tangled
1// Copyright 2022 The Jujutsu Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use itertools::Itertools;
16use regex::Regex;
17
18use crate::common::TestEnvironment;
19
20#[test]
21fn test_show() {
22 let test_env = TestEnvironment::default();
23 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
24 let repo_path = test_env.env_root().join("repo");
25
26 let stdout = test_env.jj_cmd_success(&repo_path, &["show"]);
27 let stdout = stdout.lines().skip(2).join("\n");
28
29 insta::assert_snapshot!(stdout, @r###"
30 Author: Test User <test.user@example.com> (2001-02-03 08:05:07)
31 Committer: Test User <test.user@example.com> (2001-02-03 08:05:07)
32
33 (no description set)
34 "###);
35}
36
37#[test]
38fn test_show_with_template() {
39 let test_env = TestEnvironment::default();
40 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
41 let repo_path = test_env.env_root().join("repo");
42 test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);
43
44 let stdout = test_env.jj_cmd_success(&repo_path, &["show", "-T", "description"]);
45
46 insta::assert_snapshot!(stdout, @r###"
47 a new commit
48 "###);
49}
50
51#[test]
52fn test_show_with_no_template() {
53 let test_env = TestEnvironment::default();
54 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
55 let repo_path = test_env.env_root().join("repo");
56
57 let stderr = test_env.jj_cmd_cli_error(&repo_path, &["show", "-T"]);
58 insta::assert_snapshot!(stderr, @r###"
59 error: a value is required for '--template <TEMPLATE>' but none was supplied
60
61 For more information, try '--help'.
62 Hint: The following template aliases are defined:
63 - builtin_log_comfortable
64 - builtin_log_compact
65 - builtin_log_detailed
66 - builtin_log_node
67 - builtin_log_node_ascii
68 - builtin_log_oneline
69 - builtin_op_log_comfortable
70 - builtin_op_log_compact
71 - builtin_op_log_node
72 - builtin_op_log_node_ascii
73 - commit_summary_separator
74 - description_placeholder
75 - email_placeholder
76 - name_placeholder
77 "###);
78}
79
80#[test]
81fn test_show_relative_timestamps() {
82 let test_env = TestEnvironment::default();
83 test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
84 let repo_path = test_env.env_root().join("repo");
85
86 test_env.add_config(
87 r#"
88 [template-aliases]
89 'format_timestamp(timestamp)' = 'timestamp.ago()'
90 "#,
91 );
92
93 let stdout = test_env.jj_cmd_success(&repo_path, &["show"]);
94 let timestamp_re = Regex::new(r"\([0-9]+ years ago\)").unwrap();
95 let stdout = stdout
96 .lines()
97 .skip(2)
98 .map(|x| timestamp_re.replace_all(x, "(...timestamp...)"))
99 .join("\n");
100
101 insta::assert_snapshot!(stdout, @r###"
102 Author: Test User <test.user@example.com> (...timestamp...)
103 Committer: Test User <test.user@example.com> (...timestamp...)
104
105 (no description set)
106 "###);
107}