]> git.proxmox.com Git - rustc.git/blame - vendor/compiletest_rs/tests/bless.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / vendor / compiletest_rs / tests / bless.rs
CommitLineData
f20569fa
XL
1//! Tests for the `bless` option
2
3extern crate compiletest_rs as compiletest;
4
5mod test_support;
6use test_support::{testsuite, TestsuiteBuilder, GLOBAL_ROOT};
7use compiletest::Config;
8
9fn setup(mode: &str) -> (Config, TestsuiteBuilder) {
10 let builder = testsuite(mode);
11 let mut config = Config::default();
12 let cfg_mode = mode.parse().expect("Invalid mode");
13 config.mode = cfg_mode;
14 config.src_base = builder.root.clone();
15 config.build_base = GLOBAL_ROOT.join("build_base");
16
17 (config, builder)
18}
19
20#[test]
21fn test_bless_new_file() {
22 let (mut config, builder) = setup("ui");
23 config.bless = true;
24
25 builder.mk_file(
26 "foobar.rs",
27 r#"
28 #[warn(unused_variables)]
29 fn main() {
30 let abc = "foobar";
31 }
32 "#,
33 );
34 compiletest::run_tests(&config);
35
36 // Blessing should cause the stderr to be created directly
37 assert!(builder.file_contents("foobar.stderr").contains("unused variable"));
38
39 // And a second run of the tests, with blessing disabled should work just fine
40 config.bless = false;
41 compiletest::run_tests(&config);
42}
43
44#[test]
45fn test_bless_update_file() {
46 let (mut config, builder) = setup("ui");
47 config.bless = true;
48
49 builder.mk_file(
50 "foobar2.rs",
51 r#"
52 #[warn(unused_variables)]
53 fn main() {
54 let abc = "foobar_update";
55 }
56 "#,
57 );
58 builder.mk_file(
59 "foobar2.stderr",
60 r#"
61 warning: unused variable: `abc`
62 --> $DIR/foobar2.rs:4:27
63 |
64 4 | let abc = "foobar";
65 | ^^^ help: if this is intentional, prefix it with an underscore: `_abc`
66 |
67 note: the lint level is defined here
68 --> $DIR/foobar2.rs:2:26
69 |
70 2 | #[warn(unused_variables)]
71 | ^^^^^^^^^^^^^^^^
72
73 warning: 1 warning emitted
74 "#,
75 );
76 compiletest::run_tests(&config);
77
78 // Blessing should cause the stderr to be created directly
79 assert!(builder.file_contents("foobar2.stderr").contains("unused variable"));
80 assert!(builder.file_contents("foobar2.stderr").contains("foobar_update"));
81
82 // And a second run of the tests, with blessing disabled should work just fine
83 config.bless = false;
84 compiletest::run_tests(&config);
85}