mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 00:40:19 +00:00
Fix prepare and conclude behaviour and add tests.
This commit is contained in:
1 parent
9806ed7694
commit
d4749b015f
4 files changed
+306
-6
No files matched your search
@@ -155,6 +155,20 @@ fn test_compute_relative_speed() {
|
||||
assert_relative_eq!(2.5, annotated_results[2].relative_speed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compute_relative_speed_with_reference() {
|
||||
use approx::assert_relative_eq;
|
||||
|
||||
let results = vec![create_result("cmd2", 2.0), create_result("cmd3", 5.0)];
|
||||
let reference = create_result("cmd2", 4.0);
|
||||
|
||||
let annotated_results =
|
||||
compute_with_check_from_reference(&results, &reference, SortOrder::Command).unwrap();
|
||||
|
||||
assert_relative_eq!(2.0, annotated_results[0].relative_speed);
|
||||
assert_relative_eq!(1.25, annotated_results[1].relative_speed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compute_relative_speed_for_zero_times() {
|
||||
let results = vec![create_result("cmd1", 1.0), create_result("cmd2", 0.0)];
|
||||
|
||||
+10
-6
@@ -437,21 +437,25 @@ impl Options {
|
||||
}
|
||||
|
||||
pub fn validate_against_command_list(&self, commands: &Commands) -> Result<()> {
|
||||
let num_commands = commands.num_commands()
|
||||
+ if self.reference_command.is_some() {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
if let Some(preparation_command) = &self.preparation_command {
|
||||
ensure!(
|
||||
preparation_command.len() <= 1
|
||||
|| commands.num_commands() == preparation_command.len(),
|
||||
preparation_command.len() <= 1 || num_commands == preparation_command.len(),
|
||||
"The '--prepare' option has to be provided just once or N times, where N is the \
|
||||
number of benchmark commands."
|
||||
number of benchmark commands including a potential reference."
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(conclusion_command) = &self.conclusion_command {
|
||||
ensure!(
|
||||
conclusion_command.len() <= 1
|
||||
|| commands.num_commands() == conclusion_command.len(),
|
||||
conclusion_command.len() <= 1 || num_commands == conclusion_command.len(),
|
||||
"The '--conclude' option has to be provided just once or N times, where N is the \
|
||||
number of benchmark commands."
|
||||
number of benchmark commands including a potential reference."
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user