made macro test even simpler, added a few tests
This commit is contained in:
parent
a67e0f6e2f
commit
0d651c72ff
@ -17,3 +17,5 @@ plugin = true
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
compiletest_rs = "*"
|
compiletest_rs = "*"
|
||||||
|
regex = "*"
|
||||||
|
regex_macros = "*"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#![feature(plugin_registrar, box_syntax)]
|
#![feature(plugin_registrar, box_syntax)]
|
||||||
#![feature(rustc_private, collections)]
|
#![feature(rustc_private, collections)]
|
||||||
|
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -27,7 +27,7 @@ impl LintPass for MutMut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) {
|
fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) {
|
||||||
if in_external_macro(info) { return; }
|
if in_macro(info) { return; }
|
||||||
|
|
||||||
fn unwrap_addr(expr : &Expr) -> Option<&Expr> {
|
fn unwrap_addr(expr : &Expr) -> Option<&Expr> {
|
||||||
match expr.node {
|
match expr.node {
|
||||||
@ -51,8 +51,8 @@ fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn in_external_macro(info: Option<&ExpnInfo>) -> bool {
|
fn in_macro(info: Option<&ExpnInfo>) -> bool {
|
||||||
info.map_or(false, |i| i.callee.span.is_some())
|
info.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unwrap_mut(ty : &Ty) -> Option<&Ty> {
|
fn unwrap_mut(ty : &Ty) -> Option<&Ty> {
|
||||||
|
@ -27,7 +27,7 @@ impl LintPass for PtrArg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, cx: &Context, item: &Item) {
|
fn check_item(&mut self, cx: &Context, item: &Item) {
|
||||||
if let &ItemFn(ref decl, _, _, _, _) = &item.node {
|
if let &ItemFn(ref decl, _, _, _, _, _) = &item.node {
|
||||||
check_fn(cx, decl);
|
check_fn(cx, decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
#![plugin(clippy)]
|
#![plugin(clippy)]
|
||||||
|
|
||||||
|
//#![plugin(regex_macros)]
|
||||||
|
//extern crate regex;
|
||||||
|
|
||||||
#[deny(mut_mut)]
|
#[deny(mut_mut)]
|
||||||
fn fun(x : &mut &mut u32) -> bool { //~ERROR
|
fn fun(x : &mut &mut u32) -> bool { //~ERROR
|
||||||
**x > 0
|
**x > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! mut_ptr {
|
||||||
|
($p:expr) => { &mut $p }
|
||||||
|
}
|
||||||
|
|
||||||
#[deny(mut_mut)]
|
#[deny(mut_mut)]
|
||||||
#[allow(unused_mut, unused_variables)]
|
#[allow(unused_mut, unused_variables)]
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -22,4 +29,6 @@ fn main() {
|
|||||||
//~^^^^ ERROR
|
//~^^^^ ERROR
|
||||||
***y + **x;
|
***y + **x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut z = mut_ptr!(&mut 3u32); //~ERROR
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use std::path::PathBuf;
|
|||||||
fn run_mode(mode: &'static str) {
|
fn run_mode(mode: &'static str) {
|
||||||
let mut config = compiletest::default_config();
|
let mut config = compiletest::default_config();
|
||||||
let cfg_mode = mode.parse().ok().expect("Invalid mode");
|
let cfg_mode = mode.parse().ok().expect("Invalid mode");
|
||||||
config.target_rustcflags = Some("-L target/debug/".to_string());
|
config.target_rustcflags = Some("-l regex_macros -L target/debug/".to_string());
|
||||||
|
|
||||||
config.mode = cfg_mode;
|
config.mode = cfg_mode;
|
||||||
config.src_base = PathBuf::from(format!("tests/{}", mode));
|
config.src_base = PathBuf::from(format!("tests/{}", mode));
|
||||||
|
11
tests/run-pass.rs
Normal file
11
tests/run-pass.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(clippy, regex_macros)]
|
||||||
|
|
||||||
|
extern crate regex;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[deny(mut_mut)]
|
||||||
|
fn test_regex() {
|
||||||
|
let pattern = regex!(r"^(?P<level>[#]+)\s(?P<title>.+)$");
|
||||||
|
assert!(pattern.is_match("# headline"));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user