diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-10-22 11:59:50 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-10-22 11:59:50 +0000 |
commit | 1bcbb535490511e0bc4f2826356a16bdd05360b0 (patch) | |
tree | 1e26b5616d61e9fc917278012f75d707bbfd97fa /subplotlib/src/steplibrary/runcmd.rs | |
parent | 990c506d347a6aa09af68bc6de670858cf59f133 (diff) | |
parent | 7f52ffc37e1a366f78ba3709f15b09ca22ca98c9 (diff) | |
download | subplot-1bcbb535490511e0bc4f2826356a16bdd05360b0.tar.gz |
Merge branch 'filepath-as-path' into 'main'
(derive): Support steps with &Path arguments
Closes #288
See merge request subplot/subplot!295
Diffstat (limited to 'subplotlib/src/steplibrary/runcmd.rs')
-rw-r--r-- | subplotlib/src/steplibrary/runcmd.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/subplotlib/src/steplibrary/runcmd.rs b/subplotlib/src/steplibrary/runcmd.rs index b90f8b7..6692441 100644 --- a/subplotlib/src/steplibrary/runcmd.rs +++ b/subplotlib/src/steplibrary/runcmd.rs @@ -56,7 +56,9 @@ static DEFAULT_PATHS: &[&str] = &[ ]; // This us used internally to force CWD for running commands -const USE_CWD: &str = "\0USE_CWD"; +lazy_static! { + static ref USE_CWD: PathBuf = PathBuf::from("\0USE_CWD"); +} impl ContextElement for Runcmd { fn scenario_starts(&mut self) -> StepResult { @@ -229,7 +231,7 @@ pub fn run(context: &ScenarioContext, argv0: &str, args: &str) { #[step] #[context(Datadir)] #[context(Runcmd)] -pub fn run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args: &str) { +pub fn run_in(context: &ScenarioContext, dirname: &Path, argv0: &str, args: &str) { try_to_run_in::call(context, dirname, argv0, args)?; exit_code_is::call(context, 0)?; } @@ -244,7 +246,7 @@ pub fn run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args: &str) #[context(Datadir)] #[context(Runcmd)] pub fn try_to_run(context: &ScenarioContext, argv0: &str, args: &str) { - try_to_run_in::call(context, USE_CWD, argv0, args)?; + try_to_run_in::call(context, &USE_CWD, argv0, args)?; } /// Run the given command in the given subpath of the data directory @@ -256,7 +258,7 @@ pub fn try_to_run(context: &ScenarioContext, argv0: &str, args: &str) { #[step] #[context(Datadir)] #[context(Runcmd)] -pub fn try_to_run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args: &str) { +pub fn try_to_run_in(context: &ScenarioContext, dirname: &Path, argv0: &str, args: &str) { // This is the core of runcmd and is how we handle things let argv0: PathBuf = if argv0.starts_with('.') { context.with( @@ -270,7 +272,7 @@ pub fn try_to_run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args |datadir: &Datadir| Ok(datadir.base_path().to_path_buf()), false, )?; - if dirname != USE_CWD { + if dirname != USE_CWD.as_path() { datadir = datadir.join(dirname); } let mut proc = Command::new(&argv0); |