1use std::{path::Path, time::Duration};
2
3use crate::{
4 CommandArgs, Result,
5 metrics::Metrics,
6 sandbox::{Sandbox, SandboxConfig},
7};
8
9#[derive(Debug, Clone, Copy)]
10pub struct Runner<'a> {
11 pub args: CommandArgs<'a>,
12 pub sandbox_config: SandboxConfig<'a>,
13}
14
15impl Runner<'_> {
16 pub fn run(&self, project_path: &Path, stdin: &Path, time_limit: Duration) -> Result<Metrics> {
17 let stdout = project_path.join("stdout.txt");
18 let stderr = project_path.join("stderr.txt");
19
20 let sandbox = Sandbox::new(
21 self.sandbox_config,
22 project_path,
23 self.args,
24 stdin,
25 stdout.as_path(),
26 stderr.as_path(),
27 time_limit,
28 );
29
30 let sandbox = sandbox.spawn()?;
31 sandbox.wait()
32 }
33}