radicle-cli-test: Prepare testing with `jj`

Most of this is taken from Jujutsu's own testing setup, see:
98d884827e/cli/tests/common/test_environment.rs (L106-L150)

Not all features are preserved, but this is good enough.
This commit is contained in:
Lorenz Leutgeb 2025-05-28 19:26:30 +02:00 committed by Fintan Halpenny
parent 53522288c1
commit fd5043d572
4 changed files with 42 additions and 5 deletions

View File

@ -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)

View File

@ -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()?;

View File

@ -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(())

View File

@ -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")