Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't silently ignore complete tests when missing installed shells on CI #5567

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack
- name: Install shells
if: runner.os == 'Linux'
run: sudo apt-get install -y elvish fish zsh
- name: Build
run: make build-${{matrix.features}}
- name: Test
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/rust-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- name: Install shells
if: runner.os == 'Linux'
run: sudo apt-get install -y elvish fish zsh
- name: Build
run: make build-${{matrix.features}}
- name: Test
Expand Down Expand Up @@ -96,6 +99,9 @@ jobs:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-hack
- name: Install shells
if: runner.os == 'Linux'
run: sudo apt-get install -y elvish fish zsh
- name: Update dependencues
run: cargo update
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions clap_complete/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ unicode-xid = { version = "0.2.2", optional = true }
snapbox = { version = "0.6.0", features = ["diff", "dir", "examples"] }
# Cutting out `filesystem` feature
trycmd = { version = "0.15.1", default-features = false, features = ["color-auto", "diff", "examples"] }
completest = "0.4.0"
completest-pty = "0.5.0"
completest = "0.4.1"
completest-pty = "0.5.2"
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "derive", "help"] }
automod = "1.0.14"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# expected empty file to disable loading ~/.inputrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fpath=($fpath $ZDOTDIR/zsh)
autoload -U +X compinit && compinit
autoload -U +X compinit && compinit -u # bypass compaudit security checking
precmd_functions="" # avoid the prompt being overwritten
PS1='%% '
PROMPT='%% '
2 changes: 1 addition & 1 deletion clap_complete/tests/testsuite/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub(crate) fn has_command(command: &str) -> bool {
Ok(output) => output,
Err(e) => {
// CI is expected to support all of the commands
if is_ci() && cfg!(linux) {
if is_ci() && cfg!(target_os = "linux") {
panic!(
"expected command `{}` to be somewhere in PATH: {}",
command, e
Expand Down
59 changes: 22 additions & 37 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ fn suggest_subcommand_subset() {
.subcommand(Command::new("hello-moon"))
.subcommand(Command::new("goodbye-world"));

assert_data_eq!(
complete!(cmd, "he"),
snapbox::str![
"hello-moon
assert_data_eq!(complete!(cmd, "he"), snapbox::str![[r#"
hello-moon
hello-world
help\tPrint this message or the help of the given subcommand(s)"
],
);
help Print this message or the help of the given subcommand(s)
"#]],);
}

#[test]
Expand All @@ -52,14 +49,11 @@ fn suggest_long_flag_subset() {
.action(clap::ArgAction::Count),
);

assert_data_eq!(
complete!(cmd, "--he"),
snapbox::str![
"--hello-world
assert_data_eq!(complete!(cmd, "--he"), snapbox::str![[r#"
--hello-world
--hello-moon
--help\tPrint help"
],
);
--help Print help
"#]],);
}

#[test]
Expand All @@ -71,13 +65,10 @@ fn suggest_possible_value_subset() {
"goodbye-world".into(),
]));

assert_data_eq!(
complete!(cmd, "hello"),
snapbox::str![
"hello-world\tSay hello to the world
hello-moon"
],
);
assert_data_eq!(complete!(cmd, "hello"), snapbox::str![[r#"
hello-world Say hello to the world
hello-moon
"#]],);
}

#[test]
Expand All @@ -99,15 +90,12 @@ fn suggest_additional_short_flags() {
.action(clap::ArgAction::Count),
);

assert_data_eq!(
complete!(cmd, "-a"),
snapbox::str![
"-aa
assert_data_eq!(complete!(cmd, "-a"), snapbox::str![[r#"
-aa
-ab
-ac
-ah\tPrint help"
],
);
-ah Print help
"#]],);
}

#[test]
Expand All @@ -120,16 +108,13 @@ fn suggest_subcommand_positional() {
]),
));

assert_data_eq!(
complete!(cmd, "hello-world [TAB]"),
snapbox::str![
"--help\tPrint help (see more with '--help')
-h\tPrint help (see more with '--help')
hello-world\tSay hello to the world
assert_data_eq!(complete!(cmd, "hello-world [TAB]"), snapbox::str![[r#"
--help Print help (see more with '--help')
-h Print help (see more with '--help')
hello-world Say hello to the world
hello-moon
goodbye-world"
],
);
goodbye-world
"#]],);
}

fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>) -> String {
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ fn complete() {
common::load_runtime::<completest_pty::ElvishRuntimeBuilder>("static", "exhaustive");

let input = "exhaustive \t";
let expected = snapbox::str![
r#"% exhaustive --generate
let expected = snapbox::str![[r#"
% exhaustive --generate
COMPLETING argument
--generate generate
--global everywhere
Expand All @@ -169,8 +169,8 @@ hint hint
last last
pacman pacman
quote quote
value value "#
];
value value
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
31 changes: 16 additions & 15 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,41 +182,42 @@ fn complete_dynamic() {
let mut runtime =
common::load_runtime::<completest_pty::FishRuntimeBuilder>("dynamic", "exhaustive");

let input = "exhaustive \t";
let expected = snapbox::str![
r#"% exhaustive
let input = "exhaustive \t\t";
let expected = snapbox::str![[r#"
% exhaustive action
action last -V (Print version)
alias pacman --generate (generate)
complete (Register shell completions for this program) quote --global (everywhere)
help (Print this message or the help of the given subcommand(s)) value --help (Print help)
hint -h (Print help) --version (Print version)"#
];
hint -h (Print help) --version (Print version)
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

let input = "exhaustive quote \t";
let expected = snapbox::str![
r#"% exhaustive quote
cmd-backslash (Avoid '\n')
let input = "exhaustive quote \t\t";
let expected = snapbox::str![[r#"
% exhaustive quote
cmd-backslash (Avoid '/n')
cmd-backticks (For more information see `echo test`)
cmd-brackets (List packages [filter])
cmd-double-quotes (Can be "always", "auto", or "never")
cmd-expansions (Execute the shell command with $SHELL)
cmd-single-quotes (Can be 'always', 'auto', or 'never')
escape-help (\tab "')
escape-help (/tab "')
help (Print this message or the help of the given subcommand(s))
-h (Print help)
-h (Print help (see more with '--help'))
-V (Print version)
--backslash (Avoid '\n')
--backslash (Avoid '/n')
--backticks (For more information see `echo test`)
--brackets (List packages [filter])
--choice
--double-quotes (Can be "always", "auto", or "never")
--expansions (Execute the shell command with $SHELL)
--global (everywhere)
--help (Print help)
--help (Print help (see more with '--help'))
--single-quotes (Can be 'always', 'auto', or 'never')
--version (Print version)"#
];
--version (Print version)
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
8 changes: 4 additions & 4 deletions clap_complete/tests/testsuite/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ fn complete() {
common::load_runtime::<completest_pty::ZshRuntimeBuilder>("static", "exhaustive");

let input = "exhaustive \t";
let expected = snapbox::str![
r#"% exhaustive
let expected = snapbox::str![[r#"
% exhaustive
complete -- Register shell completions for this program
help -- Print this message or the help of the given subcommand(s)
pacman action alias value quote hint last -- "#
];
pacman action alias value quote hint last --
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
2 changes: 1 addition & 1 deletion clap_complete_nushell/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub(crate) fn has_command(command: &str) -> bool {
Ok(output) => output,
Err(e) => {
// CI is expected to support all of the commands
if is_ci() && cfg!(linux) {
if is_ci() && cfg!(target_os = "linux") {
panic!(
"expected command `{}` to be somewhere in PATH: {}",
command, e
Expand Down
Loading