diff --git a/.rubocop.yml b/.rubocop.yml index acdf2e117..84d6a7c5b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,8 +4,9 @@ AllCops: Exclude: - doc/**/*.rb - rake.gemspec + - bin/* -Style/LineLength: +Metrics/LineLength: Enabled: true Max: 120 @@ -16,42 +17,42 @@ Style/StringLiterals: Enabled: true EnforcedStyle: double_quotes -Style/IndentationWidth: +Style/MultilineIfThen: Enabled: true -Style/Tab: +Style/MethodDefParentheses: Enabled: true -Style/EmptyLines: +Style/BracesAroundHashParameters: Enabled: true -Style/TrailingBlankLines: +Layout/IndentationWidth: Enabled: true -Style/TrailingWhitespace: +Layout/Tab: Enabled: true -Style/SpaceBeforeBlockBraces: +Layout/EmptyLines: Enabled: true -Style/SpaceInsideBlockBraces: +Layout/TrailingBlankLines: Enabled: true -Style/SpaceInsideHashLiteralBraces: +Layout/TrailingWhitespace: Enabled: true -Style/CaseIndentation: +Layout/SpaceBeforeBlockBraces: Enabled: true -Style/MultilineIfThen: +Layout/SpaceInsideBlockBraces: Enabled: true -Style/MethodDefParentheses: +Layout/SpaceInsideHashLiteralBraces: Enabled: true -Style/BracesAroundHashParameters: +Layout/CaseIndentation: Enabled: true -Lint/EndAlignment: +Layout/EndAlignment: Enabled: true - AlignWith: variable + EnforcedStyleAlignWith: variable diff --git a/.travis.yml b/.travis.yml index 6e1db29fe..b0bf3ebe3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,24 @@ language: ruby -sudo: false rvm: - - 1.9.3 - 2.0.0 - 2.1.10 - - 2.2.5 - - 2.3.1 + - 2.2.10 + - 2.3.8 + - 2.4.5 + - 2.5.3 + - 2.6.1 - ruby-head - - jruby-1.7.20 - - jruby-9.1.6.0 + - jruby-9.2.4.0 - jruby-head -before_install: - - gem install bundler --no-document -v '~> 1.13.3' + +matrix: + include: + - rvm: 2.5.3 + env: COVERALLS=yes + before_script: - unset JRUBY_OPTS + - unset _JAVA_OPTIONS + - if ruby -e "exit RUBY_VERSION >= '2.3.0'"; then gem update --system=3.0.1; else gem update --system=2.7.8; fi + script: ruby -Ilib exe/rake -notifications: - email: - - hsbt@ruby-lang.org - - drbrain@segment7.net diff --git a/CONTRIBUTING.rdoc b/CONTRIBUTING.rdoc index d68e8c525..e8430ddb4 100644 --- a/CONTRIBUTING.rdoc +++ b/CONTRIBUTING.rdoc @@ -3,7 +3,7 @@ Rake is currently hosted at github. The github web page is https://github.com/ruby/rake . The public git clone URL is - git://github.com/ruby/rake.git + https://github.com/ruby/rake.git = Running the Rake Test Suite @@ -12,11 +12,18 @@ If you wish to run the unit and functional tests that come with Rake: * +cd+ into the top project directory of rake. * Install gem dependency using bundler: - bundle install # Install bundler, minitest and rdoc + $ bundle install # Install bundler, minitest and rdoc -* Type one of the following: +* Run the test suite - rake # If you have run rake's tests + $ rake + += Rubocop + +Rake uses Rubocop to enforce a consistent style on new changes being +proposed. You can check your code with Rubocop using: + + $ ./bin/rubocop = Issues and Bug Reports diff --git a/History.rdoc b/History.rdoc index 16c62c8b2..16b6331a1 100644 --- a/History.rdoc +++ b/History.rdoc @@ -1,10 +1,107 @@ +=== 12.3.3 + +==== Bug fixes + +* Use the application's name in error message if a task is not found. + Pull Request #303 by tmatilai + +==== Enhancements: + +* Use File.open explicitly. + +=== 12.3.2 + +==== Bug fixes + +* Fixed test fails caused by 2.6 warnings. + Pull Request #297 by hsbt + +==== Enhancements: + +* Rdoc improvements. + Pull Request #293 by colby-swandale +* Improve multitask performance. + Pull Request #273 by jsm +* Add alias `prereqs`. + Pull Request #268 by take-cheeze + +=== 12.3.1 + +==== Bug fixes + +* Support did_you_mean >= v1.2.0 which has a breaking change on formatters. + Pull request #262 by FUJI Goro. + +==== Enhancements: + +* Don't run task if it depends on already invoked but failed task. + Pull request #252 by Gonzalo Rodriguez. +* Make space trimming consistent for all task arguments. + Pull request #259 by Gonzalo Rodriguez. +* Removes duplicated inclusion of Rake::DSL in tests. + Pull request #254 by Gonzalo Rodriguez. +* Re-raise a LoadError that didn't come from require in the test loader. + Pull request #250 by Dylan Thacker-Smith. + +=== 12.3.0 + +==== Compatibility Changes + +* Bump `required_ruby_version` to Ruby 2.0.0. Rake has already + removed support for Ruby 1.9.x. + +==== Enhancements: + +* Support `test-bundled-gems` task on ruby core. + +=== 12.2.1 + +==== Bug fixes + +* Fixed to break Capistrano::Application on capistrano3. + +=== 12.2.0 + +==== Enhancements: + +* Make rake easier to use as a library + Pull request #211 by @drbrain +* Fix quadratic performance in FileTask#out_of_date? + Pull request #224 by @doudou +* Clarify output when printing nested exception traces + Pull request #232 by @urbanautomaton + +==== Bug fixes + +* Account for a file that match 2 or more patterns. + Pull request #231 by @styd + +=== 12.1.0 + +==== Enhancements: + +* Added did_you_mean feature for invalid rake task. + Pull request #221 by @xtina-starr +* Enabled to dependency chained by extensions. Pull request #39 by Petr Skocik. +* Make all of string literals to frozen objects on Ruby 2.4 or later. + +==== Bug fixes + +* Typo fixes in rakefile.rdoc. Pull request #180 by Yuta Kurotaki. +* Fix unexpected behavior of file task with dryrun option. + Pull request #183 by @aycabta. +* Make LoadError from running tests more obvious. Pull request #195 + by Eric Hodel. +* Fix unexpected TypeError with hash style option. Pull request #202 + by Kuniaki IGARASHI. + === 12.0.0 ==== Compatibility Changes -* Remove arguments on clear #157 by Jesse Bowes +* Removed arguments on clear #157 by Jesse Bowes * Removed `rake/contrib` packages. These are extracted to `rake-contrib` gem. -* Removed to deprecated warnings for `last\_comment`. +* Removed deprecated method named `last\_comment`. ==== Enhancements: @@ -385,7 +482,7 @@ we'll repeat the changes for versions 0.9.3 through 0.9.5 here. programatically add rake task libraries. * You can specific backtrace suppression patterns (see - --supress-backtrace) + --suppress-backtrace) * Directory tasks can now take prerequisites and actions @@ -633,7 +730,7 @@ we'll repeat the changes for version 0.9.3 here. programatically add rake task libraries. * You can specific backtrace suppression patterns (see - --supress-backtrace) + --suppress-backtrace) * Directory tasks can now take prerequisites and actions @@ -843,7 +940,7 @@ a number of bug fixes. programatically add rake task libraries. * You can specific backtrace suppression patterns (see - --supress-backtrace) + --suppress-backtrace) * Directory tasks can now take prerequisites and actions @@ -1415,7 +1512,7 @@ The first argument is still the name of the task (:name in this case). The next to argumements are the names of the parameters expected by :name (:first_name and :last_name in the example). -To access the values of the paramters, the block defining the task +To access the values of the parameters, the block defining the task behaviour can now accept a second parameter: task :name, :first_name, :last_name do |t, args| @@ -1518,7 +1615,7 @@ The first argument is still the name of the task (:name in this case). The next to argumements are the names of the parameters expected by :name (:first_name and :last_name in the example). -To access the values of the paramters, the block defining the task +To access the values of the parameters, the block defining the task behaviour can now accept a second parameter: task :name, :first_name, :last_name do |t, args| @@ -1738,7 +1835,7 @@ are, I hope you enjoy them. * RDoc defaults to internal (in-process) invocation. The old behavior is still available by setting the +external+ flag to true. * Rakefiles are now loaded with the expanded path to prevent - accidental polution from the Ruby load path. + accidental pollution from the Ruby load path. * Task objects my now be used in prerequisite lists directly. * Task objects (in addition to task names) may now be included in the prerequisite list of a task. @@ -1751,7 +1848,7 @@ are, I hope you enjoy them. ===== Namespaces Tasks can now be nested inside their own namespaces. Tasks within one -namespace will not accidently interfer with tasks named in a different +namespace will not accidentally interfer with tasks named in a different namespace. For example: @@ -1809,7 +1906,7 @@ As usual, it was input from users that drove a alot of these changes. The following people either contributed patches, made suggestions or made otherwise helpful comments. Thanks to ... -* Doug Young (inspriation for the parallel task) +* Doug Young (inspiration for the parallel task) * David Heinemeier Hansson (for --trace message enhancement and for pushing for namespace support). * Ludvig Omholt (for the openAFS fix) diff --git a/README.rdoc b/README.rdoc index 690c11d66..ab136b85d 100644 --- a/README.rdoc +++ b/README.rdoc @@ -25,8 +25,8 @@ Rake has the following features: * A library of prepackaged tasks to make building rakefiles easier. For example, tasks for building tarballs. (Formerly - tasks for building RDoc, Gems and publishing to FTP were included in rake but they're now - available in RDoc, RubyGems and respectively.) + tasks for building RDoc, Gems, and publishing to FTP were included in rake but they're now + available in RDoc, RubyGems, and rake-contrib respectively.) * Supports parallel execution of tasks. @@ -75,10 +75,10 @@ Type "rake --help" for all available options. === Rake Information -* {Rake command-line}[rdoc-ref:doc/command_line_usage.rdoc] -* {Writing Rakefiles}[rdoc-ref:doc/rakefile.rdoc] -* The original {Rake announcement}[rdoc-ref:doc/rational.rdoc] -* Rake {glossary}[rdoc-ref:doc/glossary.rdoc] +* {Rake command-line}[link:doc/command_line_usage.rdoc] +* {Writing Rakefiles}[link:doc/rakefile.rdoc] +* The original {Rake announcement}[link:doc/rational.rdoc] +* Rake {glossary}[link:doc/glossary.rdoc] === Presentations and Articles about Rake @@ -130,7 +130,7 @@ Rake is available under an MIT-style license. = Other stuff Author:: Jim Weirich -Requires:: Ruby 1.9.3 or later +Requires:: Ruby 2.0.0 or later License:: Copyright Jim Weirich. Released under an MIT-style license. See the MIT-LICENSE file included in the distribution. diff --git a/Rakefile b/Rakefile index e0d2ced3d..e03dc6feb 100644 --- a/Rakefile +++ b/Rakefile @@ -9,16 +9,19 @@ lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "bundler/gem_tasks" -require "rake/testtask" -require "rdoc/task" +begin + require "bundler/gem_tasks" +rescue LoadError +end +require "rake/testtask" Rake::TestTask.new(:test) do |t| t.libs << "test" t.verbose = true t.test_files = FileList["test/**/test_*.rb"] end +require "rdoc/task" RDoc::Task.new do |doc| doc.main = "README.rdoc" doc.title = "Rake -- Ruby Make" @@ -27,7 +30,7 @@ RDoc::Task.new do |doc| end task ghpages: :rdoc do - `git checkout gh-pages` + %x[git checkout gh-pages] require "fileutils" FileUtils.rm_rf "/tmp/html" FileUtils.mv "html", "/tmp" diff --git a/appveyor.yml b/appveyor.yml index 79847873c..fa978bb4a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,15 +2,13 @@ clone_depth: 10 install: - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - - gem install bundler --no-document - - bundle install + - gem install minitest build: off test_script: - ruby -Ilib exe/rake deploy: off environment: matrix: - - ruby_version: "193" - ruby_version: "200" - ruby_version: "200-x64" - ruby_version: "21" @@ -19,3 +17,7 @@ environment: - ruby_version: "22-x64" - ruby_version: "23" - ruby_version: "23-x64" + - ruby_version: "24" + - ruby_version: "24-x64" + - ruby_version: "25" + - ruby_version: "25-x64" diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..19cce3eeb --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,11 @@ +jobs: +- job: macOS + pool: + vmImage: 'macos-10.13' + steps: + - script: | + gem install bundler + bundle install --retry=3 --jobs=4 + displayName: 'bundle install' + - script: ruby -Ilib exe/rake + displayName: 'ruby -Ilib exe/rake' diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..524dfd3f2 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,105 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= begin + env_var_version || cli_arg_version || + lockfile_version || "#{Gem::Requirement.default}.a" + end + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + # must dup string for RG < 1.8 compatibility + activate_bundler(bundler_version.dup) + end + + def activate_bundler(bundler_version) + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") + bundler_version = "< 2" + end + gem_error = activation_error_handling do + gem "bundler", bundler_version + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..9275675e8 --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rdoc b/bin/rdoc new file mode 100755 index 000000000..a952e7988 --- /dev/null +++ b/bin/rdoc @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rdoc' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rdoc", "rdoc") diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 000000000..d0c488293 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/doc/jamis.rb b/doc/jamis.rb index c7bc84ac5..531aa7573 100644 --- a/doc/jamis.rb +++ b/doc/jamis.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module RDoc module Page diff --git a/doc/rakefile.rdoc b/doc/rakefile.rdoc index 89a28ebee..4014306a1 100644 --- a/doc/rakefile.rdoc +++ b/doc/rakefile.rdoc @@ -410,7 +410,7 @@ display a list of tasks that have a description. If you use +desc+ to describe your major tasks, you have a semi-automatic way of generating a summary of your Rake file. - traken$ rake -T + $ rake -T (in /home/.../rake) rake clean # Remove any temporary products. rake clobber # Remove any generated file. diff --git a/lib/rake.rb b/lib/rake.rb index 07b03284b..0dfd05315 100644 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true #-- # Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com) # diff --git a/lib/rake/application.rb b/lib/rake/application.rb index e94f17290..9ac9b2130 100644 --- a/lib/rake/application.rb +++ b/lib/rake/application.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "optparse" require "rake/task_manager" @@ -61,6 +62,8 @@ def initialize add_loader("rake", DefaultLoader.new) @tty_output = STDOUT.tty? @terminal_columns = ENV["RAKE_COLUMNS"].to_i + + set_default_options end # Run the Rake application. The run method performs the following @@ -73,19 +76,24 @@ def initialize # If you wish to build a custom rake command, you should call # +init+ on your application. Then define any tasks. Finally, # call +top_level+ to run your top level tasks. - def run + def run(argv = ARGV) standard_exception_handling do - init + init "rake", argv load_rakefile top_level end end # Initialize the command line parameters and app name. - def init(app_name="rake") + def init(app_name="rake", argv = ARGV) standard_exception_handling do @name = app_name - args = handle_options + begin + args = handle_options argv + rescue ArgumentError + # Backward compatibility for capistrano + args = handle_options + end collect_command_line_tasks(args) end end @@ -164,7 +172,7 @@ def parse_task_string(string) # :nodoc: args = [] begin - /((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args + /\s*((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args remaining_args = $2 args << $1.gsub(/\\(.)/, '\1') @@ -204,13 +212,22 @@ def display_error_message(ex) # :nodoc: end def display_exception_details(ex) # :nodoc: - seen = Thread.current[:rake_display_exception_details_seen] ||= [] - return if seen.include? ex - seen << ex + display_exception_details_seen << ex display_exception_message_details(ex) display_exception_backtrace(ex) - display_exception_details(ex.cause) if has_cause?(ex) + display_cause_details(ex.cause) if has_cause?(ex) + end + + def display_cause_details(ex) # :nodoc: + return if display_exception_details_seen.include? ex + + trace "\nCaused by:" + display_exception_details(ex) + end + + def display_exception_details_seen # :nodoc: + Thread.current[:rake_display_exception_details_seen] ||= [] end def has_cause?(ex) # :nodoc: @@ -375,7 +392,7 @@ def trace(*strings) # :nodoc: def sort_options(options) # :nodoc: options.sort_by { |opt| - opt.select { |o| o =~ /^-/ }.map(&:downcase).sort.reverse + opt.select { |o| o.is_a?(String) && o =~ /^-/ }.map(&:downcase).sort.reverse } end private :sort_options @@ -617,9 +634,8 @@ def select_trace_output(options, trace_option, value) # :nodoc: # Read and handle the command line options. Returns the command line # arguments that we didn't understand, which should (in theory) be just # task names and env vars. - def handle_options # :nodoc: - options.rakelib = ["rakelib"] - options.trace_output = $stderr + def handle_options(argv) # :nodoc: + set_default_options OptionParser.new do |opts| opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..." @@ -633,7 +649,7 @@ def handle_options # :nodoc: standard_rake_options.each { |args| opts.on(*args) } opts.environment("RAKEOPT") - end.parse(ARGV) + end.parse(argv) end # Similar to the regular Ruby +require+ command, but will check @@ -671,7 +687,7 @@ def print_rakefile_directory(location) # :nodoc: def raw_load_rakefile # :nodoc: rakefile, location = find_rakefile_location - if (! options.ignore_system) && + if (!options.ignore_system) && (options.load_system || rakefile.nil?) && system_dir && File.directory?(system_dir) print_rakefile_directory(location) @@ -781,5 +797,28 @@ def rakefile_location(backtrace=caller) # :nodoc: backtrace.find { |str| str =~ re } || "" end + def set_default_options # :nodoc: + options.always_multitask = false + options.backtrace = false + options.build_all = false + options.dryrun = false + options.ignore_deprecate = false + options.ignore_system = false + options.job_stats = false + options.load_system = false + options.nosearch = false + options.rakelib = %w[rakelib] + options.show_all_tasks = false + options.show_prereqs = false + options.show_task_pattern = nil + options.show_tasks = nil + options.silent = false + options.suppress_backtrace_pattern = nil + options.thread_pool_size = Rake.suggested_thread_count + options.trace = false + options.trace_output = $stderr + options.trace_rules = false + end + end end diff --git a/lib/rake/backtrace.rb b/lib/rake/backtrace.rb index a89dd9f4d..31ff05450 100644 --- a/lib/rake/backtrace.rb +++ b/lib/rake/backtrace.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake module Backtrace # :nodoc: all SYS_KEYS = RbConfig::CONFIG.keys.grep(/(?:[a-z]prefix|libdir)\z/) diff --git a/lib/rake/clean.rb b/lib/rake/clean.rb index f66353a0a..5af44015e 100644 --- a/lib/rake/clean.rb +++ b/lib/rake/clean.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # The 'rake/clean' file defines two file lists (CLEAN and CLOBBER) and # two rake tasks (:clean and :clobber). # diff --git a/lib/rake/cloneable.rb b/lib/rake/cloneable.rb index d53645f2f..eddb77e2f 100644 --- a/lib/rake/cloneable.rb +++ b/lib/rake/cloneable.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake ## # Mixin for creating easily cloned objects. diff --git a/lib/rake/cpu_counter.rb b/lib/rake/cpu_counter.rb index 82a5eb8aa..564a62859 100644 --- a/lib/rake/cpu_counter.rb +++ b/lib/rake/cpu_counter.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Based on a script at: @@ -31,7 +32,7 @@ def count require 'rbconfig' def count - if defined?(Java::Java) + if RUBY_PLATFORM == 'java' count_via_java_runtime else case RbConfig::CONFIG['host_os'] diff --git a/lib/rake/default_loader.rb b/lib/rake/default_loader.rb index 6154408f4..d3b4650d3 100644 --- a/lib/rake/default_loader.rb +++ b/lib/rake/default_loader.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Default Rakefile loader used by +import+. diff --git a/lib/rake/dsl_definition.rb b/lib/rake/dsl_definition.rb index c52bd601f..c80464020 100644 --- a/lib/rake/dsl_definition.rb +++ b/lib/rake/dsl_definition.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Rake DSL functions. require "rake/file_utils_ext" @@ -25,9 +26,9 @@ module DSL private # :call-seq: - # task task_name - # task task_name: dependencies - # task task_name, arguments => dependencies + # task(task_name) + # task(task_name: dependencies) + # task(task_name, arguments => dependencies) # # Declare a basic task. The +task_name+ is always the first argument. If # the task name contains a ":" it is defined in that namespace. diff --git a/lib/rake/early_time.rb b/lib/rake/early_time.rb index abcb1872b..80cc6bfad 100644 --- a/lib/rake/early_time.rb +++ b/lib/rake/early_time.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # EarlyTime is a fake timestamp that occurs _before_ any other time value. diff --git a/lib/rake/ext/core.rb b/lib/rake/ext/core.rb index 7575df15a..226f2125b 100644 --- a/lib/rake/ext/core.rb +++ b/lib/rake/ext/core.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true class Module # Check for an existing method in the current class before extending. If # the method already exists, then a warning is printed and the extension is diff --git a/lib/rake/ext/string.rb b/lib/rake/ext/string.rb index 37764c845..c70236ae9 100644 --- a/lib/rake/ext/string.rb +++ b/lib/rake/ext/string.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/ext/core" class String @@ -136,7 +137,7 @@ def pathmap_replace(patterns, &block) # This String extension comes from Rake def pathmap(spec=nil, &block) return self if spec.nil? - result = "" + result = "".dup spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag| case frag when "%f" diff --git a/lib/rake/file_creation_task.rb b/lib/rake/file_creation_task.rb index f3c5c78a1..5a4c68492 100644 --- a/lib/rake/file_creation_task.rb +++ b/lib/rake/file_creation_task.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/file_task" require "rake/early_time" @@ -11,7 +12,7 @@ module Rake class FileCreationTask < FileTask # Is this file task needed? Yes if it doesn't exist. def needed? - ! File.exist?(name) + !File.exist?(name) end # Time stamp for file creation task. This time stamp is earlier diff --git a/lib/rake/file_list.rb b/lib/rake/file_list.rb index a30c6338c..22c339f24 100644 --- a/lib/rake/file_list.rb +++ b/lib/rake/file_list.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/cloneable" require "rake/file_utils_ext" require "rake/ext/string" @@ -293,7 +294,7 @@ def egrep(pattern, *options) matched = 0 each do |fn| begin - open(fn, "r", *options) do |inf| + File.open(fn, "r", *options) do |inf| count = 0 inf.each do |line| count += 1 @@ -317,14 +318,14 @@ def egrep(pattern, *options) # Return a new file list that only contains file names from the current # file list that exist on the file system. def existing - select { |fn| File.exist?(fn) } + select { |fn| File.exist?(fn) }.uniq end # Modify the current file list so that it contains only file name that # exist on the file system. def existing! resolve - @items = @items.select { |fn| File.exist?(fn) } + @items = @items.select { |fn| File.exist?(fn) }.uniq self end @@ -384,7 +385,7 @@ def excluded_from_list?(fn) /~$/ ] DEFAULT_IGNORE_PROCS = [ - proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) } + proc { |fn| fn =~ /(^|[\/\\])core$/ && !File.directory?(fn) } ] def import(array) # :nodoc: diff --git a/lib/rake/file_task.rb b/lib/rake/file_task.rb index 6656e7095..db790e39f 100644 --- a/lib/rake/file_task.rb +++ b/lib/rake/file_task.rb @@ -1,4 +1,5 @@ -require "rake/task.rb" +# frozen_string_literal: true +require "rake/task" require "rake/early_time" module Rake @@ -13,7 +14,7 @@ class FileTask < Task # Is this file task needed? Yes if it doesn't exist, or if its time stamp # is out of date. def needed? - ! File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all + !File.exist?(name) || out_of_date?(timestamp) || @application.options.build_all end # Time stamp for file task. @@ -29,7 +30,14 @@ def timestamp # Are there any prerequisites with a later time than the given time stamp? def out_of_date?(stamp) - @prerequisites.any? { |n| application[n, @scope].timestamp > stamp } + all_prerequisite_tasks.any? { |prereq| + prereq_task = application[prereq, @scope] + if prereq_task.instance_of?(Rake::FileTask) + prereq_task.timestamp > stamp || @application.options.build_all + else + prereq_task.timestamp > stamp + end + } end # ---------------------------------------------------------------- diff --git a/lib/rake/file_utils.rb b/lib/rake/file_utils.rb index aa065e8b4..dc434c8d9 100644 --- a/lib/rake/file_utils.rb +++ b/lib/rake/file_utils.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rbconfig" require "fileutils" @@ -34,7 +35,7 @@ module FileUtils # # # check exit status after command runs # sh %{grep pattern file} do |ok, res| - # if ! ok + # if !ok # puts "pattern not found (status = #{res.exitstatus})" # end # end @@ -50,7 +51,7 @@ def sh(*cmd, &block) Rake.rake_output_message sh_show_command cmd if verbose unless noop - res = system(*cmd, options) + res = (Hash === cmd.last) ? system(*cmd) : system(*cmd, options) status = $? status = Rake::PseudoStatus.new(1) if !res && status.nil? shell_runner.call(res, status) @@ -110,7 +111,7 @@ def ruby(*args, &block) # Attempt to do a normal file link, but fall back to a copy if the link # fails. def safe_ln(*args) - if ! LN_SUPPORTED[0] + if !LN_SUPPORTED[0] cp(*args) else begin diff --git a/lib/rake/file_utils_ext.rb b/lib/rake/file_utils_ext.rb index e5930d4ab..bf558b749 100644 --- a/lib/rake/file_utils_ext.rb +++ b/lib/rake/file_utils_ext.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/file_utils" module Rake diff --git a/lib/rake/invocation_chain.rb b/lib/rake/invocation_chain.rb index 540628957..44a995496 100644 --- a/lib/rake/invocation_chain.rb +++ b/lib/rake/invocation_chain.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # InvocationChain tracks the chain of task invocations to detect diff --git a/lib/rake/invocation_exception_mixin.rb b/lib/rake/invocation_exception_mixin.rb index 84ff3353b..b0d307a48 100644 --- a/lib/rake/invocation_exception_mixin.rb +++ b/lib/rake/invocation_exception_mixin.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake module InvocationExceptionMixin # Return the invocation chain (list of Rake tasks) that were in diff --git a/lib/rake/late_time.rb b/lib/rake/late_time.rb index d1d9470ec..8fe024943 100644 --- a/lib/rake/late_time.rb +++ b/lib/rake/late_time.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # LateTime is a fake timestamp that occurs _after_ any other time value. class LateTime diff --git a/lib/rake/linked_list.rb b/lib/rake/linked_list.rb index 54d0c1287..11fa46f0d 100644 --- a/lib/rake/linked_list.rb +++ b/lib/rake/linked_list.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Polylithic linked list structure used to implement several data diff --git a/lib/rake/loaders/makefile.rb b/lib/rake/loaders/makefile.rb index d0436bb79..46f4beaad 100644 --- a/lib/rake/loaders/makefile.rb +++ b/lib/rake/loaders/makefile.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Makefile loader to be used with the import file loader. Use this to diff --git a/lib/rake/multi_task.rb b/lib/rake/multi_task.rb index 7118dc411..3ae363cbe 100644 --- a/lib/rake/multi_task.rb +++ b/lib/rake/multi_task.rb @@ -1,49 +1,14 @@ +# frozen_string_literal: true module Rake # Same as a regular task, but the immediate prerequisites are done in # parallel using Ruby threads. # class MultiTask < Task - - # Same as invoke, but explicitly pass a call chain to detect - # circular dependencies. This is largely copied from Rake::Task - # but has been updated such that if multiple tasks depend on this - # one in parallel, they will all fail if the first execution of - # this task fails. - def invoke_with_call_chain(task_args, invocation_chain) - new_chain = Rake::InvocationChain.append(self, invocation_chain) - @lock.synchronize do - begin - if @already_invoked - if @invocation_exception - if application.options.trace - application.trace "** Previous invocation of #{name} failed #{format_trace_flags}" - end - raise @invocation_exception - else - return - end - end - - if application.options.trace - application.trace "** Invoke #{name} #{format_trace_flags}" - end - @already_invoked = true - - invoke_prerequisites(task_args, new_chain) - execute(task_args) if needed? - rescue Exception => ex - add_chain_to(ex, new_chain) - @invocation_exception = ex - raise - end - end - end - private + def invoke_prerequisites(task_args, invocation_chain) # :nodoc: invoke_prerequisites_concurrently(task_args, invocation_chain) end end - end diff --git a/lib/rake/name_space.rb b/lib/rake/name_space.rb index 0d7eb80b6..32f8139fc 100644 --- a/lib/rake/name_space.rb +++ b/lib/rake/name_space.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true ## # The NameSpace class will lookup task names in the scope defined by a # +namespace+ command. diff --git a/lib/rake/packagetask.rb b/lib/rake/packagetask.rb index 034b8e9e8..72fef4d5e 100644 --- a/lib/rake/packagetask.rb +++ b/lib/rake/packagetask.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define a package task library to aid in the definition of # redistributable package files. @@ -131,9 +132,7 @@ def define task package: ["#{package_dir}/#{file}"] file "#{package_dir}/#{file}" => [package_dir_path] + package_files do - chdir(package_dir) do - sh @tar_command, "#{flag}cvf", file, package_name - end + chdir(package_dir) { sh @tar_command, "#{flag}cvf", file, package_name } end end end @@ -142,9 +141,7 @@ def define task package: ["#{package_dir}/#{zip_file}"] file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do - chdir(package_dir) do - sh @zip_command, "-r", zip_file, package_name - end + chdir(package_dir) { sh @zip_command, "-r", zip_file, package_name } end end diff --git a/lib/rake/phony.rb b/lib/rake/phony.rb index a172f9c60..8caa5de17 100644 --- a/lib/rake/phony.rb +++ b/lib/rake/phony.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Defines a :phony task that you can use as a dependency. This allows # file-based tasks to use non-file-based tasks as prerequisites # without forcing them to rebuild. diff --git a/lib/rake/private_reader.rb b/lib/rake/private_reader.rb index 162097857..2815ce643 100644 --- a/lib/rake/private_reader.rb +++ b/lib/rake/private_reader.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Include PrivateReader to use +private_reader+. diff --git a/lib/rake/promise.rb b/lib/rake/promise.rb index 37221e427..f45af4f3a 100644 --- a/lib/rake/promise.rb +++ b/lib/rake/promise.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # A Promise object represents a promise to do work (a chore) in the @@ -70,12 +71,12 @@ def chore # Do we have a result for the promise def result? - ! @result.equal?(NOT_SET) + !@result.equal?(NOT_SET) end # Did the promise throw an error def error? - ! @error.equal?(NOT_SET) + !@error.equal?(NOT_SET) end # Are we done with the promise diff --git a/lib/rake/pseudo_status.rb b/lib/rake/pseudo_status.rb index 16e1903bd..8b3c98949 100644 --- a/lib/rake/pseudo_status.rb +++ b/lib/rake/pseudo_status.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake ## diff --git a/lib/rake/rake_module.rb b/lib/rake/rake_module.rb index 75feb1261..03c295624 100644 --- a/lib/rake/rake_module.rb +++ b/lib/rake/rake_module.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/application" module Rake @@ -33,6 +34,34 @@ def add_rakelib(*files) application.options.rakelib ||= [] application.options.rakelib.concat(files) end + + # Make +block_application+ the default rake application inside a block so + # you can load rakefiles into a different application. + # + # This is useful when you want to run rake tasks inside a library without + # running rake in a sub-shell. + # + # Example: + # + # Dir.chdir 'other/directory' + # + # other_rake = Rake.with_application do |rake| + # rake.load_rakefile + # end + # + # puts other_rake.tasks + + def with_application(block_application = Rake::Application.new) + orig_application = Rake.application + + Rake.application = block_application + + yield block_application + + block_application + ensure + Rake.application = orig_application + end end end diff --git a/lib/rake/rake_test_loader.rb b/lib/rake/rake_test_loader.rb index d299efe35..f0f7772ba 100644 --- a/lib/rake/rake_test_loader.rb +++ b/lib/rake/rake_test_loader.rb @@ -1,20 +1,26 @@ +# frozen_string_literal: true require "rake" # Load the test files from the command line. argv = ARGV.select do |argument| - case argument - when /^-/ then - argument - when /\*/ then - FileList[argument].to_a.each do |file| - require File.expand_path file - end + begin + case argument + when /^-/ then + argument + when /\*/ then + FileList[argument].to_a.each do |file| + require File.expand_path file + end - false - else - require File.expand_path argument + false + else + require File.expand_path argument - false + false + end + rescue LoadError => e + raise unless e.path + abort "\nFile does not exist: #{e.path}\n\n" end end diff --git a/lib/rake/rule_recursion_overflow_error.rb b/lib/rake/rule_recursion_overflow_error.rb index 39d44aac6..a51e77489 100644 --- a/lib/rake/rule_recursion_overflow_error.rb +++ b/lib/rake/rule_recursion_overflow_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Error indicating a recursion overflow error in task selection. diff --git a/lib/rake/scope.rb b/lib/rake/scope.rb index b432f5f29..fc1eb6c3a 100644 --- a/lib/rake/scope.rb +++ b/lib/rake/scope.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake class Scope < LinkedList # :nodoc: all @@ -15,7 +16,7 @@ def path_with_task_name(task_name) # this trim beyond the toplevel scope. def trim(n) result = self - while n > 0 && ! result.empty? + while n > 0 && !result.empty? result = result.tail n -= 1 end diff --git a/lib/rake/task.rb b/lib/rake/task.rb index 23faf96e5..10c563c92 100644 --- a/lib/rake/task.rb +++ b/lib/rake/task.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/invocation_exception_mixin" module Rake @@ -14,6 +15,7 @@ module Rake class Task # List of prerequisites for a task. attr_reader :prerequisites + alias prereqs prerequisites # List of actions attached to a task. attr_reader :actions @@ -102,6 +104,7 @@ def initialize(task_name, app) @scope = app.current_scope @arg_names = nil @locations = [] + @invocation_exception = nil end # Enhance a task with prerequisites or actions. Returns self. @@ -182,20 +185,39 @@ def invoke(*args) # Same as invoke, but explicitly pass a call chain to detect # circular dependencies. - def invoke_with_call_chain(task_args, invocation_chain) # :nodoc: - new_chain = InvocationChain.append(self, invocation_chain) + # + # If multiple tasks depend on this + # one in parallel, they will all fail if the first execution of + # this task fails. + def invoke_with_call_chain(task_args, invocation_chain) + new_chain = Rake::InvocationChain.append(self, invocation_chain) @lock.synchronize do - if application.options.trace - application.trace "** Invoke #{name} #{format_trace_flags}" + begin + if application.options.trace + application.trace "** Invoke #{name} #{format_trace_flags}" + end + + if @already_invoked + if @invocation_exception + if application.options.trace + application.trace "** Previous invocation of #{name} failed #{format_trace_flags}" + end + raise @invocation_exception + else + return + end + end + + @already_invoked = true + + invoke_prerequisites(task_args, new_chain) + execute(task_args) if needed? + rescue Exception => ex + add_chain_to(ex, new_chain) + @invocation_exception = ex + raise ex end - return if @already_invoked - @already_invoked = true - invoke_prerequisites(task_args, new_chain) - execute(task_args) if needed? end - rescue Exception => ex - add_chain_to(ex, new_chain) - raise ex end protected :invoke_with_call_chain @@ -226,7 +248,8 @@ def invoke_prerequisites_concurrently(task_args, invocation_chain)# :nodoc: r.invoke_with_call_chain(prereq_args, invocation_chain) end end - futures.each(&:value) + # Iterate in reverse to improve performance related to thread waiting and switching + futures.reverse_each(&:value) end # Format the trace flags for display. @@ -266,7 +289,7 @@ def timestamp def add_description(description) return unless description comment = description.strip - add_comment(comment) if comment && ! comment.empty? + add_comment(comment) if comment && !comment.empty? end def comment=(comment) # :nodoc: @@ -320,7 +343,7 @@ def set_arg_names(args) # Return a string describing the internal state of a task. Useful for # debugging. def investigation - result = "------------------------------\n" + result = "------------------------------\n".dup result << "Investigating #{name}\n" result << "class: #{self.class}\n" result << "task needed: #{needed?}\n" diff --git a/lib/rake/task_argument_error.rb b/lib/rake/task_argument_error.rb index 3e1dda64d..ef20076c6 100644 --- a/lib/rake/task_argument_error.rb +++ b/lib/rake/task_argument_error.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # Error indicating an ill-formed task declaration. diff --git a/lib/rake/task_arguments.rb b/lib/rake/task_arguments.rb index c98057c8f..0d3001afd 100644 --- a/lib/rake/task_arguments.rb +++ b/lib/rake/task_arguments.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake ## diff --git a/lib/rake/task_manager.rb b/lib/rake/task_manager.rb index b62edc8e3..1991088fa 100644 --- a/lib/rake/task_manager.rb +++ b/lib/rake/task_manager.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake # The TaskManager module is a mixin for managing tasks. @@ -55,7 +56,26 @@ def [](task_name, scopes=nil) self.lookup(task_name, scopes) or enhance_with_matching_rule(task_name) or synthesize_file_task(task_name) or - fail "Don't know how to build task '#{task_name}' (see --tasks)" + fail generate_message_for_undefined_task(task_name) + end + + def generate_message_for_undefined_task(task_name) + message = "Don't know how to build task '#{task_name}' "\ + "(See the list of available tasks with `#{Rake.application.name} --tasks`)" + message + generate_did_you_mean_suggestions(task_name) + end + + def generate_did_you_mean_suggestions(task_name) + return "" unless defined?(::DidYouMean::SpellChecker) + + suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s) + if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later + ::DidYouMean.formatter.message_for(suggestions) + elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0 + ::DidYouMean::Formatter.new(suggestions).to_s + else + "" + end end def synthesize_file_task(task_name) # :nodoc: @@ -126,8 +146,8 @@ def enhance_with_matching_rule(task_name, level=0) fail Rake::RuleRecursionOverflowError, "Rule Recursion Too Deep" if level >= 16 @rules.each do |pattern, args, extensions, block| - if pattern.match(task_name) - task = attempt_rule(task_name, args, extensions, block, level) + if pattern && pattern.match(task_name) + task = attempt_rule(task_name, pattern, args, extensions, block, level) return task if task end end @@ -241,8 +261,8 @@ def trace_rule(level, message) # :nodoc: end # Attempt to create a rule given the list of prerequisites. - def attempt_rule(task_name, args, extensions, block, level) - sources = make_sources(task_name, extensions) + def attempt_rule(task_name, task_pattern, args, extensions, block, level) + sources = make_sources(task_name, task_pattern, extensions) prereqs = sources.map { |source| trace_rule level, "Attempting Rule #{task_name} => #{source}" if File.exist?(source) || Rake::Task.task_defined?(source) @@ -263,7 +283,7 @@ def attempt_rule(task_name, args, extensions, block, level) # Make a list of sources from the list of file name extensions / # translation procs. - def make_sources(task_name, extensions) + def make_sources(task_name, task_pattern, extensions) result = extensions.map { |ext| case ext when /%/ @@ -271,7 +291,8 @@ def make_sources(task_name, extensions) when %r{/} ext when /^\./ - task_name.ext(ext) + source = task_name.sub(task_pattern, ext) + source == ext ? task_name.ext(ext) : source when String ext when Proc, Method diff --git a/lib/rake/tasklib.rb b/lib/rake/tasklib.rb index 7bcda1789..5354b4f94 100644 --- a/lib/rake/tasklib.rb +++ b/lib/rake/tasklib.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake" module Rake diff --git a/lib/rake/testtask.rb b/lib/rake/testtask.rb index bb7f0ee8a..537627567 100644 --- a/lib/rake/testtask.rb +++ b/lib/rake/testtask.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake" require "rake/tasklib" @@ -50,6 +51,7 @@ class TestTask < TaskLib # Request that the tests be run with the warning flag set. # E.g. warning=true implies "ruby -w" used to run the tests. + # (default is true) attr_accessor :warning # Glob pattern to match test files. (default is 'test/test*.rb') diff --git a/lib/rake/thread_history_display.rb b/lib/rake/thread_history_display.rb index 04273541e..412ea37be 100644 --- a/lib/rake/thread_history_display.rb +++ b/lib/rake/thread_history_display.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rake/private_reader" module Rake diff --git a/lib/rake/thread_pool.rb b/lib/rake/thread_pool.rb index 1c2f5f50f..b01a5efe0 100644 --- a/lib/rake/thread_pool.rb +++ b/lib/rake/thread_pool.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "set" require "rake/promise" diff --git a/lib/rake/trace_output.rb b/lib/rake/trace_output.rb index c740b9e23..d713a0926 100644 --- a/lib/rake/trace_output.rb +++ b/lib/rake/trace_output.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Rake module TraceOutput # :nodoc: all diff --git a/lib/rake/version.rb b/lib/rake/version.rb index 1908ff855..6014e9322 100644 --- a/lib/rake/version.rb +++ b/lib/rake/version.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true module Rake - VERSION = "12.0.0" + VERSION = "12.3.3" module Version # :nodoc: all MAJOR, MINOR, BUILD, *OTHER = Rake::VERSION.split "." diff --git a/lib/rake/win32.rb b/lib/rake/win32.rb index 1fc02a5ae..6e6203181 100644 --- a/lib/rake/win32.rb +++ b/lib/rake/win32.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "rbconfig" module Rake diff --git a/rake.gemspec b/rake.gemspec index 8479b9314..66c567ca9 100644 --- a/rake.gemspec +++ b/rake.gemspec @@ -1,10 +1,10 @@ +# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('../lib', __FILE__) require 'rake/version' Gem::Specification.new do |s| s.name = "rake".freeze s.version = Rake::VERSION - s.date = "2016-12-06" s.authors = ["Hiroshi SHIBATA".freeze, "Eric Hodel".freeze, "Jim Weirich".freeze] s.email = ["hsbt@ruby-lang.org".freeze, "drbrain@segment7.net".freeze, "".freeze] @@ -23,12 +23,13 @@ Rake has the following features: s.homepage = "https://github.com/ruby/rake".freeze s.licenses = ["MIT".freeze] - s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + s.files = %x[git ls-files -z].split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - + %w[.rubocop.yml .gitignore .travis.yml appveyor.yml] s.bindir = "exe" s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } s.require_paths = ["lib".freeze] - s.required_ruby_version = Gem::Requirement.new(">= 1.9.3".freeze) + s.required_ruby_version = Gem::Requirement.new(">= 2.0.0".freeze) s.rubygems_version = "2.6.1".freeze s.required_rubygems_version = Gem::Requirement.new(">= 1.3.2".freeze) s.rdoc_options = ["--main".freeze, "README.rdoc".freeze] @@ -36,4 +37,6 @@ Rake has the following features: s.add_development_dependency(%q.freeze) s.add_development_dependency(%q.freeze) s.add_development_dependency(%q.freeze) + s.add_development_dependency(%q.freeze) + s.add_development_dependency(%q.freeze) end diff --git a/test/helper.rb b/test/helper.rb index 7736da72f..64f7db7e2 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,5 +1,15 @@ +# frozen_string_literal: true $:.unshift File.expand_path("../../lib", __FILE__) +begin + if ENV["COVERALLS"] + gem "coveralls" + require "coveralls" + Coveralls.wear! + end +rescue Gem::LoadError +end + gem "minitest", "~> 5" require "minitest/autorun" require "rake" @@ -18,7 +28,7 @@ class TaskManager include Rake::TaskManager end - RUBY = Gem.ruby + RUBY = File.realpath(ENV["BUNDLE_RUBY"] || Gem.ruby) def setup ARGV.clear diff --git a/test/support/file_creation.rb b/test/support/file_creation.rb index facc57a03..a1313bc0e 100644 --- a/test/support/file_creation.rb +++ b/test/support/file_creation.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module FileCreation OLDFILE = "old" NEWFILE = "new" diff --git a/test/support/rakefile_definitions.rb b/test/support/rakefile_definitions.rb index e0af05a67..5dacd3783 100644 --- a/test/support/rakefile_definitions.rb +++ b/test/support/rakefile_definitions.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module RakefileDefinitions include FileUtils @@ -77,6 +78,24 @@ def rakefile_chains DEFAULT end + def rakefile_file_chains + rakefile <<-RAKEFILE +file "fileA" do |t| + sh "echo contentA >\#{t.name}" +end + +file "fileB" => "fileA" do |t| + sh "(cat fileA; echo transformationB) >\#{t.name}" +end + +file "fileC" => "fileB" do |t| + sh "(cat fileB; echo transformationC) >\#{t.name}" +end + +task default: "fileC" + RAKEFILE + end + def rakefile_comments rakefile <<-COMMENTS # comment for t1 diff --git a/test/support/ruby_runner.rb b/test/support/ruby_runner.rb index 199f60dd6..160a57090 100644 --- a/test/support/ruby_runner.rb +++ b/test/support/ruby_runner.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module RubyRunner include FileUtils diff --git a/test/test_private_reader.rb b/test/test_private_reader.rb index 56160f062..ee22e1b40 100644 --- a/test/test_private_reader.rb +++ b/test/test_private_reader.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/private_reader" -class TestPrivateAttrs < Rake::TestCase +class TestPrivateAttrs < Rake::TestCase # :nodoc: - class Sample + class Sample # :nodoc: include Rake::PrivateReader private_reader :reader, :a diff --git a/test/test_rake.rb b/test/test_rake.rb index dfbb7d232..a6d08fd35 100644 --- a/test/test_rake.rb +++ b/test/test_rake.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRake < Rake::TestCase +class TestRake < Rake::TestCase # :nodoc: def test_each_dir_parent assert_equal ["a"], alldirs("a") assert_equal ["a/b", "a"], alldirs("a/b") diff --git a/test/test_rake_application.rb b/test/test_rake_application.rb index 62bb4c6ac..27645ea12 100644 --- a/test/test_rake_application.rb +++ b/test/test_rake_application.rb @@ -1,7 +1,7 @@ -#encoding: UTF-8 +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeApplication < Rake::TestCase +class TestRakeApplication < Rake::TestCase # :nodoc: def setup super @@ -10,11 +10,34 @@ def setup @app.options.rakelib = [] end - def setup_command_line(*options) - ARGV.clear - options.each do |option| - ARGV << option + def test_class_with_application + orig_app = Rake.application + + return_app = Rake.with_application do |yield_app| + refute_equal orig_app, yield_app, "new application must be yielded" + + assert_equal yield_app, Rake.application, + "new application must be default in block" end + + refute_equal orig_app, return_app, "new application not returned" + assert_equal orig_app, Rake.application, "original application not default" + end + + def test_class_with_application_user_defined + orig_app = Rake.application + + user_app = Rake::Application.new + + return_app = Rake.with_application user_app do |yield_app| + assert_equal user_app, yield_app, "user application must be yielded" + + assert_equal user_app, Rake.application, + "user application must be default in block" + end + + assert_equal user_app, return_app, "user application not returned" + assert_equal orig_app, Rake.application, "original application not default" end def test_display_exception_details @@ -26,6 +49,8 @@ def test_display_exception_details end out, err = capture_io do + @app.set_default_options # reset trace output IO + @app.display_error_message ex end @@ -37,11 +62,13 @@ def test_display_exception_details def test_display_exception_details_bad_encoding begin - raise "El Niño is coming!".force_encoding("US-ASCII") + raise "El Niño is coming!".dup.force_encoding("US-ASCII") rescue => ex end out, err = capture_io do + @app.set_default_options # reset trace output IO + @app.display_error_message ex end @@ -63,39 +90,14 @@ def test_display_exception_details_cause end out, err = capture_io do - @app.display_error_message ex - end - - assert_empty out + @app.set_default_options # reset trace output IO - assert_match "cause a", err - assert_match "cause b", err - end - - def test_display_exception_details_cause_loop - skip "Exception#cause not implemented" unless - Exception.method_defined? :cause - skip if jruby9? # https://github.com/jruby/jruby/issues/3654 - - begin - begin - raise "cause a" - rescue => a - begin - raise "cause b" - rescue - raise a - end - end - rescue => ex - end - - out, err = capture_io do @app.display_error_message ex end assert_empty out + assert_match "Caused by:", err assert_match "cause a", err assert_match "cause b", err end @@ -215,7 +217,7 @@ def test_load_rakefile rakefile_unittest @app.instance_eval do - handle_options + handle_options [] options.silent = true load_rakefile end @@ -243,7 +245,7 @@ def test_load_rakefile_from_subdir Dir.chdir "subdir" @app.instance_eval do - handle_options + handle_options [] options.silent = true load_rakefile end @@ -274,7 +276,7 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent _, err = capture_io do @app.instance_eval do - handle_options + handle_options [] options.silent = true raw_load_rakefile end @@ -286,12 +288,11 @@ def test_load_rakefile_doesnt_print_rakefile_directory_from_subdir_if_silent def test_load_rakefile_not_found skip if jruby9? - ARGV.clear Dir.chdir @tempdir ENV["RAKE_SYSTEM"] = "not_exist" @app.instance_eval do - handle_options + handle_options [] options.silent = true end @@ -308,7 +309,7 @@ def test_load_from_system_rakefile rake_system_dir @app.instance_eval do - handle_options + handle_options [] options.silent = true options.load_system = true options.rakelib = [] @@ -330,7 +331,7 @@ def @app.standard_system_dir ENV["RAKE_SYSTEM"] = nil @app.instance_eval do - handle_options + handle_options [] options.silent = true options.load_system = true options.rakelib = [] @@ -390,28 +391,22 @@ def test_building_imported_files_on_demand def test_handle_options_should_not_strip_options_from_argv assert !@app.options.trace - valid_option = "--trace" - setup_command_line(valid_option) + argv = %w[--trace] + @app.handle_options argv - @app.handle_options - - assert ARGV.include?(valid_option) + assert_includes argv, "--trace" assert @app.options.trace end def test_handle_options_trace_default_is_stderr - setup_command_line("--trace") - - @app.handle_options + @app.handle_options %w[--trace] assert_equal STDERR, @app.options.trace_output assert @app.options.trace end def test_handle_options_trace_overrides_to_stdout - setup_command_line("--trace=stdout") - - @app.handle_options + @app.handle_options %w[--trace=stdout] assert_equal STDOUT, @app.options.trace_output assert @app.options.trace @@ -420,18 +415,16 @@ def test_handle_options_trace_overrides_to_stdout def test_handle_options_trace_does_not_eat_following_task_names assert !@app.options.trace - setup_command_line("--trace", "sometask") + argv = %w[--trace sometask] + @app.handle_options argv - @app.handle_options - assert ARGV.include?("sometask") + assert argv.include?("sometask") assert @app.options.trace end def test_good_run ran = false - ARGV << '--rakelib=""' - @app.options.silent = true @app.instance_eval do @@ -441,7 +434,7 @@ def test_good_run rakefile_default out, err = capture_io do - @app.run + @app.run %w[--rakelib=""] end assert ran @@ -451,10 +444,9 @@ def test_good_run def test_display_task_run ran = false - setup_command_line("-f", "-s", "--tasks", '--rakelib=""') @app.last_description = "COMMENT" @app.define_task(Rake::Task, "default") - out, = capture_io { @app.run } + out, = capture_io { @app.run %w[-f -s --tasks --rakelib=""] } assert @app.options.show_tasks assert ! ran assert_match(/rake default/, out) @@ -463,13 +455,12 @@ def test_display_task_run def test_display_prereqs ran = false - setup_command_line("-f", "-s", "--prereqs", '--rakelib=""') @app.last_description = "COMMENT" t = @app.define_task(Rake::Task, "default") t.enhance([:a, :b]) @app.define_task(Rake::Task, "a") @app.define_task(Rake::Task, "b") - out, = capture_io { @app.run } + out, = capture_io { @app.run %w[-f -s --prereqs --rakelib=""] } assert @app.options.show_prereqs assert ! ran assert_match(/rake a$/, out) @@ -479,37 +470,29 @@ def test_display_prereqs def test_bad_run @app.intern(Rake::Task, "default").enhance { fail } - setup_command_line("-f", "-s", '--rakelib=""') _, err = capture_io { - assert_raises(SystemExit) { @app.run } + assert_raises(SystemExit) { @app.run %w[-f -s --rakelib=""] } } assert_match(/see full trace/i, err) - ensure - ARGV.clear end def test_bad_run_with_trace @app.intern(Rake::Task, "default").enhance { fail } - setup_command_line("-f", "-s", "-t") _, err = capture_io { - assert_raises(SystemExit) { @app.run } + @app.set_default_options + assert_raises(SystemExit) { @app.run %w[-f -s -t] } } refute_match(/see full trace/i, err) - ensure - ARGV.clear end def test_bad_run_with_backtrace @app.intern(Rake::Task, "default").enhance { fail } - setup_command_line("-f", "-s", "--backtrace") _, err = capture_io { assert_raises(SystemExit) { - @app.run + @app.run %w[-f -s --backtrace] } } refute_match(/see full trace/, err) - ensure - ARGV.clear end CustomError = Class.new(RuntimeError) @@ -518,10 +501,9 @@ def test_bad_run_includes_exception_name @app.intern(Rake::Task, "default").enhance { raise CustomError, "intentional" } - setup_command_line("-f", "-s") _, err = capture_io { assert_raises(SystemExit) { - @app.run + @app.run %w[-f -s] } } assert_match(/CustomError: intentional/, err) @@ -531,10 +513,9 @@ def test_rake_error_excludes_exception_name @app.intern(Rake::Task, "default").enhance { fail "intentional" } - setup_command_line("-f", "-s") _, err = capture_io { assert_raises(SystemExit) { - @app.run + @app.run %w[-f -s] } } refute_match(/RuntimeError/, err) @@ -555,28 +536,22 @@ def test_printing_original_exception_cause raise custom_error, "Secondary Error" end } - setup_command_line("-f", "-s") _ ,err = capture_io { assert_raises(SystemExit) { - @app.run + @app.run %w[-f -s] } } if cause_supported? assert_match(/Original Error/, err) end assert_match(/Secondary Error/, err) - ensure - ARGV.clear end def test_run_with_bad_options @app.intern(Rake::Task, "default").enhance { fail } - setup_command_line("-f", "-s", "--xyzzy") assert_raises(SystemExit) { - capture_io { @app.run } + capture_io { @app.run %w[-f -s --xyzzy] } } - ensure - ARGV.clear end def test_standard_exception_handling_invalid_option @@ -596,6 +571,8 @@ def test_standard_exception_handling_invalid_option def test_standard_exception_handling_other out, err = capture_io do + @app.set_default_options # reset trace output IO + e = assert_raises SystemExit do @app.standard_exception_handling do raise "blah" diff --git a/test/test_rake_application_options.rb b/test/test_rake_application_options.rb index 149d8dcfd..0ca06e264 100644 --- a/test/test_rake_application_options.rb +++ b/test/test_rake_application_options.rb @@ -1,14 +1,14 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) TESTING_REQUIRE = [] -class TestRakeApplicationOptions < Rake::TestCase +class TestRakeApplicationOptions < Rake::TestCase # :nodoc: def setup super @testkey = ENV["TESTKEY"] - clear_argv Rake::FileUtilsExt.verbose_flag = false Rake::FileUtilsExt.nowrite_flag = false TESTING_REQUIRE.clear @@ -16,32 +16,27 @@ def setup def teardown ENV["TESTKEY"] = @testkey - clear_argv Rake::FileUtilsExt.verbose_flag = false Rake::FileUtilsExt.nowrite_flag = false super end - def clear_argv - ARGV.pop until ARGV.empty? - end - def test_default_options opts = command_line - assert_nil opts.backtrace - assert_nil opts.dryrun - assert_nil opts.ignore_system - assert_nil opts.load_system - assert_nil opts.always_multitask - assert_nil opts.nosearch + assert_equal false, opts.backtrace + assert_equal false, opts.dryrun + assert_equal false, opts.ignore_system + assert_equal false, opts.load_system + assert_equal false, opts.always_multitask + assert_equal false, opts.nosearch assert_equal ["rakelib"], opts.rakelib - assert_nil opts.show_prereqs + assert_equal false, opts.show_prereqs assert_nil opts.show_task_pattern assert_nil opts.show_tasks - assert_nil opts.silent - assert_nil opts.trace - assert_nil opts.thread_pool_size + assert_equal false, opts.silent + assert_equal false, opts.trace + assert_equal Rake.suggested_thread_count, opts.thread_pool_size assert_equal ["rakelib"], opts.rakelib assert ! Rake::FileUtilsExt.verbose_flag assert ! Rake::FileUtilsExt.nowrite_flag @@ -114,7 +109,7 @@ def test_help def test_jobs flags([]) do |opts| - assert_nil opts.thread_pool_size + assert_equal Rake.suggested_thread_count, opts.thread_pool_size end flags(["--jobs", "0"], ["-j", "0"]) do |opts| assert_equal 0, opts.thread_pool_size @@ -328,12 +323,12 @@ def test_tasks flags("--tasks", "-T") do |opts| assert_equal :tasks, opts.show_tasks assert_equal(//.to_s, opts.show_task_pattern.to_s) - assert_nil opts.show_all_tasks + assert_equal false, opts.show_all_tasks end flags(["--tasks", "xyz"], ["-Txyz"]) do |opts| assert_equal :tasks, opts.show_tasks assert_equal(/xyz/.to_s, opts.show_task_pattern.to_s) - assert_nil opts.show_all_tasks + assert_equal false, opts.show_all_tasks end flags(["--tasks", "xyz", "--comments"]) do |opts| assert_equal :tasks, opts.show_tasks @@ -444,8 +439,6 @@ def test_rake_explicit_task_library def flags(*sets) sets.each do |set| - ARGV.clear - @exit = catch(:system_exit) { command_line(*set) } yield(@app.options) if block_given? @@ -453,13 +446,12 @@ def flags(*sets) end def command_line(*options) - options.each do |opt| ARGV << opt end @app = Rake::Application.new def @app.exit(*args) throw :system_exit, :exit end @app.instance_eval do - args = handle_options + args = handle_options options collect_command_line_tasks(args) end @tasks = @app.top_level_tasks diff --git a/test/test_rake_backtrace.rb b/test/test_rake_backtrace.rb index ec727a292..27e3cecb7 100644 --- a/test/test_rake_backtrace.rb +++ b/test/test_rake_backtrace.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "open3" -class TestBacktraceSuppression < Rake::TestCase +class TestBacktraceSuppression < Rake::TestCase # :nodoc: def test_bin_rake_suppressed paths = ["something/bin/rake:12"] @@ -35,7 +36,7 @@ def test_near_system_dir_isnt_suppressed end end -class TestRakeBacktrace < Rake::TestCase +class TestRakeBacktrace < Rake::TestCase # :nodoc: include RubyRunner def setup diff --git a/test/test_rake_clean.rb b/test/test_rake_clean.rb index 5439a415f..b0b1ad602 100644 --- a/test/test_rake_clean.rb +++ b/test/test_rake_clean.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/clean" -class TestRakeClean < Rake::TestCase +class TestRakeClean < Rake::TestCase # :nodoc: def test_clean load "rake/clean.rb", true diff --git a/test/test_rake_cpu_counter.rb b/test/test_rake_cpu_counter.rb index aac16b2d7..5d04e7c97 100644 --- a/test/test_rake_cpu_counter.rb +++ b/test/test_rake_cpu_counter.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeCpuCounter < Rake::TestCase +class TestRakeCpuCounter < Rake::TestCase # :nodoc: def setup super @@ -27,7 +28,7 @@ def @cpu_counter.count; raise; end assert_equal(4, @cpu_counter.count_with_default) end - class TestClassMethod < Rake::TestCase + class TestClassMethod < Rake::TestCase # :nodoc: def setup super diff --git a/test/test_rake_definitions.rb b/test/test_rake_definitions.rb index 464cc6309..52e468e3b 100644 --- a/test/test_rake_definitions.rb +++ b/test/test_rake_definitions.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" -class TestRakeDefinitions < Rake::TestCase +class TestRakeDefinitions < Rake::TestCase # :nodoc: include Rake EXISTINGFILE = "existing" diff --git a/test/test_rake_directory_task.rb b/test/test_rake_directory_task.rb index e42bd9c77..5635afd13 100644 --- a/test/test_rake_directory_task.rb +++ b/test/test_rake_directory_task.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" require "pathname" -class TestRakeDirectoryTask < Rake::TestCase +class TestRakeDirectoryTask < Rake::TestCase # :nodoc: include Rake def test_directory diff --git a/test/test_rake_dsl.rb b/test/test_rake_dsl.rb index 7f82c6afa..6d0e7344d 100644 --- a/test/test_rake_dsl.rb +++ b/test/test_rake_dsl.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeDsl < Rake::TestCase +class TestRakeDsl < Rake::TestCase # :nodoc: def setup super diff --git a/test/test_rake_early_time.rb b/test/test_rake_early_time.rb index 71ee3e157..95040f67a 100644 --- a/test/test_rake_early_time.rb +++ b/test/test_rake_early_time.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeEarlyTime < Rake::TestCase +class TestRakeEarlyTime < Rake::TestCase # :nodoc: def test_create early = Rake::EarlyTime.instance assert early <= Time.now diff --git a/test/test_rake_extension.rb b/test/test_rake_extension.rb index 293ec1304..aeb8ce148 100644 --- a/test/test_rake_extension.rb +++ b/test/test_rake_extension.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "stringio" -class TestRakeExtension < Rake::TestCase +class TestRakeExtension < Rake::TestCase # :nodoc: - module Redirect + module Redirect # :nodoc: def error_redirect old_err = $stderr result = StringIO.new @@ -15,7 +16,7 @@ def error_redirect end end - class Sample + class Sample # :nodoc: extend Redirect def duplicate_method diff --git a/test/test_rake_file_creation_task.rb b/test/test_rake_file_creation_task.rb index 35f843e9e..05af13bb1 100644 --- a/test/test_rake_file_creation_task.rb +++ b/test/test_rake_file_creation_task.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" -class TestRakeFileCreationTask < Rake::TestCase +class TestRakeFileCreationTask < Rake::TestCase # :nodoc: include Rake - include Rake::DSL DUMMY_DIR = "dummy_dir" diff --git a/test/test_rake_file_list.rb b/test/test_rake_file_list.rb index 32ca7a8e3..97ab99828 100644 --- a/test/test_rake_file_list.rb +++ b/test/test_rake_file_list.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "pathname" -class TestRakeFileList < Rake::TestCase - FileList = Rake::FileList +class TestRakeFileList < Rake::TestCase # :nodoc: + FileList = Rake::FileList # :nodoc: def setup super @@ -414,13 +415,13 @@ def test_egrep_with_error end def test_existing - fl = FileList["abc.c", "notthere.c"] + fl = FileList["*c.c", "notthere.c", "a*.c"] assert_equal ["abc.c"], fl.existing assert fl.existing.is_a?(FileList) end def test_existing! - fl = FileList["abc.c", "notthere.c"] + fl = FileList["*c.c", "notthere.c", "a*.c"] result = fl.existing! assert_equal ["abc.c"], fl assert_equal fl.object_id, result.object_id diff --git a/test/test_rake_file_list_path_map.rb b/test/test_rake_file_list_path_map.rb index 28953a97a..2c51a2d72 100644 --- a/test/test_rake_file_list_path_map.rb +++ b/test/test_rake_file_list_path_map.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeFileListPathMap < Rake::TestCase +class TestRakeFileListPathMap < Rake::TestCase # :nodoc: def test_file_list_supports_pathmap assert_equal ["a", "b"], FileList["dir/a.rb", "dir/b.rb"].pathmap("%n") end diff --git a/test/test_rake_file_task.rb b/test/test_rake_file_task.rb index 24614dabe..61303d88a 100644 --- a/test/test_rake_file_task.rb +++ b/test/test_rake_file_task.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" require "pathname" -class TestRakeFileTask < Rake::TestCase +class TestRakeFileTask < Rake::TestCase # :nodoc: include Rake def setup diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb index 218c25415..7e9674fdc 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" require "stringio" -class TestRakeFileUtils < Rake::TestCase +class TestRakeFileUtils < Rake::TestCase # :nodoc: def setup super @rake_test_sh = ENV["RAKE_TEST_SH"] @@ -46,7 +47,7 @@ def test_ln assert_equal "TEST_LN\n", File.read("b") end - class BadLink + class BadLink # :nodoc: include Rake::FileUtilsExt attr_reader :cp_args @@ -180,6 +181,15 @@ def test_sh_with_spawn_options assert_equal "echocommand.rb\n", r.read end + def test_sh_with_hash_option + skip "JRuby does not support spawn options" if jruby? + check_expansion + + verbose(false) { + sh "#{RUBY} check_expansion.rb", { chdir: "." }, verbose: false + } + end + def test_sh_failure shellcommand diff --git a/test/test_rake_functional.rb b/test/test_rake_functional.rb index 7c2bd3266..afc31d28f 100644 --- a/test/test_rake_functional.rb +++ b/test/test_rake_functional.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" require "open3" -class TestRakeFunctional < Rake::TestCase +class TestRakeFunctional < Rake::TestCase # :nodoc: include RubyRunner def setup @@ -295,6 +296,26 @@ def test_rules_chaining_to_file_task "'play.app' file should exist" end + def dryrun_tasks + @err.split("\n").select { |line| + line.match(/^\*\* Execute/) + }.map { |line| + line.gsub(/^\*\* Execute \(dry run\) /, "") + } + end + + def test_update_midway_through_chaining_to_file_task + rakefile_file_chains + + rake "-n" + assert_equal(%w{fileA fileB fileC default}, dryrun_tasks) + rake + sleep 1 # Ensure the timestamp is on a new second + FileUtils.touch("fileA") + rake "-n" + assert_equal(%w{fileB fileC default}, dryrun_tasks) + end + def test_file_creation_task rakefile_file_creation diff --git a/test/test_rake_invocation_chain.rb b/test/test_rake_invocation_chain.rb index ba5f8724f..bf918f758 100644 --- a/test/test_rake_invocation_chain.rb +++ b/test/test_rake_invocation_chain.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeInvocationChain < Rake::TestCase +class TestRakeInvocationChain < Rake::TestCase # :nodoc: include Rake def setup diff --git a/test/test_rake_late_time.rb b/test/test_rake_late_time.rb index a88826da7..776b02d22 100644 --- a/test/test_rake_late_time.rb +++ b/test/test_rake_late_time.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeLateTime < Rake::TestCase +class TestRakeLateTime < Rake::TestCase # :nodoc: def test_late_time_comparisons late = Rake::LATE assert_equal late, late diff --git a/test/test_rake_linked_list.rb b/test/test_rake_linked_list.rb index a3c4d1972..656b50ac2 100644 --- a/test/test_rake_linked_list.rb +++ b/test/test_rake_linked_list.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestLinkedList < Rake::TestCase +class TestLinkedList < Rake::TestCase # :nodoc: include Rake def test_empty_list diff --git a/test/test_rake_makefile_loader.rb b/test/test_rake_makefile_loader.rb index bd70fd3b6..4f5270e0a 100644 --- a/test/test_rake_makefile_loader.rb +++ b/test/test_rake_makefile_loader.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/loaders/makefile" -class TestRakeMakefileLoader < Rake::TestCase +class TestRakeMakefileLoader < Rake::TestCase # :nodoc: include Rake def test_parse diff --git a/test/test_rake_multi_task.rb b/test/test_rake_multi_task.rb index bab25b158..641e65f4b 100644 --- a/test/test_rake_multi_task.rb +++ b/test/test_rake_multi_task.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "thread" -class TestRakeMultiTask < Rake::TestCase +class TestRakeMultiTask < Rake::TestCase # :nodoc: include Rake - include Rake::DSL def setup super @@ -82,4 +82,25 @@ def test_cross_thread_prerequisite_failures Rake::Task[:b].invoke end end + + def test_task_not_executed_if_dependant_task_failed_concurrently + multitask default: [:one, :two] + + task :one do + raise + end + + task_two_was_executed = false + task two: :one do + task_two_was_executed = true + end + + begin + Rake::Task[:default].invoke + rescue RuntimeError + ensure + sleep 0.5 + refute task_two_was_executed + end + end end diff --git a/test/test_rake_name_space.rb b/test/test_rake_name_space.rb index e043c07fa..a1a814cfd 100644 --- a/test/test_rake_name_space.rb +++ b/test/test_rake_name_space.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeNameSpace < Rake::TestCase +class TestRakeNameSpace < Rake::TestCase # :nodoc: - class TM + class TM # :nodoc: include Rake::TaskManager end diff --git a/test/test_rake_package_task.rb b/test/test_rake_package_task.rb index 7bacb7a52..d3886f8ca 100644 --- a/test/test_rake_package_task.rb +++ b/test/test_rake_package_task.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/packagetask" -class TestRakePackageTask < Rake::TestCase +class TestRakePackageTask < Rake::TestCase # :nodoc: def test_initialize touch "install.rb" diff --git a/test/test_rake_path_map.rb b/test/test_rake_path_map.rb index 040692930..1551247ec 100644 --- a/test/test_rake_path_map.rb +++ b/test/test_rake_path_map.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakePathMap < Rake::TestCase +class TestRakePathMap < Rake::TestCase # :nodoc: def test_returns_self_with_no_args assert_equal "abc.rb", "abc.rb".pathmap diff --git a/test/test_rake_path_map_explode.rb b/test/test_rake_path_map_explode.rb index 554a02266..877a8e0c9 100644 --- a/test/test_rake_path_map_explode.rb +++ b/test/test_rake_path_map_explode.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakePathMapExplode < Rake::TestCase +class TestRakePathMapExplode < Rake::TestCase # :nodoc: def setup super diff --git a/test/test_rake_path_map_partial.rb b/test/test_rake_path_map_partial.rb index 0adc24313..e73ec56b6 100644 --- a/test/test_rake_path_map_partial.rb +++ b/test/test_rake_path_map_partial.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakePathMapPartial < Rake::TestCase +class TestRakePathMapPartial < Rake::TestCase # :nodoc: def test_pathmap_partial - @path = "1/2/file" + @path = "1/2/file".dup def @path.call(n) pathmap_partial(n) end diff --git a/test/test_rake_pseudo_status.rb b/test/test_rake_pseudo_status.rb index d9fe42216..008621f49 100644 --- a/test/test_rake_pseudo_status.rb +++ b/test/test_rake_pseudo_status.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakePseudoStatus < Rake::TestCase +class TestRakePseudoStatus < Rake::TestCase # :nodoc: def test_with_zero_exit_status s = Rake::PseudoStatus.new assert_equal 0, s.exitstatus diff --git a/test/test_rake_rake_test_loader.rb b/test/test_rake_rake_test_loader.rb index 21c494ffe..4423a9b1c 100644 --- a/test/test_rake_rake_test_loader.rb +++ b/test/test_rake_rake_test_loader.rb @@ -1,6 +1,13 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeRakeTestLoader < Rake::TestCase +class TestRakeRakeTestLoader < Rake::TestCase # :nodoc: + + def setup + super + + @loader = File.join @rake_lib, "rake/rake_test_loader.rb" + end def test_pattern orig_loaded_features = $:.dup @@ -10,11 +17,45 @@ def test_pattern ARGV.replace %w[foo.rb test_*.rb -v] - load File.join(@rake_lib, "rake/rake_test_loader.rb") + load @loader assert_equal %w[-v], ARGV ensure $:.replace orig_loaded_features end + def test_load_error_from_require + out, err = capture_io do + ARGV.replace %w[no_such_test_file.rb] + + assert_raises SystemExit do + load @loader + end + end + + assert_empty out + + no_such_path = File.join @tempdir, "no_such_test_file" + + expected = + /\A\n + File\ does\ not\ exist:\ #{no_such_path}(\.rb)? # JRuby is different + \n\n\Z/x + + assert_match expected, err + end + + def test_load_error_raised_explicitly + File.write("error_test.rb", "raise LoadError, 'explicitly raised'") + out, err = capture_io do + ARGV.replace %w[error_test.rb] + + exc = assert_raises(LoadError) do + load @loader + end + assert_equal "explicitly raised", exc.message + end + assert_empty out + assert_empty err + end end diff --git a/test/test_rake_reduce_compat.rb b/test/test_rake_reduce_compat.rb index de81b474b..17986dcde 100644 --- a/test/test_rake_reduce_compat.rb +++ b/test/test_rake_reduce_compat.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "open3" -class TestRakeReduceCompat < Rake::TestCase +class TestRakeReduceCompat < Rake::TestCase # :nodoc: include RubyRunner def invoke_normal(task_name) diff --git a/test/test_rake_require.rb b/test/test_rake_require.rb index c77344cc3..6309277da 100644 --- a/test/test_rake_require.rb +++ b/test/test_rake_require.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeRequire < Rake::TestCase +class TestRakeRequire < Rake::TestCase # :nodoc: def setup super $LOAD_PATH.unshift "." if jruby17? diff --git a/test/test_rake_rules.rb b/test/test_rake_rules.rb index 7806ed11c..bfb8e775f 100644 --- a/test/test_rake_rules.rb +++ b/test/test_rake_rules.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" -class TestRakeRules < Rake::TestCase +class TestRakeRules < Rake::TestCase # :nodoc: include Rake SRCFILE = "abc.c" @@ -10,6 +11,7 @@ class TestRakeRules < Rake::TestCase OBJFILE = "abc.o" FOOFILE = "foo" DOTFOOFILE = ".foo" + MINFILE = "abc.min.o" def setup super @@ -341,6 +343,17 @@ def test_regex_rule_with_args Task[OBJFILE].invoke("arg") end + # for https://github.com/ruby/rake/pull/182 + def test_single_dependent_with_nil_args + create_file(SRCFILE) + rule nil => ".cpp" do |t| p t.name end + rule(/\.o$/ => ".c") do |t| + @runs << t.name + end + Task[OBJFILE].invoke + assert_equal [OBJFILE], @runs + end + def test_string_rule_with_args_and_lambda_prereq delete_file(OBJFILE) create_file(SRCFILE) @@ -385,4 +398,15 @@ def obj.find_prereq(task_name) assert_equal ["#{OBJFILE} - abc.c"], @runs end + def test_works_with_chained_extensions_in_rules + create_file(OBJFILE) + rule(".min.o" => [".o"]) do |t| + @runs << t.name + assert_equal OBJFILE, t.source + assert_equal MINFILE, t.name + end + Task[MINFILE].invoke + assert_equal [MINFILE], @runs + end + end diff --git a/test/test_rake_scope.rb b/test/test_rake_scope.rb index 169c0d9f9..24ac03408 100644 --- a/test/test_rake_scope.rb +++ b/test/test_rake_scope.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeScope < Rake::TestCase +class TestRakeScope < Rake::TestCase # :nodoc: include Rake def test_path_against_empty_scope diff --git a/test/test_rake_task.rb b/test/test_rake_task.rb index 5f5a63e30..688e0a3e7 100644 --- a/test/test_rake_task.rb +++ b/test/test_rake_task.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "fileutils" -class TestRakeTask < Rake::TestCase +class TestRakeTask < Rake::TestCase # :nodoc: include Rake def setup @@ -61,10 +62,14 @@ def test_invoke_with_circular_dependencies end def test_dry_run_prevents_actions - Rake.application.options.dryrun = true runlist = [] t1 = task(:t1) { |t| runlist << t.name; 3321 } - _, err = capture_io { t1.invoke } + _, err = capture_io { + Rake.application.set_default_options # reset trace output IO + Rake.application.options.dryrun = true + + t1.invoke + } assert_match(/execute .*t1/i, err) assert_match(/dry run/i, err) refute_match(/invoke/i, err) @@ -74,9 +79,11 @@ def test_dry_run_prevents_actions end def test_tasks_can_be_traced - Rake.application.options.trace = true t1 = task(:t1) _, err = capture_io { + Rake.application.set_default_options # reset trace output IO + Rake.application.options.trace = true + t1.invoke } assert_match(/invoke t1/i, err) @@ -165,7 +172,8 @@ def test_find task :tfind assert_equal "tfind", Task[:tfind].name ex = assert_raises(RuntimeError) { Task[:leaves] } - assert_equal "Don't know how to build task 'leaves' (see --tasks)", ex.message + assert_equal "Don't know how to build task 'leaves'" \ + " (See the list of available tasks with `rake --tasks`)", ex.message end def test_defined @@ -452,4 +460,20 @@ def test_source_is_first_prerequisite t = task t: ["preqA", "preqB"] assert_equal "preqA", t.source end + + def test_suggests_valid_rake_task_names + task :test + error = assert_raises(RuntimeError) { Task[:testt] } + + assert_match(/Don\'t know how to build task \'testt\'/, error.message) + + if defined?(::DidYouMean::SpellChecker) && defined?(::DidYouMean::Formatter) + assert_match(/Did you mean\? test/, error.message) + end + end + + def test_prereqs + t = task(a: %w[b c d e]) + assert_equal %w[b c d e], t.prereqs + end end diff --git a/test/test_rake_task_argument_parsing.rb b/test/test_rake_task_argument_parsing.rb index 4bc0ff0ae..ed12ea0b4 100644 --- a/test/test_rake_task_argument_parsing.rb +++ b/test/test_rake_task_argument_parsing.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTaskArgumentParsing < Rake::TestCase +class TestRakeTaskArgumentParsing < Rake::TestCase # :nodoc: def setup super @@ -37,6 +38,12 @@ def test_can_handle_spaces_between_args assert_equal ["one", "two", "three", "four"], args end + def test_can_handle_spaces_between_all_args + name, args = @app.parse_task_string("name[ one , two ,\tthree , \tfour ]") + assert_equal "name", name + assert_equal ["one", "two", "three", "four"], args + end + def test_keeps_embedded_spaces name, args = @app.parse_task_string("name[a one ana, two]") assert_equal "name", name @@ -95,16 +102,14 @@ def @app.unix?() raise end end def test_no_rakeopt - ARGV << "--trace" app = Rake::Application.new - app.init + app.init %w[--trace] assert !app.options.silent end def test_rakeopt_with_blank_options - ARGV << "--trace" app = Rake::Application.new - app.init + app.init %w[--trace] assert !app.options.silent end diff --git a/test/test_rake_task_arguments.rb b/test/test_rake_task_arguments.rb index 383d4a172..245a71661 100644 --- a/test/test_rake_task_arguments.rb +++ b/test/test_rake_task_arguments.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTaskArguments < Rake::TestCase +class TestRakeTaskArguments < Rake::TestCase # :nodoc: def teardown ENV.delete("rev") ENV.delete("VER") diff --git a/test/test_rake_task_manager.rb b/test/test_rake_task_manager.rb index a611bd737..88937c604 100644 --- a/test/test_rake_task_manager.rb +++ b/test/test_rake_task_manager.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTaskManager < Rake::TestCase +class TestRakeTaskManager < Rake::TestCase # :nodoc: def setup super @@ -24,7 +25,17 @@ def test_index @tm["bad"] end - assert_equal "Don't know how to build task 'bad' (see --tasks)", e.message + assert_equal "Don't know how to build task 'bad' (See the list of available tasks with `rake --tasks`)", e.message + end + + def test_undefined_task_with_custom_application + Rake.application.init("myrake", nil) + + e = assert_raises RuntimeError do + @tm["bad"] + end + + assert_equal "Don't know how to build task 'bad' (See the list of available tasks with `myrake --tasks`)", e.message end def test_name_lookup diff --git a/test/test_rake_task_manager_argument_resolution.rb b/test/test_rake_task_manager_argument_resolution.rb index 6d292816d..585932c5c 100644 --- a/test/test_rake_task_manager_argument_resolution.rb +++ b/test/test_rake_task_manager_argument_resolution.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTaskManagerArgumentResolution < Rake::TestCase +class TestRakeTaskManagerArgumentResolution < Rake::TestCase # :nodoc: def test_good_arg_patterns assert_equal [:t, [], []], task(:t) diff --git a/test/test_rake_task_with_arguments.rb b/test/test_rake_task_with_arguments.rb index 5f71b6b1a..46edcd112 100644 --- a/test/test_rake_task_with_arguments.rb +++ b/test/test_rake_task_with_arguments.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTaskWithArguments < Rake::TestCase +class TestRakeTaskWithArguments < Rake::TestCase # :nodoc: include Rake def setup @@ -83,7 +84,7 @@ def test_actions_of_various_arity_are_ok_with_args def test_actions_adore_keywords # A brutish trick to avoid parsing. Remove it once support for 1.9 and 2.0 is dropped # https://ci.appveyor.com/project/ruby/rake/build/1.0.301 - skip 'Keywords aren\'t a feature in this version' if RUBY_VERSION =~ /^1|^2\.0/ + skip "Keywords aren't a feature in this version" if RUBY_VERSION =~ /^1|^2\.0/ # https://github.com/ruby/rake/pull/174#issuecomment-263460761 skip if jruby9? eval <<-RUBY, binding, __FILE__, __LINE__+1 diff --git a/test/test_rake_test_task.rb b/test/test_rake_test_task.rb index 8e422f164..ed2313b91 100644 --- a/test/test_rake_test_task.rb +++ b/test/test_rake_test_task.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/testtask" -class TestRakeTestTask < Rake::TestCase +class TestRakeTestTask < Rake::TestCase # :nodoc: include Rake def test_initialize diff --git a/test/test_rake_thread_pool.rb b/test/test_rake_thread_pool.rb index d365574ba..42f648854 100644 --- a/test/test_rake_thread_pool.rb +++ b/test/test_rake_thread_pool.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/thread_pool" -class TestRakeTestThreadPool < Rake::TestCase +class TestRakeTestThreadPool < Rake::TestCase # :nodoc: include Rake def test_pool_executes_in_current_thread_for_zero_threads diff --git a/test/test_rake_top_level_functions.rb b/test/test_rake_top_level_functions.rb index a3bb2fbb8..f0dec1b76 100644 --- a/test/test_rake_top_level_functions.rb +++ b/test/test_rake_top_level_functions.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeTopLevelFunctions < Rake::TestCase +class TestRakeTopLevelFunctions < Rake::TestCase # :nodoc: def setup super diff --git a/test/test_rake_win32.rb b/test/test_rake_win32.rb index be95adb92..ed08ef09e 100644 --- a/test/test_rake_win32.rb +++ b/test/test_rake_win32.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) -class TestRakeWin32 < Rake::TestCase +class TestRakeWin32 < Rake::TestCase # :nodoc: - Win32 = Rake::Win32 + Win32 = Rake::Win32 # :nodoc: def test_win32_system_dir_uses_home_if_defined ENV["HOME"] = 'C:\\HP' @@ -64,7 +65,11 @@ def test_win32_backtrace_with_different_case rake.options.trace = true rake.instance_variable_set(:@rakefile, "Rakefile") - _, err = capture_io { rake.display_error_message(ex) } + _, err = capture_io { + rake.set_default_options # reset trace output IO + + rake.display_error_message(ex) + } assert_match(/rakefile/, err) end diff --git a/test/test_thread_history_display.rb b/test/test_thread_history_display.rb index f3466cef7..026576446 100644 --- a/test/test_thread_history_display.rb +++ b/test/test_thread_history_display.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "rake/thread_history_display" -class TestThreadHistoryDisplay < Rake::TestCase +class TestThreadHistoryDisplay < Rake::TestCase # :nodoc: def setup super @time = 1_000_000 diff --git a/test/test_trace_output.rb b/test/test_trace_output.rb index 18d2eee0f..46403870f 100644 --- a/test/test_trace_output.rb +++ b/test/test_trace_output.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true require File.expand_path("../helper", __FILE__) require "stringio" -class TestTraceOutput < Rake::TestCase +class TestTraceOutput < Rake::TestCase # :nodoc: include Rake::TraceOutput - class PrintSpy + class PrintSpy # :nodoc: attr_reader :result, :calls def initialize - @result = "" + @result = "".dup @calls = 0 end