]> git.lizzy.rs Git - rust.git/commitdiff
Use compiletest
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 13 Apr 2015 17:58:18 +0000 (23:28 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 13 Apr 2015 18:50:44 +0000 (00:20 +0530)
Cargo.toml
examples/box_vec.rs [deleted file]
examples/dlist.rs [deleted file]
examples/match_if_let.rs [deleted file]
examples/toplevel_ref_arg.rs [deleted file]
tests/compile-fail/box_vec.rs [new file with mode: 0644]
tests/compile-fail/dlist.rs [new file with mode: 0644]
tests/compile-fail/match_if_let.rs [new file with mode: 0644]
tests/compile-fail/toplevel_ref_arg.rs [new file with mode: 0644]
tests/compile-test.rs [new file with mode: 0644]

index 57133c142c8eda81dcdd977a7f5968e24a0c1dcd..6a599adcc469750f7a38e899c86c8d65323efeac 100644 (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"
diff --git a/examples/box_vec.rs b/examples/box_vec.rs
deleted file mode 100644 (file)
index a93b532..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#![feature(plugin)]
-
-#![plugin(clippy)]
-
-pub fn test(foo: Box<Vec<bool>>) {
-    println!("{:?}", foo.get(0))
-}
-
-fn main(){
-    test(Box::new(Vec::new()));
-}
\ No newline at end of file
diff --git a/examples/dlist.rs b/examples/dlist.rs
deleted file mode 100644 (file)
index d4c543b..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#![feature(plugin)]
-
-#![plugin(clippy)]
-
-extern crate collections;
-use collections::linked_list::LinkedList;
-
-pub fn test(foo: LinkedList<uint>) {
-    println!("{:?}", foo)
-}
-
-fn main(){
-    test(LinkedList::new());
-}
\ No newline at end of file
diff --git a/examples/match_if_let.rs b/examples/match_if_let.rs
deleted file mode 100644 (file)
index 255bea7..0000000
+++ /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/toplevel_ref_arg.rs b/examples/toplevel_ref_arg.rs
deleted file mode 100644 (file)
index 3ebb354..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#![feature(plugin)]
-
-#![plugin(clippy)]
-
-fn the_answer(ref mut x: u8) {
-  *x = 42;
-}
-
-fn main() {
-  let mut x = 0;
-  the_answer(x);
-  println!("The answer is {}.", x);
-}
diff --git a/tests/compile-fail/box_vec.rs b/tests/compile-fail/box_vec.rs
new file mode 100644 (file)
index 0000000..cd1270b
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(plugin)]
+
+#![plugin(clippy)]
+#![deny(clippy)]
+
+pub fn test(foo: Box<Vec<bool>>) { //~ ERROR You seem to be trying to use Box<Vec<T>>
+    println!("{:?}", foo.get(0))
+}
+
+fn main(){
+    test(Box::new(Vec::new()));
+}
\ No newline at end of file
diff --git a/tests/compile-fail/dlist.rs b/tests/compile-fail/dlist.rs
new file mode 100644 (file)
index 0000000..a2343c3
--- /dev/null
@@ -0,0 +1,15 @@
+#![feature(plugin, collections)]
+
+#![plugin(clippy)]
+#![deny(clippy)]
+
+extern crate collections;
+use collections::linked_list::LinkedList;
+
+pub fn test(foo: LinkedList<u8>) {  //~ ERROR I see you're using a LinkedList!
+    println!("{:?}", foo)
+}
+
+fn main(){
+    test(LinkedList::new());
+}
\ No newline at end of file
diff --git a/tests/compile-fail/match_if_let.rs b/tests/compile-fail/match_if_let.rs
new file mode 100644 (file)
index 0000000..b03c6e1
--- /dev/null
@@ -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/tests/compile-fail/toplevel_ref_arg.rs b/tests/compile-fail/toplevel_ref_arg.rs
new file mode 100644 (file)
index 0000000..cd4d46e
--- /dev/null
@@ -0,0 +1,15 @@
+#![feature(plugin)]
+
+#![plugin(clippy)]
+#![deny(clippy)]
+#![allow(unused)]
+
+fn the_answer(ref mut x: u8) {  //~ ERROR `ref` directly on a function argument is ignored
+  *x = 42;
+}
+
+fn main() {
+  let mut x = 0;
+  the_answer(x);
+  println!("The answer is {}.", x);
+}
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
new file mode 100644 (file)
index 0000000..3fd219d
--- /dev/null
@@ -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");
+}