-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathsimple-bencher.rs
More file actions
160 lines (148 loc) · 4.22 KB
/
Copy pathsimple-bencher.rs
File metadata and controls
160 lines (148 loc) · 4.22 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
use assert_cmd::assert::OutputAssertExt;
use predicates::prelude::*;
use predicates::str::contains;
mod helpers;
use helpers::*;
const DIR: &str = "tests/simple-bencher.in";
#[test]
fn test_simple_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_simple_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_simple_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_simple_build_single() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.args(["--bench", "another_bencher_example"])
.assert()
.success()
.stderr(contains("Built 1 benchmark suite(s)"))
.stderr(contains("another_bencher_example"));
teardown(dir);
}
#[test]
fn test_simple_build_and_run_single() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.args(["--bench", "another_bencher_example"])
.assert()
.success();
cargo_codspeed(&dir)
.arg("run")
.args(["--bench", "another_bencher_example"])
.assert()
.success()
.stderr(contains("Finished running 1 benchmark suite(s)"))
.stderr(contains("another_bencher_example"));
teardown(dir);
}
#[test]
fn test_simple_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_simple_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_simple_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);
}
#[test]
fn test_benchmark_counting_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("Done running bencher_example (2 benchmarks)"))
.stderr(contains(
"Done running another_bencher_example (2 benchmarks)",
))
.stderr(contains(
"Finished running 2 benchmark suite(s) (4 benchmarks total)",
));
teardown(dir);
}
#[test]
fn test_single_benchmark_counting_with_details() {
let dir = setup(DIR, Project::Simple);
cargo_codspeed(&dir)
.arg("build")
.args(["--bench", "bencher_example"])
.assert()
.success();
cargo_codspeed(&dir)
.arg("run")
.arg("--details")
.args(["--bench", "bencher_example"])
.assert()
.success()
.stderr(contains("Done running bencher_example (2 benchmarks)"))
.stderr(contains(
"Finished running 1 benchmark suite(s) (2 benchmarks total)",
));
teardown(dir);
}