-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsimple-criterion.rs
More file actions
170 lines (157 loc) · 4.8 KB
/
simple-criterion.rs
File metadata and controls
170 lines (157 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use assert_cmd::assert::OutputAssertExt;
use predicates::{prelude::PredicateBooleanExt, str::contains};
mod helpers;
use helpers::*;
const DIR: &str = "tests/simple-criterion.in";
const FIB_BENCH_NAME: &str = "fib 20";
const BUBBLE_SORT_BENCH_NAME: &str = "bubble sort";
#[test]
fn test_criterion_run_without_build() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("run")
.assert()
.failure()
.stderr(contains("Error: No benchmarks found."));
teardown(dir);
}
#[test]
fn test_criterion_build() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.assert()
.success()
.stderr(contains("Built 2 benchmark suite(s)"));
teardown(dir);
}
#[test]
fn test_criterion_build_and_run() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir).arg("build").assert().success();
cargo_codspeed(&dir)
.arg("run")
.assert()
.success()
.stderr(contains("Finished running 2 benchmark suite(s)"));
teardown(dir);
}
#[test]
fn test_criterion_build_single() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.args(["--bench", "another_criterion_example"])
.assert()
.success()
.stderr(contains("Built 1 benchmark suite(s)"))
.stderr(contains("another_criterion_example"));
teardown(dir);
}
#[test]
fn test_criterion_build_and_run_single() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.args(["--bench", "another_criterion_example"])
.assert()
.success();
cargo_codspeed(&dir)
.arg("run")
.args(["--bench", "another_criterion_example"])
.assert()
.success()
.stdout(contains("another_criterion_example"))
.stderr(contains("Finished running 1 benchmark suite(s)"));
teardown(dir);
}
#[test]
fn test_criterion_build_and_run_filtered_by_name() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir).arg("build").assert().success();
cargo_codspeed(&dir)
.arg("run")
.arg("fib 20")
.assert()
.success()
.stdout(contains(FIB_BENCH_NAME))
.stdout(contains(BUBBLE_SORT_BENCH_NAME).not())
.stderr(contains("Finished running 2 benchmark suite(s)"));
cargo_codspeed(&dir)
.arg("run")
.arg("bu.*le")
.assert()
.success()
.stdout(contains(FIB_BENCH_NAME).not())
.stdout(contains(BUBBLE_SORT_BENCH_NAME))
.stderr(contains("Finished running 2 benchmark suite(s)"));
teardown(dir);
}
#[test]
fn test_criterion_build_and_run_filtered_by_name_single() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir).arg("build").assert().success();
cargo_codspeed(&dir)
.arg("run")
.arg("bu.*le")
.args(["--bench", "criterion_example"])
.assert()
.success()
.stdout(contains(BUBBLE_SORT_BENCH_NAME).not()) // We are filtering with a name that is not in the selected benchmark
.stdout(contains(FIB_BENCH_NAME).not())
.stderr(contains("Finished running 1 benchmark suite(s)"));
cargo_codspeed(&dir)
.arg("run")
.arg("fib")
.args(["--bench", "criterion_example"])
.assert()
.success()
.stdout(contains(FIB_BENCH_NAME))
.stdout(contains(BUBBLE_SORT_BENCH_NAME).not())
.stderr(contains("Finished running 1 benchmark suite(s)"));
teardown(dir);
}
#[test]
fn test_criterion_cargo_bench_no_run() {
let dir = setup(DIR, Project::Simple);
std::process::Command::new("cargo")
.arg("bench")
.arg("--no-run")
.current_dir(&dir)
.assert()
.success();
teardown(dir);
}
#[test]
fn test_criterion_run_without_details() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir).arg("build").assert().success();
cargo_codspeed(&dir)
.arg("run")
.assert()
.success()
.stderr(contains("Finished running 2 benchmark suite(s)"))
.stderr(predicates::str::contains("benchmarks total").not())
.stdout(
predicates::str::is_match(r" Checked: .* \([0-9]+(\.[0-9]+)? (ns|us|ms|s)\)")
.unwrap()
.not(),
);
teardown(dir);
}
#[test]
fn test_criterion_run_with_details() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir).arg("build").assert().success();
cargo_codspeed(&dir)
.arg("run")
.arg("--details")
.assert()
.success()
.stderr(contains("benchmarks total"))
.stderr(contains("Done running"))
.stdout(
predicates::str::is_match(r" Checked: .* \([0-9]+(\.[0-9]+)? (ns|us|ms|s)\)").unwrap(),
);
teardown(dir);
}