diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/README.md | 2 | ||||
-rwxr-xr-x | tools/console | 12 | ||||
-rwxr-xr-x | tools/profile | 78 | ||||
-rw-r--r-- | tools/test.rb | 21 |
4 files changed, 65 insertions, 48 deletions
diff --git a/tools/README.md b/tools/README.md index b2e7e4b0ae..f133b27128 100644 --- a/tools/README.md +++ b/tools/README.md @@ -6,3 +6,5 @@ They aren't used by Rails apps directly. * `console` drops you in irb and loads local Rails repos * `profile` profiles `Kernel#require` to help reduce startup time * `line_statistics` provides CodeTools module and LineStatistics class to count lines + * `test` is loaded by every major component of Rails to simplify testing, for example: + `cd ./actioncable; bin/test ./path/to/actioncable_test_with_line_number.rb:5` diff --git a/tools/console b/tools/console index 98a848ff6b..ee08e22502 100755 --- a/tools/console +++ b/tools/console @@ -1,9 +1,11 @@ #!/usr/bin/env ruby -require 'bundler' +# frozen_string_literal: true + +require "bundler" Bundler.setup -require 'rails/all' -require 'active_support/all' -require 'irb' -require 'irb/completion' +require "rails/all" +require "active_support/all" +require "irb" +require "irb/completion" IRB.start diff --git a/tools/profile b/tools/profile index 191e73b3dd..6fb571f43b 100755 --- a/tools/profile +++ b/tools/profile @@ -1,21 +1,23 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # Profile require calls giving information about the time and the files that are called # when loading the provided file. # # Example: # tools/profile activesupport/lib/active_support.rb [ruby-prof mode] [ruby-prof printer] -ENV['NO_RELOAD'] ||= '1' -ENV['RAILS_ENV'] ||= 'development' +ENV["NO_RELOAD"] ||= "1" +ENV["RAILS_ENV"] ||= "development" module CodeTools class Profiler Error = Class.new(StandardError) attr_reader :path, :mode - def initialize(path, mode=nil) + def initialize(path, mode = nil) assert_ruby_file_exists(path) @path, @mode = path, mode - require 'benchmark' + require "benchmark" end def profile_requires @@ -23,7 +25,7 @@ module CodeTools before_rss = `ps -o rss= -p #{Process.pid}`.to_i if mode - require 'ruby-prof' + require "ruby-prof" RubyProf.measure_mode = RubyProf.const_get(mode.upcase) RubyProf.start else @@ -43,13 +45,13 @@ module CodeTools elsif RubyProf.const_defined?(:CallStackPrinter) filename = "#{File.basename(path, '.rb')}.#{mode}.html" puts "RubyProf outputting to #{filename}" - File.open(filename, 'w') do |out| + File.open(filename, "w") do |out| RubyProf::CallStackPrinter.new(results).print(out) end else filename = "#{File.basename(path, '.rb')}.#{mode}.callgrind" puts "RubyProf outputting to #{filename}" - File.open(filename, 'w') do |out| + File.open(filename, "w") do |out| RubyProf::CallTreePrinter.new(results).print(out) end end @@ -57,7 +59,7 @@ module CodeTools RequireProfiler.stats.each do |file, depth, sec| if sec - puts "%8.1f ms %s%s" % [sec * 1000, ' ' * depth, file] + puts "%8.1f ms %s%s" % [sec * 1000, " " * depth, file] else puts "#{' ' * (13 + depth)}#{file}" end @@ -67,51 +69,51 @@ module CodeTools private - def assert_ruby_file_exists(path) - fail Error.new("No such file") unless File.exist?(path) - fail Error.new("#{path} is a directory") if File.directory?(path) - ruby_extension = File.extname(path) == '.rb' - ruby_executable = File.open(path, 'rb') {|f| f.readline } =~ [/\A#!.*ruby/] - fail Error.new("Not a ruby file") unless ruby_extension or ruby_executable - end + def assert_ruby_file_exists(path) + fail Error.new("No such file") unless File.exist?(path) + fail Error.new("#{path} is a directory") if File.directory?(path) + ruby_extension = File.extname(path) == ".rb" + ruby_executable = File.open(path, "rb") { |f| f.readline } =~ [/\A#!.*ruby/] + fail Error.new("Not a ruby file") unless ruby_extension || ruby_executable + end - module RequireProfiler - private - def require(file, *args) RequireProfiler.profile(file) { super } end - def load(file, *args) RequireProfiler.profile(file) { super } end + module RequireProfiler + private + def require(file, *args) RequireProfiler.profile(file) { super } end + def load(file, *args) RequireProfiler.profile(file) { super } end - @depth, @stats = 0, [] - class << self - attr_accessor :depth - attr_accessor :stats + @depth, @stats = 0, [] + class << self + attr_accessor :depth + attr_accessor :stats - def profile(file) - stats << [file, depth] - self.depth += 1 - result = nil - elapsed = Benchmark.realtime { result = yield } - self.depth -= 1 - stats.pop if stats.last.first == file - stats << [file, depth, elapsed] if result - result - end + def profile(file) + stats << [file, depth] + self.depth += 1 + result = nil + elapsed = Benchmark.realtime { result = yield } + self.depth -= 1 + stats.pop if stats.last.first == file + stats << [file, depth, elapsed] if result + result + end + end end - end end end # ruby-prof printer name causes the third arg to be sent :classify # which is probably overkill if you already know the name of the ruby-prof # printer you want to use, e.g. Graph begin - require 'active_support/inflector' - require 'active_support/core_ext/string/inflections' + require "active_support/inflector" + require "active_support/core_ext/string/inflections" rescue LoadError STDERR.puts $!.message class String # File activesupport/lib/active_support/inflector/methods.rb, line 150 def classify # strip out any leading schema name - camelize(self.sub(/.*\./, '')) + camelize(sub(/.*\./, "")) end # File activesupport/lib/active_support/inflector/methods.rb, line 68 def camelize(uppercase_first_letter = true) @@ -121,7 +123,7 @@ rescue LoadError else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase } end - string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') + string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::") end end end diff --git a/tools/test.rb b/tools/test.rb index 62e0faa3db..1fd3ee30eb 100644 --- a/tools/test.rb +++ b/tools/test.rb @@ -1,15 +1,26 @@ +# frozen_string_literal: true + $: << File.expand_path("test", COMPONENT_ROOT) -require 'bundler' +require "bundler" Bundler.setup -require "rails/test_unit/minitest_plugin" +require "rails/test_unit/runner" +require "rails/test_unit/reporter" +require "rails/test_unit/line_filtering" +require "active_support" +require "active_support/test_case" -module Rails - # Necessary to get rerun-snippts working. - def self.root +class << Rails + # Necessary to get rerun-snippets working. + def root @root ||= Pathname.new(COMPONENT_ROOT) end + alias __root root end +ActiveSupport::TestCase.extend Rails::LineFiltering Rails::TestUnitReporter.executable = "bin/test" + +Rails::TestUnit::Runner.parse_options(ARGV) +Rails::TestUnit::Runner.run(ARGV) |