Skip to content

Commit 1f6e2a6

Browse files
authored
Merge pull request #2224 from rust-lang-nursery/rust-test
Apply changes that were required for running in the rustc test suite
2 parents 09d9885 + c6a4eae commit 1f6e2a6

28 files changed

+112
-149
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.171
5+
* Rustup to *rustc 1.23.0-nightly (ff0f5de3b 2017-11-14)*
6+
47
## 0.0.170
58
* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)*
69

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.170"
3+
version = "0.0.171"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -37,15 +37,15 @@ path = "src/driver.rs"
3737

3838
[dependencies]
3939
# begin automatic update
40-
clippy_lints = { version = "0.0.170", path = "clippy_lints" }
40+
clippy_lints = { version = "0.0.171", path = "clippy_lints" }
4141
# end automatic update
4242
cargo_metadata = "0.2"
43+
regex = "0.2"
4344

4445
[dev-dependencies]
4546
compiletest_rs = "0.3"
4647
duct = "0.8.2"
4748
lazy_static = "0.2"
48-
regex = "0.2"
4949
serde_derive = "1.0"
5050
clippy-mini-macro-test = { version = "0.1", path = "mini-macro" }
5151
serde = "1.0"

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.170"
4+
version = "0.0.171"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",

clippy_lints/src/lib.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
183183
match utils::conf::lookup_conf_file() {
184184
Ok(path) => path,
185185
Err(error) => {
186-
reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
186+
reg.sess.struct_err(&format!("error finding Clippy's configuration file: {}", error)).emit();
187187
None
188188
}
189189
}
190190
};
191191

192+
let file_name = file_name.map(|file_name| if file_name.is_relative() {
193+
reg.sess
194+
.local_crate_source_file
195+
.as_ref()
196+
.and_then(|file| std::path::Path::new(&file).parent().map(std::path::Path::to_path_buf))
197+
.unwrap_or_default()
198+
.join(file_name)
199+
} else {
200+
file_name
201+
});
202+
192203
let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref()));
193204

194205
// all conf errors are non-fatal, we just use the default conf in case of error
195206
for error in errors {
196-
reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit();
207+
reg.sess.struct_err(&format!("error reading Clippy's configuration file `{}`: {}", file_name.as_ref().and_then(|p| p.to_str()).unwrap_or(""), error)).emit();
197208
}
198209

199210
conf

clippy_lints/src/utils/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
99
use rustc::session::Session;
1010
use rustc::traits;
1111
use rustc::ty::{self, Ty, TyCtxt};
12-
use rustc::mir::transform::MirSource;
1312
use rustc_errors;
1413
use std::borrow::Cow;
1514
use std::env;
@@ -48,9 +47,9 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
4847

4948
pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
5049
let parent_id = cx.tcx.hir.get_parent(id);
51-
match MirSource::from_node(cx.tcx, parent_id) {
52-
MirSource::GeneratorDrop(_) | MirSource::Fn(_) => false,
53-
MirSource::Const(_) | MirSource::Static(..) | MirSource::Promoted(..) => true,
50+
match cx.tcx.hir.body_owner_kind(parent_id) {
51+
hir::BodyOwnerKind::Fn => false,
52+
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true,
5453
}
5554
}
5655

src/driver.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -129,33 +129,29 @@ fn show_version() {
129129
pub fn main() {
130130
use std::env;
131131

132-
if env::var("CLIPPY_DOGFOOD").is_ok() {
133-
panic!("yummy");
134-
}
135-
136132
if std::env::args().any(|a| a == "--version" || a == "-V") {
137133
show_version();
138134
return;
139135
}
140136

141-
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
142-
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
143-
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
144-
format!("{}/toolchains/{}", home, toolchain)
145-
} else {
146-
option_env!("SYSROOT")
147-
.map(|s| s.to_owned())
148-
.or_else(|| {
149-
Command::new("rustc")
150-
.arg("--print")
151-
.arg("sysroot")
152-
.output()
153-
.ok()
154-
.and_then(|out| String::from_utf8(out.stdout).ok())
155-
.map(|s| s.trim().to_owned())
156-
})
157-
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust")
158-
};
137+
let sys_root = option_env!("SYSROOT")
138+
.map(String::from)
139+
.or_else(|| std::env::var("SYSROOT").ok())
140+
.or_else(|| {
141+
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
142+
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
143+
home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
144+
})
145+
.or_else(|| {
146+
Command::new("rustc")
147+
.arg("--print")
148+
.arg("sysroot")
149+
.output()
150+
.ok()
151+
.and_then(|out| String::from_utf8(out.stdout).ok())
152+
.map(|s| s.trim().to_owned())
153+
})
154+
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
159155

160156
rustc_driver::in_rustc_thread(|| {
161157
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.

src/main.rs

-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ fn show_version() {
4949
}
5050

5151
pub fn main() {
52-
use std::env;
53-
54-
if env::var("CLIPPY_DOGFOOD").is_ok() {
55-
panic!("yummy");
56-
}
57-
5852
// Check for version and help flags even when invoked as 'cargo-clippy'
5953
if std::env::args().any(|a| a == "--help" || a == "-h") {
6054
show_help();

tests/compile-test.rs

+49-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#![feature(test)]
2+
13
extern crate compiletest_rs as compiletest;
4+
extern crate test;
25

3-
use std::path::PathBuf;
6+
use std::path::{PathBuf, Path};
47
use std::env::{set_var, var};
58

69
fn clippy_driver_path() -> PathBuf {
@@ -11,16 +14,37 @@ fn clippy_driver_path() -> PathBuf {
1114
}
1215
}
1316

14-
fn run_mode(dir: &'static str, mode: &'static str) {
17+
fn host_libs() -> PathBuf {
18+
if let Some(path) = option_env!("HOST_LIBS") {
19+
PathBuf::from(path)
20+
} else {
21+
Path::new("target").join(env!("PROFILE"))
22+
}
23+
}
24+
25+
fn rustc_test_suite() -> Option<PathBuf> {
26+
option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
27+
}
28+
29+
fn rustc_lib_path() -> PathBuf {
30+
option_env!("RUSTC_LIB_PATH").unwrap().into()
31+
}
32+
33+
fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
1534
let mut config = compiletest::Config::default();
1635

1736
let cfg_mode = mode.parse().expect("Invalid mode");
18-
config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps -Dwarnings".to_owned());
1937
if let Ok(name) = var::<&str>("TESTNAME") {
2038
let s: String = name.to_owned();
2139
config.filter = Some(s)
2240
}
2341

42+
if rustc_test_suite().is_some() {
43+
config.run_lib_path = rustc_lib_path();
44+
config.compile_lib_path = rustc_lib_path();
45+
}
46+
config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
47+
2448
config.mode = cfg_mode;
2549
config.build_base = {
2650
let mut path = std::env::current_dir().unwrap();
@@ -29,8 +53,11 @@ fn run_mode(dir: &'static str, mode: &'static str) {
2953
};
3054
config.src_base = PathBuf::from(format!("tests/{}", dir));
3155
config.rustc_path = clippy_driver_path();
56+
config
57+
}
3258

33-
compiletest::run_tests(&config);
59+
fn run_mode(dir: &'static str, mode: &'static str) {
60+
compiletest::run_tests(&config(dir, mode));
3461
}
3562

3663
fn prepare_env() {
@@ -45,3 +72,21 @@ fn compile_test() {
4572
run_mode("run-pass", "run-pass");
4673
run_mode("ui", "ui");
4774
}
75+
76+
#[test]
77+
fn dogfood() {
78+
prepare_env();
79+
let files = ["src/main.rs", "src/driver.rs", "src/lib.rs", "clippy_lints/src/lib.rs"];
80+
let mut config = config("dogfood", "ui");
81+
config.target_rustcflags = config.target_rustcflags.map(|flags| format!("{} -Dclippy -Dclippy_pedantic -Dclippy_internal", flags));
82+
83+
for file in &files {
84+
let paths = test::TestPaths {
85+
base: PathBuf::new(),
86+
file: PathBuf::from(file),
87+
relative_dir: PathBuf::new(),
88+
};
89+
90+
compiletest::runtest::run(config.clone(), &paths);
91+
}
92+
}

tests/conf_whitelisted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#![feature(plugin)]
2-
#![plugin(clippy(conf_file = "./tests/auxiliary/conf_whitelisted.toml"))]
2+
#![plugin(clippy(conf_file = "./auxiliary/conf_whitelisted.toml"))]

tests/dogfood.rs

-49
This file was deleted.

tests/ui/conf_bad_toml.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// error-pattern: error reading Clippy's configuration file
22

33

4-
#![plugin(clippy(conf_file="./tests/ui/conf_bad_toml.toml"))]
4+
#![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
55

66
fn main() {}

tests/ui/conf_bad_toml.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: compiler plugins are experimental and possibly buggy (see issue #29597)
22
--> $DIR/conf_bad_toml.rs:4:1
33
|
4-
4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_toml.toml"))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
4 | #![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(plugin)] to the crate attributes to enable
88

tests/ui/conf_bad_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer`
22

33

4-
#![plugin(clippy(conf_file="./tests/ui/conf_bad_type.toml"))]
4+
#![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
55

66
fn main() {}

tests/ui/conf_bad_type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: compiler plugins are experimental and possibly buggy (see issue #29597)
22
--> $DIR/conf_bad_type.rs:4:1
33
|
4-
4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_type.toml"))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
4 | #![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(plugin)] to the crate attributes to enable
88

tests/ui/conf_french_blacklisted_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))]
2+
#![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
33

44
#![allow(dead_code)]
55
#![allow(single_match)]
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: compiler plugins are experimental and possibly buggy (see issue #29597)
22
--> $DIR/conf_french_blacklisted_name.rs:2:1
33
|
4-
2 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
2 | #![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(plugin)] to the crate attributes to enable
88

tests/ui/conf_unknown_key.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// error-pattern: error reading Clippy's configuration file: unknown key `foobar`
22

33

4-
#![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))]
4+
#![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
55

66
fn main() {}

tests/ui/conf_unknown_key.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: compiler plugins are experimental and possibly buggy (see issue #29597)
22
--> $DIR/conf_unknown_key.rs:4:1
33
|
4-
4 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
4 | #![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(plugin)] to the crate attributes to enable
88

tests/ui/format.stderr

-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,3 @@ error: useless use of `format!`
66
|
77
= note: `-D useless-format` implied by `-D warnings`
88

9-
error: useless use of `format!`
10-
--> $DIR/format.rs:8:5
11-
|
12-
8 | format!("{}", "foo");
13-
| ^^^^^^^^^^^^^^^^^^^^^
14-
15-
error: useless use of `format!`
16-
--> $DIR/format.rs:15:5
17-
|
18-
15 | format!("{}", arg);
19-
| ^^^^^^^^^^^^^^^^^^^
20-

tests/ui/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(unused)]
2-
//#![feature(plugin)]#![plugin(clippy)]
2+
33
use std::collections::{HashMap, HashSet};
44
use std::cmp::Eq;
55
use std::hash::{Hash, BuildHasher};

0 commit comments

Comments
 (0)