diff --git a/Cargo.toml b/Cargo.toml index 57133c142c8e..6a599adcc469 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,7 @@ authors = ["Manish Goregaokar "] name = "clippy" crate_type = ["dylib"] + + +[dev-dependencies.compiletest] +git = "https://github.com/laumann/compiletest-rs.git" diff --git a/examples/match_if_let.rs b/examples/match_if_let.rs deleted file mode 100644 index 255bea7d73f2..000000000000 --- a/examples/match_if_let.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(plugin)] - -#![plugin(clippy)] - -fn main(){ - let x = Some(1u); - match x { - Some(y) => println!("{:?}", y), - _ => () - } - // Not linted - match x { - Some(y) => println!("{:?}", y), - None => () - } - let z = (1u,1u); - match z { - (2...3, 7...9) => println!("{:?}", z), - _ => {} - } -} diff --git a/examples/box_vec.rs b/tests/compile-fail/box_vec.rs similarity index 54% rename from examples/box_vec.rs rename to tests/compile-fail/box_vec.rs index a93b53270bdf..cd1270b2373b 100644 --- a/examples/box_vec.rs +++ b/tests/compile-fail/box_vec.rs @@ -1,8 +1,9 @@ #![feature(plugin)] #![plugin(clippy)] +#![deny(clippy)] -pub fn test(foo: Box>) { +pub fn test(foo: Box>) { //~ ERROR You seem to be trying to use Box> println!("{:?}", foo.get(0)) } diff --git a/examples/dlist.rs b/tests/compile-fail/dlist.rs similarity index 55% rename from examples/dlist.rs rename to tests/compile-fail/dlist.rs index d4c543b8e9f0..a2343c339ad2 100644 --- a/examples/dlist.rs +++ b/tests/compile-fail/dlist.rs @@ -1,11 +1,12 @@ -#![feature(plugin)] +#![feature(plugin, collections)] #![plugin(clippy)] +#![deny(clippy)] extern crate collections; use collections::linked_list::LinkedList; -pub fn test(foo: LinkedList) { +pub fn test(foo: LinkedList) { //~ ERROR I see you're using a LinkedList! println!("{:?}", foo) } diff --git a/tests/compile-fail/match_if_let.rs b/tests/compile-fail/match_if_let.rs new file mode 100644 index 000000000000..b03c6e1140af --- /dev/null +++ b/tests/compile-fail/match_if_let.rs @@ -0,0 +1,24 @@ +#![feature(plugin)] + +#![plugin(clippy)] +#![deny(clippy)] + +fn main(){ + let x = Some(1u8); + match x { //~ ERROR You seem to be trying to use match + //~^ NOTE Try if let Some(y) = x { ... } + Some(y) => println!("{:?}", y), + _ => () + } + // Not linted + match x { + Some(y) => println!("{:?}", y), + None => () + } + let z = (1u8,1u8); + match z { //~ ERROR You seem to be trying to use match + //~^ NOTE Try if let (2...3, 7...9) = z { ... } + (2...3, 7...9) => println!("{:?}", z), + _ => {} + } +} diff --git a/examples/toplevel_ref_arg.rs b/tests/compile-fail/toplevel_ref_arg.rs similarity index 52% rename from examples/toplevel_ref_arg.rs rename to tests/compile-fail/toplevel_ref_arg.rs index 3ebb354142a0..cd4d46ee3276 100644 --- a/examples/toplevel_ref_arg.rs +++ b/tests/compile-fail/toplevel_ref_arg.rs @@ -1,8 +1,10 @@ #![feature(plugin)] #![plugin(clippy)] +#![deny(clippy)] +#![allow(unused)] -fn the_answer(ref mut x: u8) { +fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument is ignored *x = 42; } diff --git a/tests/compile-test.rs b/tests/compile-test.rs new file mode 100644 index 000000000000..3fd219dfb44e --- /dev/null +++ b/tests/compile-test.rs @@ -0,0 +1,23 @@ +extern crate compiletest; + +use std::env; +use std::process::Command; +use std::path::PathBuf; + +fn run_mode(mode: &'static str) { + + let mut config = compiletest::default_config(); + let cfg_mode = mode.parse().ok().expect("Invalid mode"); + config.target_rustcflags = Some("-L target/debug/".to_string()); + + config.mode = cfg_mode; + config.src_base = PathBuf::from(format!("tests/{}", mode)); + + compiletest::run_tests(&config); +} + +#[test] +fn compile_test() { + run_mode("compile-fail"); + // run_mode("run-pass"); +}