just playing with tangled
at gvimdiff 5.9 kB view raw
1// Copyright 2024 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 crate::common::TestEnvironment; 16 17#[test] 18fn test_help() { 19 let test_env = TestEnvironment::default(); 20 21 let help_cmd = test_env.run_jj_in(".", ["help"]).success(); 22 // The help command output should be equal to the long --help flag 23 let help_flag = test_env.run_jj_in(".", ["--help"]); 24 assert_eq!(help_cmd, help_flag); 25 26 // Help command should work with commands 27 let help_cmd = test_env.run_jj_in(".", ["help", "log"]).success(); 28 let help_flag = test_env.run_jj_in(".", ["log", "--help"]); 29 assert_eq!(help_cmd, help_flag); 30 31 // Help command should work with subcommands 32 let help_cmd = test_env 33 .run_jj_in(".", ["help", "workspace", "root"]) 34 .success(); 35 let help_flag = test_env.run_jj_in(".", ["workspace", "root", "--help"]); 36 assert_eq!(help_cmd, help_flag); 37 38 // Help command should not work recursively 39 let output = test_env.run_jj_in(".", ["workspace", "help", "root"]); 40 insta::assert_snapshot!(output, @r" 41 ------- stderr ------- 42 error: unrecognized subcommand 'help' 43 44 Usage: jj workspace [OPTIONS] <COMMAND> 45 46 For more information, try '--help'. 47 [EOF] 48 [exit status: 2] 49 "); 50 51 let output = test_env.run_jj_in(".", ["workspace", "add", "help"]); 52 insta::assert_snapshot!(output, @r#" 53 ------- stderr ------- 54 Error: There is no jj repo in "." 55 [EOF] 56 [exit status: 1] 57 "#); 58 59 let output = test_env.run_jj_in(".", ["new", "help", "main"]); 60 insta::assert_snapshot!(output, @r#" 61 ------- stderr ------- 62 Error: There is no jj repo in "." 63 [EOF] 64 [exit status: 1] 65 "#); 66 67 // Help command should output the same as --help for nonexistent commands 68 let help_cmd = test_env.run_jj_in(".", ["help", "nonexistent"]); 69 let help_flag = test_env.run_jj_in(".", ["nonexistent", "--help"]); 70 assert_eq!(help_cmd.status.code(), Some(2), "{help_cmd}"); 71 assert_eq!(help_cmd, help_flag); 72 73 // Some edge cases 74 let help_cmd = test_env.run_jj_in(".", ["help", "help"]).success(); 75 let help_flag = test_env.run_jj_in(".", ["help", "--help"]); 76 assert_eq!(help_cmd, help_flag); 77 78 let output = test_env.run_jj_in(".", ["help", "unknown"]); 79 insta::assert_snapshot!(output, @r" 80 ------- stderr ------- 81 error: unrecognized subcommand 'unknown' 82 83 tip: a similar subcommand exists: 'undo' 84 85 Usage: jj [OPTIONS] <COMMAND> 86 87 For more information, try '--help'. 88 [EOF] 89 [exit status: 2] 90 "); 91 92 let output = test_env.run_jj_in(".", ["help", "log", "--", "-r"]); 93 insta::assert_snapshot!(output, @r" 94 ------- stderr ------- 95 error: a value is required for '--revisions <REVSETS>' but none was supplied 96 97 For more information, try '--help'. 98 [EOF] 99 [exit status: 2] 100 "); 101} 102 103#[test] 104fn test_help_keyword() { 105 let test_env = TestEnvironment::default(); 106 107 // It should show help for a certain keyword if the `--keyword` flag is present 108 let help_cmd = test_env 109 .run_jj_in(".", ["help", "--keyword", "revsets"]) 110 .success(); 111 // It should be equal to the docs 112 assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md")); 113 114 // It should show help for a certain keyword if the `-k` flag is present 115 let help_cmd = test_env.run_jj_in(".", ["help", "-k", "revsets"]).success(); 116 // It should be equal to the docs 117 assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md")); 118 119 // It should give hints if a similar keyword is present 120 let output = test_env.run_jj_in(".", ["help", "-k", "rev"]); 121 insta::assert_snapshot!(output, @r" 122 ------- stderr ------- 123 error: invalid value 'rev' for '--keyword <KEYWORD>' 124 [possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial] 125 126 tip: a similar value exists: 'revsets' 127 128 For more information, try '--help'. 129 [EOF] 130 [exit status: 2] 131 "); 132 133 // It should give error with a hint if no similar keyword is found 134 let output = test_env.run_jj_in(".", ["help", "-k", "<no-similar-keyword>"]); 135 insta::assert_snapshot!(output, @r" 136 ------- stderr ------- 137 error: invalid value '<no-similar-keyword>' for '--keyword <KEYWORD>' 138 [possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial] 139 140 For more information, try '--help'. 141 [EOF] 142 [exit status: 2] 143 "); 144 145 // The keyword flag with no argument should error with a hint 146 let output = test_env.run_jj_in(".", ["help", "-k"]); 147 insta::assert_snapshot!(output, @r" 148 ------- stderr ------- 149 error: a value is required for '--keyword <KEYWORD>' but none was supplied 150 [possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial] 151 152 For more information, try '--help'. 153 [EOF] 154 [exit status: 2] 155 "); 156 157 // It shouldn't show help for a certain keyword if the `--keyword` is not 158 // present 159 let output = test_env.run_jj_in(".", ["help", "revsets"]); 160 insta::assert_snapshot!(output, @r" 161 ------- stderr ------- 162 error: unrecognized subcommand 'revsets' 163 164 tip: some similar subcommands exist: 'resolve', 'prev', 'restore', 'rebase', 'revert' 165 166 Usage: jj [OPTIONS] <COMMAND> 167 168 For more information, try '--help'. 169 [EOF] 170 [exit status: 2] 171 "); 172}