From 886a7e7185c297b71a4a51e16dfea915fe3ce9d3 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 6 Jul 2019 09:12:17 -0400 Subject: [PATCH] syntax: move error test to syntax crate The problem with putting it in the regex crate proper is that it requires the regex crate to bump its minimal regex-syntax crate version. While this isn't necessarily an issue, since we can't enable Cargo's minimal version check because of the `rand` dependency, this winds up being a hazard. Plus, having it in the regex crate doesn't buy us too much. It's just as well to have the tests in regex-syntax. Fixes #593 --- CHANGELOG.md | 15 ++++++++++++--- regex-syntax/src/error.rs | 23 +++++++++++++++++++++++ tests/error_messages.rs | 19 ------------------- tests/test_default.rs | 1 - 4 files changed, 35 insertions(+), 23 deletions(-) delete mode 100644 tests/error_messages.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 4276739190..d2a198888f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +1.1.9 (2019-07-06) +================== +This release contains a bug fix that caused regex's tests to fail, due to a +dependency on an unreleased behavior in regex-syntax. + +* [BUG #593](https://github.com/rust-lang/regex/issues/593): + Move an integration-style test on error messages into regex-syntax. + + 1.1.8 (2019-07-04) ================== This release contains a few small internal refactorings. One of which fixes @@ -5,11 +14,11 @@ an instance of undefined behavior in a part of the SIMD code. Bug fixes: -* [BUG #545](https://github.com/rust-lang/regex/pull/545): +* [BUG #545](https://github.com/rust-lang/regex/issues/545): Improves error messages when a repetition operator is used without a number. -* [BUG #588](https://github.com/rust-lang/regex/pull/588): +* [BUG #588](https://github.com/rust-lang/regex/issues/588): Removes use of a repr(Rust) union used for type punning in the Teddy matcher. -* [BUG #591](https://github.com/rust-lang/regex/pull/591): +* [BUG #591](https://github.com/rust-lang/regex/issues/591): Update docs for running benchmarks and improve failure modes. diff --git a/regex-syntax/src/error.rs b/regex-syntax/src/error.rs index 1f5b8f817d..80c6a97d82 100644 --- a/regex-syntax/src/error.rs +++ b/regex-syntax/src/error.rs @@ -287,6 +287,18 @@ fn repeat_char(c: char, count: usize) -> String { mod tests { use ast::parse::Parser; + fn assert_panic_message(pattern: &str, expected_msg: &str) -> () { + let result = Parser::new().parse(pattern); + match result { + Ok(_) => { + panic!("regex should not have parsed"); + } + Err(err) => { + assert_eq!(err.to_string(), expected_msg.trim()); + } + } + } + // See: https://github.com/rust-lang/regex/issues/464 #[test] fn regression_464() { @@ -294,4 +306,15 @@ mod tests { // This test checks that the error formatter doesn't panic. assert!(!err.to_string().is_empty()); } + + // See: https://github.com/rust-lang/regex/issues/545 + #[test] + fn repetition_quantifier_expects_a_valid_decimal() { + assert_panic_message(r"\\u{[^}]*}", r#" +regex parse error: + \\u{[^}]*} + ^ +error: repetition quantifier expects a valid decimal +"#); + } } diff --git a/tests/error_messages.rs b/tests/error_messages.rs deleted file mode 100644 index 8daa9fa936..0000000000 --- a/tests/error_messages.rs +++ /dev/null @@ -1,19 +0,0 @@ -// See: https://github.com/rust-lang/regex/issues/545 -#[test] -fn repetition_quantifier_expects_a_valid_decimal() { - assert_panic_message(r"\\u{[^}]*}", r#" -regex parse error: - \\u{[^}]*} - ^ -error: repetition quantifier expects a valid decimal -"#); -} - -fn assert_panic_message(regex: &str, expected_msg: &str) -> () { - let result = regex_new!(regex); - match result { - Ok(_) => panic!("Regular expression should have panicked"), - Err(regex::Error::Syntax(msg)) => assert_eq!(msg, expected_msg.trim()), - _ => panic!("Unexpected error received") - } -} diff --git a/tests/test_default.rs b/tests/test_default.rs index 68ab8dd481..cff213b63c 100644 --- a/tests/test_default.rs +++ b/tests/test_default.rs @@ -67,7 +67,6 @@ mod suffix_reverse; mod unicode; mod word_boundary; mod word_boundary_unicode; -mod error_messages; #[test] fn disallow_non_utf8() {