diff --git a/lib/rake.rb b/lib/rake.rb index f1c6f299d..681575906 100644 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -33,8 +33,6 @@ module Rake; end require_relative "rake/ext/string" -require_relative "rake/win32" - require_relative "rake/linked_list" require_relative "rake/cpu_counter" require_relative "rake/scope" diff --git a/lib/rake/application.rb b/lib/rake/application.rb index 39ee5e191..a068a9582 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -7,7 +7,6 @@ require_relative "thread_pool" require_relative "thread_history_display" require_relative "trace_output" -require_relative "win32" module Rake @@ -384,12 +383,11 @@ def dynamic_width_tput # :nodoc: end def unix? # :nodoc: - RbConfig::CONFIG["host_os"] =~ - /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i + Rake.unix? end def windows? # :nodoc: - Win32.windows? + Rake.windows? end def truncate(string, width) # :nodoc: diff --git a/lib/rake/rake_module.rb b/lib/rake/rake_module.rb index 03c295624..7b37af358 100644 --- a/lib/rake/rake_module.rb +++ b/lib/rake/rake_module.rb @@ -14,6 +14,17 @@ def application=(app) @application = app end + # True if running on a Windows system. + def windows? + RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)! + end + + # True if running on a Unix system. + def unix? + RbConfig::CONFIG["host_os"] =~ + /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i + end + def suggested_thread_count # :nodoc: @cpu_count ||= Rake::CpuCounter.count @cpu_count + 4 diff --git a/lib/rake/win32.rb b/lib/rake/win32.rb deleted file mode 100644 index 5cccbde93..000000000 --- a/lib/rake/win32.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true -require "rbconfig" - -module Rake - # Win 32 interface methods for Rake. Windows specific functionality - # will be placed here to collect that knowledge in one spot. - module Win32 # :nodoc: all - - class << self - # True if running on a windows system. - def windows? - RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)! - end - end - - end -end diff --git a/rake.gemspec b/rake.gemspec index dbc1794c8..893fa741f 100644 --- a/rake.gemspec +++ b/rake.gemspec @@ -90,7 +90,6 @@ Gem::Specification.new do |s| "lib/rake/thread_pool.rb", "lib/rake/trace_output.rb", "lib/rake/version.rb", - "lib/rake/win32.rb", "rake.gemspec" ] s.bindir = "exe" diff --git a/test/test_rake.rb b/test/test_rake.rb index a6d08fd35..617da2585 100644 --- a/test/test_rake.rb +++ b/test/test_rake.rb @@ -38,4 +38,11 @@ def test_original_dir_reports_current_dir assert_equal @tempdir, Rake.original_dir end + def test_platform_detection + # ensure that Rake's platform detection logic + # is mutually exclusive, and doesn't claim to + # be both Windows and Unix at the same time + assert ! (Rake.windows? && Rake.unix?) + end + end diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index e661a3c3b..865872d3a 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -419,8 +419,18 @@ def test_terminal_columns end end - def test_windows - assert ! (@app.windows? && @app.unix?) + if Rake.unix? + def test_unix_platform_detection + assert @app.unix? + refute @app.windows? + end + end + + if Rake.windows? + def test_windows_platform_detection + assert @app.windows? + refute @app.unix? + end end def test_loading_imports diff --git a/test/test_rake_directory_task.rb b/test/test_rake_directory_task.rb index 628344a1b..d7060f769 100644 --- a/test/test_rake_directory_task.rb +++ b/test/test_rake_directory_task.rb @@ -27,13 +27,15 @@ def test_directory refute File.exist?("a/b/c") end - def test_directory_colon - directory "a:b" + if Rake.unix? + def test_directory_colon + directory "a:b" - assert_equal FileCreationTask, Task["a:b"].class - end unless Rake::Win32.windows? + assert_equal FileCreationTask, Task["a:b"].class + end + end - if Rake::Win32.windows? + if Rake.windows? def test_directory_win32 desc "WIN32 DESC" directory "c:/a/b/c" diff --git a/test/test_rake_file_list.rb b/test/test_rake_file_list.rb index 45f695d4f..64cf4bdb6 100644 --- a/test/test_rake_file_list.rb +++ b/test/test_rake_file_list.rb @@ -349,8 +349,8 @@ def test_string_ext assert_equal ".one", ".one".ext assert_equal ".", ".".ext("c") assert_equal "..", "..".ext("c") - # These only need to work in windows - if Rake::Win32.windows? + # These only need to work on Windows + if Rake.windows? assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net") assert_equal "one.x\\two.net", "one.x\\two".ext(".net") end