From da399ab65408a1d201440ec8fd216461e4c17b2e Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 29 Dec 2024 13:10:50 +0100 Subject: [PATCH] Move more tests to insta --- src/export/asciidoc.rs | 174 ------------------------------- src/export/csv.rs | 15 ++- src/export/markup.rs | 188 --------------------------------- src/export/orgmode.rs | 137 ------------------------ src/export/tests.rs | 231 ++++++++++++++++++++++++++++++----------- 5 files changed, 180 insertions(+), 565 deletions(-) diff --git a/src/export/asciidoc.rs b/src/export/asciidoc.rs index 0e8401b..d2edfcc 100644 --- a/src/export/asciidoc.rs +++ b/src/export/asciidoc.rs @@ -65,177 +65,3 @@ fn test_asciidoc_exporter_table_header() { assert_eq!(expect, actual); } - -/// Test helper function to create unit-based header and horizontal line -/// independently from the markup functionality for Asciidoc. -#[cfg(test)] -fn cfg_test_table_header(unit_short_name: &str) -> String { - format!( - "[cols=\"<,>,>,>,>\"]\n|===\n| Command \n| Mean [{unit_short_name}] \n| Min [{unit_short_name}] \n| Max [{unit_short_name}] \n| Relative \n" - ) -} - -#[cfg(test)] -use crate::options::SortOrder; - -#[cfg(test)] -use crate::util::units::Unit; - -#[cfg(test)] -use crate::export::BenchmarkResult; - -#[cfg(test)] -use crate::export::Exporter; - -/// Integration test -#[test] -fn test_asciidoc_format_s() { - use std::collections::BTreeMap; - let exporter = AsciidocExporter::default(); - - let results = vec![ - BenchmarkResult { - command: String::from("FOO=1 BAR=2 command | 1"), - command_with_unused_parameters: String::from("FOO=1 BAR=2 command | 1"), - mean: 1.0, - stddev: Some(2.0), - median: 1.0, - user: 3.0, - system: 4.0, - min: 5.0, - max: 6.0, - times: Some(vec![7.0, 8.0, 9.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: { - let mut params = BTreeMap::new(); - params.insert("foo".into(), "1".into()); - params.insert("bar".into(), "2".into()); - params - }, - }, - BenchmarkResult { - command: String::from("FOO=1 BAR=7 command | 2"), - command_with_unused_parameters: String::from("FOO=1 BAR=7 command | 2"), - mean: 11.0, - stddev: Some(12.0), - median: 11.0, - user: 13.0, - system: 14.0, - min: 15.0, - max: 16.0, - times: Some(vec![17.0, 18.0, 19.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: { - let mut params = BTreeMap::new(); - params.insert("foo".into(), "1".into()); - params.insert("bar".into(), "7".into()); - params - }, - }, - ]; - - let actual = String::from_utf8( - exporter - .serialize(&results, Some(Unit::Second), SortOrder::Command) - .unwrap(), - ) - .unwrap(); - let expect = format!( - "{} -| `FOO=1 BAR=2 command \\| 1` -| 1.000 ± 2.000 -| 5.000 -| 6.000 -| 1.00 - -| `FOO=1 BAR=7 command \\| 2` -| 11.000 ± 12.000 -| 15.000 -| 16.000 -| 11.00 ± 25.06 -|=== -", - cfg_test_table_header("s") - ); - - assert_eq!(expect, actual); -} - -/// This test demonstrates that the given unit (ms) is used to set -/// the units for all entries. -#[test] -fn test_asciidoc_format_ms() { - use std::collections::BTreeMap; - let exporter = AsciidocExporter::default(); - - let results = vec![ - BenchmarkResult { - command: String::from("FOO=1 BAR=7 command | 2"), - command_with_unused_parameters: String::from("FOO=1 BAR=7 command | 2"), - mean: 0.011, - stddev: Some(0.012), - median: 0.011, - user: 0.013, - system: 0.014, - min: 0.015, - max: 0.016, - times: Some(vec![0.017, 0.018, 0.019]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: { - let mut params = BTreeMap::new(); - params.insert("foo".into(), "1".into()); - params.insert("bar".into(), "7".into()); - params - }, - }, - BenchmarkResult { - command: String::from("FOO=1 BAR=2 command | 1"), - command_with_unused_parameters: String::from("FOO=1 BAR=2 command | 1"), - mean: 1.0, - stddev: Some(2.0), - median: 1.0, - user: 3.0, - system: 4.0, - min: 5.0, - max: 6.0, - times: Some(vec![7.0, 8.0, 9.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: { - let mut params = BTreeMap::new(); - params.insert("foo".into(), "1".into()); - params.insert("bar".into(), "2".into()); - params - }, - }, - ]; - - let actual = String::from_utf8( - exporter - .serialize(&results, Some(Unit::MilliSecond), SortOrder::Command) - .unwrap(), - ) - .unwrap(); - let expect = format!( - "{} -| `FOO=1 BAR=7 command \\| 2` -| 11.0 ± 12.0 -| 15.0 -| 16.0 -| 1.00 - -| `FOO=1 BAR=2 command \\| 1` -| 1000.0 ± 2000.0 -| 5000.0 -| 6000.0 -| 90.91 ± 207.11 -|=== -", - cfg_test_table_header("ms") - ); - - assert_eq!(expect, actual); -} diff --git a/src/export/csv.rs b/src/export/csv.rs index 16c4189..8b5570a 100644 --- a/src/export/csv.rs +++ b/src/export/csv.rs @@ -107,18 +107,17 @@ fn test_csv() { }, }, ]; - let exps: String = String::from( - "command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo\n\ - FOO=one BAR=two command | 1,1,2,1,3,4,5,6,two,one\n\ - FOO=one BAR=seven command | 2,11,12,11,13,14,15,16.5,seven,one\n\ - ", - ); - let gens = String::from_utf8( + + let actual = String::from_utf8( exporter .serialize(&results, Some(Unit::Second), SortOrder::Command) .unwrap(), ) .unwrap(); - assert_eq!(exps, gens); + insta::assert_snapshot!(actual, @r#" + command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo + FOO=one BAR=two command | 1,1,2,1,3,4,5,6,two,one + FOO=one BAR=seven command | 2,11,12,11,13,14,15,16.5,seven,one + "#); } diff --git a/src/export/markup.rs b/src/export/markup.rs index 9ca2bfa..2de67c5 100644 --- a/src/export/markup.rs +++ b/src/export/markup.rs @@ -119,191 +119,3 @@ impl Exporter for T { Ok(table.as_bytes().to_vec()) } } - -/// Check unit resolving for timing results and given unit 's' -#[test] -fn test_determine_unit_from_results_unit_given_s() { - use std::collections::BTreeMap; - let results = vec![ - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - let unit = Some(Unit::Second); - - let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results)); - let markup_expected = Unit::Second; - - assert_eq!(markup_expected, markup_actual); -} - -/// Check unit resolving for timing results and given unit 'ms' -#[test] -fn test_determine_unit_from_results_unit_given_ms() { - use std::collections::BTreeMap; - let results = vec![ - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - let unit = Some(Unit::MilliSecond); - - let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results)); - let markup_expected = Unit::MilliSecond; - - assert_eq!(markup_expected, markup_actual); -} - -/// Check unit resolving for timing results using the first result entry as 's' -#[test] -fn test_determine_unit_from_results_unit_first_s() { - use std::collections::BTreeMap; - let results = vec![ - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - let unit = None; - - let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results)); - let markup_expected = Unit::Second; - - assert_eq!(markup_expected, markup_actual); -} - -/// Check unit resolving for timing results using the first result entry as 'ms' -#[test] -fn test_determine_unit_from_results_unit_first_ms() { - use std::collections::BTreeMap; - let results = vec![ - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - let unit = None; - - let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results)); - let markup_expected = Unit::MilliSecond; - - assert_eq!(markup_expected, markup_actual); -} - -/// Check unit resolving for not timing results and no given unit defaulting to 's' -#[test] -fn test_determine_unit_from_results_unit_default_s() { - let results: Vec = vec![]; - let unit = None; - - let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results)); - let markup_expected = Unit::Second; - - assert_eq!(markup_expected, markup_actual); -} diff --git a/src/export/orgmode.rs b/src/export/orgmode.rs index 6a256b8..76c8835 100644 --- a/src/export/orgmode.rs +++ b/src/export/orgmode.rs @@ -22,9 +22,6 @@ impl MarkupExporter for OrgmodeExporter { } } -#[cfg(test)] -use crate::options::SortOrder; - /// Check Emacs org-mode data row formatting #[test] fn test_orgmode_formatter_table_data() { @@ -52,137 +49,3 @@ fn test_orgmode_formatter_table_line() { assert_eq!(expect, actual); } - -/// Test helper function to create unit-based header and horizontal line -/// independently from the markup functionality for Emacs org-mode. -#[cfg(test)] -fn cfg_test_table_header(unit_short_name: String) -> String { - format!( - "| Command | Mean [{unit_short_name}] | Min [{unit_short_name}] | Max [{unit_short_name}] | Relative |\n|--+--+--+--+--|\n" - ) -} - -/// Ensure the Emacs org-mode output includes the table header and the multiple -/// benchmark results as a table. The list of actual times is not included -/// in the output. -/// -/// This also demonstrates that the first entry's units (ms) are used to set -/// the units for all entries when the time unit is not given. -#[test] -fn test_orgmode_format_ms() { - use super::Exporter; - use crate::benchmark::benchmark_result::BenchmarkResult; - use std::collections::BTreeMap; - - let exporter = OrgmodeExporter::default(); - - let results = vec![ - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - - let actual = String::from_utf8( - exporter - .serialize(&results, None, SortOrder::Command) - .unwrap(), - ) - .unwrap(); - let expect = format!( - "{}\ -| =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 | -| =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 | -", - cfg_test_table_header("ms".to_string()) - ); - - assert_eq!(expect, actual); -} - -/// This test demonstrates that the given unit (s) is used to set -/// the units for all entries. -#[test] -fn test_orgmode_format_s() { - use super::Exporter; - use crate::benchmark::benchmark_result::BenchmarkResult; - use crate::util::units::Unit; - use std::collections::BTreeMap; - - let exporter = OrgmodeExporter::default(); - - let results = vec![ - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; - - let actual = String::from_utf8( - exporter - .serialize(&results, Some(Unit::Second), SortOrder::Command) - .unwrap(), - ) - .unwrap(); - let expect = format!( - "{}\ -| =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | -| =sleep 0.1= | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | -", - cfg_test_table_header("s".to_string()) - ); - - assert_eq!(expect, actual); -} diff --git a/src/export/tests.rs b/src/export/tests.rs index 96a47ae..bd7ea79 100644 --- a/src/export/tests.rs +++ b/src/export/tests.rs @@ -1,26 +1,28 @@ use super::Exporter; use crate::benchmark::benchmark_result::BenchmarkResult; +use crate::export::asciidoc::AsciidocExporter; +use crate::export::orgmode::OrgmodeExporter; use crate::util::units::Unit; use crate::{export::markdown::MarkdownExporter, options::SortOrder}; use std::collections::BTreeMap; -fn get_markdown_output( +fn get_output( results: &[BenchmarkResult], unit: Option, sort_order: SortOrder, ) -> String { - let exporter = MarkdownExporter::default(); + let exporter = E::default(); String::from_utf8(exporter.serialize(results, unit, sort_order).unwrap()).unwrap() } -/// Ensure the markdown output includes the table header and the multiple +/// Ensure the makrup output includes the table header and the multiple /// benchmark results as a table. The list of actual times is not included /// in the output. /// /// This also demonstrates that the first entry's units (ms) are used to set -/// the units for all entries when the time unit is not given. +/// the units for all entries when the time unit is not specified. #[test] -fn test_markdown_format_ms() { +fn test_markup_export_auto_ms() { let results = [ BenchmarkResult { command: String::from("sleep 0.1"), @@ -54,18 +56,48 @@ fn test_markdown_format_ms() { }, ]; - insta::assert_snapshot!(get_markdown_output(&results, None, SortOrder::Command), @r#" + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | |:---|---:|---:|---:|---:| | `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 | | `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 | "#); + + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" + [cols="<,>,>,>,>"] + |=== + | Command + | Mean [ms] + | Min [ms] + | Max [ms] + | Relative + + | `sleep 0.1` + | 105.7 ± 1.6 + | 102.3 + | 108.0 + | 1.00 + + | `sleep 2` + | 2005.0 ± 2.0 + | 2002.0 + | 2008.0 + | 18.97 ± 0.29 + |=== + "#); + + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" + | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | + |--+--+--+--+--| + | =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 | + | =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 | + "#); } /// This (again) demonstrates that the first entry's units (s) are used to set /// the units for all entries when the time unit is not given. #[test] -fn test_markdown_format_s() { +fn test_markup_export_auto_s() { let results = [ BenchmarkResult { command: String::from("sleep 2"), @@ -99,69 +131,48 @@ fn test_markdown_format_s() { }, ]; - insta::assert_snapshot!(get_markdown_output(&results, None, SortOrder::Command), @r#" + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" | Command | Mean [s] | Min [s] | Max [s] | Relative | |:---|---:|---:|---:|---:| | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | "#); -} -/// The given time unit (s) is used to set the units for all entries. -#[test] -fn test_markdown_format_time_unit_s() { - let results = [ - BenchmarkResult { - command: String::from("sleep 2"), - command_with_unused_parameters: String::from("sleep 2"), - mean: 2.0050, - stddev: Some(0.0020), - median: 2.0050, - user: 0.0009, - system: 0.0012, - min: 2.0020, - max: 2.0080, - times: Some(vec![2.0, 2.0, 2.0]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - BenchmarkResult { - command: String::from("sleep 0.1"), - command_with_unused_parameters: String::from("sleep 0.1"), - mean: 0.1057, - stddev: Some(0.0016), - median: 0.1057, - user: 0.0009, - system: 0.0011, - min: 0.1023, - max: 0.1080, - times: Some(vec![0.1, 0.1, 0.1]), - memory_usage_byte: None, - exit_codes: vec![Some(0), Some(0), Some(0)], - parameters: BTreeMap::new(), - }, - ]; + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" + [cols="<,>,>,>,>"] + |=== + | Command + | Mean [s] + | Min [s] + | Max [s] + | Relative - insta::assert_snapshot!(get_markdown_output(&results, Some(Unit::Second), SortOrder::Command), @r#" - | Command | Mean [s] | Min [s] | Max [s] | Relative | - |:---|---:|---:|---:|---:| - | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | - | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | - "#); + | `sleep 2` + | 2.005 ± 0.002 + | 2.002 + | 2.008 + | 18.97 ± 0.29 - insta::assert_snapshot!(get_markdown_output(&results, Some(Unit::Second), SortOrder::MeanTime), @r#" - | Command | Mean [s] | Min [s] | Max [s] | Relative | - |:---|---:|---:|---:|---:| - | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | - | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | - "#); + | `sleep 0.1` + | 0.106 ± 0.002 + | 0.102 + | 0.108 + | 1.00 + |=== + "#); + + insta::assert_snapshot!(get_output::(&results, None, SortOrder::Command), @r#" + | Command | Mean [s] | Min [s] | Max [s] | Relative | + |--+--+--+--+--| + | =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | + | =sleep 0.1= | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | + "#); } /// This (again) demonstrates that the given time unit (ms) is used to set /// the units for all entries. #[test] -fn test_markdown_format_time_unit_ms() { +fn test_markup_export_manual_ms() { let timing_results = [ BenchmarkResult { command: String::from("sleep 2"), @@ -195,10 +206,114 @@ fn test_markdown_format_time_unit_ms() { }, ]; - insta::assert_snapshot!(get_markdown_output(&timing_results, Some(Unit::MilliSecond), SortOrder::Command), @r#" + insta::assert_snapshot!(get_output::(&timing_results, Some(Unit::MilliSecond), SortOrder::Command), @r#" | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | |:---|---:|---:|---:|---:| | `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 | | `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 | "#); + + insta::assert_snapshot!(get_output::(&timing_results, Some(Unit::MilliSecond), SortOrder::Command), @r#" + [cols="<,>,>,>,>"] + |=== + | Command + | Mean [ms] + | Min [ms] + | Max [ms] + | Relative + + | `sleep 2` + | 2005.0 ± 2.0 + | 2002.0 + | 2008.0 + | 18.97 ± 0.29 + + | `sleep 0.1` + | 105.7 ± 1.6 + | 102.3 + | 108.0 + | 1.00 + |=== + "#); + + insta::assert_snapshot!(get_output::(&timing_results, Some(Unit::MilliSecond), SortOrder::Command), @r#" + | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | + |--+--+--+--+--| + | =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 | + | =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 | + "#); +} + +/// The given time unit (s) is used to set the units for all entries. +#[test] +fn test_markup_export_manual_s() { + let results = [ + BenchmarkResult { + command: String::from("sleep 2"), + command_with_unused_parameters: String::from("sleep 2"), + mean: 2.0050, + stddev: Some(0.0020), + median: 2.0050, + user: 0.0009, + system: 0.0012, + min: 2.0020, + max: 2.0080, + times: Some(vec![2.0, 2.0, 2.0]), + memory_usage_byte: None, + exit_codes: vec![Some(0), Some(0), Some(0)], + parameters: BTreeMap::new(), + }, + BenchmarkResult { + command: String::from("sleep 0.1"), + command_with_unused_parameters: String::from("sleep 0.1"), + mean: 0.1057, + stddev: Some(0.0016), + median: 0.1057, + user: 0.0009, + system: 0.0011, + min: 0.1023, + max: 0.1080, + times: Some(vec![0.1, 0.1, 0.1]), + memory_usage_byte: None, + exit_codes: vec![Some(0), Some(0), Some(0)], + parameters: BTreeMap::new(), + }, + ]; + + insta::assert_snapshot!(get_output::(&results, Some(Unit::Second), SortOrder::Command), @r#" + | Command | Mean [s] | Min [s] | Max [s] | Relative | + |:---|---:|---:|---:|---:| + | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | + | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | + "#); + + insta::assert_snapshot!(get_output::(&results, Some(Unit::Second), SortOrder::MeanTime), @r#" + | Command | Mean [s] | Min [s] | Max [s] | Relative | + |:---|---:|---:|---:|---:| + | `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 | + | `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 | + "#); + + insta::assert_snapshot!(get_output::(&results, Some(Unit::Second), SortOrder::Command), @r#" + [cols="<,>,>,>,>"] + |=== + | Command + | Mean [s] + | Min [s] + | Max [s] + | Relative + + | `sleep 2` + | 2.005 ± 0.002 + | 2.002 + | 2.008 + | 18.97 ± 0.29 + + | `sleep 0.1` + | 0.106 ± 0.002 + | 0.102 + | 0.108 + | 1.00 + |=== + "#); }