Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/graphicle/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ fn shell_quote(value: &str) -> String {
/// in a container. `graphicle update` and `graphicle uninstall` both use it.
pub fn installed(exe: &Path) -> Install {
let cargo_bin = std::env::var_os("CARGO_HOME")
.filter(|value| !value.is_empty())
.map(PathBuf::from)
.or_else(|| home_dir().map(|h| h.join(".cargo")))
.map(|cargo| cargo.join("bin"));
Expand Down
84 changes: 83 additions & 1 deletion crates/graphicle/tests/it/ux_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,18 @@ impl Sandbox {
}
/// The program with this sandbox's environment, in `cwd`.
fn command(&self, cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Command {
self.command_of(Path::new(env!("CARGO_BIN_EXE_graphicle")), cwd, args, env)
}
/// [`Sandbox::command`] for `program`.
fn command_of(
&self,
program: &Path,
cwd: &Path,
args: &[&str],
env: &[(&str, &str)],
) -> Command {
let home = self.home();
let mut command = Command::new(env!("CARGO_BIN_EXE_graphicle"));
let mut command = Command::new(program);
command
.current_dir(cwd)
.arg("--data-dir")
Expand Down Expand Up @@ -916,6 +926,78 @@ fn update_without_a_feed_says_how_to_update_and_sync_defaults_to_this_folder() {
assert!(again.contains("Code graph: 7 nodes"), "{again}");
}

/// Update and uninstall treat an empty CARGO_HOME as unset.
#[test]
fn update_and_uninstall_treat_an_empty_cargo_home_as_unset() {
let sandbox = Sandbox::new();
let cargo_bin = sandbox.home().join(".cargo").join("bin");
std::fs::create_dir_all(&cargo_bin).unwrap();
let program = cargo_bin.join(crate::child_env::program("graphicle"));
if std::fs::hard_link(env!("CARGO_BIN_EXE_graphicle"), &program).is_err() {
std::fs::copy(env!("CARGO_BIN_EXE_graphicle"), &program).unwrap();
}
for env in [&[][..], &[("CARGO_HOME", "")][..]] {
let update = json_of(
&crate::fork_guard::spawn(&mut sandbox.command_of(
&program,
&sandbox.elsewhere(),
&["update"],
env,
))
.unwrap()
.wait_with_output()
.unwrap(),
);
assert_eq!(update["installed"], "cargo", "{update}");
let commands = update["update"].as_array().unwrap();
assert!(
commands.iter().any(|command| {
command.as_str() == Some("cargo install --path runtime --locked --force")
}),
"{update}"
);
}
let custom = sandbox.root.join("cargo");
std::fs::create_dir_all(custom.join("bin")).unwrap();
let that_program = custom
.join("bin")
.join(crate::child_env::program("graphicle"));
if std::fs::hard_link(env!("CARGO_BIN_EXE_graphicle"), &that_program).is_err() {
std::fs::copy(env!("CARGO_BIN_EXE_graphicle"), &that_program).unwrap();
}
let update = json_of(
&crate::fork_guard::spawn(&mut sandbox.command_of(
&that_program,
&sandbox.elsewhere(),
&["update"],
&[("CARGO_HOME", custom.to_str().unwrap())],
))
.unwrap()
.wait_with_output()
.unwrap(),
);
assert_eq!(update["installed"], "cargo", "{update}");
std::fs::create_dir_all(sandbox.data()).unwrap();
let report = json_of(
&crate::fork_guard::spawn(&mut sandbox.command_of(
&program,
&sandbox.elsewhere(),
&["uninstall"],
&[("CARGO_HOME", "")],
))
.unwrap()
.wait_with_output()
.unwrap(),
);
assert_eq!(report["remove_program"]["method"], "cargo", "{report:#}");
assert!(
report["remove_program"]["command"]
.as_str()
.is_some_and(|command| command.starts_with("cargo uninstall ")),
"{report:#}"
);
}

#[test]
fn open_reuses_a_running_server_and_prints_the_address_without_a_browser() {
let sandbox = Sandbox::new();
Expand Down
Loading