|
| 1 | +use assert_cmd::assert::OutputAssertExt; |
| 2 | +use predicates::str::contains; |
| 3 | + |
| 4 | +mod helpers; |
| 5 | +use helpers::*; |
| 6 | + |
| 7 | +const DIR: &str = "tests/simple-criterion.in"; |
| 8 | + |
| 9 | +#[test] |
| 10 | +fn test_criterion_run_without_build() { |
| 11 | + let dir = setup(DIR, Project::Simple); |
| 12 | + cargo_codspeed(&dir) |
| 13 | + .arg("run") |
| 14 | + .assert() |
| 15 | + .failure() |
| 16 | + .stderr(contains("Error: No benchmarks found.")); |
| 17 | + teardown(dir); |
| 18 | +} |
| 19 | + |
| 20 | +#[test] |
| 21 | +fn test_criterion_build() { |
| 22 | + let dir = setup(DIR, Project::Simple); |
| 23 | + cargo_codspeed(&dir) |
| 24 | + .arg("build") |
| 25 | + .assert() |
| 26 | + .success() |
| 27 | + .stderr(contains("Built 2 benchmark suite(s)")); |
| 28 | + teardown(dir); |
| 29 | +} |
| 30 | + |
| 31 | +#[test] |
| 32 | +fn test_criterion_build_and_run() { |
| 33 | + let dir = setup(DIR, Project::Simple); |
| 34 | + cargo_codspeed(&dir).arg("build").assert().success(); |
| 35 | + cargo_codspeed(&dir) |
| 36 | + .arg("run") |
| 37 | + .assert() |
| 38 | + .success() |
| 39 | + .stderr(contains("Finished running 2 benchmark suite(s)")); |
| 40 | + teardown(dir); |
| 41 | +} |
| 42 | + |
| 43 | +#[test] |
| 44 | +fn test_criterion_build_single() { |
| 45 | + let dir = setup(DIR, Project::Simple); |
| 46 | + cargo_codspeed(&dir) |
| 47 | + .arg("build") |
| 48 | + .arg("another_criterion_example") |
| 49 | + .assert() |
| 50 | + .success() |
| 51 | + .stderr(contains("Built 1 benchmark suite(s)")) |
| 52 | + .stderr(contains("another_criterion_example")); |
| 53 | + teardown(dir); |
| 54 | +} |
| 55 | + |
| 56 | +#[test] |
| 57 | +fn test_criterion_build_and_run_single() { |
| 58 | + let dir = setup(DIR, Project::Simple); |
| 59 | + cargo_codspeed(&dir) |
| 60 | + .arg("build") |
| 61 | + .arg("another_criterion_example") |
| 62 | + .assert() |
| 63 | + .success(); |
| 64 | + cargo_codspeed(&dir) |
| 65 | + .arg("run") |
| 66 | + .arg("another_criterion_example") |
| 67 | + .assert() |
| 68 | + .success() |
| 69 | + .stderr(contains("Finished running 1 benchmark suite(s)")) |
| 70 | + .stderr(contains("another_criterion_example")); |
| 71 | + teardown(dir); |
| 72 | +} |
| 73 | + |
| 74 | +#[test] |
| 75 | +fn test_criterion_cargo_bench_no_run() { |
| 76 | + let dir = setup(DIR, Project::Simple); |
| 77 | + std::process::Command::new("cargo") |
| 78 | + .arg("bench") |
| 79 | + .arg("--no-run") |
| 80 | + .current_dir(&dir) |
| 81 | + .assert() |
| 82 | + .success(); |
| 83 | + teardown(dir); |
| 84 | +} |
0 commit comments