tests ~ (sub-crate/mknod) fix WSL variation in expected test values

This commit is contained in:
Roy Ivy III 2020-08-16 15:35:45 -05:00
parent 2a50dc42c1
commit 74200f368b

View file

@ -20,18 +20,37 @@ pub fn parse_mode(mode: Option<String>) -> Result<mode_t, String> {
}
}
#[test]
fn symbolic_modes() {
assert_eq!(parse_mode(Some("u+x".to_owned())).unwrap(), 0o766);
assert_eq!(parse_mode(Some("+x".to_owned())).unwrap(), 0o777);
assert_eq!(parse_mode(Some("a-w".to_owned())).unwrap(), 0o444);
assert_eq!(parse_mode(Some("g-r".to_owned())).unwrap(), 0o626);
}
#[cfg(test)]
mod test {
/// Test if the program is running under WSL
// ref: <https://github.com/microsoft/WSL/issues/4555> @@ <https://archive.is/dP0bz>
// ToDO: test on WSL2 which likely doesn't need special handling; plan change to `is_wsl_1()` if WSL2 is less needy
pub fn is_wsl() -> bool {
#[cfg(target_os = "linux")]
{
if let Ok(b) = std::fs::read("/proc/sys/kernel/osrelease") {
if let Ok(s) = std::str::from_utf8(&b) {
let a = s.to_ascii_lowercase();
return a.contains("microsoft") || a.contains("wsl");
}
}
}
false
}
#[test]
fn numeric_modes() {
assert_eq!(parse_mode(Some("644".to_owned())).unwrap(), 0o644);
assert_eq!(parse_mode(Some("+100".to_owned())).unwrap(), 0o766);
assert_eq!(parse_mode(Some("-4".to_owned())).unwrap(), 0o662);
assert_eq!(parse_mode(None).unwrap(), 0o666);
#[test]
fn symbolic_modes() {
assert_eq!(super::parse_mode(Some("u+x".to_owned())).unwrap(), 0o766);
assert_eq!(super::parse_mode(Some("+x".to_owned())).unwrap(), if !is_wsl() { 0o777 } else {0o776});
assert_eq!(super::parse_mode(Some("a-w".to_owned())).unwrap(), 0o444);
assert_eq!(super::parse_mode(Some("g-r".to_owned())).unwrap(), 0o626);
}
#[test]
fn numeric_modes() {
assert_eq!(super::parse_mode(Some("644".to_owned())).unwrap(), 0o644);
assert_eq!(super::parse_mode(Some("+100".to_owned())).unwrap(), 0o766);
assert_eq!(super::parse_mode(Some("-4".to_owned())).unwrap(), 0o662);
assert_eq!(super::parse_mode(None).unwrap(), 0o666);
}
}