MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / assert_or_bless_output

Function assert_or_bless_output

tests/disas.rs:346–399  ·  view source on GitHub ↗
(path: &Path, wat: &str, actual: &str)

Source from the content-addressed store, hash-verified

344}
345
346fn assert_or_bless_output(path: &Path, wat: &str, actual: &str) -> Result<()> {
347 log::debug!("=== actual ===\n{actual}");
348 // The test's expectation is the final comment.
349 let mut expected_lines: Vec<_> = wat
350 .lines()
351 .rev()
352 .map_while(|l| l.strip_prefix(";;"))
353 .map(|l| l.strip_prefix(" ").unwrap_or(l))
354 .collect();
355 expected_lines.reverse();
356 let expected = expected_lines.join("\n");
357 let expected = expected.trim();
358 log::debug!("=== expected ===\n{expected}");
359
360 if actual == expected {
361 return Ok(());
362 }
363
364 if std::env::var("WASMTIME_TEST_BLESS").unwrap_or_default() == "1" {
365 let old_expectation_line_count = wat
366 .lines()
367 .rev()
368 .take_while(|l| l.starts_with(";;"))
369 .count();
370 let old_wat_line_count = wat.lines().count();
371 let new_wat_lines: Vec<_> = wat
372 .lines()
373 .take(old_wat_line_count - old_expectation_line_count)
374 .map(|l| l.to_string())
375 .chain(actual.lines().map(|l| {
376 if l.is_empty() {
377 ";;".to_string()
378 } else {
379 format!(";; {l}")
380 }
381 }))
382 .collect();
383 let mut new_wat = new_wat_lines.join("\n");
384 new_wat.push('\n');
385 std::fs::write(path, new_wat)
386 .with_context(|| format!("failed to write file: {}", path.display()))?;
387 return Ok(());
388 }
389
390 bail!(
391 "Did not get the expected CLIF translation:\n\n\
392 {}\n\n\
393 Note: You can re-run with the `WASMTIME_TEST_BLESS=1` environment\n\
394 variable set to update test expectations.",
395 TextDiff::from_lines(expected, actual)
396 .unified_diff()
397 .header("expected", "actual")
398 )
399}

Callers 1

assert_outputFunction · 0.85

Calls 12

OkFunction · 0.85
collectMethod · 0.80
reverseMethod · 0.80
chainMethod · 0.80
with_contextMethod · 0.80
writeFunction · 0.50
mapMethod · 0.45
joinMethod · 0.45
takeMethod · 0.45
to_stringMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected