1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests ~ fix WSL testing

+ ToDO added ~ when possible, test under WSL2 and differentiate/liberalize if possible
This commit is contained in:
Roy Ivy III 2019-12-25 00:42:11 -06:00
parent 244bdf3d4f
commit 14c3f3aa17
3 changed files with 44 additions and 5 deletions

View file

@ -31,6 +31,22 @@ static ALREADY_RUN: &'static str =
testing();";
static MULTIPLE_STDIN_MEANINGLESS: &'static str = "Ucommand is designed around a typical use case of: provide args and input stream -> spawn process -> block until completion -> return output streams. For verifying that a particular section of the input stream is what causes a particular behavior, use the Command type directly.";
/// 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
}
fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_path: S) -> String {
let tmpdir_path = tmpd.as_ref().unwrap().as_ref().path();
AtPath::new(tmpdir_path).read(file_rel_path.as_ref().to_str().unwrap())

View file

@ -98,7 +98,10 @@ fn test_preserve_root_symlink() {
#[test]
#[cfg(target_os = "linux")]
fn test_reference() {
if get_effective_gid() != 0 {
// skip for root or MS-WSL
// * MS-WSL is bugged (as of 2019-12-25), allowing non-root accounts su-level privileges for `chgrp`
// * for MS-WSL, succeeds and stdout == 'group of /etc retained as root'
if !(get_effective_gid() == 0 || is_wsl()) {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")

View file

@ -47,7 +47,12 @@ fn _du_basics_subdir(s: String) {
}
#[cfg(not(target_os = "macos"))]
fn _du_basics_subdir(s: String) {
assert_eq!(s, "8\tsubdir/deeper\n");
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "8\tsubdir/deeper\n");
} else {
assert_eq!(s, "0\tsubdir/deeper\n");
}
}
#[test]
@ -81,7 +86,12 @@ fn _du_soft_link(s: String) {
}
#[cfg(not(target_os = "macos"))]
fn _du_soft_link(s: String) {
assert_eq!(s, "16\tsubdir/links\n");
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n");
} else {
assert_eq!(s, "8\tsubdir/links\n");
}
}
#[test]
@ -104,7 +114,12 @@ fn _du_hard_link(s: String) {
}
#[cfg(not(target_os = "macos"))]
fn _du_hard_link(s: String) {
assert_eq!(s, "16\tsubdir/links\n");
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n");
} else {
assert_eq!(s, "8\tsubdir/links\n");
}
}
#[test]
@ -123,5 +138,10 @@ fn _du_d_flag(s: String) {
}
#[cfg(not(target_os = "macos"))]
fn _du_d_flag(s: String) {
assert_eq!(s, "28\t./subdir\n36\t./\n");
// MS-WSL linux has altered expected output
if !is_wsl() {
assert_eq!(s, "28\t./subdir\n36\t./\n");
} else {
assert_eq!(s, "8\t./subdir\n8\t./\n");
}
}