use crate::common::TestEnvironment;
#[test]
fn test_help() {
let test_env = TestEnvironment::default();
let help_cmd = test_env.run_jj_in(".", ["help"]).success();
let help_flag = test_env.run_jj_in(".", ["--help"]);
assert_eq!(
help_cmd.stdout.raw(),
help_flag.stdout.raw().replace("<COMMAND>", "[COMMAND]")
);
assert_eq!(help_cmd.stderr.raw(), help_flag.stderr.raw());
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);
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);
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]
"#);
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.stdout.raw(), help_flag.stdout.raw());
assert_eq!(
help_cmd.stderr.raw(),
help_flag.stderr.raw().replace("<COMMAND>", "[COMMAND]")
);
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: Unknown command: log -r
[EOF]
[exit status: 2]
");
}
#[test]
fn test_help_keyword() {
let test_env = TestEnvironment::default();
let help_cmd = test_env
.run_jj_in(".", ["help", "--keyword", "revsets"])
.success();
assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md"));
let help_cmd = test_env.run_jj_in(".", ["help", "-k", "revsets"]).success();
assert_eq!(help_cmd.stdout.raw(), include_str!("../../docs/revsets.md"));
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]
");
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]
");
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]
");
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]
");
}