From 3689a4c867bda3e1553f68e67c94ea9c060fef87 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 5 Jul 2024 15:02:08 -0500 Subject: [PATCH 1/5] test(complete): Fix snapshots --- clap_complete/tests/testsuite/dynamic.rs | 59 +++++++++--------------- clap_complete/tests/testsuite/elvish.rs | 8 ++-- clap_complete/tests/testsuite/fish.rs | 32 ++++--------- clap_complete/tests/testsuite/zsh.rs | 8 ++-- 4 files changed, 39 insertions(+), 68 deletions(-) diff --git a/clap_complete/tests/testsuite/dynamic.rs b/clap_complete/tests/testsuite/dynamic.rs index 7cf9cf7d693..7d5f98b918d 100644 --- a/clap_complete/tests/testsuite/dynamic.rs +++ b/clap_complete/tests/testsuite/dynamic.rs @@ -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] @@ -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] @@ -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] @@ -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] @@ -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, current_dir: Option<&Path>) -> String { diff --git a/clap_complete/tests/testsuite/elvish.rs b/clap_complete/tests/testsuite/elvish.rs index eee5fee6746..17cf1cf6884 100644 --- a/clap_complete/tests/testsuite/elvish.rs +++ b/clap_complete/tests/testsuite/elvish.rs @@ -152,8 +152,8 @@ fn complete() { common::load_runtime::("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 @@ -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); } diff --git a/clap_complete/tests/testsuite/fish.rs b/clap_complete/tests/testsuite/fish.rs index 5fc88096f14..1d9b0409e49 100644 --- a/clap_complete/tests/testsuite/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -183,40 +183,26 @@ fn complete_dynamic() { common::load_runtime::("dynamic", "exhaustive"); let input = "exhaustive \t"; - let expected = snapbox::str![ - r#"% exhaustive + let expected = snapbox::str![[r#" +% exhaustive 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 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 "') -help (Print this message or the help of the given subcommand(s)) --h (Print help) --V (Print version) ---backslash (Avoid '\n') ---backticks (For more information see `echo test`) ---brackets (List packages [filter]) ---double-quotes (Can be "always", "auto", or "never") ---expansions (Execute the shell command with $SHELL) ---global (everywhere) ---help (Print help) ---single-quotes (Can be 'always', 'auto', or 'never') ---version (Print version)"# - ]; +…and 16 more rows +"#]]; let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); } diff --git a/clap_complete/tests/testsuite/zsh.rs b/clap_complete/tests/testsuite/zsh.rs index aa6b9132ec8..8acb42a6545 100644 --- a/clap_complete/tests/testsuite/zsh.rs +++ b/clap_complete/tests/testsuite/zsh.rs @@ -153,12 +153,12 @@ fn complete() { common::load_runtime::("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); } From 7c00ad2e3e4cc63ec6dbe64029e24c0e497b03c1 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 27 Jun 2024 22:36:32 +0700 Subject: [PATCH 2/5] test(comlete): Show all fish completions --- clap_complete/tests/testsuite/fish.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/clap_complete/tests/testsuite/fish.rs b/clap_complete/tests/testsuite/fish.rs index 1d9b0409e49..c6c11a4e639 100644 --- a/clap_complete/tests/testsuite/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -182,9 +182,9 @@ fn complete_dynamic() { let mut runtime = common::load_runtime::("dynamic", "exhaustive"); - let input = "exhaustive \t"; + let input = "exhaustive \t\t"; let expected = snapbox::str![[r#" -% exhaustive +% exhaustive action action last -V (Print version) alias pacman --generate (generate) complete (Register shell completions for this program) quote --global (everywhere) @@ -194,14 +194,29 @@ hint -h (Print he let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); - let input = "exhaustive quote \t"; + 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") -…and 16 more rows +cmd-expansions (Execute the shell command with $SHELL) +cmd-single-quotes (Can be 'always', 'auto', or 'never') +escape-help (/tab "') +help (Print this message or the help of the given subcommand(s)) +-h (Print help (see more with '--help')) +-V (Print version) +--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 (see more with '--help')) +--single-quotes (Can be 'always', 'auto', or 'never') +--version (Print version) "#]]; let actual = runtime.complete(input, &term).unwrap(); assert_data_eq!(actual, expected); From 2d2d1f498731d2ab70e8f15fed3765a856d52732 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 30 Jun 2024 02:14:29 +0700 Subject: [PATCH 3/5] chore: Bump completest --- Cargo.lock | 8 ++++---- clap_complete/Cargo.toml | 4 ++-- .../tests/snapshots/home/static/exhaustive/bash/.inputrc | 1 + .../tests/snapshots/home/static/exhaustive/zsh/.zshenv | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 clap_complete/tests/snapshots/home/static/exhaustive/bash/.inputrc diff --git a/Cargo.lock b/Cargo.lock index 00fa5f9a071..0a314e8a9a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,9 +571,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "completest" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8229e041ca8f8130ad7f0ce1afb9cfdb3033de7fd548e6422dbb2f4f12184f41" +checksum = "e6cda99a94266124c2cce3d239973ef8ce3160c83a3f426a314285d9bf6422d1" [[package]] name = "completest-nu" @@ -594,9 +594,9 @@ dependencies = [ [[package]] name = "completest-pty" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a6d1272e27f608f97616be67a2aed03ed8d73910b5df9a7f4a50c4ffd59d185" +checksum = "ee700748da7d34de4bbe0296d3153e8ef5217233d814d23fb68106c110dd9bc5" dependencies = [ "completest", "ptyprocess", diff --git a/clap_complete/Cargo.toml b/clap_complete/Cargo.toml index bff3f94b880..c9c094239bd 100644 --- a/clap_complete/Cargo.toml +++ b/clap_complete/Cargo.toml @@ -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" diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.inputrc b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.inputrc new file mode 100644 index 00000000000..60f4c090fad --- /dev/null +++ b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.inputrc @@ -0,0 +1 @@ +# expected empty file to disable loading ~/.inputrc diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/zsh/.zshenv b/clap_complete/tests/snapshots/home/static/exhaustive/zsh/.zshenv index f7b0671242c..6d309f24b41 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/zsh/.zshenv +++ b/clap_complete/tests/snapshots/home/static/exhaustive/zsh/.zshenv @@ -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='%% ' From 1c5a625ad0303e2407c8ab83ea7d37795e69a3a5 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 26 Jun 2024 01:18:15 +0700 Subject: [PATCH 4/5] fix: Fix wrong `cfg(linux)` --- clap_complete/tests/testsuite/common.rs | 2 +- clap_complete_nushell/tests/common.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clap_complete/tests/testsuite/common.rs b/clap_complete/tests/testsuite/common.rs index f5fe9313d0b..3534344bf12 100644 --- a/clap_complete/tests/testsuite/common.rs +++ b/clap_complete/tests/testsuite/common.rs @@ -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 diff --git a/clap_complete_nushell/tests/common.rs b/clap_complete_nushell/tests/common.rs index 871a8baf419..9ed9b5ba82d 100644 --- a/clap_complete_nushell/tests/common.rs +++ b/clap_complete_nushell/tests/common.rs @@ -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 From 5448020b188899601d641a2684833073aba0a669 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 26 Jun 2024 08:20:20 +0700 Subject: [PATCH 5/5] fix: Install shells for CI --- .github/workflows/ci.yml | 4 +++- .github/workflows/rust-next.yml | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 725b36bd91f..344527f6ce3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/rust-next.yml b/.github/workflows/rust-next.yml index 3b2d4868dc7..a5ac8529f87 100644 --- a/.github/workflows/rust-next.yml +++ b/.github/workflows/rust-next.yml @@ -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 @@ -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