refactor(complete): Make it easier to compare tests

This commit is contained in:
Ed Page 2024-09-04 09:47:21 -05:00
parent 5286385dac
commit 931d9acb71
4 changed files with 68 additions and 68 deletions

View file

@ -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::<completest_pty::BashRuntimeBuilder>("static", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("static", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"

View file

@ -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::<completest_pty::ElvishRuntimeBuilder>("static", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("static", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t";
let expected = snapbox::str![[r#"

View file

@ -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::<completest_pty::FishRuntimeBuilder>("static", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("static", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"

View file

@ -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::<completest_pty::ZshRuntimeBuilder>("static", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("static", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
common::register_example::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("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::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"