use std::process::Command;
fn sqlx_features(extra: &[&str]) -> Vec<String> {
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());
let out = Command::new(cargo)
.current_dir(env!("CARGO_MANIFEST_DIR"))
.args(["tree", "--locked", "--offline", "-p", "persistant-sqlx"])
.args(extra)
.args(["-e", "normal,build", "-i", "sqlx", "--format", "{p} [{f}]"])
.output()
.expect("run cargo tree");
assert!(
out.status.success(),
"cargo tree failed: {}",
String::from_utf8_lossy(&out.stderr)
);
let text = String::from_utf8(out.stdout).expect("utf-8");
let first = text.lines().next().expect("cargo tree printed nothing");
assert!(first.starts_with("sqlx "), "unexpected first line: {first}");
let open = first.find('[').expect("no feature list");
first[open + 1..first.len() - 1]
.split(',')
.map(str::to_owned)
.collect()
}
fn check(features: &[String]) {
assert!(
features.iter().any(|f| f == "postgres"),
"feature list not read: {features:?}"
);
assert!(
!features.iter().any(|f| f == "time"),
"persistant-sqlx enables sqlx's `time` feature, which breaks sqlx::query! for a chrono consumer: {features:?}"
);
}
#[test]
fn default_build_leaves_sqlx_time_off() {
check(&sqlx_features(&[]));
}
#[test]
fn all_features_leave_sqlx_time_off() {
check(&sqlx_features(&["--all-features"]));
}