From 931d9acb71a33a87401150a9e1471ab980e02051 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 4 Sep 2024 09:47:21 -0500 Subject: [PATCH] refactor(complete): Make it easier to compare tests --- clap_complete/tests/testsuite/bash.rs | 34 ++++++++++++------------- clap_complete/tests/testsuite/elvish.rs | 34 ++++++++++++------------- clap_complete/tests/testsuite/fish.rs | 34 ++++++++++++------------- clap_complete/tests/testsuite/zsh.rs | 34 ++++++++++++------------- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index 88dffe83..25461d6f 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -2,6 +2,11 @@ use snapbox::assert_data_eq; use crate::common; +#[cfg(unix)] +const CMD: &str = "bash"; +#[cfg(unix)] +type RuntimeBuilder = completest_pty::BashRuntimeBuilder; + #[test] fn basic() { let name = "my-app"; @@ -138,19 +143,18 @@ fn subcommand_last() { #[test] #[cfg(unix)] fn register_completion() { - common::register_example::("static", "exhaustive"); + common::register_example::("static", "exhaustive"); } #[test] #[cfg(unix)] fn complete() { - if !common::has_command("bash") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("static", "exhaustive"); + let mut runtime = common::load_runtime::("static", "exhaustive"); let input = "exhaustive \t\t"; let expected = snapbox::str![[r#" @@ -235,19 +239,18 @@ fn complete() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn register_dynamic_env() { - common::register_example::("dynamic-env", "exhaustive"); + common::register_example::("dynamic-env", "exhaustive"); } #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_toplevel() { - if !common::has_command("bash") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive \t\t"; let expected = snapbox::str![[r#" @@ -262,13 +265,12 @@ fn complete_dynamic_env_toplevel() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_help() { - if !common::has_command("bash") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote \t\t"; let expected = snapbox::str![[r#" @@ -285,13 +287,12 @@ fn complete_dynamic_env_quoted_help() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_option_value() { - if !common::has_command("bash") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive action --choice=\t\t"; let expected = snapbox::str!["% "]; @@ -307,13 +308,12 @@ fn complete_dynamic_env_option_value() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_value() { - if !common::has_command("bash") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote --choice \t\t"; let expected = snapbox::str![[r#" diff --git a/clap_complete/tests/testsuite/elvish.rs b/clap_complete/tests/testsuite/elvish.rs index b0018a1b..2dbf9437 100644 --- a/clap_complete/tests/testsuite/elvish.rs +++ b/clap_complete/tests/testsuite/elvish.rs @@ -1,6 +1,11 @@ use crate::common; use snapbox::assert_data_eq; +#[cfg(unix)] +const CMD: &str = "elvish"; +#[cfg(unix)] +type RuntimeBuilder = completest_pty::ElvishRuntimeBuilder; + #[test] fn basic() { let name = "my-app"; @@ -137,19 +142,18 @@ fn subcommand_last() { #[test] #[cfg(unix)] fn register_completion() { - common::register_example::("static", "exhaustive"); + common::register_example::("static", "exhaustive"); } #[test] #[cfg(unix)] fn complete_static_toplevel() { - if !common::has_command("elvish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("static", "exhaustive"); + let mut runtime = common::load_runtime::("static", "exhaustive"); let input = "exhaustive \t"; let expected = snapbox::str![[r#" @@ -177,19 +181,18 @@ value value #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn register_dynamic_env() { - common::register_example::("dynamic-env", "exhaustive"); + common::register_example::("dynamic-env", "exhaustive"); } #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_toplevel() { - if !common::has_command("elvish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive \t"; let expected = snapbox::str![[r#" @@ -205,13 +208,12 @@ fn complete_dynamic_env_toplevel() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_help() { - if !common::has_command("elvish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote \t"; let expected = snapbox::str![[r#" @@ -229,13 +231,12 @@ fn complete_dynamic_env_quoted_help() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_option_value() { - if !common::has_command("elvish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive action --choice=\t"; let expected = snapbox::str![[r#" @@ -259,13 +260,12 @@ fn complete_dynamic_env_option_value() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_value() { - if !common::has_command("elvish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote --choice \t"; let expected = snapbox::str![[r#" diff --git a/clap_complete/tests/testsuite/fish.rs b/clap_complete/tests/testsuite/fish.rs index 9dccb53c..f2ddf4e5 100644 --- a/clap_complete/tests/testsuite/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -1,6 +1,11 @@ use crate::common; use snapbox::assert_data_eq; +#[cfg(unix)] +const CMD: &str = "fish"; +#[cfg(unix)] +type RuntimeBuilder = completest_pty::FishRuntimeBuilder; + #[test] fn basic() { let name = "my-app"; @@ -137,19 +142,18 @@ fn subcommand_last() { #[test] #[cfg(unix)] fn register_completion() { - common::register_example::("static", "exhaustive"); + common::register_example::("static", "exhaustive"); } #[test] #[cfg(unix)] fn complete() { - if !common::has_command("fish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("static", "exhaustive"); + let mut runtime = common::load_runtime::("static", "exhaustive"); let input = "exhaustive \t"; let expected = snapbox::str![[r#" @@ -172,19 +176,18 @@ another shell (something with a space) bash (bash (shell)) fish (fish shell #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn register_dynamic_env() { - common::register_example::("dynamic-env", "exhaustive"); + common::register_example::("dynamic-env", "exhaustive"); } #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_toplevel() { - if !common::has_command("fish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive \t\t"; let expected = snapbox::str![[r#" @@ -202,13 +205,12 @@ last -V (Print ve #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_help() { - if !common::has_command("fish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote \t\t"; let expected = snapbox::str![[r#" @@ -241,13 +243,12 @@ help (Print this message or the help of the given subcommand(s)) #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_option_value() { - if !common::has_command("fish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive action --choice=\t\t"; let expected = snapbox::str![[r#" @@ -266,13 +267,12 @@ fn complete_dynamic_env_option_value() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_value() { - if !common::has_command("fish") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote --choice \t\t"; let expected = snapbox::str![[r#" diff --git a/clap_complete/tests/testsuite/zsh.rs b/clap_complete/tests/testsuite/zsh.rs index 4bc30a4d..2331ff4d 100644 --- a/clap_complete/tests/testsuite/zsh.rs +++ b/clap_complete/tests/testsuite/zsh.rs @@ -2,6 +2,11 @@ use snapbox::assert_data_eq; use crate::common; +#[cfg(unix)] +const CMD: &str = "zsh"; +#[cfg(unix)] +type RuntimeBuilder = completest_pty::ZshRuntimeBuilder; + #[test] fn basic() { let name = "my-app"; @@ -138,19 +143,18 @@ fn subcommand_last() { #[test] #[cfg(unix)] fn register_completion() { - common::register_example::("static", "exhaustive"); + common::register_example::("static", "exhaustive"); } #[test] #[cfg(unix)] fn complete() { - if !common::has_command("zsh") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("static", "exhaustive"); + let mut runtime = common::load_runtime::("static", "exhaustive"); let input = "exhaustive \t"; let expected = snapbox::str![[r#" @@ -165,19 +169,18 @@ pacman action alias value quote hint last -- #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn register_dynamic_env() { - common::register_example::("dynamic-env", "exhaustive"); + common::register_example::("dynamic-env", "exhaustive"); } #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_toplevel() { - if !common::has_command("zsh") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive \t\t"; let expected = snapbox::str![[r#" @@ -192,13 +195,12 @@ fn complete_dynamic_env_toplevel() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_help() { - if !common::has_command("zsh") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote \t\t"; let expected = snapbox::str![[r#" @@ -215,13 +217,12 @@ fn complete_dynamic_env_quoted_help() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_option_value() { - if !common::has_command("zsh") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive action --choice=\t\t"; let expected = snapbox::str![[r#" @@ -240,13 +241,12 @@ fn complete_dynamic_env_option_value() { #[test] #[cfg(all(unix, feature = "unstable-dynamic"))] fn complete_dynamic_env_quoted_value() { - if !common::has_command("zsh") { + if !common::has_command(CMD) { return; } let term = completest::Term::new(); - let mut runtime = - common::load_runtime::("dynamic-env", "exhaustive"); + let mut runtime = common::load_runtime::("dynamic-env", "exhaustive"); let input = "exhaustive quote --choice \t\t"; let expected = snapbox::str![[r#"