Skip to content

Commit f83e4d7

Browse files
Rollup merge of rust-lang#50806 - oli-obk:gesundheit, r=ehuss
Add `bless` x.py subcommand for easy ui test replacement fixes rust-lang#49815 r? @nikomatsakis
2 parents c95267e + 0ac2fd1 commit f83e4d7

File tree

12 files changed

+161
-70
lines changed

12 files changed

+161
-70
lines changed

src/bootstrap/bin/rustc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ fn main() {
297297
}
298298

299299
if verbose > 1 {
300-
eprintln!("rustc command: {:?}", cmd);
300+
eprintln!(
301+
"rustc command: {:?}={:?} {:?}",
302+
bootstrap::util::dylib_path_var(),
303+
env::join_paths(&dylib_path).unwrap(),
304+
cmd,
305+
);
301306
eprintln!("sysroot: {:?}", sysroot);
302307
eprintln!("libdir: {:?}", libdir);
303308
}

src/bootstrap/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,7 @@ mod __test {
14601460
rustc_args: vec![],
14611461
fail_fast: true,
14621462
doc_tests: DocTests::No,
1463+
bless: false,
14631464
};
14641465

14651466
let build = Build::new(config);

src/bootstrap/flags.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub enum Subcommand {
5959
},
6060
Test {
6161
paths: Vec<PathBuf>,
62+
/// Whether to automatically update stderr/stdout files
63+
bless: bool,
6264
test_args: Vec<String>,
6365
rustc_args: Vec<String>,
6466
fail_fast: bool,
@@ -173,6 +175,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`");
173175
);
174176
opts.optflag("", "no-doc", "do not run doc tests");
175177
opts.optflag("", "doc", "only run doc tests");
178+
opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests");
176179
},
177180
"bench" => { opts.optmulti("", "test-args", "extra arguments", "ARGS"); },
178181
"clean" => { opts.optflag("", "all", "clean all build artifacts"); },
@@ -258,6 +261,7 @@ Arguments:
258261
./x.py test src/test/run-pass
259262
./x.py test src/libstd --test-args hash_map
260263
./x.py test src/libstd --stage 0
264+
./x.py test src/test/ui --bless
261265
262266
If no arguments are passed then the complete artifacts for that stage are
263267
compiled and tested.
@@ -322,6 +326,7 @@ Arguments:
322326
"test" => {
323327
Subcommand::Test {
324328
paths,
329+
bless: matches.opt_present("bless"),
325330
test_args: matches.opt_strs("test-args"),
326331
rustc_args: matches.opt_strs("rustc-args"),
327332
fail_fast: !matches.opt_present("no-fail-fast"),
@@ -424,6 +429,13 @@ impl Subcommand {
424429
_ => DocTests::Yes,
425430
}
426431
}
432+
433+
pub fn bless(&self) -> bool {
434+
match *self {
435+
Subcommand::Test { bless, .. } => bless,
436+
_ => false,
437+
}
438+
}
427439
}
428440

429441
fn split(s: Vec<String>) -> Vec<String> {

src/bootstrap/test.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ pub enum TestKind {
4747
Bench,
4848
}
4949

50+
impl From<Kind> for TestKind {
51+
fn from(kind: Kind) -> Self {
52+
match kind {
53+
Kind::Test => TestKind::Test,
54+
Kind::Bench => TestKind::Bench,
55+
_ => panic!("unexpected kind in crate: {:?}", kind)
56+
}
57+
}
58+
}
59+
5060
impl TestKind {
5161
// Return the cargo subcommand for this test kind
5262
fn subcommand(self) -> &'static str {
@@ -951,6 +961,10 @@ impl Step for Compiletest {
951961
cmd.arg("--host").arg(&*compiler.host);
952962
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
953963

964+
if builder.config.cmd.bless() {
965+
cmd.arg("--bless");
966+
}
967+
954968
if let Some(ref nodejs) = builder.config.nodejs {
955969
cmd.arg("--nodejs").arg(nodejs);
956970
}
@@ -1342,13 +1356,7 @@ impl Step for CrateLibrustc {
13421356

13431357
for krate in builder.in_tree_crates("rustc-main") {
13441358
if run.path.ends_with(&krate.path) {
1345-
let test_kind = if builder.kind == Kind::Test {
1346-
TestKind::Test
1347-
} else if builder.kind == Kind::Bench {
1348-
TestKind::Bench
1349-
} else {
1350-
panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1351-
};
1359+
let test_kind = builder.kind.into();
13521360

13531361
builder.ensure(CrateLibrustc {
13541362
compiler,
@@ -1394,13 +1402,7 @@ impl Step for CrateNotDefault {
13941402
let builder = run.builder;
13951403
let compiler = builder.compiler(builder.top_stage, run.host);
13961404

1397-
let test_kind = if builder.kind == Kind::Test {
1398-
TestKind::Test
1399-
} else if builder.kind == Kind::Bench {
1400-
TestKind::Bench
1401-
} else {
1402-
panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1403-
};
1405+
let test_kind = builder.kind.into();
14041406

14051407
builder.ensure(CrateNotDefault {
14061408
compiler,
@@ -1461,13 +1463,7 @@ impl Step for Crate {
14611463
let compiler = builder.compiler(builder.top_stage, run.host);
14621464

14631465
let make = |mode: Mode, krate: &CargoCrate| {
1464-
let test_kind = if builder.kind == Kind::Test {
1465-
TestKind::Test
1466-
} else if builder.kind == Kind::Bench {
1467-
TestKind::Bench
1468-
} else {
1469-
panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1470-
};
1466+
let test_kind = builder.kind.into();
14711467

14721468
builder.ensure(Crate {
14731469
compiler,
@@ -1625,13 +1621,7 @@ impl Step for CrateRustdoc {
16251621
fn make_run(run: RunConfig) {
16261622
let builder = run.builder;
16271623

1628-
let test_kind = if builder.kind == Kind::Test {
1629-
TestKind::Test
1630-
} else if builder.kind == Kind::Bench {
1631-
TestKind::Bench
1632-
} else {
1633-
panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1634-
};
1624+
let test_kind = builder.kind.into();
16351625

16361626
builder.ensure(CrateRustdoc {
16371627
host: run.host,

src/test/COMPILER_TESTS.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,9 @@ check that the test compiles successfully.
140140
### Editing and updating the reference files
141141

142142
If you have changed the compiler's output intentionally, or you are
143-
making a new test, you can use the script `ui/update-references.sh` to
144-
update the references. When you run the test framework, it will report
145-
various errors: in those errors is a command you can use to run the
146-
`ui/update-references.sh` script, which will then copy over the files
147-
from the build directory and use them as the new reference. You can
148-
also just run `ui/update-all-references.sh`. In both cases, you can run
149-
the script with `--help` to get a help message.
143+
making a new test, you can pass `--bless` to the command you used to
144+
run the tests. This will then copy over the files
145+
from the build directory and use them as the new reference.
150146

151147
### Normalization
152148

src/test/ui/E0508.ast.nll.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
2+
--> $DIR/E0508.rs:18:18
3+
|
4+
LL | let _value = array[0]; //[ast]~ ERROR [E0508]
5+
| ^^^^^^^^ cannot move out of here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0508`.

src/test/ui/E0508.ast.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
2+
--> $DIR/E0508.rs:18:18
3+
|
4+
LL | let _value = array[0]; //[ast]~ ERROR [E0508]
5+
| ^^^^^^^^
6+
| |
7+
| cannot move out of here
8+
| help: consider using a reference instead: `&array[0]`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0508`.

src/test/ui/E0508.mir.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
2+
--> $DIR/E0508.rs:18:18
3+
|
4+
LL | let _value = array[0]; //[ast]~ ERROR [E0508]
5+
| ^^^^^^^^ cannot move out of here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0508`.

src/test/ui/E0508.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// revisions: ast mir
12+
//[mir]compile-flags: -Z borrowck=mir
13+
14+
struct NonCopy;
15+
16+
fn main() {
17+
let array = [NonCopy; 1];
18+
let _value = array[0]; //[ast]~ ERROR [E0508]
19+
//[mir]~^ ERROR [E0508]
20+
}

src/tools/compiletest/src/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ impl CompareMode {
118118

119119
#[derive(Clone)]
120120
pub struct Config {
121+
/// Whether to overwrite stderr/stdout files instead of complaining about changes in output
122+
pub bless: bool,
123+
121124
/// The library paths required for running the compiler
122125
pub compile_lib_path: PathBuf,
123126

src/tools/compiletest/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
166166
"FLAGS",
167167
)
168168
.optflag("", "verbose", "run tests verbosely, showing all output")
169+
.optflag(
170+
"",
171+
"bless",
172+
"overwrite stderr/stdout files instead of complaining about a mismatch",
173+
)
169174
.optflag(
170175
"",
171176
"quiet",
@@ -290,6 +295,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
290295
let src_base = opt_path(matches, "src-base");
291296
let run_ignored = matches.opt_present("ignored");
292297
Config {
298+
bless: matches.opt_present("bless"),
293299
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
294300
run_lib_path: make_absolute(opt_path(matches, "run-lib-path")),
295301
rustc_path: opt_path(matches, "rustc-path"),

src/tools/compiletest/src/runtest.rs

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,15 +2596,13 @@ impl<'test> TestCx<'test> {
25962596
}
25972597

25982598
if errors > 0 {
2599-
println!("To update references, run this command from build directory:");
2599+
println!("To update references, rerun the tests and pass the `--bless` flag");
26002600
let relative_path_to_file = self.testpaths
26012601
.relative_dir
26022602
.join(self.testpaths.file.file_name().unwrap());
26032603
println!(
2604-
"{}/update-references.sh '{}' '{}'",
2605-
self.config.src_base.display(),
2606-
self.config.build_base.display(),
2607-
relative_path_to_file.display()
2604+
"To only update this specific test, also pass `--test-args {}`",
2605+
relative_path_to_file.display(),
26082606
);
26092607
self.fatal_proc_rec(
26102608
&format!("{} errors occurred comparing output.", errors),
@@ -2926,29 +2924,31 @@ impl<'test> TestCx<'test> {
29262924
return 0;
29272925
}
29282926

2929-
if expected.is_empty() {
2930-
println!("normalized {}:\n{}\n", kind, actual);
2931-
} else {
2932-
println!("diff of {}:\n", kind);
2933-
let diff_results = make_diff(expected, actual, 3);
2934-
for result in diff_results {
2935-
let mut line_number = result.line_number;
2936-
for line in result.lines {
2937-
match line {
2938-
DiffLine::Expected(e) => {
2939-
println!("-\t{}", e);
2940-
line_number += 1;
2941-
}
2942-
DiffLine::Context(c) => {
2943-
println!("{}\t{}", line_number, c);
2944-
line_number += 1;
2945-
}
2946-
DiffLine::Resulting(r) => {
2947-
println!("+\t{}", r);
2927+
if !self.config.bless {
2928+
if expected.is_empty() {
2929+
println!("normalized {}:\n{}\n", kind, actual);
2930+
} else {
2931+
println!("diff of {}:\n", kind);
2932+
let diff_results = make_diff(expected, actual, 3);
2933+
for result in diff_results {
2934+
let mut line_number = result.line_number;
2935+
for line in result.lines {
2936+
match line {
2937+
DiffLine::Expected(e) => {
2938+
println!("-\t{}", e);
2939+
line_number += 1;
2940+
}
2941+
DiffLine::Context(c) => {
2942+
println!("{}\t{}", line_number, c);
2943+
line_number += 1;
2944+
}
2945+
DiffLine::Resulting(r) => {
2946+
println!("+\t{}", r);
2947+
}
29482948
}
29492949
}
2950+
println!("");
29502951
}
2951-
println!("");
29522952
}
29532953
}
29542954

@@ -2958,19 +2958,47 @@ impl<'test> TestCx<'test> {
29582958
.with_extra_extension(mode)
29592959
.with_extra_extension(kind);
29602960

2961-
match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
2962-
Ok(()) => {}
2963-
Err(e) => self.fatal(&format!(
2964-
"failed to write {} to `{}`: {}",
2961+
let mut files = vec![output_file];
2962+
if self.config.bless {
2963+
files.push(expected_output_path(
2964+
self.testpaths,
2965+
self.revision,
2966+
&self.config.compare_mode,
29652967
kind,
2966-
output_file.display(),
2967-
e
2968-
)),
2968+
));
2969+
}
2970+
2971+
for output_file in &files {
2972+
if actual.is_empty() {
2973+
if let Err(e) = ::std::fs::remove_file(output_file) {
2974+
self.fatal(&format!(
2975+
"failed to delete `{}`: {}",
2976+
output_file.display(),
2977+
e,
2978+
));
2979+
}
2980+
} else {
2981+
match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
2982+
Ok(()) => {}
2983+
Err(e) => self.fatal(&format!(
2984+
"failed to write {} to `{}`: {}",
2985+
kind,
2986+
output_file.display(),
2987+
e
2988+
)),
2989+
}
2990+
}
29692991
}
29702992

29712993
println!("\nThe actual {0} differed from the expected {0}.", kind);
2972-
println!("Actual {} saved to {}", kind, output_file.display());
2973-
1
2994+
for output_file in files {
2995+
println!("Actual {} saved to {}", kind, output_file.display());
2996+
}
2997+
if self.config.bless {
2998+
0
2999+
} else {
3000+
1
3001+
}
29743002
}
29753003

29763004
fn create_stamp(&self) {

0 commit comments

Comments
 (0)