just playing with tangled
at gvimdiff 5.3 kB view raw
1// Copyright 2023 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; 16 17use crate::common::TestEnvironment; 18 19#[test] 20fn test_util_config_schema() { 21 let test_env = TestEnvironment::default(); 22 let output = test_env.run_jj_in(".", ["util", "config-schema"]); 23 // Validate partial snapshot, redacting any lines nested 2+ indent levels. 24 insta::with_settings!({filters => vec![(r"(?m)(^ .*$\r?\n)+", " [...]\n")]}, { 25 assert_snapshot!(output, @r#" 26 { 27 "$schema": "http://json-schema.org/draft-04/schema", 28 "$comment": "`taplo` and the corresponding VS Code plugins only support draft-04 verstion of JSON Schema, see <https://taplo.tamasfe.dev/configuration/developing-schemas.html>. draft-07 is mostly compatible with it, newer versions may not be.", 29 "title": "Jujutsu config", 30 "type": "object", 31 "description": "User configuration for Jujutsu VCS. See https://jj-vcs.github.io/jj/latest/config/ for details", 32 "properties": { 33 [...] 34 } 35 } 36 [EOF] 37 "#); 38 }); 39} 40 41#[test] 42fn test_gc_args() { 43 let test_env = TestEnvironment::default(); 44 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 45 let repo_path = test_env.env_root().join("repo"); 46 47 let output = test_env.run_jj_in(&repo_path, ["util", "gc"]); 48 insta::assert_snapshot!(output, @""); 49 50 let output = test_env.run_jj_in(&repo_path, ["util", "gc", "--at-op=@-"]); 51 insta::assert_snapshot!(output, @r" 52 ------- stderr ------- 53 Error: Cannot garbage collect from a non-head operation 54 [EOF] 55 [exit status: 1] 56 "); 57 58 let output = test_env.run_jj_in(&repo_path, ["util", "gc", "--expire=foobar"]); 59 insta::assert_snapshot!(output, @r" 60 ------- stderr ------- 61 Error: --expire only accepts 'now' 62 [EOF] 63 [exit status: 1] 64 "); 65} 66 67#[test] 68fn test_gc_operation_log() { 69 let test_env = TestEnvironment::default(); 70 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 71 let repo_path = test_env.env_root().join("repo"); 72 73 // Create an operation. 74 std::fs::write(repo_path.join("file"), "a change\n").unwrap(); 75 test_env 76 .run_jj_in(&repo_path, ["commit", "-m", "a change"]) 77 .success(); 78 let op_to_remove = test_env.work_dir(&repo_path).current_operation_id(); 79 80 // Make another operation the head. 81 std::fs::write(repo_path.join("file"), "another change\n").unwrap(); 82 test_env 83 .run_jj_in(&repo_path, ["commit", "-m", "another change"]) 84 .success(); 85 86 // This works before the operation is removed. 87 test_env 88 .run_jj_in(&repo_path, ["debug", "operation", &op_to_remove]) 89 .success(); 90 91 // Remove some operations. 92 test_env 93 .run_jj_in(&repo_path, ["operation", "abandon", "..@-"]) 94 .success(); 95 test_env 96 .run_jj_in(&repo_path, ["util", "gc", "--expire=now"]) 97 .success(); 98 99 // Now this doesn't work. 100 let output = test_env.run_jj_in(&repo_path, ["debug", "operation", &op_to_remove]); 101 insta::assert_snapshot!(output, @r#" 102 ------- stderr ------- 103 Error: No operation ID matching "bda58b425f645d895ce92608576509b4fcc0c96dbc5f18717a817f09a530117dff0c2054a28781b4c7f1fdbf5a726c89ebd8666fe54dc9f3cc52ca9596110418" 104 [EOF] 105 [exit status: 1] 106 "#); 107} 108 109#[test] 110fn test_shell_completions() { 111 #[track_caller] 112 fn test(shell: &str) { 113 let test_env = TestEnvironment::default(); 114 // Use the local backend because GitBackend::gc() depends on the git CLI. 115 let output = test_env 116 .run_jj_in(".", ["util", "completion", shell]) 117 .success(); 118 // Ensures only stdout contains text 119 assert!( 120 !output.stdout.is_empty() && output.stderr.is_empty(), 121 "{output}" 122 ); 123 } 124 125 test("bash"); 126 test("fish"); 127 test("nushell"); 128 test("zsh"); 129} 130 131#[test] 132fn test_util_exec() { 133 let test_env = TestEnvironment::default(); 134 let formatter_path = assert_cmd::cargo::cargo_bin("fake-formatter"); 135 let output = test_env.run_jj_in( 136 ".", 137 [ 138 "util", 139 "exec", 140 "--", 141 formatter_path.to_str().unwrap(), 142 "--append", 143 "hello", 144 ], 145 ); 146 // Ensures only stdout contains text 147 insta::assert_snapshot!(output, @"hello[EOF]"); 148} 149 150#[test] 151fn test_util_exec_fail() { 152 let test_env = TestEnvironment::default(); 153 let output = test_env.run_jj_in(".", ["util", "exec", "--", "jj-test-missing-program"]); 154 insta::assert_snapshot!(output.strip_stderr_last_line(), @r" 155 ------- stderr ------- 156 Error: Failed to execute external command 'jj-test-missing-program' 157 [EOF] 158 [exit status: 1] 159 "); 160}