Skip to content

Commit

Permalink
fixup! fixup! ci: TRYBUILD=overwrite on stable
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Dec 12, 2024
1 parent fed16c5 commit c08b595
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 24 additions & 11 deletions hydroflow/src/declarative_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,51 @@ 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<str>) {
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)
});
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
}
Expand Down
4 changes: 0 additions & 4 deletions hydroflow/tests/surface_warnings.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit c08b595

Please sign in to comment.