1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// Copyright 2024 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::common::TestEnvironment;
#[test]
fn test_help() {
let test_env = TestEnvironment::default();
let help_cmd = test_env.run_jj_in(".", ["help"]).success();
// The help command output should be equal to the long --help flag
let help_flag = test_env.run_jj_in(".", ["--help"]);
assert_eq!(help_cmd, help_flag);
// Help command should work with commands
let help_cmd = test_env.run_jj_in(".", ["help", "log"]).success();
let help_flag = test_env.run_jj_in(".", ["log", "--help"]);
assert_eq!(help_cmd, help_flag);
// Help command should work with subcommands
let help_cmd = test_env
.run_jj_in(".", ["help", "workspace", "root"])
.success();
let help_flag = test_env.run_jj_in(".", ["workspace", "root", "--help"]);
assert_eq!(help_cmd, help_flag);
// Help command should not work recursively
let output = test_env.run_jj_in(".", ["workspace", "help", "root"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: unrecognized subcommand 'help'
Usage: jj workspace [OPTIONS] <COMMAND>
For more information, try '--help'.
[EOF]
[exit status: 2]
");
let output = test_env.run_jj_in(".", ["workspace", "add", "help"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: There is no jj repo in "."
[EOF]
[exit status: 1]
"#);
let output = test_env.run_jj_in(".", ["new", "help", "main"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: There is no jj repo in "."
[EOF]
[exit status: 1]
"#);
// Help command should output the same as --help for nonexistent commands
let help_cmd = test_env.run_jj_in(".", ["help", "nonexistent"]);
let help_flag = test_env.run_jj_in(".", ["nonexistent", "--help"]);
assert_eq!(help_cmd.status.code(), Some(2), "{help_cmd}");
assert_eq!(help_cmd, help_flag);
// Some edge cases
let help_cmd = test_env.run_jj_in(".", ["help", "help"]).success();
let help_flag = test_env.run_jj_in(".", ["help", "--help"]);
assert_eq!(help_cmd, help_flag);
let output = test_env.run_jj_in(".", ["help", "unknown"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: unrecognized subcommand 'unknown'
tip: a similar subcommand exists: 'undo'
Usage: jj [OPTIONS] <COMMAND>
For more information, try '--help'.
[EOF]
[exit status: 2]
");
let output = test_env.run_jj_in(".", ["help", "log", "--", "-r"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: a value is required for '--revisions <REVSETS>' but none was supplied
For more information, try '--help'.
[EOF]
[exit status: 2]
");
}
#[test]
fn test_help_keyword() {
let test_env = TestEnvironment::default();
// It should show help for a certain keyword if the `--keyword` flag is present
let help_cmd = test_env
.run_jj_in(".", ["help", "--keyword", "revsets"])
.success();
// It should be equal to the docs
assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md"));
// It should show help for a certain keyword if the `-k` flag is present
let help_cmd = test_env.run_jj_in(".", ["help", "-k", "revsets"]).success();
// It should be equal to the docs
assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md"));
// It should give hints if a similar keyword is present
let output = test_env.run_jj_in(".", ["help", "-k", "rev"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: invalid value 'rev' for '--keyword <KEYWORD>'
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
tip: a similar value exists: 'revsets'
For more information, try '--help'.
[EOF]
[exit status: 2]
");
// It should give error with a hint if no similar keyword is found
let output = test_env.run_jj_in(".", ["help", "-k", "<no-similar-keyword>"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: invalid value '<no-similar-keyword>' for '--keyword <KEYWORD>'
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
For more information, try '--help'.
[EOF]
[exit status: 2]
");
// The keyword flag with no argument should error with a hint
let output = test_env.run_jj_in(".", ["help", "-k"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: a value is required for '--keyword <KEYWORD>' but none was supplied
[possible values: bookmarks, config, filesets, glossary, revsets, templates, tutorial]
For more information, try '--help'.
[EOF]
[exit status: 2]
");
// It shouldn't show help for a certain keyword if the `--keyword` is not
// present
let output = test_env.run_jj_in(".", ["help", "revsets"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
error: unrecognized subcommand 'revsets'
tip: some similar subcommands exist: 'resolve', 'prev', 'restore', 'rebase', 'revert'
Usage: jj [OPTIONS] <COMMAND>
For more information, try '--help'.
[EOF]
[exit status: 2]
");
}
|