From 393ecd039ef55ea116712b483673f894fa773b9a Mon Sep 17 00:00:00 2001 From: Gordon Marler Date: Wed, 20 Mar 2024 10:03:44 -0400 Subject: [PATCH] Added --output_file option - added #cfg[test] block for main.rs --- Cargo.toml | 3 +++ src/main.rs | 23 ++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a450c64..f6b3bfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,9 @@ chrono = "*" inferno = "*" primal = "0.3" +[dev-dependencies] +assert_cmd = { version = "2" } +expect-test = { version = "1.4" } [build-dependencies] bindgen = "*" diff --git a/src/main.rs b/src/main.rs index 097807b..8f3d366 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,6 +72,9 @@ struct Cli { value_parser = sample_freq_in_range, )] sample_freq: u16, + /// Output file for Flame Graph in SVG format + #[arg(short, long, default_value = "flame.svg")] + output_file: PathBuf, } fn main() -> Result<(), Box> { @@ -128,15 +131,25 @@ fn main() -> Result<(), Box> { let mut options: flamegraph::Options<'_> = flamegraph::Options::default(); let data = folded.as_bytes(); - let flame_path = "flame.svg"; + let flame_path = args.output_file; let f = File::create(flame_path).unwrap(); flamegraph::from_reader(&mut options, data, f).unwrap(); Ok(()) } -#[test] -fn verify_cli() { - use clap::CommandFactory; - Cli::command().debug_assert() +#[cfg(test)] +mod tests { + use super::*; + use assert_cmd::Command; + use expect_test::expect; + + #[test] + fn verify_cli() { + use clap::CommandFactory; + Cli::command().debug_assert() + } + + #[test] + fn duration_arg() {} }