From 8df6e9eebbe1c5c284a6880d2dccb5715f66d1aa Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Fri, 2 Jun 2023 10:41:39 +0200 Subject: [PATCH] feat: create monado runner from profile --- src/runner.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index 57be6da..2097509 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -6,6 +6,8 @@ use std::{ process::{Child, Command, Stdio}, }; +use crate::profile::Profile; + pub struct Runner { environment: HashMap, command: String, @@ -22,8 +24,8 @@ pub enum RunnerStatus { } impl Runner { - pub fn new(environment: HashMap, command: String, args: Vec) -> Runner { - Runner { + pub fn new(environment: HashMap, command: String, args: Vec) -> Self { + Self { environment, command, args, @@ -33,6 +35,17 @@ impl Runner { } } + pub fn monado_runner_from_profile(profile: Profile) -> Self { + Self { + environment: profile.environment, + command: profile.monado_path, + args: vec![], + stdout: Vec::new(), + stderr: Vec::new(), + process: None, + } + } + pub fn start(&mut self) { match self.process { Some(_) => panic!("Cannot reuse existing Runner"), @@ -135,6 +148,8 @@ impl Runner { #[cfg(test)] mod tests { + use crate::profile::load_profile; + use super::{Runner, RunnerStatus}; use core::time; use std::{collections::HashMap, thread::sleep}; @@ -177,4 +192,11 @@ mod tests { runner.save_stdout("./target/testout/testlog".into()); runner.save_stderr("./target/testout/testlog".into()); } + + #[test] + fn can_create_from_profile() { + Runner::monado_runner_from_profile( + load_profile(&"./test/files/profile.json".to_string()).unwrap(), + ); + } }