Skip to content

Apply changes that were required for running in the rustc test suite #2224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
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
* Rustup to *rustc 1.23.0-nightly (d6b06c63a 2017-11-09)*

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.170"
version = "0.0.171"
authors = [
"Manish Goregaokar <[email protected]>",
"Andre Bogus <[email protected]>",
Expand Down Expand Up @@ -37,15 +37,15 @@ path = "src/driver.rs"

[dependencies]
# begin automatic update
clippy_lints = { version = "0.0.170", path = "clippy_lints" }
clippy_lints = { version = "0.0.171", path = "clippy_lints" }
# end automatic update
cargo_metadata = "0.2"
regex = "0.2"

[dev-dependencies]
compiletest_rs = "0.3"
duct = "0.8.2"
lazy_static = "0.2"
regex = "0.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust bootstrap is weird. I have not been able to figure out how else to get non-plugin crates working with UI tests

serde_derive = "1.0"
clippy-mini-macro-test = { version = "0.1", path = "mini-macro" }
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clippy_lints"
# begin automatic update
version = "0.0.170"
version = "0.0.171"
# end automatic update
authors = [
"Manish Goregaokar <[email protected]>",
Expand Down
15 changes: 13 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,28 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
match utils::conf::lookup_conf_file() {
Ok(path) => path,
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
}
}
};

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()));

// all conf errors are non-fatal, we just use the default conf in case of error
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
Expand Down
7 changes: 3 additions & 4 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
use rustc::session::Session;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::mir::transform::MirSource;
use rustc_errors;
use std::borrow::Cow;
use std::env;
Expand Down Expand Up @@ -48,9 +47,9 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {

pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
let parent_id = cx.tcx.hir.get_parent(id);
match MirSource::from_node(cx.tcx, parent_id) {
MirSource::GeneratorDrop(_) | MirSource::Fn(_) => false,
MirSource::Const(_) | MirSource::Static(..) | MirSource::Promoted(..) => true,
match cx.tcx.hir.body_owner_kind(parent_id) {
hir::BodyOwnerKind::Fn => false,
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(..) => true,
}
}

Expand Down
40 changes: 18 additions & 22 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,29 @@ fn show_version() {
pub fn main() {
use std::env;

if env::var("CLIPPY_DOGFOOD").is_ok() {
panic!("yummy");
}

if std::env::args().any(|a| a == "--version" || a == "-V") {
show_version();
return;
}

let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
format!("{}/toolchains/{}", home, toolchain)
} else {
option_env!("SYSROOT")
.map(|s| s.to_owned())
.or_else(|| {
Command::new("rustc")
.arg("--print")
.arg("sysroot")
.output()
.ok()
.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")
};
let sys_root = option_env!("SYSROOT")
.map(String::from)
.or_else(|| std::env::var("SYSROOT").ok())
.or_else(|| {
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
home.and_then(|home| toolchain.map(|toolchain| format!("{}/toolchains/{}", home, toolchain)))
})
.or_else(|| {
Command::new("rustc")
.arg("--print")
.arg("sysroot")
.output()
.ok()
.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");

rustc_driver::in_rustc_thread(|| {
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
Expand Down
6 changes: 0 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ fn show_version() {
}

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'
if std::env::args().any(|a| a == "--help" || a == "-h") {
show_help();
Expand Down
53 changes: 49 additions & 4 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![feature(test)]

extern crate compiletest_rs as compiletest;
extern crate test;

use std::path::PathBuf;
use std::path::{PathBuf, Path};
use std::env::{set_var, var};

fn clippy_driver_path() -> PathBuf {
Expand All @@ -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 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") {
let s: String = name.to_owned();
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.build_base = {
let mut path = std::env::current_dir().unwrap();
Expand All @@ -29,8 +53,11 @@ fn run_mode(dir: &'static str, mode: &'static str) {
};
config.src_base = PathBuf::from(format!("tests/{}", dir));
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() {
Expand All @@ -45,3 +72,21 @@ fn compile_test() {
run_mode("run-pass", "run-pass");
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);
}
}
2 changes: 1 addition & 1 deletion tests/conf_whitelisted.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#![feature(plugin)]
#![plugin(clippy(conf_file = "./tests/auxiliary/conf_whitelisted.toml"))]
#![plugin(clippy(conf_file = "./auxiliary/conf_whitelisted.toml"))]
49 changes: 0 additions & 49 deletions tests/dogfood.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/conf_bad_toml.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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() {}
4 changes: 2 additions & 2 deletions tests/ui/conf_bad_toml.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $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

2 changes: 1 addition & 1 deletion tests/ui/conf_bad_type.rs
Original file line number Diff line number Diff line change
@@ -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`


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

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/conf_bad_type.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $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

2 changes: 1 addition & 1 deletion tests/ui/conf_french_blacklisted_name.rs
Original file line number Diff line number Diff line change
@@ -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(single_match)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/conf_french_blacklisted_name.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $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

2 changes: 1 addition & 1 deletion tests/ui/conf_unknown_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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() {}
4 changes: 2 additions & 2 deletions tests/ui/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: compiler plugins are experimental and possibly buggy (see issue #29597)
--> $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

12 changes: 0 additions & 12 deletions tests/ui/format.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ error: useless use of `format!`
|
= 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);
| ^^^^^^^^^^^^^^^^^^^

2 changes: 1 addition & 1 deletion tests/ui/implicit_hasher.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused)]
//#![feature(plugin)]#![plugin(clippy)]

use std::collections::{HashMap, HashSet};
use std::cmp::Eq;
use std::hash::{Hash, BuildHasher};
Expand Down
Loading