Use compiletest

This commit is contained in:
Manish Goregaokar 2015-04-13 23:28:18 +05:30
parent 2756ebe056
commit a5c3102594
7 changed files with 59 additions and 25 deletions

View file

@ -8,3 +8,7 @@ authors = ["Manish Goregaokar <manishsmail@gmail.com>"]
name = "clippy"
crate_type = ["dylib"]
[dev-dependencies.compiletest]
git = "https://github.com/laumann/compiletest-rs.git"

View file

@ -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),
_ => {}
}
}

View file

@ -1,8 +1,9 @@
#![feature(plugin)]
#![plugin(clippy)]
#![deny(clippy)]
pub fn test(foo: Box<Vec<bool>>) {
pub fn test(foo: Box<Vec<bool>>) { //~ ERROR You seem to be trying to use Box<Vec<T>>
println!("{:?}", foo.get(0))
}

View file

@ -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<uint>) {
pub fn test(foo: LinkedList<u8>) { //~ ERROR I see you're using a LinkedList!
println!("{:?}", foo)
}

View file

@ -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),
_ => {}
}
}

View file

@ -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;
}

23
tests/compile-test.rs Normal file
View file

@ -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");
}