diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45174867e50..40e4c9ad330 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,7 @@ jobs: env: # On stable the output messages will often not match pinned-nightly, so we set to 'overwrite'. TRYBUILD: ${{ matrix.rust_release == 'pinned-nightly' && 'wip' || 'overwrite' }} + HYDROFLOW_EXPECT_WARNINGS: ${{ matrix.rust_release == 'pinned-nightly' && 'noop' || 'ignore' }} - name: Run doctests run: cargo test --no-fail-fast --features python --features deploy --doc diff --git a/hydroflow/src/declarative_macro.rs b/hydroflow/src/declarative_macro.rs index 54d790c9c7b..12f8d3ece97 100644 --- a/hydroflow/src/declarative_macro.rs +++ b/hydroflow/src/declarative_macro.rs @@ -55,24 +55,32 @@ macro_rules! hydroflow_expect_warnings { $( , )? ) => { { - let __file = std::file!(); - let __line = std::line!() as usize; - let __hf = hydroflow::hydroflow_syntax_noemit! $hf; + fn emit(msg: impl ::std::convert::AsRef) { + if Ok("ignore") == ::std::env::var("HYDROFLOW_EXPECT_WARNINGS").as_deref() { + eprintln!("{}", msg.as_ref()); + } else { + panic!("{}", msg.as_ref()); + } + } + + let __file = ::std::file!(); + let __line = ::std::line!() as usize; + let __hf = $crate::hydroflow_syntax_noemit! $hf; let actuals = __hf.diagnostics().expect("Expected `diagnostics()` to be set."); let actuals_len = actuals.len(); - let actuals = std::collections::BTreeSet::from_iter(actuals.iter().cloned().map(|mut actual| { + let actuals = ::std::collections::BTreeSet::from_iter(actuals.iter().cloned().map(|mut actual| { actual.span.line = actual.span.line.saturating_sub(__line); - std::borrow::Cow::<'static, str>::Owned(actual.to_string().replace(__file, "$FILE")) + ::std::borrow::Cow::<'static, str>::Owned(actual.to_string().replace(__file, "$FILE")) })); let expecteds = [ $( - std::borrow::Cow::Borrowed( $msg ), + ::std::borrow::Cow::Borrowed( $msg ), )* ]; let expecteds_len = expecteds.len(); - let expecteds = std::collections::BTreeSet::from(expecteds); + let expecteds = ::std::collections::BTreeSet::from(expecteds); let missing_errs = expecteds.difference(&actuals).map(|missing| { format!("Expected diagnostic `{}` was not emitted.", missing) @@ -80,13 +88,18 @@ macro_rules! hydroflow_expect_warnings { let extra_errs = actuals.difference(&expecteds).map(|extra| { format!("Unexpected extra diagnostic `{}` was emitted", extra) }); - let all_errs: Vec<_> = missing_errs.chain(extra_errs).collect(); + let all_errs: ::std::vec::Vec<_> = missing_errs.chain(extra_errs).collect(); if !all_errs.is_empty() { - panic!("{}", all_errs.join("\n")); + emit(all_errs.join("\n")); } - // TODO(mingwei): fix duplicates generated from multi-pass flow prop algorithm. - // assert_eq!(actuals_len, expecteds_len, "Wrong nubmer of diagnostics, were there duplicates?"); + if actuals_len != expecteds_len { + emit(format!( + "Number of expected warnings ({}) does not match number of actual warnings ({}), were there duplicates?", + expecteds_len, + actuals_len + )); + } __hf } diff --git a/hydroflow/tests/surface_warnings.rs b/hydroflow/tests/surface_warnings.rs index fa9826083cd..0b73113b271 100644 --- a/hydroflow/tests/surface_warnings.rs +++ b/hydroflow/tests/surface_warnings.rs @@ -1,7 +1,3 @@ -// TODO(mingwei): fix line numbers in tests -// https://github.com/hydro-project/hydroflow/issues/729 -// https://github.com/rust-lang/rust/pull/111571 - use std::cell::RefCell; use std::rc::Rc;