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

Function process_expanded

crates/component-macro/tests/expanded.rs:35–77  ·  view source on GitHub ↗
(path: &str, suffix: &str, src: &str)

Source from the content-addressed store, hash-verified

33}
34
35fn process_expanded(path: &str, suffix: &str, src: &str) -> Result<()> {
36 let formatted_src = {
37 let syn_file = syn::parse_file(src).unwrap();
38 prettyplease::unparse(&syn_file)
39 };
40 let expanded_path = {
41 let mut stem = Path::new(path).file_stem().unwrap().to_os_string();
42 stem.push(suffix);
43 Path::new("tests/expanded").join(stem).with_extension("rs")
44 };
45 if std::env::var("BINDGEN_TEST_BLESS").is_ok_and(|val| !val.is_empty()) {
46 if let Ok(prev) = std::fs::read(&expanded_path)
47 && prev == formatted_src.as_bytes()
48 {
49 return Ok(());
50 }
51 std::fs::write(expanded_path, formatted_src)?;
52 } else {
53 match std::fs::read_to_string(&expanded_path) {
54 Ok(expected) if formatted_src == expected => (),
55 Ok(expected) => {
56 bail!(
57 "checked-in expanded bindings from {expanded_path:?} \
58 do not match those generated from {path:?}
59 \n\
60 {diff}\n\
61 \n\
62 This test assertion can be automatically updated by setting the\n\
63 BINDGEN_TEST_BLESS=1 environment variable when running this test.",
64 diff = similar::TextDiff::from_lines(&expected, &formatted_src)
65 .unified_diff()
66 .header("expected", "actual")
67 )
68 }
69 Err(err) => return Err(err).with_context(|| {
70 format!(
71 "failed to read {expanded_path:?}; re-run with BINDGEN_TEST_BLESS=1 to create"
72 )
73 }),
74 }
75 }
76 Ok(())
77}
78
79#[test]
80fn expand_wits() -> Result<()> {

Callers

nothing calls this directly

Calls 11

OkFunction · 0.85
read_to_stringFunction · 0.85
as_bytesMethod · 0.80
with_contextMethod · 0.80
newFunction · 0.50
readFunction · 0.50
writeFunction · 0.50
unwrapMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected