just playing with tangled
at tmp-tutorial 137 lines 4.1 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 20pub mod common; 21 22#[test] 23fn test_debug_revset() { 24 let test_env = TestEnvironment::default(); 25 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 26 let workspace_path = test_env.env_root().join("repo"); 27 28 let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "revset", "root"]); 29 insta::with_settings!({filters => vec![ 30 (r"(?m)(^ .*\n)+", " ..\n"), 31 ]}, { 32 assert_snapshot!(stdout, @r###" 33 -- Parsed: 34 CommitRef( 35 .. 36 ) 37 38 -- Optimized: 39 CommitRef( 40 .. 41 ) 42 43 -- Resolved: 44 Commits( 45 .. 46 ) 47 48 -- Evaluated: 49 RevsetImpl { 50 .. 51 } 52 53 -- Commit IDs: 54 0000000000000000000000000000000000000000 55 "###); 56 }); 57} 58 59#[test] 60fn test_debug_index() { 61 let test_env = TestEnvironment::default(); 62 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 63 let workspace_path = test_env.env_root().join("repo"); 64 let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]); 65 assert_snapshot!(filter_index_stats(&stdout), @r###" 66 Number of commits: 2 67 Number of merges: 0 68 Max generation number: 1 69 Number of heads: 1 70 Number of changes: 2 71 Stats per level: 72 Level 0: 73 Number of commits: 2 74 Name: [hash] 75 "### 76 ); 77} 78 79#[test] 80fn test_debug_reindex() { 81 let test_env = TestEnvironment::default(); 82 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 83 let workspace_path = test_env.env_root().join("repo"); 84 test_env.jj_cmd_success(&workspace_path, &["new"]); 85 test_env.jj_cmd_success(&workspace_path, &["new"]); 86 let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]); 87 assert_snapshot!(filter_index_stats(&stdout), @r###" 88 Number of commits: 4 89 Number of merges: 0 90 Max generation number: 3 91 Number of heads: 1 92 Number of changes: 4 93 Stats per level: 94 Level 0: 95 Number of commits: 3 96 Name: [hash] 97 Level 1: 98 Number of commits: 1 99 Name: [hash] 100 "### 101 ); 102 let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "reindex"]); 103 assert_snapshot!(stdout, @r###" 104 Finished indexing 4 commits. 105 "###); 106 let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]); 107 assert_snapshot!(filter_index_stats(&stdout), @r###" 108 Number of commits: 4 109 Number of merges: 0 110 Max generation number: 3 111 Number of heads: 1 112 Number of changes: 4 113 Stats per level: 114 Level 0: 115 Number of commits: 4 116 Name: [hash] 117 "### 118 ); 119} 120 121#[test] 122fn test_debug_operation_id() { 123 let test_env = TestEnvironment::default(); 124 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 125 let workspace_path = test_env.env_root().join("repo"); 126 let stdout = 127 test_env.jj_cmd_success(&workspace_path, &["debug", "operation", "--display", "id"]); 128 assert_snapshot!(filter_index_stats(&stdout), @r###" 129 19b8089fc78b7c49171f3c8934248be6f89f52311005e961cab5780f9f138b142456d77b27d223d7ee84d21d8c30c4a80100eaf6735b548b1acd0da688f94c80 130 "### 131 ); 132} 133 134fn filter_index_stats(text: &str) -> String { 135 let regex = Regex::new(r" Name: [0-9a-z]+").unwrap(); 136 regex.replace_all(text, " Name: [hash]").to_string() 137}