about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-10-22 09:15:42 +0200
committerGitHub <noreply@github.com>2023-10-22 09:15:42 +0200
commit4d80740c1dcc079e9a95f9b4aedf05dee3dfb605 (patch)
treedba3126822527e8c82be93c9a7e7a80df282f561
parent56b9f0327fd89dbb73b885c5fdad580ca2c8da43 (diff)
parent46f68ccb8b88c77edc5ed3d5d5cfb6189910af37 (diff)
downloadrust-4d80740c1dcc079e9a95f9b4aedf05dee3dfb605.tar.gz
rust-4d80740c1dcc079e9a95f9b4aedf05dee3dfb605.zip
Rollup merge of #116989 - ChrisDenton:skip-unsupported, r=Mark-Simulacrum
Skip test if Unix sockets are unsupported

Fixes https://github.com/rust-lang/rust/pull/116683#issuecomment-1772314187

The test will be skipped if `AF_UNIX` is not supported. In that case [`WSASocketW` returns `WSAEAFNOSUPPORT`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw#return-value).

It will never skip the test when run in CI but maybe this is me being too defensive since the error code is narrowly scoped to just the af family parameter being unsupported?

Also fixed a minor typo.

r? `@Mark-Simulacrum`
-rw-r--r--library/std/src/fs/tests.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs
index f0c4be2327c..736b495343e 100644
--- a/library/std/src/fs/tests.rs
+++ b/library/std/src/fs/tests.rs
@@ -1717,7 +1717,7 @@ fn windows_unix_socket_exists() {
     let tmp = tmpdir();
     let socket_path = tmp.join("socket");
 
-    // std doesn't current support Unix sockets on Windows so manually create one here.
+    // std doesn't currently support Unix sockets on Windows so manually create one here.
     net::init();
     unsafe {
         let socket = c::WSASocketW(
@@ -1728,7 +1728,16 @@ fn windows_unix_socket_exists() {
             0,
             c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT,
         );
-        assert_ne!(socket, c::INVALID_SOCKET);
+        // AF_UNIX is not supported on earlier versions of Windows,
+        // so skip this test if it's unsupported and we're not in CI.
+        if socket == c::INVALID_SOCKET {
+            let error = c::WSAGetLastError();
+            if env::var_os("CI").is_none() && error == c::WSAEAFNOSUPPORT {
+                return;
+            } else {
+                panic!("Creating AF_UNIX socket failed (OS error {error})");
+            }
+        }
         let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() };
         let bytes = socket_path.as_os_str().as_encoded_bytes();
         addr.sun_path[..bytes.len()].copy_from_slice(bytes);