Skip to content

Commit

Permalink
refactor(complete): Make it easier to compare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 4, 2024
1 parent 5286385 commit 931d9ac
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
34 changes: 17 additions & 17 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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#"
Expand Down Expand Up @@ -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#"
Expand All @@ -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#"
Expand All @@ -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!["% "];
Expand All @@ -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#"
Expand Down
34 changes: 17 additions & 17 deletions clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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#"
Expand Down Expand Up @@ -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#"
Expand All @@ -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#"
Expand All @@ -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#"
Expand All @@ -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#"
Expand Down
34 changes: 17 additions & 17 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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#"
Expand All @@ -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#"
Expand All @@ -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#"
Expand Down Expand Up @@ -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#"
Expand All @@ -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#"
Expand Down
Loading

0 comments on commit 931d9ac

Please sign in to comment.