Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-cli-test: Prepare testing with `jj`
Lorenz Leutgeb committed 7 months ago
commit 456a0acd57b43645576a8d7bc6c7450fa09e7583
parent fde21b449271f1e6ee48298bb0253abfef94eb08
4 files changed +46 -4
modified crates/radicle-cli-test/src/lib.rs
@@ -107,6 +107,9 @@ pub struct TestRunner<'a> {
    cwd: Option<PathBuf>,
    homes: HashMap<String, Home>,
    formula: &'a TestFormula,
+

+
    /// For seeding randomness in Jujutsu.
+
    jj_seed: usize,
}

impl<'a> TestRunner<'a> {
@@ -115,6 +118,7 @@ impl<'a> TestRunner<'a> {
            cwd: None,
            homes: formula.homes.clone(),
            formula,
+
            jj_seed: 0,
        }
    }

@@ -124,6 +128,7 @@ impl<'a> TestRunner<'a> {

        if let Some(ref h) = test.home {
            if let Some(home) = self.homes.get(h) {
+
                env.insert("USER".to_owned(), h.to_owned());
                return TestRun {
                    home: home.clone(),
                    env,
@@ -464,6 +469,17 @@ impl TestFormula {
                    fs::create_dir_all(run.path())?;
                }

+
                let jj_envs = if assertion.command == "jj" {
+
                    runner.jj_seed += 1;
+
                    vec![
+
                        ("JJ_RANDOMNESS_SEED", i.to_string()),
+
                        ("JJ_TIMESTAMP", "2001-02-03T04:05:06+07:00".to_string()),
+
                        ("JJ_OP_TIMESTAMP", "2001-02-03T04:05:06+07:00".to_string()),
+
                    ]
+
                } else {
+
                    vec![]
+
                };
+

                let bins = self
                    .bins
                    .iter()
@@ -474,6 +490,7 @@ impl TestFormula {
                    .env_clear()
                    .env("PATH", &bins)
                    .env("RUST_BACKTRACE", "1")
+
                    .envs(jj_envs)
                    .envs(run.envs())
                    .current_dir(run.path())
                    .args(args)
modified crates/radicle-cli/tests/commands.rs
@@ -37,14 +37,23 @@ pub(crate) fn test<'a>(
    envs: impl IntoIterator<Item = (&'a str, &'a str)>,
) -> Result<(), Box<dyn std::error::Error>> {
    let tmp = tempfile::tempdir().unwrap();
-
    let home = if let Some(home) = home {
-
        home.path().to_path_buf()
+

+
    let (unix_home, rad_home) = if let Some(home) = home {
+
        let unix_home = home.path().to_path_buf();
+
        let unix_home = unix_home.parent().unwrap().to_path_buf();
+
        (unix_home, home.path().to_path_buf())
    } else {
-
        tmp.path().to_path_buf()
+
        let mut rad_home = tmp.path().to_path_buf();
+
        rad_home.push(".radicle");
+
        (tmp.path().to_path_buf(), rad_home)
    };

    formula(cwd.as_ref(), test)?
-
        .env("RAD_HOME", home.to_string_lossy())
+
        .env("RAD_HOME", rad_home.to_string_lossy())
+
        .env(
+
            "JJ_CONFIG",
+
            unix_home.join(".jjconfig.toml").to_string_lossy(),
+
        )
        .envs(envs)
        .run()?;

modified crates/radicle-cli/tests/util/environment.rs
@@ -246,6 +246,17 @@ impl Environment {
            "RAD_HOME",
            subject.home().path().to_path_buf().to_string_lossy(),
        )
+
        .env(
+
            "JJ_CONFIG",
+
            subject
+
                .home()
+
                .path()
+
                .parent()
+
                .unwrap()
+
                .to_path_buf()
+
                .join(".jjconfig.toml")
+
                .to_string_lossy(),
+
        )
        .run()?;

        Ok(())
modified crates/radicle-cli/tests/util/formula.rs
@@ -20,6 +20,11 @@ pub(crate) fn formula(
        .env("GIT_COMMITTER_DATE", "1671125284")
        .env("GIT_COMMITTER_EMAIL", "radicle@localhost")
        .env("GIT_COMMITTER_NAME", "radicle")
+
        .env("JJ_USER", "Test User")
+
        .env("JJ_EMAIL", "test.user@example.com")
+
        .env("JJ_OP_HOSTNAME", "host.example.com")
+
        .env("JJ_OP_USERNAME", "test-username")
+
        .env("JJ_TZ_OFFSET_MINS", "660")
        .env("EDITOR", "true")
        .env("TZ", "UTC")
        .env("LANG", "C")