1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

Merge pull request #2040 from reggaemuffin/split-wsl-detection

wsl2: wsl no longer differs in output
This commit is contained in:
Sylvestre Ledru 2021-04-24 14:58:09 +02:00 committed by GitHub
commit ea4409460c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 80 additions and 84 deletions

View file

@ -104,7 +104,7 @@ fn test_reference() {
// 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()) {
if !(get_effective_gid() == 0 || uucore::os::is_wsl_1()) {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")

View file

@ -128,7 +128,7 @@ fn test_date_set_invalid() {
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn test_date_set_permissions_error() {
if !(get_effective_uid() == 0 || is_wsl()) {
if !(get_effective_uid() == 0 || uucore::os::is_wsl_1()) {
let result = new_ucmd!()
.arg("--set")
.arg("2020-03-11 21:45:00+08:00")

View file

@ -56,7 +56,7 @@ fn _du_basics_subdir(s: &str) {
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_basics_subdir(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
if !uucore::os::is_wsl_1() {
assert_eq!(s, "8\tsubdir/deeper\n");
} else {
assert_eq!(s, "0\tsubdir/deeper\n");
@ -103,7 +103,7 @@ fn _du_soft_link(s: &str) {
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_soft_link(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
if !uucore::os::is_wsl_1() {
assert_eq!(s, "16\tsubdir/links\n");
} else {
assert_eq!(s, "8\tsubdir/links\n");
@ -144,7 +144,7 @@ fn _du_hard_link(s: &str) {
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_hard_link(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
if !uucore::os::is_wsl_1() {
assert_eq!(s, "16\tsubdir/links\n");
} else {
assert_eq!(s, "8\tsubdir/links\n");
@ -184,7 +184,7 @@ fn _du_d_flag(s: &str) {
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_d_flag(s: &str) {
// MS-WSL linux has altered expected output
if !is_wsl() {
if !uucore::os::is_wsl_1() {
assert_eq!(s, "28\t./subdir\n36\t./\n");
} else {
assert_eq!(s, "8\t./subdir\n8\t./\n");

View file

@ -9,7 +9,7 @@ fn test_normal() {
for (key, value) in env::vars() {
println!("{}: {}", key, value);
}
if (is_ci() || is_wsl()) && result.stderr_str().contains("error: no login name") {
if (is_ci() || uucore::os::is_wsl_1()) && result.stderr_str().contains("error: no login name") {
// ToDO: investigate WSL failure
// In the CI, some server are failing to return logname.
// As seems to be a configuration issue, ignoring it

View file

@ -42,22 +42,6 @@ pub fn is_ci() -> bool {
.eq_ignore_ascii_case("true")
}
/// 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
}
/// Read a test scenario fixture, returning its bytes
fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_path: S) -> Vec<u8> {
let tmpdir_path = tmpd.as_ref().unwrap().as_ref().path();