mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Move more tests to insta
This commit is contained in:
1 parent
7a9d04d35c
commit
da399ab654
5 files changed
+180
-565
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user