Merge pull request #2224 from rust-lang-nursery/rust-test

Apply changes that were required for running in the rustc test suite
This commit is contained in:
Oliver Schneider 2017-11-15 08:50:30 +01:00 committed by GitHub
commit 1f6e2a63d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 113 additions and 150 deletions

View file

@ -1,6 +1,9 @@
# Change Log # Change Log
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 0.0.171
* Rustup to *rustc 1.23.0-nightly (ff0f5de3b 2017-11-14)*
## 0.0.170 ## 0.0.170
* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)* * Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)*

View file

@ -1,6 +1,6 @@
[package] [package]
name = "clippy" name = "clippy"
version = "0.0.170" version = "0.0.171"
authors = [ authors = [
"Manish Goregaokar <manishsmail@gmail.com>", "Manish Goregaokar <manishsmail@gmail.com>",
"Andre Bogus <bogusandre@gmail.com>", "Andre Bogus <bogusandre@gmail.com>",
@ -37,15 +37,15 @@ path = "src/driver.rs"
[dependencies] [dependencies]
# begin automatic update # begin automatic update
clippy_lints = { version = "0.0.170", path = "clippy_lints" } clippy_lints = { version = "0.0.171", path = "clippy_lints" }
# end automatic update # end automatic update
cargo_metadata = "0.2" cargo_metadata = "0.2"
regex = "0.2"
[dev-dependencies] [dev-dependencies]
compiletest_rs = "0.3" compiletest_rs = "0.3"
duct = "0.8.2" duct = "0.8.2"
lazy_static = "0.2" lazy_static = "0.2"
regex = "0.2"
serde_derive = "1.0" serde_derive = "1.0"
clippy-mini-macro-test = { version = "0.1", path = "mini-macro" } clippy-mini-macro-test = { version = "0.1", path = "mini-macro" }
serde = "1.0" serde = "1.0"

View file

@ -1,7 +1,7 @@
[package] [package]
name = "clippy_lints" name = "clippy_lints"
# begin automatic update # begin automatic update
version = "0.0.170" version = "0.0.171"
# end automatic update # end automatic update
authors = [ authors = [
"Manish Goregaokar <manishsmail@gmail.com>", "Manish Goregaokar <manishsmail@gmail.com>",

View file

@ -183,17 +183,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
match utils::conf::lookup_conf_file() { match utils::conf::lookup_conf_file() {
Ok(path) => path, Ok(path) => path,
Err(error) => { Err(error) => {
reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit(); reg.sess.struct_err(&format!("error finding Clippy's configuration file: {}", error)).emit();
None None
} }
} }
}; };
let file_name = file_name.map(|file_name| if file_name.is_relative() {
reg.sess
.local_crate_source_file
.as_ref()
.and_then(|file| std::path::Path::new(&file).parent().map(std::path::Path::to_path_buf))
.unwrap_or_default()
.join(file_name)
} else {
file_name
});
let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref())); let (conf, errors) = utils::conf::read(file_name.as_ref().map(|p| p.as_ref()));
// all conf errors are non-fatal, we just use the default conf in case of error // all conf errors are non-fatal, we just use the default conf in case of error
for error in errors { for error in errors {
reg.sess.struct_err(&format!("error reading Clippy's configuration file: {}", error)).emit(); 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();
} }
conf conf

View file

@ -9,7 +9,6 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
use rustc::session::Session; use rustc::session::Session;
use rustc::traits; use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt};
use rustc::mir::transform::MirSource;
use rustc_errors; use rustc_errors;
use std::borrow::Cow; use std::borrow::Cow;
use std::env; use std::env;
@ -48,9 +47,9 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
pub fn in_constant(cx: &LateContext, id: NodeId) -> bool { pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
let parent_id = cx.tcx.hir.get_parent(id); let parent_id = cx.tcx.hir.get_parent(id);
match MirSource::from_node(cx.tcx, parent_id) { match cx.tcx.hir.body_owner_kind(parent_id) {
MirSource::GeneratorDrop(_) | MirSource::Fn(_) => false, hir::BodyOwnerKind::Fn => false,
MirSource::Const(_) | MirSource::Static(..) | MirSource::Promoted(..) => true, hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true,
} }
} }

View file

@ -129,33 +129,29 @@ fn show_version() {
pub fn main() { pub fn main() {
use std::env; use std::env;
if env::var("CLIPPY_DOGFOOD").is_ok() {
panic!("yummy");
}
if std::env::args().any(|a| a == "--version" || a == "-V") { if std::env::args().any(|a| a == "--version" || a == "-V") {
show_version(); show_version();
return; return;
} }
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); let sys_root = option_env!("SYSROOT")
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); .map(String::from)
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) { .or_else(|| std::env::var("SYSROOT").ok())
format!("{}/toolchains/{}", home, toolchain) .or_else(|| {
} else { let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
option_env!("SYSROOT") let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
.map(|s| s.to_owned()) home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
.or_else(|| { })
Command::new("rustc") .or_else(|| {
.arg("--print") Command::new("rustc")
.arg("sysroot") .arg("--print")
.output() .arg("sysroot")
.ok() .output()
.and_then(|out| String::from_utf8(out.stdout).ok()) .ok()
.map(|s| s.trim().to_owned()) .and_then(|out| String::from_utf8(out.stdout).ok())
}) .map(|s| s.trim().to_owned())
.expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust") })
}; .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
rustc_driver::in_rustc_thread(|| { rustc_driver::in_rustc_thread(|| {
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument. // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.

View file

@ -49,12 +49,6 @@ fn show_version() {
} }
pub fn main() { pub fn main() {
use std::env;
if env::var("CLIPPY_DOGFOOD").is_ok() {
panic!("yummy");
}
// Check for version and help flags even when invoked as 'cargo-clippy' // Check for version and help flags even when invoked as 'cargo-clippy'
if std::env::args().any(|a| a == "--help" || a == "-h") { if std::env::args().any(|a| a == "--help" || a == "-h") {
show_help(); show_help();

View file

@ -1,6 +1,9 @@
extern crate compiletest_rs as compiletest; #![feature(test)]
use std::path::PathBuf; extern crate compiletest_rs as compiletest;
extern crate test;
use std::path::{PathBuf, Path};
use std::env::{set_var, var}; use std::env::{set_var, var};
fn clippy_driver_path() -> PathBuf { fn clippy_driver_path() -> PathBuf {
@ -11,16 +14,37 @@ fn clippy_driver_path() -> PathBuf {
} }
} }
fn run_mode(dir: &'static str, mode: &'static str) { fn host_libs() -> PathBuf {
if let Some(path) = option_env!("HOST_LIBS") {
PathBuf::from(path)
} else {
Path::new("target").join(env!("PROFILE"))
}
}
fn rustc_test_suite() -> Option<PathBuf> {
option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
}
fn rustc_lib_path() -> PathBuf {
option_env!("RUSTC_LIB_PATH").unwrap().into()
}
fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
let mut config = compiletest::Config::default(); let mut config = compiletest::Config::default();
let cfg_mode = mode.parse().expect("Invalid mode"); let cfg_mode = mode.parse().expect("Invalid mode");
config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps -Dwarnings".to_owned());
if let Ok(name) = var::<&str>("TESTNAME") { if let Ok(name) = var::<&str>("TESTNAME") {
let s: String = name.to_owned(); let s: String = name.to_owned();
config.filter = Some(s) config.filter = Some(s)
} }
if rustc_test_suite().is_some() {
config.run_lib_path = rustc_lib_path();
config.compile_lib_path = rustc_lib_path();
}
config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
config.mode = cfg_mode; config.mode = cfg_mode;
config.build_base = { config.build_base = {
let mut path = std::env::current_dir().unwrap(); let mut path = std::env::current_dir().unwrap();
@ -29,8 +53,11 @@ fn run_mode(dir: &'static str, mode: &'static str) {
}; };
config.src_base = PathBuf::from(format!("tests/{}", dir)); config.src_base = PathBuf::from(format!("tests/{}", dir));
config.rustc_path = clippy_driver_path(); config.rustc_path = clippy_driver_path();
config
}
compiletest::run_tests(&config); fn run_mode(dir: &'static str, mode: &'static str) {
compiletest::run_tests(&config(dir, mode));
} }
fn prepare_env() { fn prepare_env() {
@ -45,3 +72,21 @@ fn compile_test() {
run_mode("run-pass", "run-pass"); run_mode("run-pass", "run-pass");
run_mode("ui", "ui"); run_mode("ui", "ui");
} }
#[test]
fn dogfood() {
prepare_env();
let files = ["src/main.rs", "src/driver.rs", "src/lib.rs", "clippy_lints/src/lib.rs"];
let mut config = config("dogfood", "ui");
config.target_rustcflags = config.target_rustcflags.map(|flags| format!("{} -Dclippy -Dclippy_pedantic -Dclippy_internal", flags));
for file in &files {
let paths = test::TestPaths {
base: PathBuf::new(),
file: PathBuf::from(file),
relative_dir: PathBuf::new(),
};
compiletest::runtest::run(config.clone(), &paths);
}
}

View file

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

View file

@ -1,49 +0,0 @@
#![feature(test, plugin)]
#![plugin(clippy)]
#![deny(clippy, clippy_pedantic)]
extern crate compiletest_rs as compiletest;
extern crate test;
use std::env::{set_var, var};
use std::path::PathBuf;
use test::TestPaths;
#[test]
fn dogfood() {
// don't run dogfood on travis, cargo-clippy already runs clippy on itself
if let Ok(travis) = var("TRAVIS") {
if travis == "true" {
return;
}
}
let mut config = compiletest::Config::default();
let cfg_mode = "run-fail".parse().expect("Invalid mode");
let mut s = String::new();
s.push_str(" -L target/debug/");
s.push_str(" -L target/debug/deps");
s.push_str(" -Zextra-plugins=clippy -Ltarget_recur/debug -Dwarnings -Dclippy_pedantic -Dclippy -Dclippy_internal");
config.target_rustcflags = Some(s);
if let Ok(name) = var("TESTNAME") {
config.filter = Some(name.to_owned())
}
config.mode = cfg_mode;
config.verbose = true;
let files = ["src/main.rs", "src/lib.rs", "clippy_lints/src/lib.rs"];
for file in &files {
let paths = TestPaths {
base: PathBuf::new(),
file: PathBuf::from(file),
relative_dir: PathBuf::new(),
};
set_var("CLIPPY_DOGFOOD", "tastes like chicken");
compiletest::runtest::run(config.clone(), &paths);
}
}

View file

@ -1,6 +1,6 @@
// error-pattern: error reading Clippy's configuration file // error-pattern: error reading Clippy's configuration file
#![plugin(clippy(conf_file="./tests/ui/conf_bad_toml.toml"))] #![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
fn main() {} fn main() {}

View file

@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597) error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $DIR/conf_bad_toml.rs:4:1 --> $DIR/conf_bad_toml.rs:4:1
| |
4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_toml.toml"))] 4 | #![plugin(clippy(conf_file="../ui/conf_bad_toml.toml"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: add #![feature(plugin)] to the crate attributes to enable = help: add #![feature(plugin)] to the crate attributes to enable

View file

@ -1,6 +1,6 @@
// error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer` // error-pattern: error reading Clippy's configuration file: `blacklisted-names` is expected to be a `Vec < String >` but is a `integer`
#![plugin(clippy(conf_file="./tests/ui/conf_bad_type.toml"))] #![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
fn main() {} fn main() {}

View file

@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597) error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $DIR/conf_bad_type.rs:4:1 --> $DIR/conf_bad_type.rs:4:1
| |
4 | #![plugin(clippy(conf_file="./$DIR/conf_bad_type.toml"))] 4 | #![plugin(clippy(conf_file="../ui/conf_bad_type.toml"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: add #![feature(plugin)] to the crate attributes to enable = help: add #![feature(plugin)] to the crate attributes to enable

View file

@ -1,5 +1,5 @@
#![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))] #![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
#![allow(dead_code)] #![allow(dead_code)]
#![allow(single_match)] #![allow(single_match)]

View file

@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597) error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $DIR/conf_french_blacklisted_name.rs:2:1 --> $DIR/conf_french_blacklisted_name.rs:2:1
| |
2 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_french_blacklisted_name.toml"))] 2 | #![plugin(clippy(conf_file="../auxiliary/conf_french_blacklisted_name.toml"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: add #![feature(plugin)] to the crate attributes to enable = help: add #![feature(plugin)] to the crate attributes to enable

View file

@ -1,6 +1,6 @@
// error-pattern: error reading Clippy's configuration file: unknown key `foobar` // error-pattern: error reading Clippy's configuration file: unknown key `foobar`
#![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))] #![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
fn main() {} fn main() {}

View file

@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597) error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $DIR/conf_unknown_key.rs:4:1 --> $DIR/conf_unknown_key.rs:4:1
| |
4 | #![plugin(clippy(conf_file="./tests/auxiliary/conf_unknown_key.toml"))] 4 | #![plugin(clippy(conf_file="../auxiliary/conf_unknown_key.toml"))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: add #![feature(plugin)] to the crate attributes to enable = help: add #![feature(plugin)] to the crate attributes to enable

View file

@ -6,15 +6,3 @@ error: useless use of `format!`
| |
= note: `-D useless-format` implied by `-D warnings` = note: `-D useless-format` implied by `-D warnings`
error: useless use of `format!`
--> $DIR/format.rs:8:5
|
8 | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^^
error: useless use of `format!`
--> $DIR/format.rs:15:5
|
15 | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^^

View file

@ -1,5 +1,5 @@
#![allow(unused)] #![allow(unused)]
//#![feature(plugin)]#![plugin(clippy)]
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::cmp::Eq; use std::cmp::Eq;
use std::hash::{Hash, BuildHasher}; use std::hash::{Hash, BuildHasher};

View file

@ -1,5 +1,5 @@
#![feature(plugin)]
#![plugin(clippy)]
#[allow(no_effect, unnecessary_operation)] #[allow(no_effect, unnecessary_operation)]
#[warn(int_plus_one)] #[warn(int_plus_one)]

View file

@ -1,5 +1,3 @@
warning: running cargo clippy on a crate that also imports the clippy plugin
error: Unnecessary `>= y + 1` or `x - 1 >=` error: Unnecessary `>= y + 1` or `x - 1 >=`
--> $DIR/int_plus_one.rs:10:5 --> $DIR/int_plus_one.rs:10:5
| |

View file

@ -1,5 +1,5 @@
#![feature(plugin)]
#![plugin(clippy)]
#![allow(unused)] #![allow(unused)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]

View file

@ -1,5 +1,3 @@
warning: running cargo clippy on a crate that also imports the clippy plugin
error: reference to zeroed memory error: reference to zeroed memory
--> $DIR/invalid_ref.rs:27:24 --> $DIR/invalid_ref.rs:27:24
| |

View file

@ -1,5 +1,5 @@
#![feature(plugin)]
#![plugin(clippy)]
#![allow(unused)] #![allow(unused)]

View file

@ -1,5 +1,3 @@
warning: running cargo clippy on a crate that also imports the clippy plugin
error: attempt to mutate range bound within loop; note that the range of the loop is unchanged error: attempt to mutate range bound within loop; note that the range of the loop is unchanged
--> $DIR/mut_range_bound.rs:18:21 --> $DIR/mut_range_bound.rs:18:21
| |

View file

@ -23,7 +23,7 @@ error: the loop variable `i` is only used to index `ms`.
help: consider using an iterator help: consider using an iterator
| |
29 | for <item> in &mut ms { 29 | for <item> in &mut ms {
| ^^^^^^ |
error: the loop variable `i` is only used to index `ms`. error: the loop variable `i` is only used to index `ms`.
--> $DIR/needless_range_loop.rs:35:5 --> $DIR/needless_range_loop.rs:35:5
@ -37,5 +37,5 @@ error: the loop variable `i` is only used to index `ms`.
help: consider using an iterator help: consider using an iterator
| |
35 | for <item> in &mut ms { 35 | for <item> in &mut ms {
| ^^^^^^ |

View file

@ -6,21 +6,3 @@ error: using `print!()` with a format string that ends in a newline, consider us
| |
= note: `-D print-with-newline` implied by `-D warnings` = note: `-D print-with-newline` implied by `-D warnings`
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:7:5
|
7 | print!("Hello {}/n", "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:8:5
|
8 | print!("Hello {} {}/n/n", "world", "#2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `print!()` with a format string that ends in a newline, consider using `println!()` instead
--> $DIR/print_with_newline.rs:9:5
|
9 | print!("{}/n", 1265);
| ^^^^^^^^^^^^^^^^^^^^^