How to use cygwin method of Platform Package

Best Selenium code snippet using Platform.cygwin

compat.rb

Source:compat.rb Github

copy

Full Screen

...20ENABLE_PROCESSED_INPUT = 121#22# Platform detection23#24@@is_windows = @@is_cygwin = @@is_macosx = @@is_linux = @@is_bsdi = @@is_freebsd = @@is_netbsd = @@is_openbsd = @@is_java = @@is_android = false25@@loaded_win32api = false26@@loaded_tempfile = false27@@loaded_fileutils = false28def self.is_windows29 return @@is_windows if @@is_windows30 @@is_windows = (RUBY_PLATFORM =~ /mswin(32|64)|mingw(32|64)/) ? true : false31end32def self.is_cygwin33 return @@is_cygwin if @@is_cygwin34 @@is_cygwin = (RUBY_PLATFORM =~ /cygwin/) ? true : false35end36def self.is_macosx37 return @@is_macosx if @@is_macosx38 @@is_macosx = (RUBY_PLATFORM =~ /darwin/) ? true : false39end40def self.is_linux41 return @@is_linux if @@is_linux42 @@is_linux = (RUBY_PLATFORM =~ /linux/) ? true : false43end44def self.is_bsdi45 return @@is_bsdi if @@is_bsdi46 @@is_bsdi = (RUBY_PLATFORM =~ /bsdi/i) ? true : false47end48def self.is_netbsd49 return @@is_netbsd if @@is_netbsd50 @@is_netbsd = (RUBY_PLATFORM =~ /netbsd/) ? true : false51end52def self.is_freebsd53 return @@is_freebsd if @@is_freebsd54 @@is_freebsd = (RUBY_PLATFORM =~ /freebsd/) ? true : false55end56def self.is_openbsd57 return @@is_openbsd if @@is_openbsd58 @@is_openbsd = (RUBY_PLATFORM =~ /openbsd/) ? true : false59end60def self.is_java61 return @@is_java if @@is_java62 @@is_java = (RUBY_PLATFORM =~ /java/) ? true : false63end64def self.is_android65 return @@is_android if @@is_android66 @@is_android = (RUBY_PLATFORM =~ /android/) ? true : false67end68def self.is_wow6469 return false if not is_windows70 is64 = false71 begin72 buff = "\x00" * 473 Win32API.new("kernel32","IsWow64Process",['L','P'],'L').call(-1, buff)74 is64 = (buff.unpack("V")[0]) == 1 ? true : false75 rescue ::Exception76 end77 is6478end79def self.cygwin_to_win32(path)80 if(path !~ /^\/cygdrive/)81 return ::IO.popen("cygpath -w #{path}", "rb").read.strip82 end83 dir = path.split("/")84 dir.shift85 dir.shift86 dir[0] = dir[0] + ":"87 dir.join("\\")88end89def self.open_file(url='')90 case RUBY_PLATFORM91 when /cygwin/92 path = self.cygwin_to_win32(url)93 system(["cmd", "cmd"], "/c", "explorer", path)94 else95 self.open_browser(url)96 end97end98def self.open_browser(url='http://google.com/')99 case RUBY_PLATFORM100 when /cygwin/101 if(url[0,1] == "/")102 self.open_file(url)103 end104 return if not @@loaded_win32api105 Win32API.new("shell32.dll", "ShellExecute", ["PPPPPL"], "L").call(nil, "open", url, nil, nil, 0)106 when /mswin32|mingw/107 return if not @@loaded_win32api108 Win32API.new("shell32.dll", "ShellExecute", ["PPPPPL"], "L").call(nil, "open", url, nil, nil, 0)109 when /darwin/110 system("open #{url}")111 when /android/112 url = "file://#{url}" if url.to_s.start_with?('/')113 system("am start --user 0 -a android.intent.action.VIEW -d #{url}")114 else115 # Search through the PATH variable (if it exists) and chose a browser116 # We are making an assumption about the nature of "PATH" so tread lightly117 if defined? ENV['PATH']118 # "xdg-open" is more general than "sensible-browser" and can be useful for lots of119 # file types -- text files, pcaps, or URLs. It's nearly always120 # going to use the application the user is expecting. If we're not121 # on something Debian-based, fall back to likely browsers.122 ['xdg-open', 'sensible-browser', 'firefox', 'firefox-bin', 'opera', 'konqueror', 'chromium-browser'].each do |browser|123 ENV['PATH'].split(':').each do |path|124 # Does the browser exists?125 if File.exist?("#{path}/#{browser}")126 system("#{browser} #{url} &")127 return128 end129 end130 end131 end132 end133end134def self.open_webrtc_browser(url='http://google.com/')135 case RUBY_PLATFORM136 when /mswin2|mingw|cygwin/137 paths = [138 "Google\\Chrome\\Application\\chrome.exe",139 "Mozilla Firefox\\firefox.exe",140 "Opera\\launcher.exe"141 ]142 prog_files = ENV['ProgramFiles']143 paths = paths.map { |p| "#{prog_files}\\#{p}" }144 # Old chrome path145 app_data = ENV['APPDATA']146 paths << "#{app_data}\\Google\\Chrome\\Application\\chrome.exe"147 paths.each do |path|148 if File.exist?(path)149 args = (path =~ /chrome\.exe/) ? "--allow-file-access-from-files" : ""150 system("\"#{path}\" #{args} \"#{url}\"")151 return true152 end153 end154 when /darwin/155 ['Google Chrome.app', 'Firefox.app'].each do |browser|156 browser_path = "/Applications/#{browser}"157 if File.directory?(browser_path)158 args = (browser_path =~ /Chrome/) ? "--args --allow-file-access-from-files" : ""159 system("open #{url} -a \"#{browser_path}\" #{args} &")160 return true161 end162 end163 when /android/164 url = "file://#{url}" if url.to_s.start_with?('/')165 system("am start --user 0 -a android.intent.action.VIEW -d #{url}")166 else167 if defined? ENV['PATH']168 ['google-chrome', 'chrome', 'chromium', 'firefox' , 'firefox', 'opera'].each do |browser|169 ENV['PATH'].split(':').each do |path|170 browser_path = "#{path}/#{browser}"171 if File.exist?(browser_path)172 args = (browser_path =~ /Chrome/) ? "--allow-file-access-from-files" : ""173 system("#{browser_path} #{args} #{url} &")174 return true175 end176 end177 end178 end179 end180 false181end182def self.open_email(addr)183 case RUBY_PLATFORM184 when /mswin32|cygwin/185 return if not @@loaded_win32api186 Win32API.new("shell32.dll", "ShellExecute", ["PPPPPL"], "L").call(nil, "open", "mailto:"+addr, nil, nil, 0)187 when /darwin/188 system("open mailto:#{addr}")189 when /android/190 system("am start --user 0 -a android.intent.action.VIEW -d mailto:#{addr}")191 else192 # ?193 end194end195def self.play_sound(path)196 case RUBY_PLATFORM197 when /cygwin/198 path = self.cygwin_to_win32(path)199 return if not @@loaded_win32api200 Win32API.new("winmm.dll", "sndPlaySoundA", ["SI"], "I").call(path, 0x20000)201 when /mswin32/202 return if not @@loaded_win32api203 Win32API.new("winmm.dll", "sndPlaySoundA", ["SI"], "I").call(path, 0x20000)204 when /darwin/205 system("afplay #{path} >/dev/null 2>&1")206 when /android/207 system("termux-open #{path}")208 else209 system("aplay #{path} >/dev/null 2>&1")210 end211end212def self.getenv(var)213 if (is_windows and @@loaded_win32api)214 f = Win32API.new("kernel32", "GetEnvironmentVariable", ["P", "P", "I"], "I")215 buff = "\x00" * 16384216 sz = f.call(var, buff, buff.length)217 return nil if sz == 0218 buff[0,sz]219 else220 ENV[var]221 end222end223def self.setenv(var,val)224 if (is_windows and @@loaded_win32api)225 f = Win32API.new("kernel32", "SetEnvironmentVariable", ["P", "P"], "I")226 f.call(var, val + "\x00")227 else228 ENV[var]= val229 end230end231#232# Obtain the path to our interpreter233#234def self.win32_ruby_path235 return nil if ! (is_windows and @@loaded_win32api)236 gmh = Win32API.new("kernel32", "GetModuleHandle", ["P"], "L")237 gmf = Win32API.new("kernel32", "GetModuleFileName", ["LPL"], "L")238 mod = gmh.call(nil)239 inf = "\x00" * 1024240 gmf.call(mod, inf, 1024)241 inf.unpack("Z*")[0]242end243#244# Call WinExec (equiv to system("cmd &"))245#246def self.win32_winexec(cmd)247 return nil if ! (is_windows and @@loaded_win32api)248 exe = Win32API.new("kernel32", "WinExec", ["PL"], "L")249 exe.call(cmd, 0)250end251#252# Verify the Console2 environment253#254def self.win32_console2_verify255 return nil if ! (is_windows and @@loaded_win32api)256 buf = "\x00" * 512257 out = Win32API.new("kernel32", "GetStdHandle", ["L"], "L").call(STD_OUTPUT_HANDLE)258 res = Win32API.new("kernel32","GetConsoleTitle", ["PL"], "L").call(buf, buf.length-1) rescue 0259 ( res > 0 and buf.index("Console2 command").nil? ) ? false : true260end261#262# Expand a 8.3 path to a full path263#264def self.win32_expand_path(path)265 return nil if ! (is_windows and @@loaded_win32api)266 glp = Win32API.new('kernel32', 'GetLongPathName', 'PPL', 'L')267 buf = "\x00" * 260268 len = glp.call(path, buf, buf.length)269 buf[0, len]270end271#272# Platform independent socket pair273#274def self.pipe275 if (! is_windows())276 # Standard pipes should be fine277 return ::IO.pipe278 end279 # Create a socket connection for Windows280 serv = nil281 port = 1024282 while (! serv and port < 65535)283 begin284 serv = TCPServer.new('127.0.0.1', (port += 1))285 rescue ::Exception286 end287 end288 pipe1 = TCPSocket.new('127.0.0.1', port)289 # Accept the forked child290 pipe2 = serv.accept291 # Shutdown the server292 serv.close293 return [pipe1, pipe2]294end295#296# Copy a file to a temporary path297#298def self.temp_copy(path)299 raise RuntimeError,"missing Tempfile" if not @@loaded_tempfile300 fd = File.open(path, "rb")301 tp = Tempfile.new("msftemp")302 tp.binmode303 tp.write(fd.read(File.size(path)))304 tp.close305 fd.close306 tp307end308#309# Delete an opened temporary file310#311def self.temp_delete(tp)312 raise RuntimeError,"missing FileUtils" if not @@loaded_fileutils313 begin314 FileUtils.rm(tp.path)315 rescue316 end317end318#319# Initialization320#321if(is_windows or is_cygwin)322 begin323 require "Win32API"324 @@loaded_win32api = true325 rescue ::Exception326 end327end328begin329 require "tempfile"330 @@loaded_tempfile = true331rescue ::Exception332end333begin334 require "fileutils"335 @@loaded_fileutils = true...

Full Screen

Full Screen

platform.rb

Source:platform.rb Github

copy

Full Screen

...6 module Util7 # This class just contains some platform checking code.8 class Platform9 class << self10 def cygwin?11 return @_cygwin if defined?(@_cygwin)12 @_cygwin = -> {13 # Installer detects Cygwin14 return true if ENV["VAGRANT_DETECTED_OS"] &&15 ENV["VAGRANT_DETECTED_OS"].downcase.include?("cygwin")16 # Ruby running in Cygwin17 return true if platform.include?("cygwin")18 # Heuristic. If the path contains Cygwin, we just assume we're19 # in Cygwin. It is generally a safe bet.20 path = ENV["PATH"] || ""21 return path.include?("cygwin")22 }.call23 return @_cygwin24 end25 [:darwin, :bsd, :freebsd, :linux, :solaris].each do |type|26 define_method("#{type}?") do27 platform.include?(type.to_s)28 end29 end30 def windows?31 return @_windows if defined?(@_windows)32 @_windows = %w[mingw mswin].any? { |t| platform.include?(t) }33 return @_windows34 end35 # Checks if the user running Vagrant on Windows has administrative36 # privileges.37 #38 # @return [Boolean]39 def windows_admin?40 return @_windows_admin if defined?(@_windows_admin)41 # We lazily-load this because it is only available on Windows42 require "win32/registry"43 # Verify that we have administrative privileges. The odd method of44 # detecting this is based on this StackOverflow question:45 #46 # https://stackoverflow.com/questions/560366/47 # detect-if-running-with-administrator-privileges-under-windows-xp48 @_windows_admin = -> {49 begin50 Win32::Registry::HKEY_USERS.open("S-1-5-19") {}51 # The above doesn't seem to be 100% bullet proof. See GH-5616.52 return (`reg query HKU\\S-1-5-19 2>&1` =~ /ERROR/).nil?53 rescue Win32::Registry::Error54 return false55 end56 }.call57 return @_windows_admin58 end59 # Checks if the user running Vagrant on Windows is a member of the60 # "Hyper-V Administrators" group.61 #62 # From: https://support.microsoft.com/en-us/kb/24333063 # SID: S-1-5-32-57864 # Name: BUILTIN\Hyper-V Administrators65 #66 # @return [Boolean]67 def windows_hyperv_admin?68 return @_windows_hyperv_admin if defined?(@_windows_hyperv_admin)69 @_windows_hyperv_admin = -> {70 begin71 username = ENV["USERNAME"]72 process = Subprocess.execute("net", "localgroup", "Hyper-V Administrators")73 return process.stdout.include?(username)74 rescue Errors::CommandUnavailableWindows75 return false76 end77 }.call78 return @_windows_hyperv_admin79 end80 # This takes any path and converts it from a Windows path to a81 # Cygwin or msys style path.82 #83 # @param [String] path84 # @return [String]85 def cygwin_path(path)86 if cygwin?87 begin88 # First try the real cygpath89 process = Subprocess.execute("cygpath", "-u", "-a", path.to_s)90 return process.stdout.chomp91 rescue Errors::CommandUnavailableWindows92 end93 end94 # Sometimes cygpath isn't available (msys). Instead, do what we95 # can with bash tricks.96 process = Subprocess.execute(97 "bash",98 "--noprofile",99 "--norc",100 "-c", "cd #{Shellwords.escape(path)} && pwd")101 return process.stdout.chomp102 end103 # This takes any path and converts it to a full-length Windows104 # path on Windows machines in Cygwin.105 #106 # @return [String]107 def cygwin_windows_path(path)108 return path if !cygwin?109 # Replace all "\" with "/", otherwise cygpath doesn't work.110 path = path.gsub("\\", "/")111 # Call out to cygpath and gather the result112 process = Subprocess.execute("cygpath", "-w", "-l", "-a", path.to_s)113 return process.stdout.chomp114 end115 # This checks if the filesystem is case sensitive. This is not a116 # 100% correct check, since it is possible that the temporary117 # directory runs a different filesystem than the root directory.118 # However, this works in many cases.119 def fs_case_sensitive?120 return @_fs_case_sensitive if defined?(@_fs_case_sensitive)121 @_fs_case_sensitive = Dir.mktmpdir("vagrant-fs-case-sensitive") do |dir|122 tmp_file = File.join(dir, "FILE")123 File.open(tmp_file, "w") do |f|124 f.write("foo")125 end126 # The filesystem is case sensitive if the lowercased version127 # of the filename is NOT reported as existing.128 !File.file?(File.join(dir, "file"))129 end130 return @_fs_case_sensitive131 end132 # This expands the path and ensures proper casing of each part133 # of the path.134 def fs_real_path(path, **opts)135 path = Pathname.new(File.expand_path(path))136 if path.exist? && !fs_case_sensitive?137 # If the path contains a Windows short path, then we attempt to138 # expand. The require below is embedded here since it requires139 # windows to work.140 if windows? && path.to_s =~ /~\d(\/|\\)/141 require_relative "windows_path"142 path = Pathname.new(WindowsPath.longname(path.to_s))143 end144 # Build up all the parts of the path145 original = []146 while !path.root?147 original.unshift(path.basename.to_s)148 path = path.parent149 end150 # Traverse each part and join it into the resulting path151 original.each do |single|152 Dir.entries(path).each do |entry|153 if entry.downcase == single.encode('filesystem').downcase154 path = path.join(entry)155 end156 end157 end158 end159 if windows?160 # Fix the drive letter to be uppercase.161 path = path.to_s162 if path[1] == ":"163 path[0] = path[0].upcase164 end165 path = Pathname.new(path)166 end167 path168 end169 # Converts a given path to UNC format by adding a prefix and converting slashes.170 # @param [String] path Path to convert to UNC for Windows171 # @return [String]172 def windows_unc_path(path)173 path = path.gsub("/", "\\")174 # If the path is just a drive letter, then return that as-is175 return path + "\\" if path =~ /^[a-zA-Z]:\\?$/176 # Convert to UNC path177 "\\\\?\\" + path.gsub("/", "\\")178 end179 # Returns a boolean noting whether the terminal supports color.180 # output.181 def terminal_supports_colors?182 return @_terminal_supports_colors if defined?(@_terminal_supports_colors)183 @_terminal_supports_colors = -> {184 if windows?185 return true if ENV.key?("ANSICON")186 return true if cygwin?187 return true if ENV["TERM"] == "cygwin"188 return false189 end190 return true191 }.call192 return @_terminal_supports_colors193 end194 def platform195 return @_platform if defined?(@_platform)196 @_platform = RbConfig::CONFIG["host_os"].downcase197 return @_platform198 end199 # @private200 # Reset the cached values for platform. This is not considered a public201 # API and should only be used for testing....

Full Screen

Full Screen

platforms.rb

Source:platforms.rb Github

copy

Full Screen

...29 # Test if current OS is +os+.30 def self.os?(os)31 OS == os32 end33 IS_CYGWIN = os?('cygwin')34 IS_WINDOWS = os?('windows')35 IS_LINUX = os?('linux')36 def self.cygwin?37 IS_CYGWIN38 end39 def self.linux?40 IS_LINUX41 end42 def self.windows?43 IS_WINDOWS44 end45 end46 module Support47 # OS-specific things48 # Mixin module help work with things as paths and env in other plases49 # @example50 # include AssLauncher::Support::Platforms51 #52 # if cigwin?53 # #do if run in Cygwin54 # end55 #56 # # Find env value on regex57 # pf = platform.env[/program\s*files/i]58 # return if pf.size == 059 #60 # # Use #path61 # p = platform.path(pf[0])62 # p.exists?63 #64 # # Use #path_class65 # platform.path_class.glob('C:/*').each do |path|66 # path.exists?67 # end68 #69 # # Use #glob directly70 # platform.glob('C:/*').each do |path|71 # path.exists?72 # end73 #74 #75 module Platforms76 # True if run in Cygwin77 def cygwin?78 Platform.cygwin?79 end80 module_function :cygwin?81 # True if run in MinGW82 def windows?83 Platform.windows?84 end85 module_function :windows?86 # True if run in Linux87 def linux?88 Platform.linux?89 end90 module_function :linux?91 # Return module [Platforms] as helper92 # @return [Platforms]93 def platform94 AssLauncher::Support::Platforms95 end96 private :platform97 require 'pathname'98 # Return suitable class99 # @return [UnixPath | WinPath | CygPath]100 def self.path_class101 if cygwin?102 PathnameExt::CygPath103 elsif windows?104 PathnameExt::WinPath105 else106 PathnameExt::UnixPath107 end108 end109 # Return suitable class instance110 # @return [UnixPath | WinPath | CygPath]111 def self.path(string)112 path_class.new(string)113 end114 # (see PathnameExt.glob)115 def self.glob(p1, *args)116 path_class.glob(p1, *args)117 end118 # Parent for OS-specific *Path classes119 # @todo TRANSLATE THIS:120 #121 # rubocop:disable AsciiComments122 # @note123 # Класс предназначен для унификации работы с путями ФС в различных124 # ОС.125 # ОС зависимые методы будут переопределены в классах потомках126 # [UnixPath | WinPath | CygPath].127 #128 # Пути могут приходить из следующих источников:129 # - из консоли - при этом в Cygwin путь вида '/cygdrive/c' будет130 # непонятен за пределами Cygwin131 # - из ENV - при этом путь \\\\host\\share будет непонятен в Unix132 #133 # Общая мысль в следующем:134 # - пути приводятся к mixed_path - /cygwin/c -> C:/, C:\\ -> C:/,135 # \\\\host\\share -> //host/share136 # - переопределяется метод glob класса [Pathname] при этом метод в137 # Cygwin будет иметь свою реализацию т.к. в cygwin138 # Dirname.glob('C:/') вернет пустой массив,139 # а Dirname.glob('/cygdrive/c') отработает правильно.140 # rubocop:enable AsciiComments141 class PathnameExt < Pathname142 # Override constructor for lead path to (#mixed_path)143 # @param string [String] - string of path144 def initialize(string)145 @raw = string.to_s.strip146 super mixed_path(@raw)147 end148 # This is fix (bug or featere)? of [Pathname] method. Called in149 # chiled clesses returns not childe class instance but returns150 # [Pathname] instance151 def +(other)152 self.class.new(super(other).to_s)153 end154 # Return mixed_path where delimiter is '/'155 # @return [String]156 def mixed_path(string)157 string.tr('\\', '/')158 end159 private :mixed_path160 # Return path suitable for windows apps. In Unix this method overridden161 # @return [String]162 def win_string163 to_s.tr('/', '\\')164 end165 # Override (Pathname.glob) method for correct work with windows paths166 # like a '\\\\host\\share', 'C:\\' and Cygwin paths like a '/cygdrive/c'167 # @param (see Pathname.glob)168 # @return [Array<PathnameExt>]169 def self.glob(p1, *args)170 super p1.tr('\\', '/'), *args171 end172 # Class for MinGW Ruby173 class WinPath < PathnameExt; end174 # Class for Unix Ruby175 class UnixPath < PathnameExt176 # (see PathnameExt#win_string)177 def win_string178 to_s179 end180 end181 # Class for Cygwin Ruby182 class CygPath < PathnameExt183 # (cee PathnameExt#mixed_path)184 def mixed_path(string)185 cygpath(string, :m)186 end187 # (see PathnameExt.glob)188 def self.glob(p1, *args)189 super cygpath(p1, :u), *args190 end191 def self.cygpath(p1, flag)192 fail ArgumentError, 'Only accepts :w | :m | :u flags'\193 unless %w(w m u).include? flag.to_s194 # TODO, extract shell call into Shell module195 out = `cygpath -#{flag} #{p1.escape} 2>&1`.chomp196 fail Shell::RunError, out unless exitstatus == 0197 out198 end199 # TODO, extract shell call into Shell module200 def self.exitstatus201 # rubocop:disable all202 fail Shell::Error, 'Unexpected $?.nil?' if $?.nil?203 $?.exitstatus204 # rubocop:enable all205 end206 private_class_method :exitstatus207 def cygpath(p1, flag)208 self.class.cygpath(p1, flag)209 end210 end211 end212 # Return suitable class213 # @return [UnixEnv | WinEnv | CygEnv]214 def self.env215 if cygwin?216 CygEnv217 elsif windows?218 WinEnv219 else220 UnixEnv221 end222 end223 # Wrapper for ENV in Unix Ruby224 class UnixEnv225 # Return values ENV on regex226 def self.[](regex)227 ENV.map { |k, v| v if k =~ regex }.compact228 end229 end...

Full Screen

Full Screen

platforms_test.rb

Source:platforms_test.rb Github

copy

Full Screen

1require 'test_helper'2class PlatformsTest < Minitest::Test3 def test_ffi_platform4 assert_respond_to AssLauncher::Platform, :cygwin?5 assert_equal AssLauncher::Platform::IS_CYGWIN, AssLauncher::Platform.cygwin?6 assert_respond_to AssLauncher::Platform, :windows?7 assert_equal AssLauncher::Platform::IS_WINDOWS, AssLauncher::Platform.windows?8 assert_respond_to AssLauncher::Platform, :linux?9 assert_equal AssLauncher::Platform::IS_LINUX, AssLauncher::Platform.linux?10 end11 def mod12 AssLauncher::Support::Platforms13 end14 def cls_include_mod15 Class.new do16 include AssLauncher::Support::Platforms17 end.new18 end19 def test_class_include_mod_metods?20 %w(cygwin? windows? linux?).map(&:to_sym).each do |method|21 AssLauncher::Platform.expects(method).returns('fake value')22 assert_equal 'fake value', cls_include_mod.send(method)23 end24 end25 def test_mod_metods?26 %w(cygwin? windows? linux?).map(&:to_sym).each do |method|27 AssLauncher::Platform.expects(method).returns('fake value')28 assert_equal 'fake value', mod.send(method)29 end30 end31 def test_platform32 assert_equal mod, cls_include_mod.send(:platform)33 end34 def test_path_class35 mod.expects(:cygwin?).returns(true)36 assert_equal AssLauncher::Support::Platforms::PathnameExt::CygPath, mod.path_class37 mod.expects(:cygwin?).returns(false)38 mod.expects(:windows?).returns(true)39 assert_equal AssLauncher::Support::Platforms::PathnameExt::WinPath, mod.path_class40 mod.expects(:cygwin?).returns(false)41 mod.expects(:windows?).returns(false)42 assert_equal AssLauncher::Support::Platforms::PathnameExt::UnixPath, mod.path_class43 end44 def test_path45 mock_path_class = mock()46 mock_path_class.expects(:new).with('fake path').returns('fake path')47 mod.expects(:path_class).returns(mock_path_class)48 assert_equal 'fake path', mod.path('fake path')49 end50 def test_glob51 mock_path_class = mock()52 mock_path_class.expects(:glob).with('fake path', %w'arg1 arg2').returns('fake glob value')53 mod.expects(:path_class).returns(mock_path_class)54 assert_equal 'fake glob value', mod.glob('fake path', %w'arg1 arg2')55 end56 def test_env57 mod.expects(:cygwin?).returns(true)58 assert_equal AssLauncher::Support::Platforms::CygEnv, mod.env59 mod.expects(:cygwin?).returns(false)60 mod.expects(:windows?).returns(true)61 assert_equal AssLauncher::Support::Platforms::WinEnv, mod.env62 mod.expects(:cygwin?).returns(false)63 mod.expects(:windows?).returns(false)64 assert_equal AssLauncher::Support::Platforms::UnixEnv, mod.env65 end66end67class UnixEnvTest < Minitest::Test68 def cls69 AssLauncher::Support::Platforms::UnixEnv70 end71 def test_brakets72 assert_instance_of Array, cls[/./]73 end74end75class PathnameExtTest < Minitest::Test76 def cls77 AssLauncher::Support::Platforms::PathnameExt78 end79 def test_initialize80 mock_object = mock()81 cls.any_instance.expects(:mixed_path).with('path string').returns('path string')82 mock_object.expects(:to_s).returns(mock_object)83 mock_object.expects(:strip).returns('path string')84 assert_instance_of cls, cls.new(mock_object)85 end86 def test_methods_should_returns_right_class_instance87 #metod #+(other)88 assert_instance_of cls, (cls.new('.') + '1')89 assert_equal '../1', (cls.new('..') + '1').to_s90 #method #join91 assert_instance_of cls, cls.new('.').join('1','2','3')92 #method #parent93 assert_instance_of cls, cls.new('.').parent94 #method ::glob95 arr = cls.glob(__FILE__.tr('/','\\'))96 assert_equal 1, arr.size97 assert_instance_of cls, arr[0]98 end99 def test_cls_glob100 String.any_instance.expects(:tr).with('\\','/').returns('mixed path')101 Pathname.expects(:glob).with('mixed path', 'arg1', 'arg2').returns('fake glob')102 assert_equal 'fake glob', cls.glob('string', 'arg1', 'arg2')103 end104 def test_win_string105 assert_equal '\\\\host\\share', cls.new('//host/share').win_string106 end107 def test_mixed_path108 assert_equal 'C:/mixed/path', cls.new('').send(:mixed_path, 'C:\\mixed\\path')109 end110end111class WinPathTest < Minitest::Test112 def cls113 AssLauncher::Support::Platforms::PathnameExt::WinPath114 end115 def test_initialize116 assert_equal 'C:/mixed/path', cls.new('C:\\mixed\\path').to_s117 end118end119class UnixPathTest < Minitest::Test120 def cls121 AssLauncher::Support::Platforms::PathnameExt::UnixPath122 end123 def test_initialize124 assert_equal '//host/share', cls.new('\\\\host\\share').to_s125 end126 def test_win_string127 AssLauncher::Support::Platforms::PathnameExt.any_instance.expects(:win_string).never128 assert_equal 'path', cls.new('path').win_string129 end130end131class CygPathTest < Minitest::Test132 def cls133 AssLauncher::Support::Platforms::PathnameExt::CygPath134 end135 def test_initialize136 cls.any_instance.expects(:mixed_path).with('fake path').returns('fake path')137 assert_equal 'fake path', cls.new('fake path').to_s138 end139 def test_cls_cygpath140 %w(m u w).map(&:to_sym).each do |flag|141 String.any_instance.expects(:escape).returns('path')142 String.any_instance.expects(:chomp).returns('chomp path')143 cls.expects(:exitstatus).returns(0)144 cls.expects(:"`").with("cygpath -#{flag} path 2>&1").returns("path")145 assert_equal 'chomp path', cls.cygpath('path', flag)146 end147 end148 # TODO extract shell call into Shell module149 def test_cls_cygpath_fail_with_shell_run_error150 String.any_instance.expects(:escape).returns('path')151 String.any_instance.expects(:chomp).returns('chomp path')152 cls.expects(:exitstatus).returns(1)153 cls.expects(:"`").returns('out')154 assert_raises AssLauncher::Support::Shell::RunError do155 cls.cygpath('path', :m)156 end157 end158 # TODO extract shell call into Shell module159 def test_cls_exitstatus_fail160 skip 'TODO extract shell call into Shell module'161 end162 def test_cls_cygpath_fail_with_argument_error163 assert_raises ArgumentError do164 cls.cygpath('path', :bad_flag)165 end166 end167 def cygwin?168 RUBY_PLATFORM.match('cygwin')169 end170 def test_real_cygpath171 skip 'Runing on not Cygwin platform. Skiped' unless cygwin?172 assert_equal 'Q:/', cls.cygpath('/cygdrive/q', :m)173 end174 def test_cygpath175 cls.any_instance.expects(:mixed_path).returns('fake path')176 inst = cls.new('')177 cls.expects(:cygpath).with('arg1', 'arg2')178 inst.cygpath('arg1', 'arg2')179 end180 def test_mixed_path181 cls.any_instance.expects(:cygpath).with('fake path', :m).returns('fake path')182 cls.new('fake path')183 end184 def test_glob185 cls.expects(:cygpath).with('fake path', :u).returns('fake path')...

Full Screen

Full Screen

os.rb

Source:os.rb Github

copy

Full Screen

1require 'rbconfig'2require 'yaml'3# a set of friendly files for determining your Ruby runtime4# treats cygwin as linux5# also treats IronRuby on mono as...linux6class OS7 attr_reader :config8 def self.config9 @config ||= RbConfig::CONFIG10 end11 # true if on windows [and/or jruby]12 # false if on linux or cygwin on windows13 14 def self.windows?15 @windows ||= begin16 if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin17 false18 elsif ENV['OS'] == 'Windows_NT'19 true20 else21 false22 end23 end24 end25 # true for linux, os x, cygwin26 def self.posix?27 @posix ||=28 begin29 if OS.windows?30 begin31 begin32 # what if we're on interix...33 # untested, of course34 Process.wait fork{}35 true36 rescue NotImplementedError, NoMethodError37 false38 end39 end40 else41 # assume non windows is posix42 true43 end44 end45 end46 # true for linux, false for windows, os x, cygwin47 def self.linux?48 if (host_os =~ /linux/)49 true50 else51 false52 end53 end54 def self.iron_ruby?55 @iron_ruby ||= begin56 if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')57 true58 else59 false60 end61 end62 end63 def self.bits64 @bits ||= begin65 if host_cpu =~ /_64$/ || RUBY_PLATFORM =~ /x86_64/66 6467 elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#88061368 ENV_JAVA['sun.arch.data.model'].to_i69 elsif host_cpu == 'i386'70 3271 elsif host_os =~ /32$/ # mingw32, mswin3272 3273 else # cygwin only...I think74 if 1.size == 875 6476 else77 3278 end79 end80 end81 end82 def self.java?83 @java ||= begin84 if RUBY_PLATFORM =~ /java/85 true86 else87 false88 end89 end90 end91 def self.ruby_bin92 @ruby_exe ||= begin93 File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']94 end95 end96 def self.mac?97 @mac = begin98 if host_os =~ /darwin/99 true100 else101 false102 end103 end 104 end105 def self.osx?106 mac?107 end108 def self.x?109 mac?110 end111 # amount of memory the current process "is using", in RAM112 # (doesn't include any swap memory that it may be using, just that in actual RAM)113 # raises 'unknown' on jruby currently114 def self.rss_bytes115 # attempt to do this in a jruby friendly way116 if OS::Underlying.windows?117 # MRI, Java, IronRuby, Cygwin118 if OS.java?119 # no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P120 require 'java'121 mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean122 mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used123 else124 wmi = nil125 begin126 require 'win32ole'127 wmi = WIN32OLE.connect("winmgmts://")128 rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]129 raise 'rss unknown for this platform ' + e.to_s130 end 131 processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")132 memory_used = nil133 # only allow for one...134 for process in processes135 raise if memory_used136 memory_used = process.WorkingSetSize.to_i137 end138 memory_used139 end140 elsif OS.posix? # linux [though I've heard it works in OS X]141 kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes142 else143 raise 'unknown rss for this platform'144 end145 end146 class Underlying147 def self.bsd?148 OS.osx?149 end150 def self.windows?151 ENV['OS'] == 'Windows_NT'152 end153 def self.linux?154 OS.host_os =~ /linux/ ? true : false155 end156 end157 158 def self.cygwin?159 @cygwin = begin160 if RUBY_PLATFORM =~ /-cygwin/161 true162 else163 false164 end165 end166 end167 168 def self.dev_null169 @dev_null ||= begin170 if OS.windows?171 "NUL"172 else173 "/dev/null"174 end175 end176 end177 # provides easy way to see the relevant config entries178 def self.report179 relevant_keys = [180 'arch',181 'host',182 'host_cpu',183 'host_os',184 'host_vendor',185 'target',186 'target_cpu',187 'target_os',188 'target_vendor',189 ]190 RbConfig::CONFIG.reject {|key, val| !relevant_keys.include? key }.merge({'RUBY_PLATFORM' => RUBY_PLATFORM}).to_yaml191 end192 def self.cpu_count193 @cpu_count ||=194 case RUBY_PLATFORM195 when /darwin9/196 `hwprefs cpu_count`.to_i197 when /darwin10/198 (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i199 when /linux/200 `cat /proc/cpuinfo | grep processor | wc -l`.to_i201 when /freebsd/202 `sysctl -n hw.ncpu`.to_i203 else204 if RbConfig::CONFIG['host_os'] =~ /darwin/205 (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i206 elsif self.windows?207 # ENV counts hyper threaded...not good.208 # out = ENV['NUMBER_OF_PROCESSORS'].to_i209 require 'win32ole'210 wmi = WIN32OLE.connect("winmgmts://")211 cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # don't count hyper-threaded in this212 cpu.to_enum.first.NumberOfCores213 else214 raise 'unknown platform processor_count'215 end216 end217 end218 219 def self.open_file_command220 if OS.doze? || OS.cygwin?221 "start"222 elsif OS.mac?223 "open"224 else225 # linux...what about cygwin?226 "xdg-open"227 end228 end229 class << self230 alias :doze? :windows? # a joke name but I use it and like it :P231 alias :jruby? :java?232 # delegators for relevant config values233 %w(host host_cpu host_os).each do |method_name|234 define_method(method_name) { config[method_name] }235 end236 237 end238 private239 def self.hwprefs_available?...

Full Screen

Full Screen

environment.rb

Source:environment.rb Github

copy

Full Screen

...22 LINUX = :linux23 SOLARIS = :solaris24 WINDOWS = :windows25 OSX = :osx26 CYGWIN = :cygwin27 UNKNOWN = :unknown # keep this as last constant28 end29 30 def self.java?31 32 RUBY_PLATFORM == "java"33 end34 def self.posix?35 36 ( platform == LINUX || platform == OSX || platform == CYGWIN || platform == SOLARIS ) 37 38 end39 def self.cygwin?40 platform == CYGWIN41 42 end43 def self.solaris?44 platform == SOLARIS45 46 end47 def self.linux?48 platform == LINUX49 end50 def self.windows?51 platform == WINDOWS52 end53 def self.osx?54 platform == OSX55 end56 def self.unknown_os?57 platform == UNKNOWN58 end59 # Function to retrieve platform type60 # == returns61 # Integer:: LINUX 62 def self.platform63 case RbConfig::CONFIG[ 'host_os' ]64 when /mswin|mingw|windows/i65 WINDOWS66 when /cygwin/i67 68 CYGWIN69 when /linux/i70 LINUX71 when /sunos|solaris/i72 SOLARIS73 when /darwin/74 OSX75 else76 OTHER77 end78 end79 # Function to retrieve platform type80 # == returns...

Full Screen

Full Screen

platform_test.rb

Source:platform_test.rb Github

copy

Full Screen

2require "vagrant/util/platform"3describe Vagrant::Util::Platform do4 include_context "unit"5 subject { described_class }6 describe "#cygwin?" do7 before do8 allow(subject).to receive(:platform).and_return("test")9 end10 around do |example|11 with_temp_env(VAGRANT_DETECTED_OS: "nope", PATH: "") do12 example.run13 end14 end15 it "returns true if VAGRANT_DETECTED_OS includes cygwin" do16 with_temp_env(VAGRANT_DETECTED_OS: "cygwin") do17 expect(subject).to be_cygwin18 end19 end20 it "returns true if platform has cygwin" do21 allow(subject).to receive(:platform).and_return("cygwin")22 expect(subject).to be_cygwin23 end24 it "returns true if the PATH contains cygwin" do25 with_temp_env(PATH: "C:/cygwin") do26 expect(subject).to be_cygwin27 end28 end29 it "returns false if nothing is available" do30 expect(subject).to_not be_cygwin31 end32 end33 describe "#fs_real_path" do34 it "fixes drive letters on Windows", :windows do35 expect(described_class.fs_real_path("c:/foo").to_s).to eql("C:/foo")36 end37 end38 describe "#windows_unc_path" do39 it "correctly converts a path" do40 expect(described_class.windows_unc_path("c:/foo").to_s).to eql("\\\\?\\c:\\foo")41 end42 end43end...

Full Screen

Full Screen

cygwin

Using AI Code Generation

copy

Full Screen

1 def self.execute(*args)2 system(*args)3 def self.execute(*args)4 system(*args.join(' '))5 def self.execute(*args)6 system(*args.join(' '))7 def self.execute(*args)8 system(*args.join(' '))9 def self.execute(*args)10 system(*args.join(' '))11 def self.execute(*args)12 system(*args.join(' '))13 def self.execute(*args)14 system(*args.join(' '))15 def self.execute(*args)16 system(*args.join(' '))17 def self.execute(*args)18 system(*args.join(' '))19 def self.execute(*args)20 system(*args.join(' '))21 def self.execute(*args)22 system(*args.join(' '))23 def self.execute(*args)24 system(*args.join(' '))25 def self.execute(*args)26 system(*args.join(' '))

Full Screen

Full Screen

cygwin

Using AI Code Generation

copy

Full Screen

1def cygwin2win(path)2 path.gsub!(/3def cygwin2win(path)4 path.gsub!(/

Full Screen

Full Screen

cygwin

Using AI Code Generation

copy

Full Screen

1 def self.execute(*args)2 system(*args.join(' '))3 def self.execute(*args)4 system(*args.join(' '))5 def self.execute(*args)6 system(*args.join(' '))

Full Screen

Full Screen

cygwin

Using AI Code Generation

copy

Full Screen

1def cygwin2win(path)2 path.gsub!(/3def cygwin2win(path)4 path.gsub!(/

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful