use crate::support::{sandbox_with_plugin, stderr_of, Sandbox};
#[test]
fn plugin_ls_says_how_to_start() {
let sb = Sandbox::new();
let out = sb.ok(&["plugin", "ls"]);
assert!(out.contains("pmpx plugin add"), "{out}");
}
#[test]
fn plugin_set_writes_a_pmpx_toml_and_it_takes_effect() {
let (_build, sb, _lib) = sandbox_with_plugin();
sb.file("fakepm.lock").file("fakepm.json");
sb.ok(&["plugin", "set", "fakepm"]);
let cfg = sb.project.join(".pmpx.toml");
assert!(cfg.is_file(), "it should have written .pmpx.toml");
let text = std::fs::read_to_string(&cfg).unwrap();
assert!(text.contains("faketest"), "the key is the family: {text}");
assert!(text.contains("fakepm"), "{text}");
let out = sb.ok(&[]);
assert!(out.contains("fakepm"), "{out}");
}
#[test]
fn plugin_unset_removes_it_and_cleans_up_the_file() {
let (_build, sb, _lib) = sandbox_with_plugin();
sb.file("fakepm.lock");
sb.ok(&["plugin", "set", "fakepm"]);
let cfg = sb.project.join(".pmpx.toml");
assert!(cfg.is_file());
sb.ok(&["plugin", "unset", "faketest"]);
assert!(
!cfg.exists(),
"an empty config file should be deleted, not left as a shell"
);
}
#[test]
fn unset_without_a_family_needs_yes_when_there_are_several() {
let (_build, sb, _lib) = sandbox_with_plugin();
sb.file("fakepm.lock");
std::fs::write(
sb.project.join(".pmpx.toml"),
"[plugin]\nfaketest = \"fakepm\"\npython = \"poetry\"\n",
)
.unwrap();
let out = sb.run(&["plugin", "unset"]);
assert_eq!(
out.status.code(),
Some(2),
"requiring --yes is a usage error"
);
let err = stderr_of(&out);
assert!(err.contains("--yes"), "{err}");
assert!(err.contains("faketest"), "{err}");
assert!(err.contains("python"), "{err}");
sb.ok(&["plugin", "unset", "--yes"]);
assert!(!sb.project.join(".pmpx.toml").exists());
}
#[test]
fn a_manifest_without_family_is_listed_with_its_problem() {
let sb = Sandbox::new();
sb.install_plugin(
"pmpx-plugin-broken",
"[plugin]\nname = \"broken\"\nversion = \"0.1.0\"\n\n[detect]\nstrong = [\"x.lock\"]\n",
None,
);
sb.file("x.lock");
let out = sb.ok(&["plugin", "ls"]);
assert!(out.contains("broken"), "{out}");
assert!(out.contains("family"), "it should state the problem: {out}");
let out = sb.run(&[]);
assert_eq!(
out.status.code(),
Some(3),
"an unusable plugin takes no part in detection"
);
}
#[test]
fn an_unknown_plugin_flag_lists_what_is_installed() {
let (_build, sb, _lib) = sandbox_with_plugin();
sb.file("fakepm.lock");
let out = sb.run(&["-p", "nope", "build"]);
assert_eq!(out.status.code(), Some(3));
let err = stderr_of(&out);
assert!(err.contains("nope"), "{err}");
assert!(
err.contains("fakepm"),
"it should list what is installed: {err}"
);
}
#[test]
fn the_plugin_flag_beats_the_project_config() {
let (_build, sb, _lib) = sandbox_with_plugin();
sb.file("fakepm.lock");
std::fs::write(
sb.project.join(".pmpx.toml"),
"[plugin]\nfaketest = \"ghost\"\n",
)
.unwrap();
let out = sb.run(&["build"]);
assert_eq!(out.status.code(), Some(3), "{}", stderr_of(&out));
let out = sb.run(&["-p", "fakepm", "build"]);
assert!(
out.status.success(),
"-p must beat .pmpx.toml: {}",
stderr_of(&out)
);
}
#[test]
fn an_abi_mismatch_is_refused_with_both_versions() {
let (_build, sb, lib) = sandbox_with_plugin();
sb.file("fakepm.lock");
let out = sb.ok(&["plugin", "info", "fakepm"]);
assert!(out.contains("ABI"), "{out}");
let _ = lib;
}