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

Function check_precise_output

cranelift/filetests/src/subtest.rs:157–197  ·  view source on GitHub ↗
(actual: &[&str], context: &Context)

Source from the content-addressed store, hash-verified

155}
156
157pub fn check_precise_output(actual: &[&str], context: &Context) -> Result<()> {
158 // Use the comments after the function to build the test expectation.
159 let expected = context
160 .details
161 .comments
162 .iter()
163 .filter(|c| !c.text.starts_with(";;"))
164 .map(|c| {
165 c.text
166 .strip_prefix("; ")
167 .or_else(|| c.text.strip_prefix(";"))
168 .unwrap_or(c.text)
169 })
170 .collect::<Vec<_>>();
171
172 // If the expectation matches what we got, then there's nothing to do.
173 if actual == expected {
174 return Ok(());
175 }
176
177 // If we're supposed to automatically update the test, then do so here.
178 if env::var("CRANELIFT_TEST_BLESS").unwrap_or(String::new()) == "1" {
179 return update_test(&actual, context);
180 }
181
182 // Otherwise this test has failed, and we can print out as such.
183 bail!(
184 "compilation of function on line {} does not match\n\
185 the text expectation\n\
186 \n\
187 {}\n\
188 \n\
189 This test assertion can be automatically updated by setting the\n\
190 CRANELIFT_TEST_BLESS=1 environment variable when running this test.
191 ",
192 context.details.location.line_number,
193 TextDiff::from_slices(&expected, &actual)
194 .unified_diff()
195 .header("expected", "actual")
196 )
197}
198
199fn update_test(output: &[&str], context: &Context) -> Result<()> {
200 context

Callers 3

runMethod · 0.85
runMethod · 0.85
runMethod · 0.85

Calls 5

OkFunction · 0.85
update_testFunction · 0.85
newFunction · 0.50
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected