mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
tests ~ (sub-crate/mknod) fix WSL variation in expected test values
This commit is contained in:
parent
2a50dc42c1
commit
74200f368b
1 changed files with 32 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue