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 4a26110 commit 1d463bf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 80 deletions.
52 changes: 23 additions & 29 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use snapbox::assert_data_eq;

use crate::common;

const CMD: &str = "bash";
type RuntimeBuilder = completest_pty::BashRuntimeBuilder;

#[test]
fn basic() {
let name = "my-app";
Expand Down Expand Up @@ -138,19 +141,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_static_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>("static", "exhaustive");
let mut runtime = common::load_runtime::<RuntimeBuilder>("static", "exhaustive");

let input = "exhaustive \t\t";
let expected = snapbox::str![[r#"
Expand All @@ -165,13 +167,12 @@ fn complete_static_toplevel() {
#[test]
#[cfg(unix)]
fn complete_static_file_hint() {
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 hint --file test\t";
let expected = snapbox::str!["exhaustive hint --file test % exhaustive hint --file tests/"];
Expand All @@ -182,13 +183,12 @@ fn complete_static_file_hint() {
#[test]
#[cfg(unix)]
fn complete_static_dir_hint() {
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");

{
use std::fs::File;
Expand Down Expand Up @@ -235,13 +235,12 @@ fn complete_static_dir_hint() {
#[test]
#[cfg(unix)]
fn complete_file_hint_escaping() {
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");

{
use std::fs::File;
Expand All @@ -265,13 +264,12 @@ fn complete_file_hint_escaping() {
#[test]
#[cfg(unix)]
fn complete_static_other_hint() {
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 hint --other \t";
let expected = snapbox::str!["exhaustive hint --other % exhaustive hint --other "];
Expand All @@ -282,19 +280,18 @@ fn complete_static_other_hint() {
#[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 @@ -309,13 +306,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 @@ -332,13 +328,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 @@ -354,13 +349,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
32 changes: 15 additions & 17 deletions clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::common;
use snapbox::assert_data_eq;

const CMD: &str = "elvish";
type RuntimeBuilder = completest_pty::ElvishRuntimeBuilder;

#[test]
fn basic() {
let name = "my-app";
Expand Down Expand Up @@ -137,19 +140,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 +179,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 +206,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 +229,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 +258,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
32 changes: 15 additions & 17 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::common;
use snapbox::assert_data_eq;

const CMD: &str = "fish";
type RuntimeBuilder = completest_pty::FishRuntimeBuilder;

#[test]
fn basic() {
let name = "my-app";
Expand Down Expand Up @@ -137,19 +140,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 +174,18 @@ bash (bash (shell)) fish (fish shell) zsh (zsh 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 +203,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 +241,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 +265,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 1d463bf

Please sign in to comment.