From d57192d5c17e3af2b1e73b26e5d35ac4af3e7160 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Sat, 25 Jun 2016 18:12:29 +0200 Subject: [PATCH 1/2] don't depend on regex_macros anymore --- .travis.yml | 7 ------- Cargo.toml | 6 +++--- mini-macro/Cargo.toml | 16 ++++++++++++++ mini-macro/src/lib.rs | 22 ++++++++++++++++++++ tests/compile-fail-regex_macros/regex.rs | 12 ----------- tests/compile-test.rs | 15 +------------ tests/run-pass-regex_macros/mut_mut_macro.rs | 12 ----------- tests/run-pass/procedural_macro.rs | 7 +++++++ 8 files changed, 49 insertions(+), 48 deletions(-) create mode 100644 mini-macro/Cargo.toml create mode 100644 mini-macro/src/lib.rs delete mode 100644 tests/compile-fail-regex_macros/regex.rs delete mode 100644 tests/run-pass-regex_macros/mut_mut_macro.rs create mode 100644 tests/run-pass/procedural_macro.rs 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..9b68a7364ff 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" +mini-macro = { 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..171e5dd8172 --- /dev/null +++ b/mini-macro/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "mini-macro" +version = "0.1.0" +authors = [ + "Manish Goregaokar ", + "Andre Bogus ", + "Georg Brandl ", + "Martin Carton ", + "Oliver Schneider " +] + +[lib] +name = "mini_macro" +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..68d86a4d394 --- /dev/null +++ b/tests/run-pass/procedural_macro.rs @@ -0,0 +1,7 @@ +#![feature(plugin)] +#![plugin(clippy, mini_macro)] + +#[deny(warnings)] +fn main() { + let _ = mini_macro!(); +} From 2e86eb88f3e36a74ab59bfaa77fe01cf8d1cc028 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider <git-spam-no-reply9815368754983@oli-obk.de> Date: Sun, 26 Jun 2016 13:26:30 +0200 Subject: [PATCH 2/2] rename mini-macro to clippy-mini-macro-test --- Cargo.toml | 2 +- mini-macro/Cargo.toml | 7 +++++-- tests/run-pass/procedural_macro.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b68a7364ff..5dc1363f3f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ compiletest_rs = "0.2.0" lazy_static = "0.1.15" regex = "0.1.71" rustc-serialize = "0.3" -mini-macro = { version = "0.1", path = "mini-macro" } +clippy-mini-macro-test = { version = "0.1", path = "mini-macro" } [features] diff --git a/mini-macro/Cargo.toml b/mini-macro/Cargo.toml index 171e5dd8172..f884ab48059 100644 --- a/mini-macro/Cargo.toml +++ b/mini-macro/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mini-macro" +name = "clippy-mini-macro-test" version = "0.1.0" authors = [ "Manish Goregaokar <manishsmail@gmail.com>", @@ -8,9 +8,12 @@ authors = [ "Martin Carton <cartonmartin@gmail.com>", "Oliver Schneider <clippy-iethah7aipeen8neex1a@oli-obk.de>" ] +license = "MPL-2.0" +description = "A macro to test clippy's procedural macro checks" +repository = "https://github.com/Manishearth/rust-clippy" [lib] -name = "mini_macro" +name = "clippy_mini_macro_test" plugin = true [dependencies] diff --git a/tests/run-pass/procedural_macro.rs b/tests/run-pass/procedural_macro.rs index 68d86a4d394..91269726172 100644 --- a/tests/run-pass/procedural_macro.rs +++ b/tests/run-pass/procedural_macro.rs @@ -1,5 +1,5 @@ #![feature(plugin)] -#![plugin(clippy, mini_macro)] +#![plugin(clippy, clippy_mini_macro_test)] #[deny(warnings)] fn main() {