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

Method run

cranelift/src/interpret.rs:100–138  ·  view source on GitHub ↗

Run the file; this searches for annotations like `; run: %fn0(42)` or `; test: %fn0(42) == 2` and executes them, performing any test comparisons if necessary.

(&self)

Source from the content-addressed store, hash-verified

98 /// Run the file; this searches for annotations like `; run: %fn0(42)` or
99 /// `; test: %fn0(42) == 2` and executes them, performing any test comparisons if necessary.
100 pub fn run(&self) -> Result<(), FileInterpreterFailure> {
101 // parse file
102 let test = parse_test(&self.contents, ParseOptions::default())
103 .map_err(|e| FileInterpreterFailure::ParsingClif(self.path(), e))?;
104
105 // collect functions
106 let mut env = FunctionStore::default();
107 let mut commands = vec![];
108 for (func, details) in test.functions.iter() {
109 for comment in &details.comments {
110 if let Some(command) = parse_run_command(comment.text, &func.signature)
111 .map_err(|e| FileInterpreterFailure::ParsingClif(self.path(), e))?
112 {
113 commands.push(command);
114 }
115 }
116 // Note: func.name may truncate the function name
117 env.add(func.name.to_string(), func);
118 }
119
120 // Run assertion commands
121 for command in commands {
122 command
123 .run(|func_name, args| {
124 // Because we have stored function names with a leading %, we need to re-add it.
125 let func_name = &format!("%{func_name}");
126 let state = InterpreterState::default().with_function_store(env.clone());
127 match Interpreter::new(state).call_by_name(func_name, args) {
128 Ok(ControlFlow::Return(results)) => Ok(results.to_vec()),
129 Ok(ControlFlow::Trap(trap)) => Err(trap.to_string()),
130 Ok(_) => panic!("Unexpected returned control flow--this is likely a bug."),
131 Err(t) => Err(t.to_string()),
132 }
133 })
134 .map_err(|s| FileInterpreterFailure::FailedExecution(s))?;
135 }
136
137 Ok(())
138 }
139}
140
141/// Possible sources of failure in this file.

Callers 5

runFunction · 0.45
nopFunction · 0.45
run_file_contentsFunction · 0.45
handle_requestFunction · 0.45
run-tests.pyFile · 0.45

Calls 13

parse_testFunction · 0.85
parse_run_commandFunction · 0.85
OkFunction · 0.85
with_function_storeMethod · 0.80
call_by_nameMethod · 0.80
newFunction · 0.50
pathMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
addMethod · 0.45
to_stringMethod · 0.45
cloneMethod · 0.45

Tested by 1

nopFunction · 0.36