mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
test: add test for display help (#1623)
This commit is contained in:
@ -38,7 +38,7 @@ pub fn run() -> eyre::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Commands to be executed
|
/// Commands to be executed
|
||||||
#[derive(Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
/// Start the node
|
/// Start the node
|
||||||
#[command(name = "node")]
|
#[command(name = "node")]
|
||||||
@ -74,7 +74,7 @@ pub enum Commands {
|
|||||||
TestVectors(test_vectors::Command),
|
TestVectors(test_vectors::Command),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(author, version = "0.1", about = "Reth", long_about = None)]
|
#[command(author, version = "0.1", about = "Reth", long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
/// The command to run
|
/// The command to run
|
||||||
@ -89,7 +89,7 @@ struct Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The log configuration.
|
/// The log configuration.
|
||||||
#[derive(Args)]
|
#[derive(Debug, Args)]
|
||||||
#[command(next_help_heading = "Logging")]
|
#[command(next_help_heading = "Logging")]
|
||||||
pub struct Logs {
|
pub struct Logs {
|
||||||
/// The path to put log files in.
|
/// The path to put log files in.
|
||||||
@ -131,7 +131,7 @@ impl Logs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The verbosity settings for the cli.
|
/// The verbosity settings for the cli.
|
||||||
#[derive(Args)]
|
#[derive(Debug, Copy, Clone, Args)]
|
||||||
#[command(next_help_heading = "Display")]
|
#[command(next_help_heading = "Display")]
|
||||||
pub struct Verbosity {
|
pub struct Verbosity {
|
||||||
/// Set the minimum log level.
|
/// Set the minimum log level.
|
||||||
@ -168,3 +168,23 @@ impl Verbosity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use clap::CommandFactory;
|
||||||
|
|
||||||
|
/// Tests that the help message is parsed correctly. This ensures that clap args are configured
|
||||||
|
/// correctly and no conflicts are introduced via attributes that would result in a panic at
|
||||||
|
/// runtime
|
||||||
|
#[test]
|
||||||
|
fn test_parse_help_all_subcommands() {
|
||||||
|
let reth = Cli::command();
|
||||||
|
for sub_command in reth.get_subcommands() {
|
||||||
|
let err = Cli::try_parse_from(["reth", sub_command.get_name(), "--help"]).unwrap_err();
|
||||||
|
// --help is treated as error, but
|
||||||
|
// > Not a true "error" as it means --help or similar was used. The help message will be sent to stdout.
|
||||||
|
assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -504,6 +504,12 @@ async fn run_network_until_shutdown<C>(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_help_node_command() {
|
||||||
|
let err = Command::try_parse_from(["reth", "--help"]).unwrap_err();
|
||||||
|
assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_common_node_command_chain_args() {
|
fn parse_common_node_command_chain_args() {
|
||||||
for chain in ["mainnet", "sepolia", "goerli"] {
|
for chain in ["mainnet", "sepolia", "goerli"] {
|
||||||
|
|||||||
Reference in New Issue
Block a user