Skip to content

Commit

Permalink
test: Add test of derive functionality
Browse files Browse the repository at this point in the history
It was noticed that between clap-rs#4443 and clap-rs#4432, an issue in the behavior
was that the derive api handles tasks with values slightly differently
than the declarative api. Added a test to show parity between
declaritive and derive api.
  • Loading branch information
Calder-Ty committed Nov 30, 2022
1 parent b0f6289 commit 330141c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion clap_mangen/Cargo.toml
Expand Up @@ -45,7 +45,7 @@ clap = { path = "../", version = "4.0.0", default-features = false, features = [

[dev-dependencies]
snapbox = { version = "0.4", features = ["diff"] }
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help"] }
clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "help", "derive"] }

[features]
default = []
Expand Down
14 changes: 0 additions & 14 deletions clap_mangen/tests/common.rs
Expand Up @@ -312,17 +312,3 @@ pub fn possible_values_command(name: &'static str) -> clap::Command {
]),
)
}

/// Checks to make sure boolean valued "Flag options" do not generate
/// suggestions for a parameter. i.e:
/// --boolean_flag=BOOLEAN_FLAG
///
/// This is both confusing and suggest erroneous behavior as clap will fail if you
/// pass a value to a boolean flag
pub fn flag_without_value(name: &'static str) -> clap::Command {
clap::Command::new(name).arg(
clap::Arg::new("is_bool")
.long("is_bool")
.action(clap::ArgAction::SetTrue),
)
}
14 changes: 14 additions & 0 deletions clap_mangen/tests/derive.rs
@@ -0,0 +1,14 @@
use clap::Parser;

/// Checks to make sure boolean valued "Flag options" do not generate
/// suggestions for a parameter. i.e:
/// --boolean_flag=BOOLEAN_FLAG
///
/// This is both confusing and suggest erroneous behavior as clap will fail if you
/// pass a value to a boolean flag
#[derive(Parser, Debug)]
#[command(name = "my-app")]
pub struct FlagWithoutValue {
#[clap(long)]
boolean_flag: bool,
}
6 changes: 4 additions & 2 deletions clap_mangen/tests/roff.rs
@@ -1,4 +1,7 @@
mod common;
mod derive;

use clap::CommandFactory;

#[test]
fn basic() {
Expand Down Expand Up @@ -72,8 +75,7 @@ fn possible_values() {

#[test]
fn flag_without_value() {
let name = "my-app";
let cmd = common::flag_without_value(name);
let cmd = derive::FlagWithoutValue::command();
common::assert_matches_path("tests/snapshots/flag_without_value.bash.roff", cmd);
}

Expand Down
11 changes: 7 additions & 4 deletions clap_mangen/tests/snapshots/flag_without_value.bash.roff
Expand Up @@ -2,14 +2,17 @@
.el .ds Aq '
.TH my-app 1 "my-app "
.SH NAME
my/-app
my/-app /- Checks to make sure boolean valued "Flag options" do not generate suggestions for a parameter. i.e: /-/-boolean_flag=BOOLEAN_FLAG
.SH SYNOPSIS
/fBmy/-app/fR [/fB/-/-is_bool/fR] [/fB/-h/fR|/fB/-/-help/fR]
/fBmy/-app/fR [/fB/-/-boolean/-flag/fR] [/fB/-h/fR|/fB/-/-help/fR]
.SH DESCRIPTION
Checks to make sure boolean valued "Flag options" do not generate suggestions for a parameter. i.e: /-/-boolean_flag=BOOLEAN_FLAG
.PP
This is both confusing and suggest erroneous behavior as clap will fail if you pass a value to a boolean flag
.SH OPTIONS
.TP
/fB/-/-is_bool/fR
/fB/-/-boolean/-flag/fR

.TP
/fB/-h/fR, /fB/-/-help/fR
Print help information
Print help information (use `/-h` for a summary)

0 comments on commit 330141c

Please sign in to comment.