Skip to content

Commit

Permalink
Skip test if Unix sockets are unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Oct 20, 2023
1 parent 274455a commit 46f68cc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit 46f68cc

Please sign in to comment.