diff --git a/.travis.yml b/.travis.yml index d33f8604bcf..34e50956cc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,13 +26,6 @@ script: - cd clippy_lints && PATH=$PATH:~/rust/cargo/bin cargo clippy -- -D clippy && cd .. after_success: -# only test regex_macros if it compiles -- | - #!/bin/bash - cargo test --no-run --features 'debugging test-regex_macros' - if [ "$?" != 101 ]; then - cargo test --features 'debugging test-regex_macros' compile_test - fi # trigger rebuild of the clippy-service, to keep it up to date with clippy itself - | #!/bin/bash diff --git a/Cargo.toml b/Cargo.toml index d3e67bdb7e1..5dc1363f3f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ name = "cargo-clippy" test = false [dependencies] -regex_macros = { version = "0.1.33", optional = true } # begin automatic update clippy_lints = { version = "0.0.77", path = "clippy_lints" } # end automatic update @@ -32,9 +31,10 @@ clippy_lints = { version = "0.0.77", path = "clippy_lints" } [dev-dependencies] compiletest_rs = "0.2.0" lazy_static = "0.1.15" -regex = "0.1.56" +regex = "0.1.71" rustc-serialize = "0.3" +clippy-mini-macro-test = { version = "0.1", path = "mini-macro" } + [features] debugging = [] -test-regex_macros = ["regex_macros"] diff --git a/mini-macro/Cargo.toml b/mini-macro/Cargo.toml new file mode 100644 index 00000000000..f884ab48059 --- /dev/null +++ b/mini-macro/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "clippy-mini-macro-test" +version = "0.1.0" +authors = [ + "Manish Goregaokar ", + "Andre Bogus ", + "Georg Brandl ", + "Martin Carton ", + "Oliver Schneider " +] +license = "MPL-2.0" +description = "A macro to test clippy's procedural macro checks" +repository = "https://github.com/Manishearth/rust-clippy" + +[lib] +name = "clippy_mini_macro_test" +plugin = true + +[dependencies] diff --git a/mini-macro/src/lib.rs b/mini-macro/src/lib.rs new file mode 100644 index 00000000000..699d17d4d70 --- /dev/null +++ b/mini-macro/src/lib.rs @@ -0,0 +1,22 @@ +#![feature(plugin_registrar, rustc_private)] + +extern crate syntax; +extern crate rustc; +extern crate rustc_plugin; + +use syntax::codemap::Span; +use syntax::ast::TokenTree; +use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; +use syntax::ext::build::AstBuilder; // trait for expr_usize +use rustc_plugin::Registry; + +fn expand_macro(cx: &mut ExtCtxt, sp: Span, _: &[TokenTree]) -> Box { + let e = cx.expr_usize(sp, 42); + let e = cx.expr_mut_addr_of(sp, e); + MacEager::expr(cx.expr_mut_addr_of(sp, e)) +} + +#[plugin_registrar] +pub fn plugin_registrar(reg: &mut Registry) { + reg.register_macro("mini_macro", expand_macro); +} diff --git a/tests/compile-fail-regex_macros/regex.rs b/tests/compile-fail-regex_macros/regex.rs deleted file mode 100644 index aab196fb795..00000000000 --- a/tests/compile-fail-regex_macros/regex.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(plugin)] -#![plugin(clippy, regex_macros)] - -#![allow(unused)] -#![deny(invalid_regex, trivial_regex, regex_macro)] - -extern crate regex; - -fn main() { - let some_regex = regex!("for real!"); //~ERROR `regex!(_)` - let other_regex = regex!("[a-z]_[A-Z]"); //~ERROR `regex!(_)` -} diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 2e50f7d9241..d21d9750924 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -1,7 +1,7 @@ extern crate compiletest_rs as compiletest; use std::path::PathBuf; -use std::env::{set_var, var, temp_dir}; +use std::env::{set_var, var}; fn run_mode(dir: &'static str, mode: &'static str) { let mut config = compiletest::default_config(); @@ -14,10 +14,6 @@ fn run_mode(dir: &'static str, mode: &'static str) { } config.mode = cfg_mode; - if cfg!(windows) { - // work around https://github.com/laumann/compiletest-rs/issues/35 on msvc windows - config.build_base = temp_dir(); - } config.src_base = PathBuf::from(format!("tests/{}", dir)); compiletest::run_tests(&config); @@ -28,17 +24,8 @@ fn prepare_env() { } #[test] -#[cfg(not(feature = "test-regex_macros"))] fn compile_test() { prepare_env(); run_mode("run-pass", "run-pass"); run_mode("compile-fail", "compile-fail"); } - -#[test] -#[cfg(feature = "test-regex_macros")] -fn compile_test() { - prepare_env(); - run_mode("run-pass-regex_macros", "run-pass"); - run_mode("compile-fail-regex_macros", "compile-fail"); -} diff --git a/tests/run-pass-regex_macros/mut_mut_macro.rs b/tests/run-pass-regex_macros/mut_mut_macro.rs deleted file mode 100644 index 92b44dbdd48..00000000000 --- a/tests/run-pass-regex_macros/mut_mut_macro.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(plugin)] -#![plugin(clippy, regex_macros)] - -#[macro_use] -extern crate regex; - -#[deny(mut_mut)] -#[allow(regex_macro)] -fn main() { - let pattern = regex!(r"^(?P[#]+)\s(?P.+)$"); - assert!(pattern.is_match("# headline")); -} diff --git a/tests/run-pass/procedural_macro.rs b/tests/run-pass/procedural_macro.rs new file mode 100644 index 00000000000..91269726172 --- /dev/null +++ b/tests/run-pass/procedural_macro.rs @@ -0,0 +1,7 @@ +#![feature(plugin)] +#![plugin(clippy, clippy_mini_macro_test)] + +#[deny(warnings)] +fn main() { + let _ = mini_macro!(); +}