Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLATFORM-863]: Improve code coverage test for error messages in Veil #62

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions veil-tests/src/code_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn test_code_coverage_for_errors() {
code_coverage: Vec<&'b OsStr>,
}
impl std::fmt::Debug for ErrorMessage<'_, '_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ErrorMessage")
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fmt.debug_struct("ErrorMessage")
.field(
"message",
&self
Expand Down Expand Up @@ -100,7 +100,7 @@ fn test_code_coverage_for_errors() {
macro_src_files.push(SourceFile::new(path).expect("Failed to read veil-macros src file"));
}

let re_syn_error = regex::Regex::new(r#"syn::Error::new\(\s*.+?,\s*"(.+?)",?\s*\)"#).unwrap();
let re_syn_error = regex::Regex::new(r#"syn::Error::new(?:_spanned)?\(\s*.+?,\s*"(.+?)",?\s*\)"#).unwrap();
for src in macro_src_files.iter() {
for cap in re_syn_error.captures_iter(&src.contents) {
let error_msg = cap.get(1).unwrap();
Expand Down
1 change: 1 addition & 0 deletions veil-tests/src/compile_tests/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ macro_rules! fail_tests {
)*};
}
fail_tests! {
redact_invalid_flags,
redact_all_on_field,
redact_all_variant_on_variant,
redact_enum_without_variant,
Expand Down
7 changes: 7 additions & 0 deletions veil-tests/src/compile_tests/fail/redact_invalid_flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {}

#[derive(veil::Redact)]
struct InvalidChar(#[redact(with = "this isn't a char")] ());

#[derive(veil::Redact)]
struct InvalidFixedWidth(#[redact(fixed = 0)] ());
13 changes: 13 additions & 0 deletions veil-tests/src/compile_tests/fail/redact_invalid_flags.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: expected a character literal
--> src/compile_tests/fail/redact_invalid_flags.rs:4:36
|
4 | struct InvalidChar(#[redact(with = "this isn't a char")] ());
| ^^^^^^^^^^^^^^^^^^^

error: fixed redacting width must be greater than zero
--> src/compile_tests/fail/redact_invalid_flags.rs:6:10
|
6 | #[derive(veil::Redact)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `veil::Redact` (in Nightly builds, run with -Z macro-backtrace for more info)