use std::path::PathBuf;
use wrath::{parser, TryFromEnv};
#[derive(Debug, TryFromEnv)]
#[wrath(error(
#[derive(Debug)]
EnvError
))]
struct Env {
#[allow(dead_code)]
foo: parser::From<PathBuf>,
#[allow(dead_code)]
bar: parser::FromStr<i32>,
#[allow(dead_code)]
baz: parser::IntoString,
}
#[test]
fn ok() {
make_snapshot_test!(
Env,
env_map! {
"FOO" = "some/path",
"BAR" = "100",
"BAZ" = "just text",
}
);
}
#[test]
#[should_panic = expect_msg!()]
fn parse_bar() {
make_snapshot_test!(
Env,
env_map! {
"BAR" = "no",
}
);
}
#[cfg(unix)]
#[test]
#[should_panic = expect_msg!()]
fn convert_bar_baz() {
use std::{collections::HashMap, os::unix::ffi::OsStringExt};
let invalid_utf8 = vec![0xC3, 0x28];
let mut env = HashMap::new();
env.insert("FOO".into(), "some/path".into());
env.insert("BAR".into(), OsStringExt::from_vec(invalid_utf8.clone()));
env.insert("BAZ".into(), OsStringExt::from_vec(invalid_utf8));
make_snapshot_test!(Env, env,);
}
#[test]
#[should_panic = expect_msg!()]
fn unset() {
make_snapshot_test!(Env, env_map! {});
}