Skip to content

Commit e75f187

Browse files
authored
Merge pull request #330 from apiraino/custom-satisfy-terms
Add custom "Satisfies" terms
2 parents 0859f47 + ba7eb63 commit e75f187

File tree

8 files changed

+129
-4
lines changed

8 files changed

+129
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v0.6.9
4+
5+
### Added
6+
- Flags `--term-old` and `--term-new` to allow custom messages when bisecting a regression.
7+
38
## v0.6.8
49

510
### Added

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ This tool bisects either Rust nightlies or CI artifacts.
66

77
[**Documentation**](https://rust-lang.github.io/cargo-bisect-rustc/)
88

9+
To run the documentation book locally, install [mdBook](https://github.com/rust-lang/mdBook):
10+
11+
``` sh
12+
cd guide
13+
mdbook serve # launch a local server to allow you to easily see and update changes you make
14+
mdbook build # build the book HTML
15+
```
16+
917
## License
1018

1119
Licensed under either of

guide/src/tutorial.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,34 @@ cargo bisect-rustc --script=./test.sh \
135135

136136
[issue #53157]: https://github.com/rust-lang/rust/issues/53157
137137
[issue #55036]: https://github.com/rust-lang/rust/issues/55036
138+
139+
## Custom bisection messages
140+
141+
[Available from v0.6.9]
142+
143+
You can add custom messages when bisecting a regression. Taking inspiration from git-bisect, with `term-new` and `term-old` you can set custom messages to indicate if a regression matches the condition set by the bisection.
144+
145+
Example:
146+
```sh
147+
cargo bisect-rustc \
148+
--start=2018-08-14 \
149+
--end=2018-10-11 \
150+
--term-old "No, this build did not reproduce the regression, compile successful" \
151+
--term-new "Yes, this build reproduces the regression, compile error"
152+
```
153+
154+
Note that `--term-{old,new}` are aware of the `--regress` parameter. If the bisection is looking for a build to reproduce a regression (i.e. `--regress {error,ice}`), `--term-old` indicates a point in time where the regression does not reproduce and `--term-new` indicates that it does.
155+
156+
On the other hand, if `--regress {non-error,non-ice,success}` you are looking into bisecting when a condition of error stopped being reproducible (e.g. some faulty code does not produce an error anymore). In this case `cargo-bisect` flips the meaning of these two parameters.
157+
158+
Example:
159+
```sh
160+
cargo bisect-rustc \
161+
--start=2018-08-14 \
162+
--end=2018-10-11 \
163+
--regress=success \
164+
--term-old "This build does not compile" \
165+
--term-new "This build compiles"
166+
```
167+
168+
See [`--regress`](usage.html#regression-check) for more details.

src/least_satisfying.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::BTreeMap;
22
use std::fmt;
33

4+
use crate::RegressOn;
5+
46
pub fn least_satisfying<T, P>(slice: &[T], mut predicate: P) -> usize
57
where
68
T: fmt::Display + fmt::Debug,
@@ -172,6 +174,32 @@ pub enum Satisfies {
172174
Unknown,
173175
}
174176

177+
impl Satisfies {
178+
pub fn msg_with_context(&self, regress: &RegressOn, term_old: &str, term_new: &str) -> String {
179+
let msg_yes = if regress == &RegressOn::Error || regress == &RegressOn::Ice {
180+
// YES: compiles, does not reproduce the regression
181+
term_new
182+
} else {
183+
// NO: compile error, reproduces the regression
184+
term_old
185+
};
186+
187+
let msg_no = if regress == &RegressOn::Error || regress == &RegressOn::Ice {
188+
// YES: compile error
189+
term_old
190+
} else {
191+
// NO: compiles
192+
term_new
193+
};
194+
195+
match self {
196+
Self::Yes => msg_yes.to_string(),
197+
Self::No => msg_no.to_string(),
198+
Self::Unknown => "Unable to figure out if the condition matched".to_string(),
199+
}
200+
}
201+
}
202+
175203
impl fmt::Display for Satisfies {
176204
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
177205
write!(f, "{:?}", self)

src/main.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ a date (YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA."
180180

181181
#[arg(long, help = "Do not install cargo [default: install cargo]")]
182182
without_cargo: bool,
183+
184+
#[arg(
185+
long,
186+
default_value = "Test condition NOT matched",
187+
help = "Text shown when a test fails to match the condition requested"
188+
)]
189+
term_new: Option<String>,
190+
191+
#[arg(
192+
long,
193+
default_value = "Test condition matched",
194+
help = "Text shown when a test does match the condition requested"
195+
)]
196+
term_old: Option<String>,
183197
}
184198

185199
pub type GitDate = NaiveDate;
@@ -337,7 +351,7 @@ enum RegressOn {
337351
/// Marks test outcome as `Regressed` if and only if the `rustc`
338352
/// process issues a diagnostic indicating that an internal compiler error
339353
/// (ICE) occurred. This covers the use case for when you want to bisect to
340-
/// see when an ICE was introduced pon a codebase that is meant to produce
354+
/// see when an ICE was introduced on a codebase that is meant to produce
341355
/// a clean error.
342356
Ice,
343357

@@ -865,6 +879,9 @@ impl Config {
865879
t: &Toolchain,
866880
dl_spec: &DownloadParams,
867881
) -> Result<Satisfies, InstallError> {
882+
let regress = self.args.regress;
883+
let term_old = self.args.term_old.clone().unwrap_or_default();
884+
let term_new = self.args.term_new.clone().unwrap_or_default();
868885
match t.install(&self.client, dl_spec) {
869886
Ok(()) => {
870887
let outcome = t.test(self);
@@ -873,7 +890,11 @@ impl Config {
873890
TestOutcome::Baseline => Satisfies::No,
874891
TestOutcome::Regressed => Satisfies::Yes,
875892
};
876-
eprintln!("RESULT: {}, ===> {}", t, r);
893+
eprintln!(
894+
"RESULT: {}, ===> {}",
895+
t,
896+
r.msg_with_context(&regress, &term_old, &term_new)
897+
);
877898
remove_toolchain(self, t, dl_spec);
878899
eprintln!();
879900
Ok(r)

tests/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Quick guidelines for tests
2+
3+
If you change the command line parameters of cargo-bisect, tests will fail, the crate `trycmd` is used to keep track of these changes.
4+
5+
In order to update files under `tests/cmd/*.{stdout,stderr}`, run the test generating the new expected results:
6+
7+
`TRYCMD=dump cargo test`
8+
9+
it will create a `dump` directory in the project root. Then move `dump/*.{stdout,stderr}` into `./tests/cmd` and run tests again. They should be all green now.
10+
11+
Note: if the local tests generate output specific for your machine, please replace that output with `[..]`, else CI tests will fail. Example:
12+
13+
``` diff
14+
- --host <HOST> Host triple for the compiler [default: x86_64-unknown-linux-gnu]
15+
+ --host <HOST> Host triple for the compiler [default: [..]]
16+
```
17+
18+
See the trycmd [documentation](https://docs.rs/trycmd/latest/trycmd/) for more info.

tests/cmd/h.stdout

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Options:
1515
(YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA.
1616
--force-install Force installation over existing artifacts
1717
-h, --help Print help (see more with '--help')
18-
...
18+
--host <HOST> Host triple for the compiler [default: [..]]
1919
--install <INSTALL> Install the given artifact
2020
--preserve Preserve the downloaded artifacts
2121
--preserve-target Preserve the target directory used for builds
@@ -28,6 +28,10 @@ Options:
2828
-t, --timeout <TIMEOUT> Assume failure after specified number of seconds (for bisecting
2929
hangs)
3030
--target <TARGET> Cross-compilation target platform
31+
--term-new <TERM_NEW> Text shown when a test fails to match the condition requested
32+
[default: "Test condition NOT matched"]
33+
--term-old <TERM_OLD> Text shown when a test does match the condition requested [default:
34+
"Test condition matched"]
3135
--test-dir <TEST_DIR> Root directory for tests [default: .]
3236
-v, --verbose...
3337
-V, --version Print version

tests/cmd/help.stdout

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Options:
6565
fixed
6666
- ice: Marks test outcome as `Regressed` if and only if the `rustc` process issues a
6767
diagnostic indicating that an internal compiler error (ICE) occurred. This covers the
68-
use case for when you want to bisect to see when an ICE was introduced pon a codebase
68+
use case for when you want to bisect to see when an ICE was introduced on a codebase
6969
that is meant to produce a clean error
7070
- non-ice: Marks test outcome as `Regressed` if and only if the `rustc` process does not
7171
issue a diagnostic indicating that an internal compiler error (ICE) occurred. This
@@ -91,6 +91,16 @@ Options:
9191
--target <TARGET>
9292
Cross-compilation target platform
9393

94+
--term-new <TERM_NEW>
95+
Text shown when a test fails to match the condition requested
96+
97+
[default: "Test condition NOT matched"]
98+
99+
--term-old <TERM_OLD>
100+
Text shown when a test does match the condition requested
101+
102+
[default: "Test condition matched"]
103+
94104
--test-dir <TEST_DIR>
95105
Root directory for tests
96106

0 commit comments

Comments
 (0)