Skip to content

Commit 9430a46

Browse files
committed
refactor least_satisfying to eliminate duplicated start date checks
This occurred during nighty testing when a start date is defined on the command line
1 parent 25e566a commit 9430a46

File tree

2 files changed

+79
-19
lines changed

2 files changed

+79
-19
lines changed

src/least_satisfying.rs

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::collections::BTreeMap;
99
use std::fmt;
1010

11-
pub fn least_satisfying<T, P>(slice: &[T], mut predicate: P) -> usize
11+
pub fn least_satisfying<T, P>(slice: &[T], start_check: bool, mut predicate: P) -> usize
1212
where
1313
T: fmt::Display + fmt::Debug,
1414
P: FnMut(&T) -> Satisfies,
@@ -18,12 +18,14 @@ where
1818
let mut unknown_ranges: Vec<(usize, usize)> = Vec::new();
1919
let mut rm_no = 0; // presume that the slice starts with a no
2020

21-
eprintln!("verifying the start of the range does not reproduce the regression");
22-
match predicate(rm_no) {
23-
Satisfies::No => {
24-
eprintln!("confirmed the start of the range does not reproduce the regression")
21+
if start_check {
22+
eprintln!("verifying the start of the range does not reproduce the regression");
23+
match predicate(rm_no) {
24+
Satisfies::No => {
25+
eprintln!("confirmed the start of the range does not reproduce the regression")
26+
}
27+
_ => panic!("the start of the range to test must not reproduce the regression"),
2528
}
26-
_ => panic!("the start of the range to test must not reproduce the regression"),
2729
}
2830

2931
let mut lm_yes = slice.len() - 1; // presume that the slice ends with a yes
@@ -103,59 +105,111 @@ mod tests {
103105
}
104106
}
105107

106-
let res = least_satisfying(&satisfies_v, |i| *i);
108+
let res = least_satisfying(&satisfies_v, true, |i| *i);
107109
let exp = first_yes.unwrap();
108110
TestResult::from_bool(res == exp)
109111
}
110112

111113
#[test]
112114
fn least_satisfying_1() {
113115
assert_eq!(
114-
least_satisfying(&[No, Unknown, Unknown, No, Yes], |i| *i),
116+
least_satisfying(&[No, Unknown, Unknown, No, Yes], true,|i| *i),
117+
4
118+
);
119+
}
120+
121+
#[test]
122+
fn least_satisfying_1f() {
123+
assert_eq!(
124+
least_satisfying(&[No, Unknown, Unknown, No, Yes], false,|i| *i),
115125
4
116126
);
117127
}
118128

119129
#[test]
120130
fn least_satisfying_2() {
121131
assert_eq!(
122-
least_satisfying(&[No, Unknown, Yes, Unknown, Yes], |i| *i),
132+
least_satisfying(&[No, Unknown, Yes, Unknown, Yes], true, |i| *i),
133+
2
134+
);
135+
}
136+
137+
#[test]
138+
fn least_satisfying_2f() {
139+
assert_eq!(
140+
least_satisfying(&[No, Unknown, Yes, Unknown, Yes], false, |i| *i),
123141
2
124142
);
125143
}
126144

127145
#[test]
128146
fn least_satisfying_3() {
129-
assert_eq!(least_satisfying(&[No, No, No, No, Yes], |i| *i), 4);
147+
assert_eq!(least_satisfying(&[No, No, No, No, Yes], true, |i| *i), 4);
148+
}
149+
150+
#[test]
151+
fn least_satisfying_3f() {
152+
assert_eq!(least_satisfying(&[No, No, No, No, Yes], false, |i| *i), 4);
130153
}
131154

132155
#[test]
133156
fn least_satisfying_4() {
134-
assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], |i| *i), 2);
157+
assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], true, |i| *i), 2);
158+
}
159+
160+
#[test]
161+
fn least_satisfying_4f() {
162+
assert_eq!(least_satisfying(&[No, No, Yes, Yes, Yes], false, |i| *i), 2);
135163
}
136164

137165
#[test]
138166
fn least_satisfying_5() {
139-
assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], |i| *i), 1);
167+
assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], true, |i| *i), 1);
168+
}
169+
170+
#[test]
171+
fn least_satisfying_5f() {
172+
assert_eq!(least_satisfying(&[No, Yes, Yes, Yes, Yes], false, |i| *i), 1);
140173
}
141174

142175
#[test]
143176
fn least_satisfying_6() {
144177
assert_eq!(
145-
least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], |i| *i),
178+
least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], true, |i| *i),
179+
1
180+
);
181+
}
182+
183+
#[test]
184+
fn least_satisfying_6f() {
185+
assert_eq!(
186+
least_satisfying(&[No, Yes, Yes, Unknown, Unknown, Yes, Unknown, Yes], false, |i| *i),
146187
1
147188
);
148189
}
149190

150191
#[test]
151192
fn least_satisfying_7() {
152-
assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], |i| *i), 1);
193+
assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], true, |i| *i), 1);
194+
}
195+
196+
#[test]
197+
fn least_satisfying_7f() {
198+
assert_eq!(least_satisfying(&[No, Yes, Unknown, Yes], false, |i| *i), 1);
153199
}
154200

155201
#[test]
156202
fn least_satisfying_8() {
157203
assert_eq!(
158-
least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], |i| *i),
204+
least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], true,|i| *i),
205+
5
206+
);
207+
}
208+
209+
#[test]
210+
fn least_satisfying_8f() {
211+
assert_eq!(
212+
least_satisfying(&[No, Unknown, No, No, Unknown, Yes, Yes], false,|i| *i),
159213
5
160214
);
161215
}

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,17 +1298,19 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
12981298
}
12991299
match t.install(client, &dl_spec) {
13001300
Ok(()) => {
1301+
eprintln!("verifying the start of the range does not reproduce the regression");
13011302
let outcome = t.test(&cfg);
13021303

13031304
if !cfg.args.preserve {
13041305
let _ = t.remove(&dl_spec);
13051306
}
13061307

13071308
if let TestOutcome::Baseline = outcome {
1309+
eprintln!("confirmed {} does not reproduce the regression", t);
13081310
first_success = Some(nightly_date);
13091311
break;
13101312
} else if has_start {
1311-
return Err(format_err!("the --start nightly has the regression"))?;
1313+
return Err(format_err!("the start of the range to test must not reproduce the regression"))?;
13121314
} else {
13131315
last_failure = nightly_date;
13141316
}
@@ -1322,7 +1324,7 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
13221324
let _ = t.remove(&dl_spec);
13231325
}
13241326
if has_start {
1325-
return Err(format_err!("could not find the --start nightly"))?;
1327+
return Err(format_err!("could not find {}", t))?;
13261328
}
13271329
}
13281330
Err(e) => {
@@ -1344,7 +1346,11 @@ fn bisect_nightlies(cfg: &Config, client: &Client) -> Result<BisectionResult, Er
13441346
ToolchainSpec::Nightly { date: last_failure },
13451347
);
13461348

1347-
let found = least_satisfying(&toolchains, |t| {
1349+
// First success check has been performed above so it is not necessary
1350+
// to repeat it within the least_satisfying function in the call here.
1351+
// Set `start_check` to false to prevent a repeat check on the same
1352+
// nightly in `least_satisfying`
1353+
let found = least_satisfying(&toolchains, false, |t| {
13481354
match t.install(&client, &dl_spec) {
13491355
Ok(()) => {
13501356
let outcome = t.test(&cfg);
@@ -1488,7 +1494,7 @@ fn bisect_ci_in_commits(
14881494
.collect::<Vec<_>>();
14891495

14901496
eprintln!("testing commits");
1491-
let found = least_satisfying(&toolchains, |t| {
1497+
let found = least_satisfying(&toolchains, true,|t| {
14921498
eprintln!("installing {}", t);
14931499
match t.install(&client, &dl_spec) {
14941500
Ok(()) => {

0 commit comments

Comments
 (0)