ruby-changes:56621
From: Nobuyoshi <ko1@a...>
Date: Tue, 23 Jul 2019 05:22:05 +0900 (JST)
Subject: [ruby-changes:56621] Nobuyoshi Nakada: d2710ba866 (master): Split test/ripper/test_files.rb to run in parallel
https://git.ruby-lang.org/ruby.git/commit/?id=d2710ba866 From d2710ba86677380f016b6a84d81e5cb39837c04d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 23 Jul 2019 05:21:41 +0900 Subject: Split test/ripper/test_files.rb to run in parallel diff --git a/test/ripper/assert_parse_files.rb b/test/ripper/assert_parse_files.rb new file mode 100644 index 0000000..85d20cf --- /dev/null +++ b/test/ripper/assert_parse_files.rb @@ -0,0 +1,32 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/assert_parse_files.rb#L1 +# frozen_string_literal: true +require 'test/unit' + +module TestRipper; end +class TestRipper::Generic < Test::Unit::TestCase + SRCDIR = File.expand_path("../../..", __FILE__) + + def assert_parse_files(dir, pattern = "**/*.rb") + assert_separately(%W[--disable-gem -rripper - #{SRCDIR}/#{dir} #{pattern}], + __FILE__, __LINE__, "#{<<-"begin;"}\n#{<<-'end;'}", timeout: Float::INFINITY) + pattern = "#{pattern}" + begin; + TEST_RATIO = ENV["TEST_RIPPER_RATIO"]&.tap {|s|break s.to_f} || 0.05 # testing all files needs too long time... + class Parser < Ripper + PARSER_EVENTS.each {|n| eval "def on_#{n}(*args) r = [:#{n}, *args]; r.inspect; Object.new end" } + SCANNER_EVENTS.each {|n| eval "def on_#{n}(*args) r = [:#{n}, *args]; r.inspect; Object.new end" } + end + dir = ARGV.shift + scripts = Dir.chdir(dir) {Dir[pattern]} + if (1...scripts.size).include?(num = scripts.size * TEST_RATIO) + scripts = scripts.sample(num) + end + scripts.sort! + for script in scripts + assert_nothing_raised { + parser = Parser.new(File.read("#{dir}/#{script}"), script) + parser.instance_eval "parse", "<#{script}>" + } + end + end; + end +end diff --git a/test/ripper/test_files.rb b/test/ripper/test_files.rb deleted file mode 100644 index d90cd64..0000000 --- a/test/ripper/test_files.rb +++ /dev/null @@ -1,50 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/assert_parse_files.rb#L0 -# frozen_string_literal: true -require 'test/unit' - -module TestRipper; end -class TestRipper::Generic < Test::Unit::TestCase - SRCDIR = File.expand_path("../../..", __FILE__) - - %w[sample ext].each do |dir| - define_method("test_parse_files:#{dir}") do - assert_parse_files(dir) - end - end - - %w[lib test].each do |dir| - define_method("test_parse_files:#{dir}") do - assert_parse_files(dir, "*.rb") - end - Dir["#{SRCDIR}/#{dir}/*/"].each do |dir| - dir = dir[(SRCDIR.length+1)..-2] - define_method("test_parse_files:#{dir}") do - assert_parse_files(dir) - end - end - end - - def assert_parse_files(dir, pattern = "**/*.rb") - assert_separately(%W[--disable-gem -rripper - #{SRCDIR}/#{dir} #{pattern}], - __FILE__, __LINE__, "#{<<-"begin;"}\n#{<<-'end;'}", timeout: Float::INFINITY) - pattern = "#{pattern}" - begin; - TEST_RATIO = ENV["TEST_RIPPER_RATIO"]&.tap {|s|break s.to_f} || 0.05 # testing all files needs too long time... - class Parser < Ripper - PARSER_EVENTS.each {|n| eval "def on_#{n}(*args) r = [:#{n}, *args]; r.inspect; Object.new end" } - SCANNER_EVENTS.each {|n| eval "def on_#{n}(*args) r = [:#{n}, *args]; r.inspect; Object.new end" } - end - dir = ARGV.shift - scripts = Dir.chdir(dir) {Dir[pattern]} - if (1...scripts.size).include?(num = scripts.size * TEST_RATIO) - scripts = scripts.sample(num) - end - scripts.sort! - for script in scripts - assert_nothing_raised { - parser = Parser.new(File.read("#{dir}/#{script}"), script) - parser.instance_eval "parse", "<#{script}>" - } - end - end; - end -end diff --git a/test/ripper/test_files_ext.rb b/test/ripper/test_files_ext.rb new file mode 100644 index 0000000..b77ec0f --- /dev/null +++ b/test/ripper/test_files_ext.rb @@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_ext.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + %w[ext].each do |dir| + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir) + end + end +end diff --git a/test/ripper/test_files_lib.rb b/test/ripper/test_files_lib.rb new file mode 100644 index 0000000..19f204d --- /dev/null +++ b/test/ripper/test_files_lib.rb @@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_lib.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + %w[lib].each do |dir| + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir, "*.rb") + end + Dir["#{SRCDIR}/#{dir}/*/"].each do |dir| + dir = dir[(SRCDIR.length+1)..-2] + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir) + end + end + end +end diff --git a/test/ripper/test_files_sample.rb b/test/ripper/test_files_sample.rb new file mode 100644 index 0000000..57538b1 --- /dev/null +++ b/test/ripper/test_files_sample.rb @@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_sample.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + %w[sample].each do |dir| + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir) + end + end +end diff --git a/test/ripper/test_files_test.rb b/test/ripper/test_files_test.rb new file mode 100644 index 0000000..5a8e368 --- /dev/null +++ b/test/ripper/test_files_test.rb @@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_test.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + %w[test].each do |dir| + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir, "*.rb") + end + end +end diff --git a/test/ripper/test_files_test_1.rb b/test/ripper/test_files_test_1.rb new file mode 100644 index 0000000..25db877 --- /dev/null +++ b/test/ripper/test_files_test_1.rb @@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_test_1.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + Dir["#{SRCDIR}/test/[-a-n]*/"].each do |dir| + dir = dir[(SRCDIR.length+1)..-2] + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir) + end + end +end diff --git a/test/ripper/test_files_test_2.rb b/test/ripper/test_files_test_2.rb new file mode 100644 index 0000000..24e935e --- /dev/null +++ b/test/ripper/test_files_test_2.rb @@ -0,0 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/test/ripper/test_files_test_2.rb#L1 +require_relative 'assert_parse_files.rb' +class TestRipper::Generic + Dir["#{SRCDIR}/test/[o-z]*/"].each do |dir| + dir = dir[(SRCDIR.length+1)..-2] + define_method("test_parse_files:#{dir}") do + assert_parse_files(dir) + end + end +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/