Skip to content

Commit 88ac226

Browse files
committed
Merge pull request #745 from mcarton/tests
Don’t fail tests when regex_macros does not compile
2 parents d3e460a + 6ad2f64 commit 88ac226

File tree

7 files changed

+44
-25
lines changed

7 files changed

+44
-25
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ sudo: false
44

55
script:
66
- python util/update_lints.py -c
7+
- cargo build --features debugging
78
- cargo test --features debugging
9+
10+
# only test regex_macros if it compiles
11+
- if [[ "$(cargo build --features 'debugging test-regex_macros')" = 101 ]]; then cargo test --features 'debugging test-regex_macros'; fi

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ name = "clippy"
1818
plugin = true
1919

2020
[dependencies]
21-
unicode-normalization = "0.1"
22-
semver = "0.2.1"
2321
regex-syntax = "0.2.2"
22+
regex_macros = { version = "0.1.28", optional = true }
23+
semver = "0.2.1"
24+
unicode-normalization = "0.1"
2425

2526
[dev-dependencies]
2627
compiletest_rs = "0.0.11"
27-
regex = "0.1.47"
28-
regex_macros = "0.1.28"
2928
lazy_static = "0.1.15"
29+
regex = "0.1.47"
3030
rustc-serialize = "0.3"
3131

3232
[features]
33-
3433
debugging = []
34+
test-regex_macros = ["regex_macros"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(plugin)]
2+
#![plugin(clippy, regex_macros)]
3+
4+
#![allow(unused)]
5+
#![deny(invalid_regex, trivial_regex, regex_macro)]
6+
7+
extern crate regex;
8+
9+
fn main() {
10+
let some_regex = regex!("for real!"); //~ERROR `regex!(_)`
11+
let other_regex = regex!("[a-z]_[A-Z]"); //~ERROR `regex!(_)`
12+
}

tests/compile-fail/regex.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(plugin)]
2-
#![plugin(clippy, regex_macros)]
2+
#![plugin(clippy)]
33

44
#![allow(unused)]
55
#![deny(invalid_regex, trivial_regex, regex_macro)]
@@ -70,14 +70,7 @@ fn trivial_regex() {
7070
let non_trivial_ends_with = Regex::new("foo|bar");
7171
}
7272

73-
fn regex_macro() {
74-
let some_regex = regex!("for real!"); //~ERROR `regex!(_)`
75-
let other_regex = regex!("[a-z]_[A-Z]"); //~ERROR `regex!(_)`
76-
}
77-
78-
7973
fn main() {
80-
regex_macro();
8174
syntax_error();
8275
trivial_regex();
8376
}

tests/compile-test.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ fn run_mode(mode: &'static str) {
2020
}
2121

2222
#[test]
23+
#[cfg(not(feature = "test-regex_macros"))]
2324
fn compile_test() {
2425
run_mode("run-pass");
2526
run_mode("compile-fail");
2627
}
28+
29+
#[test]
30+
#[cfg(feature = "test-regex_macros")]
31+
fn compile_test() {
32+
run_mode("run-pass-regex_macros");
33+
run_mode("compile-fail-regex_macros");
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(plugin)]
2+
#![plugin(clippy, regex_macros)]
3+
4+
#[macro_use]
5+
extern crate regex;
6+
7+
#[deny(mut_mut)]
8+
#[allow(regex_macro)]
9+
fn main() {
10+
let pattern = regex!(r"^(?P<level>[#]+)\s(?P<title>.+)$");
11+
assert!(pattern.is_match("# headline"));
12+
}

tests/mut_mut_macro.rs renamed to tests/run-pass/mut_mut_macro.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
#![feature(plugin)]
2-
#![plugin(clippy, regex_macros)]
2+
#![plugin(clippy)]
33

44
#[macro_use]
55
extern crate lazy_static;
6-
extern crate regex;
76

87
use std::collections::HashMap;
98

10-
#[test]
11-
#[deny(mut_mut)]
12-
#[allow(regex_macro)]
13-
fn test_regex() {
14-
let pattern = regex!(r"^(?P<level>[#]+)\s(?P<title>.+)$");
15-
assert!(pattern.is_match("# headline"));
16-
}
17-
18-
#[test]
199
#[deny(mut_mut)]
2010
#[allow(unused_variables, unused_mut)]
21-
fn test_lazy_static() {
11+
fn main() {
2212
lazy_static! {
2313
static ref MUT_MAP : HashMap<usize, &'static str> = {
2414
let mut m = HashMap::new();

0 commit comments

Comments
 (0)