use crate::cli::doctor::unset_env_vars;
fn tree(body: &str) -> toml::Value {
toml::from_str(body).expect("fixture parses")
}
#[test]
fn unset_env_vars_dedupes_and_filters_set_names() {
let unset = unset_env_vars(&tree(
"api_key = \"${DREP_TEST_DOCTOR_DEDUPE_UNSET_NEVER_SET_XYZ}\"\n\
other_key = \"${DREP_TEST_DOCTOR_DEDUPE_UNSET_NEVER_SET_XYZ}\"\n",
));
assert_eq!(
unset,
vec!["DREP_TEST_DOCTOR_DEDUPE_UNSET_NEVER_SET_XYZ".to_owned()],
"two references to one name are one warning"
);
assert!(
std::env::var("CARGO_PKG_NAME").is_ok(),
"cargo sets this for every test run; the assertion below relies on it"
);
let unset = unset_env_vars(&tree("model = \"${CARGO_PKG_NAME}\"\n"));
assert!(
unset.is_empty(),
"a variable that IS set must not be reported, got {unset:?}"
);
}
#[test]
fn the_reference_grammar_matches_the_substituters_not_a_stricter_one() {
let unset = unset_env_vars(&tree(
"a = \"${lower_case_never_set_xyz}\"\nb = \"${Mixed_Case_Never_Set_Xyz}\"\n",
));
assert_eq!(
unset,
vec![
"lower_case_never_set_xyz".to_owned(),
"Mixed_Case_Never_Set_Xyz".to_owned()
],
"config::expand_string would fail on both, so doctor must warn about both"
);
let unset = unset_env_vars(&tree("a = \"${DREP_UNSET_XYZ}_TAIL\"\n"));
assert_eq!(unset, vec!["DREP_UNSET_XYZ".to_owned()]);
}
#[test]
fn a_reference_inside_a_comment_is_not_reported() {
let unset = unset_env_vars(&tree(
"# example: api_key = \"${DREP_COMMENT_ONLY_NEVER_SET_XYZ}\"\nmodel = \"m\"\n",
));
assert!(
unset.is_empty(),
"a commented-out example is not a reference, got {unset:?}"
);
}