(input: ReplInput)
| 2374 | } |
| 2375 | |
| 2376 | fn execute_repl(input: ReplInput) -> Result<ReplOutput, String> { |
| 2377 | if input.code.trim().is_empty() { |
| 2378 | return Err(String::from("code must not be empty")); |
| 2379 | } |
| 2380 | let _ = input.timeout_ms; |
| 2381 | let runtime = resolve_repl_runtime(&input.language)?; |
| 2382 | let started = Instant::now(); |
| 2383 | let output = Command::new(runtime.program) |
| 2384 | .args(runtime.args) |
| 2385 | .arg(&input.code) |
| 2386 | .output() |
| 2387 | .map_err(|error| error.to_string())?; |
| 2388 | |
| 2389 | Ok(ReplOutput { |
| 2390 | language: input.language, |
| 2391 | stdout: String::from_utf8_lossy(&output.stdout).into_owned(), |
| 2392 | stderr: String::from_utf8_lossy(&output.stderr).into_owned(), |
| 2393 | exit_code: output.status.code().unwrap_or(1), |
| 2394 | duration_ms: started.elapsed().as_millis(), |
| 2395 | }) |
| 2396 | } |
| 2397 | |
| 2398 | struct ReplRuntime { |
| 2399 | program: &'static str, |
no test coverage detected