2022-02-06 12:06:27 +01:00
|
|
|
|
mod common;
|
2022-02-22 22:00:12 +01:00
|
|
|
|
use common::hyperfine;
|
2021-08-23 21:48:31 +02:00
|
|
|
|
|
2022-02-06 12:15:09 +01:00
|
|
|
|
use predicates::prelude::*;
|
|
|
|
|
|
|
2022-02-22 08:36:56 +01:00
|
|
|
|
pub fn hyperfine_debug() -> assert_cmd::Command {
|
|
|
|
|
|
let mut cmd = hyperfine();
|
|
|
|
|
|
cmd.arg("--debug-mode");
|
|
|
|
|
|
cmd
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-23 21:48:31 +02:00
|
|
|
|
#[test]
|
2022-02-22 22:15:15 +01:00
|
|
|
|
fn runs_successfully() {
|
2021-08-23 21:48:31 +02:00
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=2")
|
2021-08-23 22:00:33 +02:00
|
|
|
|
.arg("echo dummy benchmark")
|
2021-08-23 21:48:31 +02:00
|
|
|
|
.assert()
|
|
|
|
|
|
.success();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-11-11 14:10:58 +01:00
|
|
|
|
fn one_run_is_supported() {
|
2021-08-23 21:48:31 +02:00
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
2021-08-23 22:00:33 +02:00
|
|
|
|
.arg("echo dummy benchmark")
|
2021-08-23 21:48:31 +02:00
|
|
|
|
.assert()
|
2021-11-11 14:10:58 +01:00
|
|
|
|
.success();
|
2021-08-23 21:48:31 +02:00
|
|
|
|
}
|
2022-02-06 12:15:09 +01:00
|
|
|
|
|
2022-02-22 22:15:15 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn can_run_commands_without_a_shell() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("--show-output")
|
|
|
|
|
|
.arg("--shell=none")
|
|
|
|
|
|
.arg("echo 'hello world' argument2")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("hello world argument2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-06 12:15:09 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_with_wrong_number_of_command_name_arguments() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--command-name=a")
|
|
|
|
|
|
.arg("--command-name=b")
|
|
|
|
|
|
.arg("echo a")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains("Too many --command-name options"));
|
|
|
|
|
|
}
|
2022-02-06 13:48:39 +01:00
|
|
|
|
|
2022-02-06 13:54:09 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_with_wrong_number_of_prepare_options() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("--prepare=echo a")
|
|
|
|
|
|
.arg("--prepare=echo b")
|
|
|
|
|
|
.arg("echo a")
|
|
|
|
|
|
.arg("echo b")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success();
|
|
|
|
|
|
|
|
|
|
|
|
hyperfine()
|
2022-02-07 21:03:23 +01:00
|
|
|
|
.arg("--runs=1")
|
2022-02-06 13:54:09 +01:00
|
|
|
|
.arg("--prepare=echo a")
|
|
|
|
|
|
.arg("--prepare=echo b")
|
|
|
|
|
|
.arg("echo a")
|
|
|
|
|
|
.arg("echo b")
|
|
|
|
|
|
.arg("echo c")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"The '--prepare' option has to be provided",
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-06 17:23:43 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_with_duplicate_parameter_names() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--parameter-list")
|
|
|
|
|
|
.arg("x")
|
|
|
|
|
|
.arg("1,2,3")
|
|
|
|
|
|
.arg("--parameter-list")
|
|
|
|
|
|
.arg("x")
|
|
|
|
|
|
.arg("a,b,c")
|
|
|
|
|
|
.arg("echo test")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains("Duplicate parameter names: x"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-06 13:48:39 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_for_unknown_command() {
|
|
|
|
|
|
hyperfine()
|
2022-02-22 13:31:03 +01:00
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
2022-02-22 22:00:12 +01:00
|
|
|
|
"Command terminated with non-zero exit code",
|
2022-02-22 13:31:03 +01:00
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2022-02-22 22:00:12 +01:00
|
|
|
|
fn fails_for_unknown_command_without_shell() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--shell=none")
|
2022-02-21 20:45:04 +01:00
|
|
|
|
.arg("--runs=1")
|
2022-02-06 13:48:39 +01:00
|
|
|
|
.arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
2022-02-22 22:00:12 +01:00
|
|
|
|
"Failed to run command 'some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577'",
|
2022-02-06 13:48:39 +01:00
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-22 22:19:35 +01:00
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_for_failing_command_without_shell() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--shell=none")
|
|
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("false")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"Command terminated with non-zero exit code",
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-20 17:31:54 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_for_unknown_setup_command() {
|
|
|
|
|
|
hyperfine()
|
2022-02-21 20:45:04 +01:00
|
|
|
|
.arg("--runs=1")
|
2022-02-20 17:31:54 +01:00
|
|
|
|
.arg("--setup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
|
|
|
|
|
.arg("echo test")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"The setup command terminated with a non-zero exit code.",
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_for_unknown_cleanup_command() {
|
|
|
|
|
|
hyperfine()
|
2022-02-21 20:45:04 +01:00
|
|
|
|
.arg("--runs=1")
|
2022-02-20 17:31:54 +01:00
|
|
|
|
.arg("--cleanup=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
|
|
|
|
|
.arg("echo test")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"The cleanup command terminated with a non-zero exit code.",
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn fails_for_unknown_prepare_command() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--prepare=some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
|
|
|
|
|
|
.arg("echo test")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"The preparation command terminated with a non-zero exit code.",
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-06 13:48:39 +01:00
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn can_run_failing_commands_with_ignore_failure_option() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("false")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
|
|
|
|
|
.stderr(predicate::str::contains(
|
|
|
|
|
|
"Command terminated with non-zero exit code",
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("--ignore-failure")
|
|
|
|
|
|
.arg("false")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success();
|
|
|
|
|
|
}
|
2022-02-21 08:59:57 +01:00
|
|
|
|
|
2022-02-22 11:57:05 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn shows_output_of_benchmarked_command() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=2")
|
|
|
|
|
|
.arg("--command-name=dummy")
|
|
|
|
|
|
.arg("--show-output")
|
|
|
|
|
|
.arg("echo 4fd47015")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("4fd47015").count(2));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-21 08:59:57 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn runs_commands_using_user_defined_shell() {
|
|
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
|
|
|
|
|
.arg("--show-output")
|
|
|
|
|
|
.arg("--shell")
|
|
|
|
|
|
.arg("echo 'custom_shell' '--shell-arg'")
|
|
|
|
|
|
.arg("echo benchmark")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(
|
|
|
|
|
|
predicate::str::contains("custom_shell --shell-arg -c echo benchmark").or(
|
|
|
|
|
|
predicate::str::contains("custom_shell --shell-arg /C echo benchmark"),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2022-02-22 08:36:56 +01:00
|
|
|
|
|
2022-09-11 16:20:22 -05:00
|
|
|
|
#[test]
|
2023-03-15 08:58:52 +01:00
|
|
|
|
fn can_pass_input_to_command_from_a_file() {
|
2022-09-11 16:20:22 -05:00
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
2023-03-15 08:58:52 +01:00
|
|
|
|
.arg("--input=example_input_file.txt")
|
2022-09-11 16:20:22 -05:00
|
|
|
|
.arg("--show-output")
|
|
|
|
|
|
.arg("cat")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
2023-03-15 08:58:52 +01:00
|
|
|
|
.stdout(predicate::str::contains("This text is part of a file"));
|
2022-09-11 16:20:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2022-09-11 17:11:05 -05:00
|
|
|
|
fn fails_if_invalid_stdin_data_file_provided() {
|
2022-09-11 16:20:22 -05:00
|
|
|
|
hyperfine()
|
|
|
|
|
|
.arg("--runs=1")
|
2023-03-15 09:12:14 +01:00
|
|
|
|
.arg("--input=example_non_existent_file.txt")
|
2022-09-11 16:20:22 -05:00
|
|
|
|
.arg("--show-output")
|
|
|
|
|
|
.arg("cat")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.failure()
|
2022-09-11 17:11:05 -05:00
|
|
|
|
.stderr(predicate::str::contains(
|
2023-03-15 09:12:14 +01:00
|
|
|
|
"The file 'example_non_existent_file.txt' specified as '--input' does not exist",
|
2022-09-11 17:11:05 -05:00
|
|
|
|
));
|
2022-09-11 16:20:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-22 08:36:56 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn returns_mean_time_in_correct_unit() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("sleep 1.234")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("Time (mean ± σ): 1.234 s ±"));
|
|
|
|
|
|
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("sleep 0.123")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("Time (mean ± σ): 123.0 ms ±"));
|
|
|
|
|
|
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("--time-unit=millisecond")
|
|
|
|
|
|
.arg("sleep 1.234")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("Time (mean ± σ): 1234.0 ms ±"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn performs_ten_runs_for_slow_commands() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("sleep 0.5")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("10 runs"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn performs_three_seconds_of_benchmarking_for_fast_commands() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("sleep 0.01")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("300 runs"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2022-02-22 08:58:57 +01:00
|
|
|
|
fn takes_shell_spawning_time_into_account_for_computing_number_of_runs() {
|
2022-02-22 08:36:56 +01:00
|
|
|
|
hyperfine_debug()
|
2022-02-22 08:58:57 +01:00
|
|
|
|
.arg("--shell=sleep 0.02")
|
2022-02-22 08:36:56 +01:00
|
|
|
|
.arg("sleep 0.01")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("100 runs"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-22 08:58:57 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn takes_preparation_command_into_account_for_computing_number_of_runs() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("--prepare=sleep 0.02")
|
|
|
|
|
|
.arg("sleep 0.01")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("100 runs"));
|
|
|
|
|
|
|
|
|
|
|
|
// Shell overhead needs to be added to both the prepare command and the actual command,
|
|
|
|
|
|
// leading to a total benchmark time of (prepare + shell + cmd + shell = 0.1 s)
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("--shell=sleep 0.01")
|
|
|
|
|
|
.arg("--prepare=sleep 0.03")
|
|
|
|
|
|
.arg("sleep 0.05")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(predicate::str::contains("30 runs"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-22 08:36:56 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn shows_benchmark_comparison_with_relative_times() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("sleep 1.0")
|
|
|
|
|
|
.arg("sleep 2.0")
|
|
|
|
|
|
.arg("sleep 3.0")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(
|
|
|
|
|
|
predicate::str::contains("2.00 ± 0.00 times faster")
|
|
|
|
|
|
.and(predicate::str::contains("3.00 ± 0.00 times faster")),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn performs_all_benchmarks_in_parameter_scan() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("--parameter-scan")
|
|
|
|
|
|
.arg("time")
|
|
|
|
|
|
.arg("30")
|
|
|
|
|
|
.arg("45")
|
|
|
|
|
|
.arg("--parameter-step-size")
|
|
|
|
|
|
.arg("5")
|
|
|
|
|
|
.arg("sleep {time}")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(
|
|
|
|
|
|
predicate::str::contains("Benchmark 1: sleep 30")
|
|
|
|
|
|
.and(predicate::str::contains("Benchmark 2: sleep 35"))
|
|
|
|
|
|
.and(predicate::str::contains("Benchmark 3: sleep 40"))
|
|
|
|
|
|
.and(predicate::str::contains("Benchmark 4: sleep 45"))
|
|
|
|
|
|
.and(predicate::str::contains("Benchmark 5: sleep 50").not()),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2023-04-20 12:49:53 +02:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn intermediate_results_are_not_exported_to_stdout() {
|
|
|
|
|
|
hyperfine_debug()
|
|
|
|
|
|
.arg("--style=none") // To only see the Markdown export on stdout
|
|
|
|
|
|
.arg("--export-markdown")
|
|
|
|
|
|
.arg("-")
|
|
|
|
|
|
.arg("sleep 1")
|
|
|
|
|
|
.arg("sleep 2")
|
|
|
|
|
|
.assert()
|
|
|
|
|
|
.success()
|
|
|
|
|
|
.stdout(
|
|
|
|
|
|
(predicate::str::contains("sleep 1").count(1))
|
|
|
|
|
|
.and(predicate::str::contains("sleep 2").count(1)),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|