just playing with tangled
at gvimdiff 7.6 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 insta::assert_snapshot; 16use regex::Regex; 17 18use crate::common::CommandOutput; 19use crate::common::TestEnvironment; 20 21#[test] 22fn test_debug_fileset() { 23 let test_env = TestEnvironment::default(); 24 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 25 let work_dir = test_env.work_dir("repo"); 26 27 let output = work_dir.run_jj(["debug", "fileset", "all()"]); 28 assert_snapshot!(output, @r" 29 -- Parsed: 30 All 31 32 -- Matcher: 33 EverythingMatcher 34 [EOF] 35 "); 36 37 let output = work_dir.run_jj(["debug", "fileset", "cwd:.."]); 38 assert_snapshot!(output.normalize_backslash(), @r#" 39 ------- stderr ------- 40 Error: Failed to parse fileset: Invalid file pattern 41 Caused by: 42 1: --> 1:1 43 | 44 1 | cwd:.. 45 | ^----^ 46 | 47 = Invalid file pattern 48 2: Path ".." is not in the repo "." 49 3: Invalid component ".." in repo-relative path "../" 50 [EOF] 51 [exit status: 1] 52 "#); 53} 54 55#[test] 56fn test_debug_revset() { 57 let test_env = TestEnvironment::default(); 58 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 59 let work_dir = test_env.work_dir("repo"); 60 61 let output = work_dir.run_jj(["debug", "revset", "root()"]); 62 insta::with_settings!({filters => vec![ 63 (r"(?m)(^ .*\n)+", " ..\n"), 64 ]}, { 65 assert_snapshot!(output, @r" 66 -- Parsed: 67 Root 68 69 -- Resolved: 70 Root 71 72 -- Optimized: 73 Root 74 75 -- Backend: 76 Commits( 77 .. 78 ) 79 80 -- Evaluated: 81 RevsetImpl { 82 .. 83 } 84 85 -- Commit IDs: 86 0000000000000000000000000000000000000000 87 [EOF] 88 "); 89 }); 90} 91 92#[test] 93fn test_debug_index() { 94 let test_env = TestEnvironment::default(); 95 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 96 let work_dir = test_env.work_dir("repo"); 97 let output = work_dir.run_jj(["debug", "index"]); 98 assert_snapshot!(filter_index_stats(output), @r" 99 Number of commits: 2 100 Number of merges: 0 101 Max generation number: 1 102 Number of heads: 1 103 Number of changes: 2 104 Stats per level: 105 Level 0: 106 Number of commits: 2 107 Name: [hash] 108 [EOF] 109 "); 110} 111 112#[test] 113fn test_debug_reindex() { 114 let test_env = TestEnvironment::default(); 115 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 116 let work_dir = test_env.work_dir("repo"); 117 work_dir.run_jj(["new"]).success(); 118 work_dir.run_jj(["new"]).success(); 119 let output = work_dir.run_jj(["debug", "index"]); 120 assert_snapshot!(filter_index_stats(output), @r" 121 Number of commits: 4 122 Number of merges: 0 123 Max generation number: 3 124 Number of heads: 1 125 Number of changes: 4 126 Stats per level: 127 Level 0: 128 Number of commits: 3 129 Name: [hash] 130 Level 1: 131 Number of commits: 1 132 Name: [hash] 133 [EOF] 134 "); 135 let output = work_dir.run_jj(["debug", "reindex"]); 136 insta::assert_snapshot!(output, @r" 137 ------- stderr ------- 138 Finished indexing 4 commits. 139 [EOF] 140 "); 141 let output = work_dir.run_jj(["debug", "index"]); 142 assert_snapshot!(filter_index_stats(output), @r" 143 Number of commits: 4 144 Number of merges: 0 145 Max generation number: 3 146 Number of heads: 1 147 Number of changes: 4 148 Stats per level: 149 Level 0: 150 Number of commits: 4 151 Name: [hash] 152 [EOF] 153 "); 154} 155 156#[test] 157fn test_debug_tree() { 158 let test_env = TestEnvironment::default(); 159 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 160 let work_dir = test_env.work_dir("repo"); 161 let sub_dir = work_dir.create_dir_all("dir/subdir"); 162 sub_dir.write_file("file1", "contents 1"); 163 work_dir.run_jj(["new"]).success(); 164 sub_dir.write_file("file2", "contents 2"); 165 166 // Defaults to showing the tree at the current commit 167 let output = work_dir.run_jj(["debug", "tree"]); 168 assert_snapshot!(output.normalize_backslash(), @r#" 169 dir/subdir/file1: Ok(Resolved(Some(File { id: FileId("498e9b01d79cb8d31cdf0df1a663cc1fcefd9de3"), executable: false }))) 170 dir/subdir/file2: Ok(Resolved(Some(File { id: FileId("b2496eaffe394cd50a9db4de5787f45f09fd9722"), executable: false }))) 171 [EOF] 172 "# 173 ); 174 175 // Can show the tree at another commit 176 let output = work_dir.run_jj(["debug", "tree", "-r@-"]); 177 assert_snapshot!(output.normalize_backslash(), @r#" 178 dir/subdir/file1: Ok(Resolved(Some(File { id: FileId("498e9b01d79cb8d31cdf0df1a663cc1fcefd9de3"), executable: false }))) 179 [EOF] 180 "# 181 ); 182 183 // Can filter by paths 184 let output = work_dir.run_jj(["debug", "tree", "dir/subdir/file2"]); 185 assert_snapshot!(output.normalize_backslash(), @r#" 186 dir/subdir/file2: Ok(Resolved(Some(File { id: FileId("b2496eaffe394cd50a9db4de5787f45f09fd9722"), executable: false }))) 187 [EOF] 188 "# 189 ); 190 191 // Can a show the root tree by id 192 let output = work_dir.run_jj([ 193 "debug", 194 "tree", 195 "--id=0958358e3f80e794f032b25ed2be96cf5825da6c", 196 ]); 197 assert_snapshot!(output.normalize_backslash(), @r#" 198 dir/subdir/file1: Ok(Resolved(Some(File { id: FileId("498e9b01d79cb8d31cdf0df1a663cc1fcefd9de3"), executable: false }))) 199 dir/subdir/file2: Ok(Resolved(Some(File { id: FileId("b2496eaffe394cd50a9db4de5787f45f09fd9722"), executable: false }))) 200 [EOF] 201 "# 202 ); 203 204 // Can a show non-root tree by id 205 let output = work_dir.run_jj([ 206 "debug", 207 "tree", 208 "--dir=dir", 209 "--id=6ac232efa713535ae518a1a898b77e76c0478184", 210 ]); 211 assert_snapshot!(output.normalize_backslash(), @r#" 212 dir/subdir/file1: Ok(Resolved(Some(File { id: FileId("498e9b01d79cb8d31cdf0df1a663cc1fcefd9de3"), executable: false }))) 213 dir/subdir/file2: Ok(Resolved(Some(File { id: FileId("b2496eaffe394cd50a9db4de5787f45f09fd9722"), executable: false }))) 214 [EOF] 215 "# 216 ); 217 218 // Can filter by paths when showing non-root tree (matcher applies from root) 219 let output = work_dir.run_jj([ 220 "debug", 221 "tree", 222 "--dir=dir", 223 "--id=6ac232efa713535ae518a1a898b77e76c0478184", 224 "dir/subdir/file2", 225 ]); 226 assert_snapshot!(output.normalize_backslash(), @r#" 227 dir/subdir/file2: Ok(Resolved(Some(File { id: FileId("b2496eaffe394cd50a9db4de5787f45f09fd9722"), executable: false }))) 228 [EOF] 229 "# 230 ); 231} 232 233#[test] 234fn test_debug_operation_id() { 235 let test_env = TestEnvironment::default(); 236 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 237 let work_dir = test_env.work_dir("repo"); 238 let output = work_dir.run_jj(["debug", "operation", "--display", "id"]); 239 assert_snapshot!(filter_index_stats(output), @r" 240 eac759b9ab75793fd3da96e60939fb48f2cd2b2a9c1f13ffe723cf620f3005b8d3e7e923634a07ea39513e4f2f360c87b9ad5d331cf90d7a844864b83b72eba1 241 [EOF] 242 "); 243} 244 245fn filter_index_stats(output: CommandOutput) -> CommandOutput { 246 let regex = Regex::new(r" Name: [0-9a-z]+").unwrap(); 247 output.normalize_stdout_with(|text| regex.replace_all(&text, " Name: [hash]").into_owned()) 248}