diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/xflags-macros/tests | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/xflags-macros/tests')
-rw-r--r-- | vendor/xflags-macros/tests/data/help.rs (renamed from vendor/xflags-macros/tests/it/src/help.rs) | 5 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/data/repeated_pos.rs (renamed from vendor/xflags-macros/tests/it/src/repeated_pos.rs) | 3 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/data/smoke.rs (renamed from vendor/xflags-macros/tests/it/src/smoke.rs) | 3 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/data/subcommands.rs (renamed from vendor/xflags-macros/tests/it/src/subcommands.rs) | 3 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/it/help.rs | 84 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/it/main.rs | 36 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/it/repeated_pos.rs | 64 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/it/smoke.rs | 61 | ||||
-rw-r--r-- | vendor/xflags-macros/tests/it/subcommands.rs | 174 |
9 files changed, 218 insertions, 215 deletions
diff --git a/vendor/xflags-macros/tests/it/src/help.rs b/vendor/xflags-macros/tests/data/help.rs index d552c1e63..f252e34fa 100644 --- a/vendor/xflags-macros/tests/it/src/help.rs +++ b/vendor/xflags-macros/tests/data/help.rs @@ -2,16 +2,17 @@ xflags! { /// Does stuff /// /// Helpful stuff. - cmd helpful + cmd helpful { /// With an arg. optional src: PathBuf + /// Another arg. /// /// This time, we provide some extra info about the /// arg. Maybe some caveats, or what kinds of /// values are accepted. optional extra: String - { + /// And a switch. required -s, --switch diff --git a/vendor/xflags-macros/tests/it/src/repeated_pos.rs b/vendor/xflags-macros/tests/data/repeated_pos.rs index 4106c65eb..be7c552e0 100644 --- a/vendor/xflags-macros/tests/it/src/repeated_pos.rs +++ b/vendor/xflags-macros/tests/data/repeated_pos.rs @@ -1,9 +1,8 @@ xflags! { - cmd RepeatedPos + cmd RepeatedPos { required a: PathBuf optional b: u32 optional c: OsString repeated rest: OsString - { } } diff --git a/vendor/xflags-macros/tests/it/src/smoke.rs b/vendor/xflags-macros/tests/data/smoke.rs index ae303779e..55da2d3ef 100644 --- a/vendor/xflags-macros/tests/it/src/smoke.rs +++ b/vendor/xflags-macros/tests/data/smoke.rs @@ -1,10 +1,9 @@ xflags! { /// LSP server for rust. - cmd rust-analyzer + cmd rust-analyzer { required workspace: PathBuf /// Number of concurrent jobs. optional jobs: u32 - { /// Path to log file. By default, logs go to stderr. optional --log-file path: PathBuf repeated -v, --verbose diff --git a/vendor/xflags-macros/tests/it/src/subcommands.rs b/vendor/xflags-macros/tests/data/subcommands.rs index 70a0a5049..45fab8232 100644 --- a/vendor/xflags-macros/tests/it/src/subcommands.rs +++ b/vendor/xflags-macros/tests/data/subcommands.rs @@ -11,9 +11,8 @@ xflags! { } } - cmd analysis-stats + cmd analysis-stats { required path: PathBuf - { optional --parallel } } diff --git a/vendor/xflags-macros/tests/it/help.rs b/vendor/xflags-macros/tests/it/help.rs index 36a966485..f17062988 100644 --- a/vendor/xflags-macros/tests/it/help.rs +++ b/vendor/xflags-macros/tests/it/help.rs @@ -21,7 +21,10 @@ pub struct Sub { } impl Helpful { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result<Self> { @@ -35,6 +38,9 @@ impl Helpful { } impl Helpful { + fn from_env_or_exit_() -> Self { + Self::from_env_().unwrap_or_else(|err| err.exit()) + } fn from_env_() -> xflags::Result<Self> { let mut p = xflags::rt::Parser::new_from_env(); Self::parse_(&mut p) @@ -47,68 +53,51 @@ impl Helpful { impl Helpful { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { + #![allow(non_snake_case)] let mut switch = Vec::new(); - let mut src = (false, Vec::new()); let mut extra = (false, Vec::new()); + let mut sub__flag = Vec::new(); - let mut sub_ = None; + let mut state_ = 0u8; while let Some(arg_) = p_.pop_flag() { match arg_ { - Ok(flag_) => match flag_.as_str() { - "--switch" | "-s" => switch.push(()), + Ok(flag_) => match (state_, flag_.as_str()) { + (0 | 1, "--switch" | "-s") => switch.push(()), + (0 | 1, "--help" | "-h") => return Err(p_.help(Self::HELP_)), + (1, "--flag" | "-f") => sub__flag.push(()), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - match arg_.to_str().unwrap_or("") { - "sub" => { - sub_ = Some(HelpfulCmd::Sub(Sub::parse_(p_)?)); - break; + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, "sub") => state_ = 1, + (0, _) => { + if let (done_ @ false, buf_) = &mut src { + buf_.push(arg_.into()); + *done_ = true; + continue; } - _ => (), - } - if let (done_ @ false, buf_) = &mut src { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - if let (done_ @ false, buf_) = &mut extra { - buf_.push(p_.value_from_str::<String>("extra", arg_)?); - *done_ = true; - continue; + if let (done_ @ false, buf_) = &mut extra { + buf_.push(p_.value_from_str::<String>("extra", arg_)?); + *done_ = true; + continue; + } + return Err(p_.unexpected_arg(arg_)); } - return Err(p_.unexpected_arg(arg_)); - } + _ => return Err(p_.unexpected_arg(arg_)), + }, } } - Ok(Self { + Ok(Helpful { + switch: p_.required("--switch", switch)?, src: p_.optional("src", src.1)?, extra: p_.optional("extra", extra.1)?, - - switch: p_.required("--switch", switch)?, - subcommand: p_.subcommand(sub_)?, + subcommand: match state_ { + 1 => HelpfulCmd::Sub(Sub { flag: p_.optional("--flag", sub__flag)?.is_some() }), + _ => return Err(p_.subcommand_required()), + }, }) } } - -impl Sub { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut flag = Vec::new(); - - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--flag" | "-f" => flag.push(()), - _ => return Err(p_.unexpected_flag(&flag_)), - }, - Err(arg_) => { - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { flag: p_.optional("--flag", flag)?.is_some() }) - } -} impl Helpful { const HELP_: &'static str = "\ helpful @@ -131,6 +120,9 @@ OPTIONS: -s, --switch And a switch. + -h, --help + Prints help information. + SUBCOMMANDS: helpful sub diff --git a/vendor/xflags-macros/tests/it/main.rs b/vendor/xflags-macros/tests/it/main.rs index 1ce058814..7d77bda36 100644 --- a/vendor/xflags-macros/tests/it/main.rs +++ b/vendor/xflags-macros/tests/it/main.rs @@ -67,9 +67,10 @@ fn smoke() { "-n 92 --werbose", expect![[r#"unexpected flag: `--werbose`"#]], ); - check(smoke::RustAnalyzer::from_vec, "", expect![[r#"flag is required: `workspace`"#]]); + check(smoke::RustAnalyzer::from_vec, "", expect!["flag is required: `--number`"]); check(smoke::RustAnalyzer::from_vec, ".", expect![[r#"flag is required: `--number`"#]]); check(smoke::RustAnalyzer::from_vec, "-n", expect![[r#"expected a value for `-n`"#]]); + check(smoke::RustAnalyzer::from_vec, "-n 92", expect!["flag is required: `workspace`"]); check( smoke::RustAnalyzer::from_vec, "-n lol", @@ -196,3 +197,36 @@ fn subcommands() { check(subcommands::RustAnalyzer::from_vec, "", expect![[r#"subcommand is required"#]]); } + +#[test] +fn subcommand_flag_inheritance() { + check( + subcommands::RustAnalyzer::from_vec, + "server watch --verbose --dir .", + expect![[r#" + RustAnalyzer { + verbose: 1, + subcommand: Server( + Server { + dir: Some( + ".", + ), + subcommand: Watch( + Watch, + ), + }, + ), + } + "#]], + ); + check( + subcommands::RustAnalyzer::from_vec, + "analysis-stats --verbose --dir .", + expect!["unexpected flag: `--dir`"], + ); + check( + subcommands::RustAnalyzer::from_vec, + "--dir . server", + expect!["unexpected flag: `--dir`"], + ); +} diff --git a/vendor/xflags-macros/tests/it/repeated_pos.rs b/vendor/xflags-macros/tests/it/repeated_pos.rs index 334af371d..b11b90717 100644 --- a/vendor/xflags-macros/tests/it/repeated_pos.rs +++ b/vendor/xflags-macros/tests/it/repeated_pos.rs @@ -10,7 +10,10 @@ pub struct RepeatedPos { } impl RepeatedPos { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result<Self> { @@ -24,6 +27,9 @@ impl RepeatedPos { } impl RepeatedPos { + fn from_env_or_exit_() -> Self { + Self::from_env_().unwrap_or_else(|err| err.exit()) + } fn from_env_() -> xflags::Result<Self> { let mut p = xflags::rt::Parser::new_from_env(); Self::parse_(&mut p) @@ -36,41 +42,47 @@ impl RepeatedPos { impl RepeatedPos { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { + #![allow(non_snake_case)] let mut a = (false, Vec::new()); let mut b = (false, Vec::new()); let mut c = (false, Vec::new()); let mut rest = (false, Vec::new()); + let mut state_ = 0u8; while let Some(arg_) = p_.pop_flag() { match arg_ { - Ok(flag_) => match flag_.as_str() { + Ok(flag_) => match (state_, flag_.as_str()) { + (0, "--help" | "-h") => return Err(p_.help(Self::HELP_)), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - if let (done_ @ false, buf_) = &mut a { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - if let (done_ @ false, buf_) = &mut b { - buf_.push(p_.value_from_str::<u32>("b", arg_)?); - *done_ = true; - continue; + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, _) => { + if let (done_ @ false, buf_) = &mut a { + buf_.push(arg_.into()); + *done_ = true; + continue; + } + if let (done_ @ false, buf_) = &mut b { + buf_.push(p_.value_from_str::<u32>("b", arg_)?); + *done_ = true; + continue; + } + if let (done_ @ false, buf_) = &mut c { + buf_.push(arg_.into()); + *done_ = true; + continue; + } + if let (false, buf_) = &mut rest { + buf_.push(arg_.into()); + continue; + } + return Err(p_.unexpected_arg(arg_)); } - if let (done_ @ false, buf_) = &mut c { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - if let (false, buf_) = &mut rest { - buf_.push(arg_.into()); - continue; - } - return Err(p_.unexpected_arg(arg_)); - } + _ => return Err(p_.unexpected_arg(arg_)), + }, } } - Ok(Self { + Ok(RepeatedPos { a: p_.required("a", a.1)?, b: p_.optional("b", b.1)?, c: p_.optional("c", c.1)?, @@ -90,5 +102,9 @@ ARGS: [c] <rest>... + +OPTIONS: + -h, --help + Prints help information. "; } diff --git a/vendor/xflags-macros/tests/it/smoke.rs b/vendor/xflags-macros/tests/it/smoke.rs index e22c4f1f6..f2ebbb712 100644 --- a/vendor/xflags-macros/tests/it/smoke.rs +++ b/vendor/xflags-macros/tests/it/smoke.rs @@ -14,7 +14,10 @@ pub struct RustAnalyzer { } impl RustAnalyzer { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result<Self> { @@ -28,6 +31,9 @@ impl RustAnalyzer { } impl RustAnalyzer { + fn from_env_or_exit_() -> Self { + Self::from_env_().unwrap_or_else(|err| err.exit()) + } fn from_env_() -> xflags::Result<Self> { let mut p = xflags::rt::Parser::new_from_env(); Self::parse_(&mut p) @@ -40,49 +46,53 @@ impl RustAnalyzer { impl RustAnalyzer { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { + #![allow(non_snake_case)] let mut log_file = Vec::new(); let mut verbose = Vec::new(); let mut number = Vec::new(); let mut data = Vec::new(); let mut emoji = Vec::new(); - let mut workspace = (false, Vec::new()); let mut jobs = (false, Vec::new()); + let mut state_ = 0u8; while let Some(arg_) = p_.pop_flag() { match arg_ { - Ok(flag_) => match flag_.as_str() { - "--log-file" => log_file.push(p_.next_value(&flag_)?.into()), - "--verbose" | "-v" => verbose.push(()), - "--number" | "-n" => number.push(p_.next_value_from_str::<u32>(&flag_)?), - "--data" => data.push(p_.next_value(&flag_)?.into()), - "--emoji" => emoji.push(()), + Ok(flag_) => match (state_, flag_.as_str()) { + (0, "--log-file") => log_file.push(p_.next_value(&flag_)?.into()), + (0, "--verbose" | "-v") => verbose.push(()), + (0, "--number" | "-n") => number.push(p_.next_value_from_str::<u32>(&flag_)?), + (0, "--data") => data.push(p_.next_value(&flag_)?.into()), + (0, "--emoji") => emoji.push(()), + (0, "--help" | "-h") => return Err(p_.help(Self::HELP_)), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - if let (done_ @ false, buf_) = &mut workspace { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - if let (done_ @ false, buf_) = &mut jobs { - buf_.push(p_.value_from_str::<u32>("jobs", arg_)?); - *done_ = true; - continue; + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, _) => { + if let (done_ @ false, buf_) = &mut workspace { + buf_.push(arg_.into()); + *done_ = true; + continue; + } + if let (done_ @ false, buf_) = &mut jobs { + buf_.push(p_.value_from_str::<u32>("jobs", arg_)?); + *done_ = true; + continue; + } + return Err(p_.unexpected_arg(arg_)); } - return Err(p_.unexpected_arg(arg_)); - } + _ => return Err(p_.unexpected_arg(arg_)), + }, } } - Ok(Self { - workspace: p_.required("workspace", workspace.1)?, - jobs: p_.optional("jobs", jobs.1)?, - + Ok(RustAnalyzer { log_file: p_.optional("--log-file", log_file)?, verbose: verbose.len() as u32, number: p_.required("--number", number)?, data: data, emoji: p_.optional("--emoji", emoji)?.is_some(), + workspace: p_.required("workspace", workspace.1)?, + jobs: p_.optional("jobs", jobs.1)?, }) } } @@ -108,5 +118,8 @@ OPTIONS: --data <value> --emoji + + -h, --help + Prints help information. "; } diff --git a/vendor/xflags-macros/tests/it/subcommands.rs b/vendor/xflags-macros/tests/it/subcommands.rs index 7941a395d..4d0a64923 100644 --- a/vendor/xflags-macros/tests/it/subcommands.rs +++ b/vendor/xflags-macros/tests/it/subcommands.rs @@ -41,7 +41,10 @@ pub struct AnalysisStats { } impl RustAnalyzer { - pub const HELP: &'static str = Self::HELP_; + #[allow(dead_code)] + pub fn from_env_or_exit() -> Self { + Self::from_env_or_exit_() + } #[allow(dead_code)] pub fn from_env() -> xflags::Result<Self> { @@ -55,6 +58,9 @@ impl RustAnalyzer { } impl RustAnalyzer { + fn from_env_or_exit_() -> Self { + Self::from_env_().unwrap_or_else(|err| err.exit()) + } fn from_env_() -> xflags::Result<Self> { let mut p = xflags::rt::Parser::new_from_env(); Self::parse_(&mut p) @@ -67,130 +73,71 @@ impl RustAnalyzer { impl RustAnalyzer { fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { + #![allow(non_snake_case)] let mut verbose = Vec::new(); + let mut server__dir = Vec::new(); + let mut server__launch__log = Vec::new(); + let mut analysis_stats__parallel = Vec::new(); + let mut analysis_stats__path = (false, Vec::new()); - let mut sub_ = None; + let mut state_ = 0u8; while let Some(arg_) = p_.pop_flag() { match arg_ { - Ok(flag_) => match flag_.as_str() { - "--verbose" | "-v" => verbose.push(()), + Ok(flag_) => match (state_, flag_.as_str()) { + (0 | 1 | 2 | 3 | 4, "--verbose" | "-v") => verbose.push(()), + (0 | 1 | 2 | 3 | 4, "--help" | "-h") => return Err(p_.help(Self::HELP_)), + (1 | 2 | 3, "--dir") => server__dir.push(p_.next_value(&flag_)?.into()), + (1, _) => { + p_.push_back(Ok(flag_)); + state_ = 2; + } + (2, "--log") => server__launch__log.push(()), + (4, "--parallel") => analysis_stats__parallel.push(()), _ => return Err(p_.unexpected_flag(&flag_)), }, - Err(arg_) => { - match arg_.to_str().unwrap_or("") { - "server" => { - sub_ = Some(RustAnalyzerCmd::Server(Server::parse_(p_)?)); - break; - } - "analysis-stats" => { - sub_ = Some(RustAnalyzerCmd::AnalysisStats(AnalysisStats::parse_(p_)?)); - break; - } - _ => (), + Err(arg_) => match (state_, arg_.to_str().unwrap_or("")) { + (0, "server") => state_ = 1, + (0, "analysis-stats") => state_ = 4, + (0, _) => { + return Err(p_.unexpected_arg(arg_)); } - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { verbose: verbose.len() as u32, subcommand: p_.subcommand(sub_)? }) - } -} - -impl Server { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut dir = Vec::new(); - - let mut sub_ = None; - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--dir" => dir.push(p_.next_value(&flag_)?.into()), - _ => { - p_.push_back(Ok(flag_)); - break; + (1, "watch") => state_ = 3, + (1, _) => { + p_.push_back(Err(arg_)); + state_ = 2; } - }, - Err(arg_) => { - match arg_.to_str().unwrap_or("") { - "watch" => { - sub_ = Some(ServerCmd::Watch(Watch::parse_(p_)?)); - break; + (4, _) => { + if let (done_ @ false, buf_) = &mut analysis_stats__path { + buf_.push(arg_.into()); + *done_ = true; + continue; } - _ => (), + return Err(p_.unexpected_arg(arg_)); } - p_.push_back(Err(arg_)); - break; - } - } - } - if sub_.is_none() { - sub_ = Some(ServerCmd::Launch(Launch::parse_(p_)?)); - } - Ok(Self { dir: p_.optional("--dir", dir)?, subcommand: p_.subcommand(sub_)? }) - } -} - -impl Launch { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut log = Vec::new(); - - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--log" => log.push(()), - _ => return Err(p_.unexpected_flag(&flag_)), - }, - Err(arg_) => { - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { log: p_.optional("--log", log)?.is_some() }) - } -} - -impl Watch { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - _ => return Err(p_.unexpected_flag(&flag_)), + _ => return Err(p_.unexpected_arg(arg_)), }, - Err(arg_) => { - return Err(p_.unexpected_arg(arg_)); - } } } - Ok(Self {}) - } -} - -impl AnalysisStats { - fn parse_(p_: &mut xflags::rt::Parser) -> xflags::Result<Self> { - let mut parallel = Vec::new(); - - let mut path = (false, Vec::new()); - - while let Some(arg_) = p_.pop_flag() { - match arg_ { - Ok(flag_) => match flag_.as_str() { - "--parallel" => parallel.push(()), - _ => return Err(p_.unexpected_flag(&flag_)), - }, - Err(arg_) => { - if let (done_ @ false, buf_) = &mut path { - buf_.push(arg_.into()); - *done_ = true; - continue; - } - return Err(p_.unexpected_arg(arg_)); - } - } - } - Ok(Self { - path: p_.required("path", path.1)?, - - parallel: p_.optional("--parallel", parallel)?.is_some(), + state_ = if state_ == 1 { 2 } else { state_ }; + Ok(RustAnalyzer { + verbose: verbose.len() as u32, + subcommand: match state_ { + 2 | 3 => RustAnalyzerCmd::Server(Server { + dir: p_.optional("--dir", server__dir)?, + subcommand: match state_ { + 2 => ServerCmd::Launch(Launch { + log: p_.optional("--log", server__launch__log)?.is_some(), + }), + 3 => ServerCmd::Watch(Watch {}), + _ => return Err(p_.subcommand_required()), + }, + }), + 4 => RustAnalyzerCmd::AnalysisStats(AnalysisStats { + parallel: p_.optional("--parallel", analysis_stats__parallel)?.is_some(), + path: p_.required("path", analysis_stats__path.1)?, + }), + _ => return Err(p_.subcommand_required()), + }, }) } } @@ -201,6 +148,9 @@ rust-analyzer OPTIONS: -v, --verbose + -h, --help + Prints help information. + SUBCOMMANDS: rust-analyzer server |