[前][次][番号順一覧][スレッド一覧]

ruby-changes:61425

From: Yusuke <ko1@a...>
Date: Sat, 30 May 2020 01:52:54 +0900 (JST)
Subject: [ruby-changes:61425] e73e504e2f (master): spec: add wsl guard

https://git.ruby-lang.org/ruby.git/commit/?id=e73e504e2f

From e73e504e2f2618453c75cc322fa4813ab9661c60 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Sat, 30 May 2020 01:45:46 +0900
Subject: spec: add wsl guard

WSL 2 is officially released.  It uses Linux kernel, so almost all specs
for Linux work on WSL, except one: gethostbyaddr.  I guess network
resolution in WSL is based on Windows, so the behavior seems a bit
different from normal Linux.

This change adds `platform_is_not :wsl` guard, and guards out the test
in question.

diff --git a/spec/mspec/lib/mspec/guards/platform.rb b/spec/mspec/lib/mspec/guards/platform.rb
index 2d22d4f..2d5c2de 100644
--- a/spec/mspec/lib/mspec/guards/platform.rb
+++ b/spec/mspec/lib/mspec/guards/platform.rb
@@ -26,8 +26,11 @@ class PlatformGuard < SpecGuard https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/guards/platform.rb#L26
   def self.os?(*oses)
     oses.any? do |os|
       raise ":java is not a valid OS" if os == :java
-      if os == :windows
+      case os
+      when :windows
         PLATFORM =~ /(mswin|mingw)/
+      when :wsl
+        wsl?
       else
         PLATFORM.include?(os.to_s)
       end
@@ -38,6 +41,14 @@ class PlatformGuard < SpecGuard https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/guards/platform.rb#L41
     os?(:windows)
   end
 
+  def self.wsl?
+    if defined?(@wsl_p)
+      @wsl_p
+    else
+      @wsl_p = `uname -r`.match?(/microsoft/i)
+    end
+  end
+
   WORD_SIZE = 1.size * 8
 
   POINTER_SIZE = begin
diff --git a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
index 5d97341..8bebeb0 100644
--- a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
+++ b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb
@@ -113,7 +113,7 @@ describe 'Socket.gethostbyaddr' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb#L113
           Socket.gethostbyaddr(@addr, :INET6).should be_an_instance_of(Array)
         end
 
-        platform_is_not :windows do
+        platform_is_not :windows, :wsl do
           it 'raises SocketError when the address is not supported by the family' do
             -> { Socket.gethostbyaddr(@addr, :INET) }.should raise_error(SocketError)
           end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]