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