diff --git a/crates/radicle-cli-test/src/lib.rs b/crates/radicle-cli-test/src/lib.rs index 66f3245a..cf016b9a 100644 --- a/crates/radicle-cli-test/src/lib.rs +++ b/crates/radicle-cli-test/src/lib.rs @@ -124,6 +124,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, @@ -420,7 +421,7 @@ impl TestFormula { let mut run = runner.run(test); // For each command. - for assertion in &test.assertions { + for (i, assertion) in test.assertions.iter().enumerate() { // Expand environment variables. let mut args = assertion.args.clone(); for arg in &mut args { @@ -464,6 +465,16 @@ impl TestFormula { fs::create_dir_all(run.path())?; } + let jj_envs = if assertion.command == "jj" { + 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 +485,7 @@ impl TestFormula { .env_clear() .env("PATH", &bins) .env("RUST_BACKTRACE", "1") + .envs(jj_envs) .envs(run.envs()) .current_dir(run.path()) .args(args) diff --git a/crates/radicle-cli/tests/commands.rs b/crates/radicle-cli/tests/commands.rs index 90237014..5ef3c0fb 100644 --- a/crates/radicle-cli/tests/commands.rs +++ b/crates/radicle-cli/tests/commands.rs @@ -37,14 +37,23 @@ pub(crate) fn test<'a>( envs: impl IntoIterator, ) -> Result<(), Box> { 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()?; diff --git a/crates/radicle-cli/tests/util/environment.rs b/crates/radicle-cli/tests/util/environment.rs index d6305ef6..5fc512e1 100644 --- a/crates/radicle-cli/tests/util/environment.rs +++ b/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(()) diff --git a/crates/radicle-cli/tests/util/formula.rs b/crates/radicle-cli/tests/util/formula.rs index fe44a0de..7e75bc3d 100644 --- a/crates/radicle-cli/tests/util/formula.rs +++ b/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")