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
|
//! Tests for the `bless` option
extern crate compiletest_rs as compiletest;
mod test_support;
use test_support::{testsuite, TestsuiteBuilder, GLOBAL_ROOT};
use compiletest::Config;
fn setup(mode: &str) -> (Config, TestsuiteBuilder) {
let builder = testsuite(mode);
let mut config = Config::default();
let cfg_mode = mode.parse().expect("Invalid mode");
config.mode = cfg_mode;
config.src_base = builder.root.clone();
config.build_base = GLOBAL_ROOT.join("build_base");
(config, builder)
}
#[test]
fn test_bless_new_file() {
let (mut config, builder) = setup("ui");
config.bless = true;
builder.mk_file(
"foobar.rs",
r#"
#[warn(unused_variables)]
fn main() {
let abc = "foobar";
}
"#,
);
compiletest::run_tests(&config);
// Blessing should cause the stderr to be created directly
assert!(builder.file_contents("foobar.stderr").contains("unused variable"));
// And a second run of the tests, with blessing disabled should work just fine
config.bless = false;
compiletest::run_tests(&config);
}
#[test]
fn test_bless_update_file() {
let (mut config, builder) = setup("ui");
config.bless = true;
builder.mk_file(
"foobar2.rs",
r#"
#[warn(unused_variables)]
fn main() {
let abc = "foobar_update";
}
"#,
);
builder.mk_file(
"foobar2.stderr",
r#"
warning: unused variable: `abc`
--> $DIR/foobar2.rs:4:27
|
4 | let abc = "foobar";
| ^^^ help: if this is intentional, prefix it with an underscore: `_abc`
|
note: the lint level is defined here
--> $DIR/foobar2.rs:2:26
|
2 | #[warn(unused_variables)]
| ^^^^^^^^^^^^^^^^
warning: 1 warning emitted
"#,
);
compiletest::run_tests(&config);
// Blessing should cause the stderr to be created directly
assert!(builder.file_contents("foobar2.stderr").contains("unused variable"));
assert!(builder.file_contents("foobar2.stderr").contains("foobar_update"));
// And a second run of the tests, with blessing disabled should work just fine
config.bless = false;
compiletest::run_tests(&config);
}
|