just playing with tangled
at diffedit3 112 lines 4.2 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 stdout = test_env.jj_cmd_success(test_env.env_root(), &["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!(stdout, @r###" 26 { 27 "$schema": "http://json-schema.org/draft-07/schema", 28 "title": "Jujutsu config", 29 "type": "object", 30 "description": "User configuration for Jujutsu VCS. See https://github.com/martinvonz/jj/blob/main/docs/config.md for details", 31 "properties": { 32 [...] 33 } 34 } 35 "###) 36 }); 37} 38 39#[test] 40fn test_gc_args() { 41 let test_env = TestEnvironment::default(); 42 // Use the local backend because GitBackend::gc() depends on the git CLI. 43 test_env.jj_cmd_ok( 44 test_env.env_root(), 45 &["init", "repo", "--config-toml=ui.allow-init-native=true"], 46 ); 47 let repo_path = test_env.env_root().join("repo"); 48 49 let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["util", "gc"]); 50 insta::assert_snapshot!(stderr, @""); 51 52 let stderr = test_env.jj_cmd_failure(&repo_path, &["util", "gc", "--at-op=@-"]); 53 insta::assert_snapshot!(stderr, @r###" 54 Error: Cannot garbage collect from a non-head operation 55 "###); 56 57 let stderr = test_env.jj_cmd_failure(&repo_path, &["util", "gc", "--expire=foobar"]); 58 insta::assert_snapshot!(stderr, @r###" 59 Error: --expire only accepts 'now' 60 "###); 61} 62 63#[test] 64fn test_gc_operation_log() { 65 let test_env = TestEnvironment::default(); 66 // Use the local backend because GitBackend::gc() depends on the git CLI. 67 test_env.jj_cmd_ok( 68 test_env.env_root(), 69 &["init", "repo", "--config-toml=ui.allow-init-native=true"], 70 ); 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.jj_cmd_ok(&repo_path, &["commit", "-m", "a change"]); 76 let op_to_remove = test_env.current_operation_id(&repo_path); 77 78 // Make another operation the head. 79 std::fs::write(repo_path.join("file"), "another change\n").unwrap(); 80 test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "another change"]); 81 82 // This works before the operation is removed. 83 test_env.jj_cmd_ok(&repo_path, &["debug", "operation", &op_to_remove]); 84 85 // Remove some operations. 86 test_env.jj_cmd_ok(&repo_path, &["operation", "abandon", "..@-"]); 87 test_env.jj_cmd_ok(&repo_path, &["util", "gc", "--expire=now"]); 88 89 // Now this doesn't work. 90 let stderr = test_env.jj_cmd_failure(&repo_path, &["debug", "operation", &op_to_remove]); 91 insta::assert_snapshot!(stderr, @r###" 92 Error: No operation ID matching "6b842a00d6a5655d32c8a0ee40c4aaaed49337cdcaca98b8d7c1f3a1c82f58b4968c2ed5b13d9d2a5d41f04040f42e6daf77c0f4646d09138bd1e25c754e2411" 93 "###); 94} 95 96#[test] 97fn test_shell_completions() { 98 #[track_caller] 99 fn test(shell: &str) { 100 let test_env = TestEnvironment::default(); 101 // Use the local backend because GitBackend::gc() depends on the git CLI. 102 let (out, err) = test_env.jj_cmd_ok(test_env.env_root(), &["util", "completion", shell]); 103 // Ensures only stdout contains text 104 assert!(!out.is_empty()); 105 assert!(err.is_empty()); 106 } 107 108 test("bash"); 109 test("fish"); 110 test("nushell"); 111 test("zsh"); 112}