Skip to content

Commit

Permalink
ci: fix stable tests (#1608)
Browse files Browse the repository at this point in the history
Sets `TRYBUILD=overwrite` on stable, as the output messages will often
not match `pinned-nightly`

Adds env `HYDROFLOW_EXPECT_WARNINGS=ignore` to allow warning tests to
pass
  • Loading branch information
MingweiSamuel authored Dec 12, 2024
1 parent 1058b51 commit 7dea92b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ jobs:

- name: Run cargo nextest on all targets
run: cargo nextest run --no-fail-fast --features python --features deploy --all-targets
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
6 changes: 5 additions & 1 deletion hydroflow_lang/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ pub struct SerdeSpan {
}
impl From<Span> for SerdeSpan {
fn from(span: Span) -> Self {
#[cfg_attr(
not(nightly),
expect(unused_labels, reason = "conditional compilation")
)]
let path = 'a: {
#[cfg(nightly)]
if proc_macro::is_available() {
Expand All @@ -204,7 +208,7 @@ impl From<Span> for SerdeSpan {
.into();
}

break 'a "unknown".into();
"unknown".into()
};

Self {
Expand Down
8 changes: 6 additions & 2 deletions hydroflow_lang/src/graph/hydroflow_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,10 @@ impl HydroflowGraph {
subgraph_op_iter_code.push(write_iterator);

if include_type_guards {
#[cfg_attr(
not(nightly),
expect(unused_labels, reason = "conditional compilation")
)]
let source_info = 'a: {
#[cfg(nightly)]
if proc_macro::is_available() {
Expand All @@ -1027,13 +1031,13 @@ impl HydroflowGraph {
);
}

break 'a format!(
format!(
"loc_nopath_{}_{}_{}_{}",
op_span.start().line,
op_span.start().column,
op_span.end().line,
op_span.end().column
);
)
};

let fn_ident = format_ident!(
Expand Down

0 comments on commit 7dea92b

Please sign in to comment.