Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli-test: Expand env vars in commands
cloudhead committed 2 years ago
commit 50460842f48b461a53529814078e20efc9dfda32
parent 2d710936087a0a41fc5f31bf2ab2c3dbe0a6e77f
2 files changed +20 -8
modified radicle-cli-test/src/lib.rs
@@ -85,8 +85,16 @@ impl TestRun {
        self.home.path = path;
    }

-
    fn envs(&self) -> impl Iterator<Item = (&String, &String)> {
-
        self.home.envs.iter().chain(self.env.iter())
+
    fn envs(&self) -> impl Iterator<Item = (String, String)> + '_ {
+
        self.home
+
            .envs
+
            .iter()
+
            .chain(self.env.iter())
+
            .map(|(k, v)| (k.to_owned(), v.to_owned()))
+
            .chain(Some((
+
                "PWD".to_owned(),
+
                self.home.path.to_string_lossy().to_string(),
+
            )))
    }

    fn path(&self) -> PathBuf {
@@ -403,6 +411,13 @@ impl TestFormula {

            // For each command.
            for assertion in &test.assertions {
+
                // Expand environment variables.
+
                let mut args = assertion.args.clone();
+
                for arg in &mut args {
+
                    for (k, v) in run.envs() {
+
                        *arg = arg.replace(format!("${k}").as_str(), &v);
+
                    }
+
                }
                let path = assertion
                    .path
                    .file_name()
@@ -411,10 +426,7 @@ impl TestFormula {
                let cmd = if assertion.command == "rad" {
                    snapbox::cmd::cargo_bin("rad")
                } else if assertion.command == "cd" {
-
                    let mut arg = assertion.args.first().unwrap().clone();
-
                    for (k, v) in run.envs() {
-
                        arg = arg.replace(&format!("${k}"), v);
-
                    }
+
                    let arg = assertion.args.first().unwrap();
                    let dir: PathBuf = arg.into();
                    let dir = run.path().join(dir);

@@ -454,7 +466,7 @@ impl TestFormula {
                    .env("RUST_BACKTRACE", "1")
                    .envs(run.envs())
                    .current_dir(run.path())
-
                    .args(&assertion.args)
+
                    .args(args)
                    .with_assert(assert.clone())
                    .output();

modified radicle/src/git.rs
@@ -584,7 +584,7 @@ pub fn push<'a>(
) -> Result<(), git2::Error> {
    let refspecs = refspecs
        .into_iter()
-
        .map(|(src, dst)| format!("{}:{}", src.as_str(), dst.as_str()));
+
        .map(|(src, dst)| format!("{src}:{dst}"));

    repo.find_remote(remote)?
        .push(refspecs.collect::<Vec<_>>().as_slice(), None)?;