From 7acd025d7f6570b114f52a86019468490bf6a0e1 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 22 Nov 2023 15:46:55 +0100 Subject: [PATCH] cli: Make sure envs don't bleed Previously, if you set an env var in one test, it could also appear in a later test. This ensures we don't persist envs between tests. --- radicle-cli-test/src/lib.rs | 34 +++++++++----------- radicle-cli/examples/git/git-push-diverge.md | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/radicle-cli-test/src/lib.rs b/radicle-cli-test/src/lib.rs index 9938e0ae..8e794d12 100644 --- a/radicle-cli-test/src/lib.rs +++ b/radicle-cli-test/src/lib.rs @@ -77,6 +77,7 @@ pub struct Home { #[derive(Debug)] pub struct TestRun { home: Home, + env: HashMap, } impl TestRun { @@ -85,7 +86,7 @@ impl TestRun { } fn envs(&self) -> impl Iterator { - self.home.envs.iter() + self.home.envs.iter().chain(self.env.iter()) } fn path(&self) -> PathBuf { @@ -110,31 +111,26 @@ impl<'a> TestRunner<'a> { } fn run(&mut self, test: &'a Test) -> TestRun { - let mut envs = self.formula.env.clone(); + let mut env = self.formula.env.clone(); + env.extend(test.env.clone()); if let Some(ref h) = test.home { if let Some(home) = self.homes.get(h) { - envs.extend(home.envs.clone()); - envs.extend(test.env.clone()); - - let home = Home { - name: home.name.clone(), - path: home.path.clone(), - envs, + return TestRun { + home: home.clone(), + env, }; - return TestRun { home }; } else { panic!("TestRunner::test: home `~{h}` does not exist"); } } - envs.extend(test.env.clone()); - TestRun { home: Home { name: None, path: self.cwd.clone().unwrap_or_else(|| self.formula.cwd.clone()), - envs, + envs: HashMap::new(), }, + env, } } @@ -504,7 +500,7 @@ mod tests { fn test_parse() { let input = r#" Let's try to track @dave and @sean: -``` +``` RAD_HINT=true $ rad track @dave Tracking relationship established for @dave. Nothing to do. @@ -514,7 +510,7 @@ Tracking relationship established for @sean. Nothing to do. ``` Super, now let's move on to the next step. -``` +``` ~alice (stderr) $ rad sync ``` "# @@ -564,11 +560,13 @@ $ rad sync ], fail: false, stderr: false, - env: HashMap::default(), + env: vec![("RAD_HINT".to_owned(), "true".to_owned())] + .into_iter() + .collect(), }, Test { context: vec![String::from("Super, now let's move on to the next step.")], - home: None, + home: Some("alice".to_owned()), assertions: vec![Assertion { path: path.clone(), command: String::from("rad"), @@ -577,7 +575,7 @@ $ rad sync exit: ExitStatus::Success, }], fail: false, - stderr: false, + stderr: true, env: HashMap::default(), }, ], diff --git a/radicle-cli/examples/git/git-push-diverge.md b/radicle-cli/examples/git/git-push-diverge.md index 6e32754e..256478a4 100644 --- a/radicle-cli/examples/git/git-push-diverge.md +++ b/radicle-cli/examples/git/git-push-diverge.md @@ -77,7 +77,7 @@ $ git push -f We have to use the `allow.rollback` option: -``` ~alice (stderr) +``` ~alice RAD_SOCKET=/dev/null (stderr) $ git push -f -o allow.rollback To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi + f6cff86...319a7dc master -> master (forced update)