cli: Fix flaky tests
We were setting the CWD for the parent process, which wasn't such a good idea. Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
aa05f676f7
commit
9ec7a0a2ce
|
|
@ -9,7 +9,8 @@ use framework::TestFormula;
|
||||||
|
|
||||||
/// Run a CLI test file.
|
/// Run a CLI test file.
|
||||||
fn test(
|
fn test(
|
||||||
path: impl AsRef<Path>,
|
test: impl AsRef<Path>,
|
||||||
|
cwd: impl AsRef<Path>,
|
||||||
profile: Option<&Profile>,
|
profile: Option<&Profile>,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let base = Path::new(env!("CARGO_MANIFEST_DIR"));
|
let base = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
|
@ -24,7 +25,8 @@ fn test(
|
||||||
.env("RAD_PASSPHRASE", "radicle")
|
.env("RAD_PASSPHRASE", "radicle")
|
||||||
.env("RAD_HOME", home.to_string_lossy())
|
.env("RAD_HOME", home.to_string_lossy())
|
||||||
.env("RAD_DEBUG", "1")
|
.env("RAD_DEBUG", "1")
|
||||||
.file(base.join(path))?
|
.cwd(cwd)
|
||||||
|
.file(base.join(test))?
|
||||||
.run()?;
|
.run()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -40,7 +42,7 @@ fn profile(home: &Path) -> Profile {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rad_auth() {
|
fn rad_auth() {
|
||||||
test("examples/rad-auth.md", None).unwrap();
|
test("examples/rad-auth.md", Path::new("."), None).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -51,12 +53,11 @@ fn rad_issue() {
|
||||||
|
|
||||||
// Setup a test repository.
|
// Setup a test repository.
|
||||||
fixtures::repository(working.path());
|
fixtures::repository(working.path());
|
||||||
// Navigate to repository.
|
// Set a fixed commit time.
|
||||||
env::set_current_dir(working.path()).unwrap();
|
|
||||||
env::set_var(radicle_cob::git::RAD_COMMIT_TIME, "1671125284");
|
env::set_var(radicle_cob::git::RAD_COMMIT_TIME, "1671125284");
|
||||||
|
|
||||||
test("examples/rad-init.md", Some(&profile)).unwrap();
|
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
||||||
test("examples/rad-issue.md", Some(&profile)).unwrap();
|
test("examples/rad-issue.md", working.path(), Some(&profile)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -67,10 +68,8 @@ fn rad_init() {
|
||||||
|
|
||||||
// Setup a test repository.
|
// Setup a test repository.
|
||||||
fixtures::repository(working.path());
|
fixtures::repository(working.path());
|
||||||
// Navigate to repository.
|
|
||||||
env::set_current_dir(working.path()).unwrap();
|
|
||||||
|
|
||||||
test("examples/rad-init.md", Some(&profile)).unwrap();
|
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -81,9 +80,7 @@ fn rad_delegate() {
|
||||||
|
|
||||||
// Setup a test repository.
|
// Setup a test repository.
|
||||||
fixtures::repository(working.path());
|
fixtures::repository(working.path());
|
||||||
// Navigate to repository.
|
|
||||||
env::set_current_dir(working.path()).unwrap();
|
|
||||||
|
|
||||||
test("examples/rad-init.md", Some(&profile)).unwrap();
|
test("examples/rad-init.md", working.path(), Some(&profile)).unwrap();
|
||||||
test("examples/rad-delegate.md", Some(&profile)).unwrap();
|
test("examples/rad-delegate.md", working.path(), Some(&profile)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ impl TestFormula {
|
||||||
|
|
||||||
Command::new(program)
|
Command::new(program)
|
||||||
.envs(self.env.clone())
|
.envs(self.env.clone())
|
||||||
|
.current_dir(&self.cwd)
|
||||||
.args(&assertion.args)
|
.args(&assertion.args)
|
||||||
.with_assert(assert.clone())
|
.with_assert(assert.clone())
|
||||||
.assert()
|
.assert()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue