just playing with tangled
at ig/vimdiffwarn 327 lines 12 kB view raw
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 regex::Regex; 16 17use crate::common::TestEnvironment; 18 19#[test] 20fn test_show() { 21 let test_env = TestEnvironment::default(); 22 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 23 let repo_path = test_env.env_root().join("repo"); 24 25 let output = test_env.run_jj_in(&repo_path, ["show"]); 26 let output = output.normalize_stdout_with(|s| s.split_inclusive('\n').skip(2).collect()); 27 28 insta::assert_snapshot!(output, @r" 29 Author : Test User <test.user@example.com> (2001-02-03 08:05:07) 30 Committer: Test User <test.user@example.com> (2001-02-03 08:05:07) 31 32 (no description set) 33 34 [EOF] 35 "); 36} 37 38#[test] 39fn test_show_basic() { 40 let test_env = TestEnvironment::default(); 41 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 42 let repo_path = test_env.env_root().join("repo"); 43 44 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 45 std::fs::write(repo_path.join("file2"), "foo\nbaz qux\n").unwrap(); 46 test_env.run_jj_in(&repo_path, ["new"]).success(); 47 std::fs::remove_file(repo_path.join("file1")).unwrap(); 48 std::fs::write(repo_path.join("file2"), "foo\nbar\nbaz quux\n").unwrap(); 49 std::fs::write(repo_path.join("file3"), "foo\n").unwrap(); 50 51 let output = test_env.run_jj_in(&repo_path, ["show"]); 52 insta::assert_snapshot!(output, @r" 53 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 54 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 55 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 56 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 57 58 (no description set) 59 60 Modified regular file file2: 61 1 1: foo 62 2: bar 63 2 3: baz quxquux 64 Modified regular file file3 (file1 => file3): 65 [EOF] 66 "); 67 68 let output = test_env.run_jj_in(&repo_path, ["show", "--context=0"]); 69 insta::assert_snapshot!(output, @r" 70 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 71 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 72 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 73 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 74 75 (no description set) 76 77 Modified regular file file2: 78 1 1: foo 79 2: bar 80 2 3: baz quxquux 81 Modified regular file file3 (file1 => file3): 82 [EOF] 83 "); 84 85 let output = test_env.run_jj_in(&repo_path, ["show", "--color=debug"]); 86 insta::assert_snapshot!(output, @r" 87 Commit ID: <<commit_id::e34f04317a81edc6ba41fef239c0d0180f10656f>> 88 Change ID: <<change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>> 89 Author : <<author name::Test User>> <<<author email local::test.user>><<author email::@>><<author email domain::example.com>>> (<<author timestamp local format::2001-02-03 08:05:09>>) 90 Committer: <<committer name::Test User>> <<<committer email local::test.user>><<committer email::@>><<committer email domain::example.com>>> (<<committer timestamp local format::2001-02-03 08:05:09>>) 91 92 <<description placeholder:: (no description set)>> 93 94 <<diff header::Modified regular file file2:>> 95 <<diff removed line_number:: 1>><<diff:: >><<diff added line_number:: 1>><<diff::: foo>> 96 <<diff:: >><<diff added line_number:: 2>><<diff::: >><<diff added token::bar>> 97 <<diff removed line_number:: 2>><<diff:: >><<diff added line_number:: 3>><<diff::: baz >><<diff removed token::qux>><<diff added token::quux>><<diff::>> 98 <<diff header::Modified regular file file3 (file1 => file3):>> 99 [EOF] 100 "); 101 102 let output = test_env.run_jj_in(&repo_path, ["show", "-s"]); 103 insta::assert_snapshot!(output, @r" 104 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 105 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 106 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 107 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 108 109 (no description set) 110 111 M file2 112 R {file1 => file3} 113 [EOF] 114 "); 115 116 let output = test_env.run_jj_in(&repo_path, ["show", "--types"]); 117 insta::assert_snapshot!(output, @r" 118 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 119 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 120 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 121 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 122 123 (no description set) 124 125 FF file2 126 FF {file1 => file3} 127 [EOF] 128 "); 129 130 let output = test_env.run_jj_in(&repo_path, ["show", "--git"]); 131 insta::assert_snapshot!(output, @r" 132 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 133 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 134 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 135 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 136 137 (no description set) 138 139 diff --git a/file2 b/file2 140 index 523a4a9de8..485b56a572 100644 141 --- a/file2 142 +++ b/file2 143 @@ -1,2 +1,3 @@ 144 foo 145 -baz qux 146 +bar 147 +baz quux 148 diff --git a/file1 b/file3 149 rename from file1 150 rename to file3 151 [EOF] 152 "); 153 154 let output = test_env.run_jj_in(&repo_path, ["show", "--git", "--context=0"]); 155 insta::assert_snapshot!(output, @r" 156 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 157 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 158 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 159 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 160 161 (no description set) 162 163 diff --git a/file2 b/file2 164 index 523a4a9de8..485b56a572 100644 165 --- a/file2 166 +++ b/file2 167 @@ -2,1 +2,2 @@ 168 -baz qux 169 +bar 170 +baz quux 171 diff --git a/file1 b/file3 172 rename from file1 173 rename to file3 174 [EOF] 175 "); 176 177 let output = test_env.run_jj_in(&repo_path, ["show", "--git", "--color=debug"]); 178 insta::assert_snapshot!(output, @r" 179 Commit ID: <<commit_id::e34f04317a81edc6ba41fef239c0d0180f10656f>> 180 Change ID: <<change_id::rlvkpnrzqnoowoytxnquwvuryrwnrmlp>> 181 Author : <<author name::Test User>> <<<author email local::test.user>><<author email::@>><<author email domain::example.com>>> (<<author timestamp local format::2001-02-03 08:05:09>>) 182 Committer: <<committer name::Test User>> <<<committer email local::test.user>><<committer email::@>><<committer email domain::example.com>>> (<<committer timestamp local format::2001-02-03 08:05:09>>) 183 184 <<description placeholder:: (no description set)>> 185 186 <<diff file_header::diff --git a/file2 b/file2>> 187 <<diff file_header::index 523a4a9de8..485b56a572 100644>> 188 <<diff file_header::--- a/file2>> 189 <<diff file_header::+++ b/file2>> 190 <<diff hunk_header::@@ -1,2 +1,3 @@>> 191 <<diff context:: foo>> 192 <<diff removed::-baz >><<diff removed token::qux>><<diff removed::>> 193 <<diff added::+>><<diff added token::bar>> 194 <<diff added::+baz >><<diff added token::quux>><<diff added::>> 195 <<diff file_header::diff --git a/file1 b/file3>> 196 <<diff file_header::rename from file1>> 197 <<diff file_header::rename to file3>> 198 [EOF] 199 "); 200 201 let output = test_env.run_jj_in(&repo_path, ["show", "-s", "--git"]); 202 insta::assert_snapshot!(output, @r" 203 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 204 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 205 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 206 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 207 208 (no description set) 209 210 M file2 211 R {file1 => file3} 212 diff --git a/file2 b/file2 213 index 523a4a9de8..485b56a572 100644 214 --- a/file2 215 +++ b/file2 216 @@ -1,2 +1,3 @@ 217 foo 218 -baz qux 219 +bar 220 +baz quux 221 diff --git a/file1 b/file3 222 rename from file1 223 rename to file3 224 [EOF] 225 "); 226 227 let output = test_env.run_jj_in(&repo_path, ["show", "--stat"]); 228 insta::assert_snapshot!(output, @r" 229 Commit ID: e34f04317a81edc6ba41fef239c0d0180f10656f 230 Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp 231 Author : Test User <test.user@example.com> (2001-02-03 08:05:09) 232 Committer: Test User <test.user@example.com> (2001-02-03 08:05:09) 233 234 (no description set) 235 236 file2 | 3 ++- 237 {file1 => file3} | 0 238 2 files changed, 2 insertions(+), 1 deletion(-) 239 [EOF] 240 "); 241} 242 243#[test] 244fn test_show_with_template() { 245 let test_env = TestEnvironment::default(); 246 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 247 let repo_path = test_env.env_root().join("repo"); 248 test_env 249 .run_jj_in(&repo_path, ["new", "-m", "a new commit"]) 250 .success(); 251 252 let output = test_env.run_jj_in(&repo_path, ["show", "-T", "description"]); 253 254 insta::assert_snapshot!(output, @r" 255 a new commit 256 [EOF] 257 "); 258} 259 260#[test] 261fn test_show_with_no_template() { 262 let test_env = TestEnvironment::default(); 263 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 264 let repo_path = test_env.env_root().join("repo"); 265 266 let output = test_env.run_jj_in(&repo_path, ["show", "-T"]); 267 insta::assert_snapshot!(output, @r" 268 ------- stderr ------- 269 error: a value is required for '--template <TEMPLATE>' but none was supplied 270 271 For more information, try '--help'. 272 Hint: The following template aliases are defined: 273 - builtin_config_list 274 - builtin_config_list_detailed 275 - builtin_draft_commit_description 276 - builtin_log_comfortable 277 - builtin_log_compact 278 - builtin_log_compact_full_description 279 - builtin_log_detailed 280 - builtin_log_node 281 - builtin_log_node_ascii 282 - builtin_log_oneline 283 - builtin_op_log_comfortable 284 - builtin_op_log_compact 285 - builtin_op_log_node 286 - builtin_op_log_node_ascii 287 - builtin_op_log_oneline 288 - commit_summary_separator 289 - description_placeholder 290 - email_placeholder 291 - name_placeholder 292 [EOF] 293 [exit status: 2] 294 "); 295} 296 297#[test] 298fn test_show_relative_timestamps() { 299 let test_env = TestEnvironment::default(); 300 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 301 let repo_path = test_env.env_root().join("repo"); 302 303 test_env.add_config( 304 r#" 305 [template-aliases] 306 'format_timestamp(timestamp)' = 'timestamp.ago()' 307 "#, 308 ); 309 310 let output = test_env.run_jj_in(&repo_path, ["show"]); 311 let timestamp_re = Regex::new(r"\([0-9]+ years ago\)").unwrap(); 312 let output = output.normalize_stdout_with(|s| { 313 s.split_inclusive('\n') 314 .skip(2) 315 .map(|x| timestamp_re.replace_all(x, "(...timestamp...)")) 316 .collect() 317 }); 318 319 insta::assert_snapshot!(output, @r" 320 Author : Test User <test.user@example.com> (...timestamp...) 321 Committer: Test User <test.user@example.com> (...timestamp...) 322 323 (no description set) 324 325 [EOF] 326 "); 327}