Files
hyperfine/tests/integration_tests.rs
T

103 lines
2.2 KiB
Rust
Raw Normal View History

2022-02-06 12:06:27 +01:00
mod common;
use common::hyperfine;
2021-08-23 21:48:31 +02:00
2022-02-06 12:15:09 +01:00
use predicates::prelude::*;
2021-08-23 21:48:31 +02:00
#[test]
fn hyperfine_runs_successfully() {
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
#[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",
));
}
#[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()
.arg("some-nonexisting-program-b5d9574198b7e4b12a71fa4747c0a577")
.assert()
.failure()
.stderr(predicate::str::contains(
"Command terminated with non-zero exit code",
));
}
#[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();
}