summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
Diffstat (limited to 'tool')
-rw-r--r--tool/bundler/rubocop_gems.rb.lock1
-rw-r--r--tool/bundler/standard_gems.rb.lock1
-rw-r--r--tool/ci_functions.sh29
-rwxr-xr-xtool/enc-unicode.rb6
-rwxr-xr-xtool/extlibs.rb2
-rw-r--r--tool/lib/colorize.rb2
-rw-r--r--tool/lib/core_assertions.rb (renamed from tool/lib/test/unit/core_assertions.rb)12
-rw-r--r--tool/lib/leakchecker.rb2
-rw-r--r--tool/lib/minitest/autorun.rb14
-rw-r--r--tool/lib/minitest/benchmark.rb418
-rw-r--r--tool/lib/minitest/mock.rb196
-rw-r--r--tool/lib/minitest/unit.rb52
-rw-r--r--tool/lib/test/unit.rb12
-rw-r--r--tool/lib/test/unit/assertions.rb12
-rw-r--r--tool/m4/_colorize_result_prepare.m41
-rwxr-xr-xtool/make-snapshot6
-rw-r--r--tool/mjit_tabs.rb8
-rwxr-xr-xtool/rbinstall.rb59
-rw-r--r--tool/ruby_vm/views/_mjit_compile_send.erb4
-rw-r--r--tool/sync_default_gems.rb60
-rw-r--r--tool/test-bundled-gems.rb6
-rw-r--r--tool/test/minitest/metametameta.rb1
-rw-r--r--tool/test/minitest/test_minitest_benchmark.rb131
-rw-r--r--tool/test/minitest/test_minitest_mock.rb404
-rw-r--r--tool/test/webrick/test_httpresponse.rb8
-rwxr-xr-xtool/travis_wait.sh18
-rwxr-xr-x[-rw-r--r--]tool/update-bundled_gems.rb8
27 files changed, 177 insertions, 1296 deletions
diff --git a/tool/bundler/rubocop_gems.rb.lock b/tool/bundler/rubocop_gems.rb.lock
index 19a4555..ab8c259 100644
--- a/tool/bundler/rubocop_gems.rb.lock
+++ b/tool/bundler/rubocop_gems.rb.lock
@@ -44,6 +44,7 @@ GEM
unicode-display_width (2.0.0)
PLATFORMS
+ arm64-darwin-20
universal-java-11
x86_64-linux
diff --git a/tool/bundler/standard_gems.rb.lock b/tool/bundler/standard_gems.rb.lock
index 1d36421..c4e3ee6 100644
--- a/tool/bundler/standard_gems.rb.lock
+++ b/tool/bundler/standard_gems.rb.lock
@@ -50,6 +50,7 @@ GEM
unicode-display_width (2.0.0)
PLATFORMS
+ arm64-darwin-20
universal-java-11
x86_64-linux
diff --git a/tool/ci_functions.sh b/tool/ci_functions.sh
new file mode 100644
index 0000000..7066bbe
--- /dev/null
+++ b/tool/ci_functions.sh
@@ -0,0 +1,29 @@
+# -*- BASH -*-
+# Manage functions used on a CI.
+# Run `. tool/ci_functions.sh` to use it.
+
+# Create options with patterns `-n !/name1/ -n !/name2/ ..` to exclude the test
+# method names by the method names `name1 name2 ..`.
+# See `ruby tool/test/runner.rb --help` `-n` option.
+function ci_to_excluded_test_opts {
+ local tests_str="${1}"
+ # Use the backward matching `!/name$/`, as the perfect matching doesn't work.
+ # https://bugs.ruby-lang.org/issues/16936
+ ruby <<EOF
+ opts = "${tests_str}".split.map { |test| "-n \!/#{test}\$$/" }
+ puts opts.join(' ')
+EOF
+ return 0
+}
+
+# Create options with patterns `-n name1 -n name2 ..` to include the test
+# method names by the method names `name1 name2 ..`.
+# See `ruby tool/test/runner.rb --help` `-n` option.
+function ci_to_included_test_opts {
+ local tests_str="${1}"
+ ruby <<EOF
+ opts = "${tests_str}".split.map { |test| "-n #{test}" }
+ puts opts.join(' ')
+EOF
+ return 0
+}
diff --git a/tool/enc-unicode.rb b/tool/enc-unicode.rb
index f64cecb..93f6e86 100755
--- a/tool/enc-unicode.rb
+++ b/tool/enc-unicode.rb
@@ -138,7 +138,7 @@ def parse_scripts(data, categories)
{:fn => 'DerivedCoreProperties.txt', :title => 'Derived Property'},
{:fn => 'Scripts.txt', :title => 'Script'},
{:fn => 'PropList.txt', :title => 'Binary Property'},
- {:fn => 'emoji-data.txt', :title => 'Emoji'}
+ {:fn => 'emoji/emoji-data.txt', :title => 'Emoji'}
]
current = nil
cps = []
@@ -305,13 +305,13 @@ def constantize_blockname(name)
end
def get_file(name)
- File.join(ARGV[name.start_with?("emoji-") ? 1 : 0], name)
+ File.join(ARGV[name.start_with?("emoji-[stz]") ? 1 : 0], name)
end
def data_foreach(name, &block)
fn = get_file(name)
warn "Reading #{name}"
- if /^emoji-/ =~ name
+ if /^emoji/ =~ name
sep = ""
pat = /^# #{Regexp.quote(File.basename(name))}.*^# Version: ([\d.]+)/m
type = :Emoji
diff --git a/tool/extlibs.rb b/tool/extlibs.rb
index 5e8628c..cd8e523 100755
--- a/tool/extlibs.rb
+++ b/tool/extlibs.rb
@@ -243,7 +243,7 @@ class ExtLibs
begin
extracted = do_command(mode, dest, url, cache_dir, chksums)
rescue => e
- warn e.inspect
+ warn e.full_message
success = false
end
url = chksums = nil
diff --git a/tool/lib/colorize.rb b/tool/lib/colorize.rb
index 6699aef..11b878d 100644
--- a/tool/lib/colorize.rb
+++ b/tool/lib/colorize.rb
@@ -8,7 +8,7 @@ class Colorize
@colors = @reset = nil
@color = (opts[:color] if opts)
if color or (color == nil && STDOUT.tty?)
- if (/\A\e\[.*m\z/ =~ IO.popen("tput smso", "r", :err => IO::NULL, &:read) rescue nil)
+ if (%w[smso so].any? {|attr| /\A\e\[.*m\z/ =~ IO.popen("tput #{attr}", "r", :err => IO::NULL, &:read)} rescue nil)
@beg = "\e["
colors = (colors = ENV['TEST_COLORS']) ? Hash[colors.scan(/(\w+)=([^:\n]*)/)] : {}
if opts and colors_file = opts[:colors_file]
diff --git a/tool/lib/test/unit/core_assertions.rb b/tool/lib/core_assertions.rb
index ff78c2b..c0c69e0 100644
--- a/tool/lib/test/unit/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -25,7 +25,7 @@ module Test
module CoreAssertions
if defined?(MiniTest)
- require_relative '../../envutil'
+ require_relative 'envutil'
# for ruby core testing
include MiniTest::Assertions
@@ -718,6 +718,16 @@ eom
end
end
+ def assert_all?(obj, m = nil, &blk)
+ failed = []
+ obj.each do |*a, &b|
+ unless blk.call(*a, &b)
+ failed << (a.size > 1 ? a : a[0])
+ end
+ end
+ assert(failed.empty?, message(m) {failed.pretty_inspect})
+ end
+
def assert_all_assertions(msg = nil)
all = AllFailures.new
yield all
diff --git a/tool/lib/leakchecker.rb b/tool/lib/leakchecker.rb
index 4b01d57..1d45a3a 100644
--- a/tool/lib/leakchecker.rb
+++ b/tool/lib/leakchecker.rb
@@ -112,7 +112,7 @@ class LeakChecker
}
unless fd_leaked.empty?
unless @@try_lsof == false
- @@try_lsof |= system("lsof -p #$$", out: MiniTest::Unit.output)
+ @@try_lsof |= system(*%W[lsof -a -d #{fd_leaked.minmax.uniq.join("-")} -p #$$], out: MiniTest::Unit.output)
end
end
h.each {|fd, list|
diff --git a/tool/lib/minitest/autorun.rb b/tool/lib/minitest/autorun.rb
deleted file mode 100644
index 8440966..0000000
--- a/tool/lib/minitest/autorun.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-begin
- require 'rubygems'
- gem 'minitest'
-rescue Gem::LoadError
- # do nothing
-end
-
-require 'minitest/unit'
-require 'minitest/mock'
-
-MiniTest::Unit.autorun
diff --git a/tool/lib/minitest/benchmark.rb b/tool/lib/minitest/benchmark.rb
deleted file mode 100644
index 547b516..0000000
--- a/tool/lib/minitest/benchmark.rb
+++ /dev/null
@@ -1,418 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-require 'minitest/unit'
-
-class MiniTest::Unit # :nodoc:
- def run_benchmarks # :nodoc:
- _run_anything :benchmark
- end
-
- def benchmark_suite_header suite # :nodoc:
- "\n#{suite}\t#{suite.bench_range.join("\t")}"
- end
-
- class TestCase
- ##
- # Returns a set of ranges stepped exponentially from +min+ to
- # +max+ by powers of +base+. Eg:
- #
- # bench_exp(2, 16, 2) # => [2, 4, 8, 16]
-
- def self.bench_exp min, max, base = 10
- min = (Math.log10(min) / Math.log10(base)).to_i
- max = (Math.log10(max) / Math.log10(base)).to_i
-
- (min..max).map { |m| base ** m }.to_a
- end
-
- ##
- # Returns a set of ranges stepped linearly from +min+ to +max+ by
- # +step+. Eg:
- #
- # bench_linear(20, 40, 10) # => [20, 30, 40]
-
- def self.bench_linear min, max, step = 10
- (min..max).step(step).to_a
- rescue LocalJumpError # 1.8.6
- r = []; (min..max).step(step) { |n| r << n }; r
- end
-
- ##
- # Returns the benchmark methods (methods that start with bench_)
- # for that class.
-
- def self.benchmark_methods # :nodoc:
- public_instance_methods(true).grep(/^bench_/).map { |m| m.to_s }.sort
- end
-
- ##
- # Returns all test suites that have benchmark methods.
-
- def self.benchmark_suites
- TestCase.test_suites.reject { |s| s.benchmark_methods.empty? }
- end
-
- ##
- # Specifies the ranges used for benchmarking for that class.
- # Defaults to exponential growth from 1 to 10k by powers of 10.
- # Override if you need different ranges for your benchmarks.
- #
- # See also: ::bench_exp and ::bench_linear.
-
- def self.bench_range
- bench_exp 1, 10_000
- end
-
- ##
- # Runs the given +work+, gathering the times of each run. Range
- # and times are then passed to a given +validation+ proc. Outputs
- # the benchmark name and times in tab-separated format, making it
- # easy to paste into a spreadsheet for graphing or further
- # analysis.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # validation = proc { |x, y| ... }
- # assert_performance validation do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def assert_performance validation, &work
- range = self.class.bench_range
-
- io.print "#{__name__}"
-
- times = []
-
- range.each do |x|
- GC.start
- t0 = Time.now
- instance_exec(x, &work)
- t = Time.now - t0
-
- io.print "\t%9.6f" % t
- times << t
- end
- io.puts
-
- validation[range, times]
- end
-
- ##
- # Runs the given +work+ and asserts that the times gathered fit to
- # match a constant rate (eg, linear slope == 0) within a given
- # +threshold+. Note: because we're testing for a slope of 0, R^2
- # is not a good determining factor for the fit, so the threshold
- # is applied against the slope itself. As such, you probably want
- # to tighten it from the default.
- #
- # See http://www.graphpad.com/curvefit/goodness_of_fit.htm for
- # more details.
- #
- # Fit is calculated by #fit_linear.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # assert_performance_constant 0.9999 do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def assert_performance_constant threshold = 0.99, &work
- validation = proc do |range, times|
- a, b, rr = fit_linear range, times
- assert_in_delta 0, b, 1 - threshold
- [a, b, rr]
- end
-
- assert_performance validation, &work
- end
-
- ##
- # Runs the given +work+ and asserts that the times gathered fit to
- # match a exponential curve within a given error +threshold+.
- #
- # Fit is calculated by #fit_exponential.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # assert_performance_exponential 0.9999 do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def assert_performance_exponential threshold = 0.99, &work
- assert_performance validation_for_fit(:exponential, threshold), &work
- end
-
- ##
- # Runs the given +work+ and asserts that the times gathered fit to
- # match a logarithmic curve within a given error +threshold+.
- #
- # Fit is calculated by #fit_logarithmic.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # assert_performance_logarithmic 0.9999 do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def assert_performance_logarithmic threshold = 0.99, &work
- assert_performance validation_for_fit(:logarithmic, threshold), &work
- end
-
- ##
- # Runs the given +work+ and asserts that the times gathered fit to
- # match a straight line within a given error +threshold+.
- #
- # Fit is calculated by #fit_linear.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # assert_performance_linear 0.9999 do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def assert_performance_linear threshold = 0.99, &work
- assert_performance validation_for_fit(:linear, threshold), &work
- end
-
- ##
- # Runs the given +work+ and asserts that the times gathered curve
- # fit to match a power curve within a given error +threshold+.
- #
- # Fit is calculated by #fit_power.
- #
- # Ranges are specified by ::bench_range.
- #
- # Eg:
- #
- # def bench_algorithm
- # assert_performance_power 0.9999 do |x|
- # @obj.algorithm
- # end
- # end
-
- def assert_performance_power threshold = 0.99, &work
- assert_performance validation_for_fit(:power, threshold), &work
- end
-
- ##
- # Takes an array of x/y pairs and calculates the general R^2 value.
- #
- # See: https://en.wikipedia.org/wiki/Coefficient_of_determination
-
- def fit_error xys
- y_bar = sigma(xys) { |x, y| y } / xys.size.to_f
- ss_tot = sigma(xys) { |x, y| (y - y_bar) ** 2 }
- ss_err = sigma(xys) { |x, y| (yield(x) - y) ** 2 }
-
- 1 - (ss_err / ss_tot)
- end
-
- ##
- # To fit a functional form: y = ae^(bx).
- #
- # Takes x and y values and returns [a, b, r^2].
- #
- # See: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
-
- def fit_exponential xs, ys
- n = xs.size
- xys = xs.zip(ys)
- sxlny = sigma(xys) { |x,y| x * Math.log(y) }
- slny = sigma(xys) { |x,y| Math.log(y) }
- sx2 = sigma(xys) { |x,y| x * x }
- sx = sigma xs
-
- c = n * sx2 - sx ** 2
- a = (slny * sx2 - sx * sxlny) / c
- b = ( n * sxlny - sx * slny ) / c
-
- return Math.exp(a), b, fit_error(xys) { |x| Math.exp(a + b * x) }
- end
-
- ##
- # To fit a functional form: y = a + b*ln(x).
- #
- # Takes x and y values and returns [a, b, r^2].
- #
- # See: http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
-
- def fit_logarithmic xs, ys
- n = xs.size
- xys = xs.zip(ys)
- slnx2 = sigma(xys) { |x,y| Math.log(x) ** 2 }
- slnx = sigma(xys) { |x,y| Math.log(x) }
- sylnx = sigma(xys) { |x,y| y * Math.log(x) }
- sy = sigma(xys) { |x,y| y }
-
- c = n * slnx2 - slnx ** 2
- b = ( n * sylnx - sy * slnx ) / c
- a = (sy - b * slnx) / n
-
- return a, b, fit_error(xys) { |x| a + b * Math.log(x) }
- end
-
-
- ##
- # Fits the functional form: a + bx.
- #
- # Takes x and y values and returns [a, b, r^2].
- #
- # See: http://mathworld.wolfram.com/LeastSquaresFitting.html
-
- def fit_linear xs, ys
- n = xs.size
- xys = xs.zip(ys)
- sx = sigma xs
- sy = sigma ys
- sx2 = sigma(xs) { |x| x ** 2 }
- sxy = sigma(xys) { |x,y| x * y }
-
- c = n * sx2 - sx**2
- a = (sy * sx2 - sx * sxy) / c
- b = ( n * sxy - sx * sy ) / c
-
- return a, b, fit_error(xys) { |x| a + b * x }
- end
-
- ##
- # To fit a functional form: y = ax^b.
- #
- # Takes x and y values and returns [a, b, r^2].
- #
- # See: http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
-
- def fit_power xs, ys
- n = xs.size
- xys = xs.zip(ys)
- slnxlny = sigma(xys) { |x, y| Math.log(x) * Math.log(y) }
- slnx = sigma(xs) { |x | Math.log(x) }
- slny = sigma(ys) { | y| Math.log(y) }
- slnx2 = sigma(xs) { |x | Math.log(x) ** 2 }
-
- b = (n * slnxlny - slnx * slny) / (n * slnx2 - slnx ** 2);
- a = (slny - b * slnx) / n
-
- return Math.exp(a), b, fit_error(xys) { |x| (Math.exp(a) * (x ** b)) }
- end
-
- ##
- # Enumerates over +enum+ mapping +block+ if given, returning the
- # sum of the result. Eg:
- #
- # sigma([1, 2, 3]) # => 1 + 2 + 3 => 7
- # sigma([1, 2, 3]) { |n| n ** 2 } # => 1 + 4 + 9 => 14
-
- def sigma enum, &block
- enum = enum.map(&block) if block
- enum.inject { |sum, n| sum + n }
- end
-
- ##
- # Returns a proc that calls the specified fit method and asserts
- # that the error is within a tolerable threshold.
-
- def validation_for_fit msg, threshold
- proc do |range, times|
- a, b, rr = send "fit_#{msg}", range, times
- assert_operator rr, :>=, threshold
- [a, b, rr]
- end
- end
- end
-end
-
-class MiniTest::Spec
- ##
- # This is used to define a new benchmark method. You usually don't
- # use this directly and is intended for those needing to write new
- # performance curve fits (eg: you need a specific polynomial fit).
- #
- # See ::bench_performance_linear for an example of how to use this.
-
- def self.bench name, &block
- define_method "bench_#{name.gsub(/\W+/, '_')}", &block
- end
-
- ##
- # Specifies the ranges used for benchmarking for that class.
- #
- # bench_range do
- # bench_exp(2, 16, 2)
- # end
- #
- # See Unit::TestCase.bench_range for more details.
-
- def self.bench_range &block
- return super unless block
-
- meta = (class << self; self; end)
- meta.send :define_method, "bench_range", &block
- end
-
- ##
- # Create a benchmark that verifies that the performance is linear.
- #
- # describe "my class" do
- # bench_performance_linear "fast_algorithm", 0.9999 do |n|
- # @obj.fast_algorithm(n)
- # end
- # end
-
- def self.bench_performance_linear name, threshold = 0.99, &work
- bench name do
- assert_performance_linear threshold, &work
- end
- end
-
- ##
- # Create a benchmark that verifies that the performance is constant.
- #
- # describe "my class" do
- # bench_performance_constant "zoom_algorithm!" do |n|
- # @obj.zoom_algorithm!(n)
- # end
- # end
-
- def self.bench_performance_constant name, threshold = 0.99, &work
- bench name do
- assert_performance_constant threshold, &work
- end
- end
-
- ##
- # Create a benchmark that verifies that the performance is exponential.
- #
- # describe "my class" do
- # bench_performance_exponential "algorithm" do |n|
- # @obj.algorithm(n)
- # end
- # end
-
- def self.bench_performance_exponential name, threshold = 0.99, &work
- bench name do
- assert_performance_exponential threshold, &work
- end
- end
-end
diff --git a/tool/lib/minitest/mock.rb b/tool/lib/minitest/mock.rb
deleted file mode 100644
index 224b06c..0000000
--- a/tool/lib/minitest/mock.rb
+++ /dev/null
@@ -1,196 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: true
-
-class MockExpectationError < StandardError; end # :nodoc:
-
-##
-# A simple and clean mock object framework.
-
-module MiniTest # :nodoc:
-
- ##
- # All mock objects are an instance of Mock
-
- class Mock
- alias :__respond_to? :respond_to?
-
- skip_methods = %w(object_id respond_to_missing? inspect === to_s)
-
- instance_methods.each do |m|
- undef_method m unless skip_methods.include?(m.to_s) || m =~ /^__/
- end
-
- def initialize # :nodoc:
- @expected_calls = Hash.new { |calls, name| calls[name] = [] }
- @actual_calls = Hash.new { |calls, name| calls[name] = [] }
- end
-
- ##
- # Expect that method +name+ is called, optionally with +args+ or a
- # +blk+, and returns +retval+.
- #
- # @mock.expect(:meaning_of_life, 42)
- # @mock.meaning_of_life # => 42
- #
- # @mock.expect(:do_something_with, true, [some_obj, true])
- # @mock.do_something_with(some_obj, true) # => true
- #
- # @mock.expect(:do_something_else, true) do |a1, a2|
- # a1 == "buggs" && a2 == :bunny
- # end
- #
- # +args+ is compared to the expected args using case equality (ie, the
- # '===' operator), allowing for less specific expectations.
- #
- # @mock.expect(:uses_any_string, true, [String])
- # @mock.uses_any_string("foo") # => true
- # @mock.verify # => true
- #
- # @mock.expect(:uses_one_string, true, ["foo"]
- # @mock.uses_one_string("bar") # => true
- # @mock.verify # => raises MockExpectationError
-
- def expect(name, retval, args=[], &blk)
- if block_given?
- raise ArgumentError, "args ignored when block given" unless args.empty?
- @expected_calls[name] << { :retval => retval, :block => blk }
- else
- raise ArgumentError, "args must be an array" unless Array === args
- @expected_calls[name] << { :retval => retval, :args => args }
- end
- self
- end
-
- def __call name, data # :nodoc:
- case data
- when Hash then
- "#{name}(#{data[:args].inspect[1..-2]}) => #{data[:retval].inspect}"
- else
- data.map { |d| __call name, d }.join ", "
- end
- end
-
- ##
- # Verify that all methods were called as expected. Raises
- # +MockExpectationError+ if the mock object was not called as
- # expected.
-
- def verify
- @expected_calls.each do |name, calls|
- calls.each do |expected|
- msg1 = "expected #{__call name, expected}"
- msg2 = "#{msg1}, got [#{__call name, @actual_calls[name]}]"
-
- raise MockExpectationError, msg2 if
- @actual_calls.has_key?(name) and
- not @actual_calls[name].include?(expected)
-
- raise MockExpectationError, msg1 unless
- @actual_calls.has_key?(name) and
- @actual_calls[name].include?(expected)
- end
- end
- true
- end
-
- def method_missing(sym, *args) # :nodoc:
- unless @expected_calls.has_key?(sym) then
- raise NoMethodError, "unmocked method %p, expected one of %p" %
- [sym, @expected_calls.keys.sort_by(&:to_s)]
- end
-
- index = @actual_calls[sym].length
- expected_call = @expected_calls[sym][index]
-
- unless expected_call then
- raise MockExpectationError, "No more expects available for %p: %p" %
- [sym, args]
- end
-
- expected_args, retval, val_block =
- expected_call.values_at(:args, :retval, :block)
-
- if val_block then
- raise MockExpectationError, "mocked method %p failed block w/ %p" %
- [sym, args] unless val_block.call(args)
-
- # keep "verify" happy
- @actual_calls[sym] << expected_call
- return retval
- end
-
- if expected_args.size != args.size then
- raise ArgumentError, "mocked method %p expects %d arguments, got %d" %
- [sym, expected_args.size, args.size]
- end
-
- fully_matched = expected_args.zip(args).all? { |mod, a|
- mod === a or mod == a
- }
-
- unless fully_matched then
- raise MockExpectationError, "mocked method %p called with unexpected arguments %p" %
- [sym, args]
- end
-
- @actual_calls[sym] << {
- :retval => retval,
- :args => expected_args.zip(args).map { |mod, a| mod === a ? mod : a }
- }
-
- retval
- end
-
- def respond_to?(sym, include_private = false) # :nodoc:
- return true if @expected_calls.has_key?(sym.to_sym)
- return __respond_to?(sym, include_private)
- end
- end
-end
-
-class Object # :nodoc:
-
- ##
- # Add a temporary stubbed method replacing +name+ for the duration
- # of the +block+. If +val_or_callable+ responds to #call, then it
- # returns the result of calling it, otherwise returns the value
- # as-is. Cleans up the stub at the end of the +block+. The method
- # +name+ must exist before stubbing.
- #
- # def test_stale_eh
- # obj_under_test = Something.new
- # refute obj_under_test.stale?
- #
- # Time.stub :now, Time.at(0) do
- # assert obj_under_test.stale?
- # end
- # end
-
- def stub name, val_or_callable, &block
- new_name = "__minitest_stub__#{name}"
-
- metaclass = class << self; self; end
-
- if respond_to? name and not methods.map(&:to_s).include? name.to_s then
- metaclass.send :define_method, name do |*args|
- super(*args)
- end
- end
-
- metaclass.send :alias_method, new_name, name
-
- metaclass.send :define_method, name do |*args|
- if val_or_callable.respond_to? :call then
- val_or_callable.call(*args)
- else
- val_or_callable
- end
- end
-
- yield self
- ensure
- metaclass.send :undef_method, name
- metaclass.send :alias_method, name, new_name
- metaclass.send :undef_method, new_name
- end
-end
diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb
index 6097dc3..2cda29a 100644
--- a/tool/lib/minitest/unit.rb
+++ b/tool/lib/minitest/unit.rb
@@ -961,37 +961,37 @@ module MiniTest
}
leakchecker = LeakChecker.new
+ if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
+ require "objspace"
+ trace = true
+ end
- continuation = proc do
- assertions = filtered_test_methods.map { |method|
- inst = suite.new method
- inst._assertions = 0
-
- print "#{suite}##{method} = " if @verbose
-
- start_time = Time.now if @verbose
- result = inst.run self
+ assertions = filtered_test_methods.map { |method|
+ inst = suite.new method
+ inst._assertions = 0
- print "%.2f s = " % (Time.now - start_time) if @verbose
- print result
- puts if @verbose
- $stdout.flush
+ print "#{suite}##{method} = " if @verbose
- unless defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # compiler process is wrongly considered as leak
- leakchecker.check("#{inst.class}\##{inst.__name__}")
+ start_time = Time.now if @verbose
+ result =
+ if trace
+ ObjectSpace.trace_object_allocations {inst.run self}
+ else
+ inst.run self
end
- inst._assertions
- }
- return assertions.size, assertions.inject(0) { |sum, n| sum + n }
- end
+ print "%.2f s = " % (Time.now - start_time) if @verbose
+ print result
+ puts if @verbose
+ $stdout.flush
- if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
- require "objspace"
- ObjectSpace.trace_object_allocations(&continuation)
- else
- continuation.call
- end
+ unless defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # compiler process is wrongly considered as leak
+ leakchecker.check("#{inst.class}\##{inst.__name__}")
+ end
+
+ inst._assertions
+ }
+ return assertions.size, assertions.inject(0) { |sum, n| sum + n }
end
##
@@ -1419,7 +1419,7 @@ module MiniTest
end
suites = suites.sort_by do |suite|
crc32 = 0xffffffff
- (suite.name + salt).each_byte do |data|
+ "#{suite.name}#{salt}".each_byte do |data|
crc32 = crc_tbl[(crc32 ^ data) & 0xff] ^ (crc32 >> 8)
end
crc32 ^ 0xffffffff
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index f4ee194..391c065 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -1,9 +1,6 @@
# frozen_string_literal: true
-begin
- gem 'minitest', '< 5.0.0' if defined? Gem
-rescue Gem::LoadError
-end
-require 'minitest/unit'
+
+require_relative '../minitest/unit'
require 'test/unit/assertions'
require_relative '../envutil'
require_relative '../colorize'
@@ -65,13 +62,16 @@ module Test
non_options(args, options)
@run_options = orig_args
+ order = options[:test_order]
if seed = options[:seed]
+ order ||= :random
srand(seed)
else
seed = options[:seed] = srand % 100_000
srand(seed)
orig_args.unshift "--seed=#{seed}"
end
+ MiniTest::Unit::TestCase.test_order = order if order
@help = "\n" + orig_args.map { |s|
" " + (s =~ /[\s|&<>$()]/ ? s.inspect : s)
@@ -103,7 +103,7 @@ module Test
end
opts.on '--test-order=random|alpha|sorted|nosort', [:random, :alpha, :sorted, :nosort] do |a|
- MiniTest::Unit::TestCase.test_order = a
+ options[:test_order] = a
end
end
diff --git a/tool/lib/test/unit/assertions.rb b/tool/lib/test/unit/assertions.rb
index 14442c0..c61f296 100644
--- a/tool/lib/test/unit/assertions.rb
+++ b/tool/lib/test/unit/assertions.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'minitest/unit'
-require 'test/unit/core_assertions'
+require_relative '../../core_assertions'
require 'pp'
module Test
@@ -215,16 +215,6 @@ EOT
alias assert_include assert_includes
alias assert_not_include assert_not_includes
- def assert_all?(obj, m = nil, &blk)
- failed = []
- obj.each do |*a, &b|
- unless blk.call(*a, &b)
- failed << (a.size > 1 ? a : a[0])
- end
- end
- assert(failed.empty?, message(m) {failed.pretty_inspect})
- end
-
def assert_not_all?(obj, m = nil, &blk)
failed = []
obj.each do |*a, &b|
diff --git a/tool/m4/_colorize_result_prepare.m4 b/tool/m4/_colorize_result_prepare.m4
index c8478bd..8439acf 100644
--- a/tool/m4/_colorize_result_prepare.m4
+++ b/tool/m4/_colorize_result_prepare.m4
@@ -9,6 +9,7 @@ AC_DEFUN([_COLORIZE_RESULT_PREPARE], [
[configure_tty=0])])
AS_IF([test $configure_tty -eq 1], [
msg_begin="`tput smso 2>/dev/null`"
+ AS_IF([test -z "$msg_begin"], [msg_begin="`tput so 2>/dev/null`"])
AS_CASE(["$msg_begin"], ['@<:@'*m],
[msg_begin="`echo "$msg_begin" | sed ['s/[0-9]*m$//']`"
msg_checking="${msg_begin}33m"
diff --git a/tool/make-snapshot b/tool/make-snapshot
index b03bb93..589d742 100755
--- a/tool/make-snapshot
+++ b/tool/make-snapshot
@@ -1,5 +1,8 @@
#!/usr/bin/ruby -s
# -*- coding: us-ascii -*-
+require 'rubygems'
+require 'rubygems/package'
+require 'rubygems/package/tar_writer'
require 'uri'
require 'digest/sha1'
require 'digest/sha2'
@@ -158,9 +161,6 @@ at_exit {
} unless $keep_temp
def tar_create(tarball, dir)
- require 'rubygems'
- require 'rubygems/package'
- require 'rubygems/package/tar_writer'
header = Gem::Package::TarHeader
dir_type = "5"
uname = gname = "ruby"
diff --git a/tool/mjit_tabs.rb b/tool/mjit_tabs.rb
index 8b91af2..edcbf6c 100644
--- a/tool/mjit_tabs.rb
+++ b/tool/mjit_tabs.rb
@@ -20,6 +20,8 @@ SKIPPED_FILES = %w[
vm_debug.h
vm_exec.h
vm_opts.h
+ vm_sync.h
+ vm_sync.c
]
srcdir = File.expand_path('..', __dir__)
@@ -32,14 +34,14 @@ mjit_tabs, *command = ARGV
targets.each do |target|
next if mjit_tabs != 'false'
unless File.writable?(target)
- puts "tool/mjit_without_tabs.rb: Skipping #{target.dump} as it's not writable."
+ puts "tool/mjit_tabs.rb: Skipping #{target.dump} as it's not writable."
next
end
source = File.read(target)
begin
expanded = source.gsub(/^\t+/) { |tab| ' ' * 8 * tab.length }
rescue ArgumentError # invalid byte sequence in UTF-8 (Travis, RubyCI)
- puts "tool/mjit_without_tabs.rb: Skipping #{target.dump} as the encoding is #{source.encoding}."
+ puts "tool/mjit_tabs.rb: Skipping #{target.dump} as the encoding is #{source.encoding}."
next
end
@@ -47,7 +49,7 @@ targets.each do |target|
mtimes[target] = File.mtime(target)
if sources[target] == expanded
- puts "#{target.dump} has no hard tab indentation. This should be ignored in tool/mjit_without_tabs.rb."
+ puts "#{target.dump} has no hard tab indentation. This should be ignored in tool/mjit_tabs.rb."
end
File.write(target, expanded)
FileUtils.touch(target, mtime: mtimes[target])
diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index 141b670..305287c 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -22,7 +22,6 @@ require 'fileutils'
require 'shellwords'
require 'optparse'
require 'optparse/shellwords'
-require 'pathname'
require 'rubygems'
begin
require "zlib"
@@ -56,6 +55,7 @@ def parse_args(argv = ARGV)
File.exist?("rubystub.exe") ? 'exe' : 'cmd'
end)
mflags = []
+ gnumake = false
opt = OptionParser.new
opt.on('-n', '--dry-run') {$dryrun = true}
opt.on('--dest-dir=DIR') {|dir| $destdir = dir}
@@ -91,6 +91,7 @@ def parse_args(argv = ARGV)
opt.on('--html-output [DIR]') {|dir| $htmldir = dir}
opt.on('--cmd-type=TYPE', %w[cmd plain]) {|cmd| $cmdtype = (cmd unless cmd == 'plain')}
opt.on('--[no-]strip') {|strip| $strip = strip}
+ opt.on('--gnumake') {gnumake = true}
opt.order!(argv) do |v|
case v
@@ -113,6 +114,7 @@ def parse_args(argv = ARGV)
$make, *rest = Shellwords.shellwords($make)
$mflags.unshift(*rest) unless rest.empty?
$mflags.unshift(*mflags)
+ $mflags.reject! {|v| /\A-[OW]/ =~ v} if gnumake
def $mflags.set?(flag)
grep(/\A-(?!-).*#{flag.chr}/i) { return true }
@@ -679,6 +681,28 @@ install?(:dbg, :nodefault) do
end
module RbInstall
+ def self.no_write(options = nil)
+ u = File.umask(0022)
+ if $dryrun
+ fu = ::Object.class_eval do
+ fu = remove_const(:FileUtils)
+ const_set(:FileUtils, fu::NoWrite)
+ fu
+ end
+ dir_mode = options.delete(:dir_mode) if options
+ end
+ yield
+ ensure
+ options[:dir_mode] = dir_mode if dir_mode
+ if fu
+ ::Object.class_eval do
+ remove_const(:FileUtils)
+ const_set(:FileUtils, fu)
+ end
+ end
+ File.umask(u)
+ end
+
module Specs
class FileCollector
def initialize(gemspec)
@@ -705,7 +729,7 @@ module RbInstall
base = @base_dir
prefix = base.sub(/lib\/.*?\z/, "")
# for lib/net/net-smtp.gemspec
- if m = Pathname.new(@gemspec).basename(".gemspec").to_s.match(/.*\-(.*)\z/)
+ if m = File.basename(@gemspec, ".gemspec").match(/.*\-(.*)\z/)
base = "#{@base_dir}/#{m[1]}" unless remove_prefix(prefix, @base_dir).include?(m[1])
end
end
@@ -718,7 +742,7 @@ module RbInstall
[File.basename(@gemspec, '.gemspec') + '.rb']
end
- case Pathname.new(@gemspec).basename(".gemspec").to_s
+ case File.basename(@gemspec, ".gemspec")
when "net-http"
files << "lib/net/https.rb"
when "optparse"
@@ -846,25 +870,7 @@ module RbInstall
class GemInstaller
def install
spec.post_install_message = nil
- u = File.umask(0022)
- if $dryrun
- fu = ::Object.class_eval do
- fu = remove_const(:FileUtils)
- const_set(:FileUtils, fu::NoWrite)
- fu
- end
- dir_mode = options.delete(:dir_mode)
- end
- super
- ensure
- options[:dir_mode] = dir_mode if dir_mode
- if fu
- ::Object.class_eval do
- remove_const(:FileUtils)
- const_set(:FileUtils, fu)
- end
- end
- File.umask(u)
+ RbInstall.no_write(options) {super}
end
def generate_bin_script(filename, bindir)
@@ -927,7 +933,9 @@ def install_default_gem(dir, srcdir, bindir)
gem_dir = Gem.default_dir
install_dir = with_destdir(gem_dir)
prepare "default gems from #{dir}", gem_dir
- makedirs(Gem.ensure_default_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)})
+ RbInstall.no_write do
+ makedirs(Gem.ensure_default_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)})
+ end
options = {
:install_dir => with_destdir(gem_dir),
@@ -971,7 +979,10 @@ install?(:ext, :comm, :gem, :'bundled-gems') do
gem_dir = Gem.default_dir
install_dir = with_destdir(gem_dir)
prepare "bundled gems", gem_dir
- makedirs(Gem.ensure_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)})
+ RbInstall.no_write do
+ makedirs(Gem.ensure_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)})
+ end
+
installed_gems = {}
options = {
:install_dir => install_dir,
diff --git a/tool/ruby_vm/views/_mjit_compile_send.erb b/tool/ruby_vm/views/_mjit_compile_send.erb
index d1540f6..28e316a 100644
--- a/tool/ruby_vm/views/_mjit_compile_send.erb
+++ b/tool/ruby_vm/views/_mjit_compile_send.erb
@@ -13,7 +13,9 @@
MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>];
% end
% # compiler: Use captured cc to avoid race condition
- const struct rb_callcache *captured_cc = captured_cc_entries(status)[call_data_index(cd, body)];
+ size_t cd_index = call_data_index(cd, body);
+ const struct rb_callcache **cc_entries = captured_cc_entries(status);
+ const struct rb_callcache *captured_cc = cc_entries[cd_index];
%
% # compiler: Inline send insn where some supported fastpath is used.
const rb_iseq_t *iseq = NULL;
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 8afa574..9a13f4d 100644
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -16,8 +16,6 @@ REPOSITORIES = {
"io-nonblock": 'ruby/io-nonblock',
"io-wait": 'ruby/io-wait',
csv: 'ruby/csv',
- dbm: 'ruby/dbm',
- gdbm: 'ruby/gdbm',
etc: 'ruby/etc',
date: 'ruby/date',
zlib: 'ruby/zlib',
@@ -25,11 +23,8 @@ REPOSITORIES = {
strscan: 'ruby/strscan',
ipaddr: 'ruby/ipaddr',
logger: 'ruby/logger',
- prime: 'ruby/prime',
- matrix: 'ruby/matrix',
ostruct: 'ruby/ostruct',
irb: 'ruby/irb',
- tracer: 'ruby/tracer',
forwardable: "ruby/forwardable",
mutex_m: "ruby/mutex_m",
racc: "ruby/racc",
@@ -39,8 +34,6 @@ REPOSITORIES = {
pstore: "ruby/pstore",
delegate: "ruby/delegate",
benchmark: "ruby/benchmark",
- "net-pop": "ruby/net-pop",
- "net-smtp": "ruby/net-smtp",
cgi: "ruby/cgi",
readline: "ruby/readline",
"readline-ext": "ruby/readline-ext",
@@ -55,8 +48,6 @@ REPOSITORIES = {
tmpdir: "ruby/tmpdir",
English: "ruby/English",
"net-protocol": "ruby/net-protocol",
- "net-imap": "ruby/net-imap",
- "net-ftp": "ruby/net-ftp",
"net-http": "ruby/net-http",
bigdecimal: "ruby/bigdecimal",
optparse: "ruby/optparse",
@@ -80,6 +71,7 @@ REPOSITORIES = {
drb: "ruby/drb",
pathname: "ruby/pathname",
digest: "ruby/digest",
+ error_highlight: "ruby/error_highlight",
}
def sync_default_gems(gem)
@@ -98,7 +90,7 @@ def sync_default_gems(gem)
cp_r(Dir.glob("#{upstream}/bundler/exe/bundle*"), "libexec")
gemspec_content = File.readlines("#{upstream}/bundler/bundler.gemspec").map do |line|
- next if line =~ /extra_rdoc_files/
+ next if line =~ /LICENSE\.md/
line.gsub("bundler.gemspec", "lib/bundler/bundler.gemspec").gsub('"exe"', '"libexec"')
end.compact.join
@@ -192,18 +184,6 @@ def sync_default_gems(gem)
cp_r("#{upstream}/test/io/wait", "test/io")
cp_r("#{upstream}/io-wait.gemspec", "ext/io/wait")
`git checkout ext/io/wait/depend`
- when "dbm"
- rm_rf(%w[ext/dbm test/dbm])
- cp_r("#{upstream}/ext/dbm", "ext")
- cp_r("#{upstream}/test/dbm", "test")
- cp_r("#{upstream}/dbm.gemspec", "ext/dbm")
- `git checkout ext/dbm/depend`
- when "gdbm"
- rm_rf(%w[ext/gdbm test/gdbm])
- cp_r("#{upstream}/ext/gdbm", "ext")
- cp_r("#{upstream}/test/gdbm", "test")
- cp_r("#{upstream}/gdbm.gemspec", "ext/gdbm")
- `git checkout ext/gdbm/depend ext/gdbm/README`
when "etc"
rm_rf(%w[ext/etc test/etc])
cp_r("#{upstream}/ext/etc", "ext")
@@ -262,32 +242,11 @@ def sync_default_gems(gem)
cp_r("#{upstream}/openssl.gemspec", "ext/openssl")
cp_r("#{upstream}/History.md", "ext/openssl")
`git checkout ext/openssl/depend`
- when "net-pop"
- rm_rf(%w[lib/net/pop.rb lib/net/net-pop.gemspec test/net/pop])
- cp_r("#{upstream}/lib/net/pop.rb", "lib/net")
- cp_r("#{upstream}/test/net/pop", "test/net")
- cp_r("#{upstream}/net-pop.gemspec", "lib/net")
- when "net-smtp"
- rm_rf(%w[lib/net/smtp.rb lib/net/net-smtp.gemspec test/net/smtp])
- cp_r("#{upstream}/lib/net/smtp.rb", "lib/net")
- cp_r("#{upstream}/test/net/smtp", "test/net")
- cp_r("#{upstream}/net-smtp.gemspec", "lib/net")
when "net-protocol"
rm_rf(%w[lib/net/protocol.rb lib/net/net-protocol.gemspec test/net/protocol])
cp_r("#{upstream}/lib/net/protocol.rb", "lib/net")
cp_r("#{upstream}/test/net/protocol", "test/net")
cp_r("#{upstream}/net-protocol.gemspec", "lib/net")
- when "net-imap"
- rm_rf(%w[lib/net/imap.rb lib/net/imap test/net/imap])
- cp_r("#{upstream}/lib/net/imap.rb", "lib/net")
- cp_r("#{upstream}/lib/net/imap", "lib/net")
- cp_r("#{upstream}/test/net/imap", "test/net")
- cp_r("#{upstream}/net-imap.gemspec", "lib/net/imap")
- when "net-ftp"
- rm_rf(%w[lib/net/ftp.rb lib/net/net-ftp.gemspec test/net/ftp])
- cp_r("#{upstream}/lib/net/ftp.rb", "lib/net")
- cp_r("#{upstream}/test/net/ftp", "test/net")
- cp_r("#{upstream}/net-ftp.gemspec", "lib/net")
when "net-http"
rm_rf(%w[lib/net/http.rb lib/net/http test/net/http])
cp_r("#{upstream}/lib/net/http.rb", "lib/net")
@@ -345,7 +304,7 @@ def sync_default_gems(gem)
when "digest"
rm_rf(%w[ext/digest test/digest])
cp_r("#{upstream}/ext/digest", "ext")
- mkdir_p("#{upstream}/ext/digest/lib")
+ mkdir_p("ext/digest/lib")
cp_r("#{upstream}/lib/digest.rb", "ext/digest/lib/")
cp_r("#{upstream}/test/digest", "test")
cp_r("#{upstream}/digest.gemspec", "ext/digest")
@@ -353,6 +312,11 @@ def sync_default_gems(gem)
when "set"
sync_lib gem, upstream
cp_r("#{upstream}/test", ".")
+ when "error_highlight"
+ rm_rf(%w[lib/error_highlight lib/error_highlight.rb test/error_highlight])
+ cp_r(Dir.glob("#{upstream}/lib/error_highlight*"), "lib")
+ cp_r("#{upstream}/error_highlight.gemspec", "lib/error_highlight")
+ cp_r("#{upstream}/test", "test/error_highlight")
else
sync_lib gem, upstream
end
@@ -369,8 +333,12 @@ IGNORE_FILE_PATTERN =
def message_filter(repo, sha)
log = STDIN.read
- print "[#{repo}] ", log.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
- "\n\n" "https://github.com/#{repo}/commit/#{sha[0,10]}\n"
+ log.delete!("\r")
+ url = "https://github.com/#{repo}"
+ print "[#{repo}] ", log.gsub(/fix +#\d+|\(#\d+\)/i) {
+ $&.sub(/#/) {"#{url}/pull/"}
+ }.sub(/\s*(?=(?i:\nCo-authored-by:.*)*\Z)/) {
+ "\n\n" "#{url}/commit/#{sha[0,10]}\n"
}
end
diff --git a/tool/test-bundled-gems.rb b/tool/test-bundled-gems.rb
index b9a1e55..53c88c1 100644
--- a/tool/test-bundled-gems.rb
+++ b/tool/test-bundled-gems.rb
@@ -27,6 +27,12 @@ File.foreach("#{gem_dir}/bundled_gems") do |line|
first_timeout *= 3
end
+ if gem == "minitest"
+ # Tentatively exclude some tests that conflict with error_highlight
+ # https://github.com/seattlerb/minitest/pull/880
+ test_command << " 'TESTOPTS=-e /test_stub_value_block_args_5__break_if_not_passed|test_no_method_error_on_unexpected_methods/'"
+ end
+
puts test_command
pid = Process.spawn(test_command, "#{/mingw|mswin/ =~ RUBY_PLATFORM ? 'new_' : ''}pgroup": true)
{nil => first_timeout, INT: 30, TERM: 10, KILL: nil}.each do |sig, sec|
diff --git a/tool/test/minitest/metametameta.rb b/tool/test/minitest/metametameta.rb
index a12717c..dbc422f 100644
--- a/tool/test/minitest/metametameta.rb
+++ b/tool/test/minitest/metametameta.rb
@@ -3,7 +3,6 @@
require 'tempfile'
require 'stringio'
-require 'minitest/autorun'
class MiniTest::Unit::TestCase
def clean s
diff --git a/tool/test/minitest/test_minitest_benchmark.rb b/tool/test/minitest/test_minitest_benchmark.rb
deleted file mode 100644
index a783e68..0000000
--- a/tool/test/minitest/test_minitest_benchmark.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: false
-
-require 'minitest/autorun'
-require 'minitest/benchmark'
-
-##
-# Used to verify data:
-# http://www.wolframalpha.com/examples/RegressionAnalysis.html
-
-class TestMiniTestBenchmark < MiniTest::Unit::TestCase
- def test_cls_bench_exp
- assert_equal [2, 4, 8, 16, 32], self.class.bench_exp(2, 32, 2)
- end
-
- def test_cls_bench_linear
- assert_equal [2, 4, 6, 8, 10], self.class.bench_linear(2, 10, 2)
- end
-
- def test_cls_benchmark_methods
- assert_equal [], self.class.benchmark_methods
-
- c = Class.new(MiniTest::Unit::TestCase) do
- def bench_blah
- end
- end
-
- assert_equal ["bench_blah"], c.benchmark_methods
- end
-
- def test_cls_bench_range
- assert_equal [1, 10, 100, 1_000, 10_000], self.class.bench_range
- end
-
- def test_fit_exponential_clean
- x = [1.0, 2.0, 3.0, 4.0, 5.0]
- y = x.map { |n| 1.1 * Math.exp(2.1 * n) }
-
- assert_fit :exponential, x, y, 1.0, 1.1, 2.1
- end
-
- def test_fit_exponential_noisy
- x = [1.0, 1.9, 2.6, 3.4, 5.0]
- y = [12, 10, 8.2, 6.9, 5.9]
-
- # verified with Numbers and R
- assert_fit :exponential, x, y, 0.95, 13.81148, -0.1820
- end
-
- def test_fit_logarithmic_clean
- x = [1.0, 2.0, 3.0, 4.0, 5.0]
- y = x.map { |n| 1.1 + 2.1 * Math.log(n) }
-
- assert_fit :logarithmic, x, y, 1.0, 1.1, 2.1
- end
-
- def test_fit_logarithmic_noisy
- x = [1.0, 2.0, 3.0, 4.0, 5.0]
- # Generated with
- # y = x.map { |n| jitter = 0.999 + 0.002 * rand; (Math.log(n) ) * jitter }
- y = [0.0, 0.6935, 1.0995, 1.3873, 1.6097]
-
- assert_fit :logarithmic, x, y, 0.95, 0, 1
- end
-
- def test_fit_constant_clean
- x = (1..5).to_a
- y = [5.0, 5.0, 5.0, 5.0, 5.0]
-
- assert_fit :linear, x, y, nil, 5.0, 0
- end
-
- def test_fit_constant_noisy
- x = (1..5).to_a
- y = [1.0, 1.2, 1.0, 0.8, 1.0]
-
- # verified in numbers and R
- assert_fit :linear, x, y, nil, 1.12, -0.04
- end
-
- def test_fit_linear_clean
- # y = m * x + b where m = 2.2, b = 3.1
- x = (1..5).to_a
- y = x.map { |n| 2.2 * n + 3.1 }
-
- assert_fit :linear, x, y, 1.0, 3.1, 2.2
- end
-
- def test_fit_linear_noisy
- x = [ 60, 61, 62, 63, 65]
- y = [3.1, 3.6, 3.8, 4.0, 4.1]
-
- # verified in numbers and R
- assert_fit :linear, x, y, 0.8315, -7.9635, 0.1878
- end
-
- def test_fit_power_clean
- # y = A x ** B, where B = b and A = e ** a
- # if, A = 1, B = 2, then
-
- x = [1.0, 2.0, 3.0, 4.0, 5.0]
- y = [1.0, 4.0, 9.0, 16.0, 25.0]
-
- assert_fit :power, x, y, 1.0, 1.0, 2.0
- end
-
- def test_fit_power_noisy
- # from www.engr.uidaho.edu/thompson/courses/ME330/lecture/least_squares.html
- x = [10, 12, 15, 17, 20, 22, 25, 27, 30, 32, 35]
- y = [95, 105, 125, 141, 173, 200, 253, 298, 385, 459, 602]
-
- # verified in numbers
- assert_fit :power, x, y, 0.90, 2.6217, 1.4556
-
- # income to % of households below income amount
- # http://library.wolfram.com/infocenter/Conferences/6461/PowerLaws.nb
- x = [15000, 25000, 35000, 50000, 75000, 100000]
- y = [0.154, 0.283, 0.402, 0.55, 0.733, 0.843]
-
- # verified in numbers
- assert_fit :power, x, y, 0.96, 3.119e-5, 0.8959
- end
-
- def assert_fit msg, x, y, fit, exp_a, exp_b
- a, b, rr = send "fit_#{msg}", x, y
-
- assert_operator rr, :>=, fit if fit
- assert_in_delta exp_a, a
- assert_in_delta exp_b, b
- end
-end
diff --git a/tool/test/minitest/test_minitest_mock.rb b/tool/test/minitest/test_minitest_mock.rb
deleted file mode 100644
index da222c5a..0000000
--- a/tool/test/minitest/test_minitest_mock.rb
+++ /dev/null
@@ -1,404 +0,0 @@
-# encoding: utf-8
-# frozen_string_literal: false
-
-require 'minitest/autorun'
-
-class TestMiniTestMock < MiniTest::Unit::TestCase
- def setup
- @mock = MiniTest::Mock.new.expect(:foo, nil)
- @mock.expect(:meaning_of_life, 42)
- end
-
- def test_create_stub_method
- assert_nil @mock.foo
- end
-
- def test_allow_return_value_specification
- assert_equal 42, @mock.meaning_of_life
- end
-
- def test_blow_up_if_not_called
- @mock.foo
-
- util_verify_bad "expected meaning_of_life() => 42, got []"
- end
-
- def test_not_blow_up_if_everything_called
- @mock.foo
- @mock.meaning_of_life
-
- assert @mock.verify
- end
-
- def test_allow_expectations_to_be_added_after_creation
- @mock.expect(:bar, true)
- assert @mock.bar
- end
-
- def test_not_verify_if_new_expected_method_is_not_called
- @mock.foo
- @mock.meaning_of_life
- @mock.expect(:bar, true)
-
- util_verify_bad "expected bar() => true, got []"
- end
-
- def test_blow_up_on_wrong_number_of_arguments
- @mock.foo
- @mock.meaning_of_life
- @mock.expect(:sum, 3, [1, 2])
-
- e = assert_raises ArgumentError do
- @mock.sum
- end
-
- assert_equal "mocked method :sum expects 2 arguments, got 0", e.message
- end
-
- def test_return_mock_does_not_raise
- retval = MiniTest::Mock.new
- mock = MiniTest::Mock.new
- mock.expect(:foo, retval)
- mock.foo
-
- assert mock.verify
- end
-
- def test_mock_args_does_not_raise
- skip "non-opaque use of ==" if maglev?
-
- arg = MiniTest::Mock.new
- mock = MiniTest::Mock.new
- mock.expect(:foo, nil, [arg])
- mock.foo(arg)
-
- assert mock.verify
- end
-
- def test_blow_up_on_wrong_arguments
- @mock.foo
- @mock.meaning_of_life
- @mock.expect(:sum, 3, [1, 2])
-
- e = assert_raises MockExpectationError do
- @mock.sum(2, 4)
- end
-
- exp = "mocked method :sum called with unexpected arguments [2, 4]"
- assert_equal exp, e.message
- end
-
- def test_expect_with_non_array_args
- e = assert_raises ArgumentError do
- @mock.expect :blah, 3, false
- end
-
- assert_equal "args must be an array", e.message
- end
-
- def test_respond_appropriately
- assert @mock.respond_to?(:foo)
- assert @mock.respond_to?(:foo, true)
- assert @mock.respond_to?('foo')
- assert !@mock.respond_to?(:bar)
- end
-
- def test_no_method_error_on_unexpected_methods
- e = assert_raises NoMethodError do
- @mock.bar
- end
-
- expected = "unmocked method :bar, expected one of [:foo, :meaning_of_life]"
-
- assert_equal expected, e.message
- end
-
- def test_assign_per_mock_return_values
- a = MiniTest::Mock.new
- b = MiniTest::Mock.new
-
- a.expect(:foo, :a)
- b.expect(:foo, :b)
-
- assert_equal :a, a.foo
- assert_equal :b, b.foo
- end
-
- def test_do_not_create_stub_method_on_new_mocks
- a = MiniTest::Mock.new
- a.expect(:foo, :a)
-
- assert !MiniTest::Mock.new.respond_to?(:foo)
- end
-
- def test_mock_is_a_blank_slate
- @mock.expect :kind_of?, true, [Integer]
- @mock.expect :==, true, [1]
-
- assert @mock.kind_of?(Integer), "didn't mock :kind_of\?"
- assert @mock == 1, "didn't mock :=="
- end
-
- def test_verify_allows_called_args_to_be_loosely_specified
- mock = MiniTest::Mock.new
- mock.expect :loose_expectation, true, [Integer]
- mock.loose_expectation 1
-
- assert mock.verify
- end
-
- def test_verify_raises_with_strict_args
- mock = MiniTest::Mock.new
- mock.expect :strict_expectation, true, [2]
-
- e = assert_raises MockExpectationError do
- mock.strict_expectation 1
- end
-
- exp = "mocked method :strict_expectation called with unexpected arguments [1]"
- assert_equal exp, e.message
- end
-
- def test_method_missing_empty
- mock = MiniTest::Mock.new
-
- mock.expect :a, nil
-
- mock.a
-
- e = assert_raises MockExpectationError do
- mock.a
- end
-
- assert_equal "No more expects available for :a: []", e.message
- end
-
- def test_same_method_expects_are_verified_when_all_called
- mock = MiniTest::Mock.new
- mock.expect :foo, nil, [:bar]
- mock.expect :foo, nil, [:baz]
-
- mock.foo :bar
- mock.foo :baz
-
- assert mock.verify
- end
-
- def test_same_method_expects_blow_up_when_not_all_called
- mock = MiniTest::Mock.new
- mock.expect :foo, nil, [:bar]
- mock.expect :foo, nil, [:baz]
-
- mock.foo :bar
-
- e = assert_raises(MockExpectationError) { mock.verify }
-
- exp = "expected foo(:baz) => nil, got [foo(:bar) => nil]"
-
- assert_equal exp, e.message
- end
-
- def test_verify_passes_when_mock_block_returns_true
- mock = MiniTest::Mock.new
- mock.expect :foo, nil do
- true
- end
-
- mock.foo
-
- assert mock.verify
- end
-
- def test_mock_block_is_passed_function_params
- arg1, arg2, arg3 = :bar, [1,2,3], {:a => 'a'}
- mock = MiniTest::Mock.new
- mock.expect :foo, nil do |a1, a2, a3|
- a1 == arg1 &&
- a2 == arg2 &&
- a3 == arg3
- end
-
- mock.foo arg1, arg2, arg3
-
- assert mock.verify
- end
-
- def test_verify_fails_when_mock_block_returns_false
- mock = MiniTest::Mock.new
- mock.expect :foo, nil do
- false
- end
-
- e = assert_raises(MockExpectationError) { mock.foo }
- exp = "mocked method :foo failed block w/ []"
-
- assert_equal exp, e.message
- end
-
- def test_mock_block_throws_if_args_passed
- mock = MiniTest::Mock.new
-
- e = assert_raises(ArgumentError) do
- mock.expect :foo, nil, [:a, :b, :c] do
- true
- end
- end
-
- exp = "args ignored when block given"
-
- assert_equal exp, e.message
- end
-
- def test_mock_returns_retval_when_called_with_block
- mock = MiniTest::Mock.new
- mock.expect(:foo, 32) do
- true
- end
-
- rs = mock.foo
-
- assert_equal rs, 32
- end
-
- def util_verify_bad exp
- e = assert_raises MockExpectationError do
- @mock.verify
- end
-
- assert_equal exp, e.message
- end
-end
-
-require_relative "metametameta"
-
-class TestMiniTestStub < MiniTest::Unit::TestCase
- def setup
- super
- MiniTest::Unit::TestCase.reset
-
- @tc = MiniTest::Unit::TestCase.new 'fake tc'
- @assertion_count = 1
- end
-
- def teardown
- super
- assert_equal @assertion_count, @tc._assertions
- end
-
- class Time
- def self.now
- 24
- end
- end
-
- def assert_stub val_or_callable
- @assertion_count += 1
-
- t = Time.now.to_i
-
- Time.stub :now, val_or_callable do
- @tc.assert_equal 42, Time.now
- end
-
- @tc.assert_operator Time.now.to_i, :>=, t
- end
-
- def test_stub_private_module_method
- @assertion_count += 1
-
- t0 = Time.now
-
- self.stub :sleep, nil do
- @tc.assert_nil sleep(10)
- end
-
- @tc.assert_operator Time.now - t0, :<=, 1
- end
-
- def test_stub_private_module_method_indirect
- @assertion_count += 1
-
- slow_clapper = Class.new do
- def slow_clap
- sleep 3
- :clap
- end
- end.new
-
- slow_clapper.stub :sleep, nil do |fast_clapper|
- @tc.assert_equal :clap, fast_clapper.slow_clap # either form works
- @tc.assert_equal :clap, slow_clapper.slow_clap # yay closures
- end
- end
-
- def test_stub_public_module_method
- Math.stub(:log10, 42.0) do
- @tc.assert_in_delta 42.0, Math.log10(1000)
- end
- end
-
- def test_stub_value
- assert_stub 42
- end
-
- def test_stub_block
- assert_stub lambda { 42 }
- end
-
- def test_stub_block_args
- @assertion_count += 1
-
- t = Time.now.to_i
-
- Time.stub :now, lambda { |n| n * 2 } do
- @tc.assert_equal 42, Time.now(21)
- end
-
- @tc.assert_operator Time.now.to_i, :>=, t
- end
-
- def test_stub_callable
- obj = Object.new
-
- def obj.call
- 42
- end
-
- assert_stub obj
- end
-
- def test_stub_yield_self
- obj = "foo"
-
- val = obj.stub :to_s, "bar" do |s|
- s.to_s
- end
-
- @tc.assert_equal "bar", val
- end
-
- def test_dynamic_method
- @assertion_count = 2
-
- dynamic = Class.new do
- def self.respond_to?(meth)
- meth == :found
- end
-
- def self.method_missing(meth, *args, &block)
- if meth == :found
- false
- else
- super
- end
- end
- end
-
- val = dynamic.stub(:found, true) do |s|
- s.found
- end
-
- @tc.assert_equal true, val
- @tc.assert_equal false, dynamic.found
- end
-end
diff --git a/tool/test/webrick/test_httpresponse.rb b/tool/test/webrick/test_httpresponse.rb
index 89a0f70..4410f63 100644
--- a/tool/test/webrick/test_httpresponse.rb
+++ b/tool/test/webrick/test_httpresponse.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: false
require "webrick"
-require "minitest/autorun"
+require "test/unit"
require "stringio"
require "net/http"
module WEBrick
- class TestHTTPResponse < MiniTest::Unit::TestCase
+ class TestHTTPResponse < Test::Unit::TestCase
class FakeLogger
attr_reader :messages
@@ -94,14 +94,14 @@ module WEBrick
def test_set_redirect_response_splitting
url = "malicious\r\nCookie: cracked_indicator_for_test"
- assert_raises(URI::InvalidURIError) do
+ assert_raise(URI::InvalidURIError) do
res.set_redirect(WEBrick::HTTPStatus::MultipleChoices, url)
end
end
def test_set_redirect_html_injection
url = 'http://example.com////?a</a><head></head><body><img src=1></body>'
- assert_raises(WEBrick::HTTPStatus::MultipleChoices) do
+ assert_raise(WEBrick::HTTPStatus::MultipleChoices) do
res.set_redirect(WEBrick::HTTPStatus::MultipleChoices, url)
end
res.status = 300
diff --git a/tool/travis_wait.sh b/tool/travis_wait.sh
new file mode 100755
index 0000000..471b765
--- /dev/null
+++ b/tool/travis_wait.sh
@@ -0,0 +1,18 @@
+#!/bin/bash -eu
+# The modified version of `travis_wait` to output a log as the command goes.
+# https://github.com/travis-ci/travis-ci/issues/4190#issuecomment-353342526
+
+# Produce an output log every 9 minutes as the timeout without output is 10
+# minutes. A job finishes with a timeout if it takes longer than 50 minutes.
+# https://docs.travis-ci.com/user/customizing-the-build#build-timeouts
+while sleep 9m; do
+ # Print message with bash variable SECONDS.
+ echo "====[ $SECONDS seconds still running ]===="
+done &
+
+echo "+ $@"
+"$@"
+
+jobs
+kill %1
+exit 0
diff --git a/tool/update-bundled_gems.rb b/tool/update-bundled_gems.rb
index cef31e2..48dcaa9 100644..100755
--- a/tool/update-bundled_gems.rb
+++ b/tool/update-bundled_gems.rb
@@ -9,6 +9,12 @@ unless /^[^#]/ !~ (gem = $F[0])
gem = src.fetch_spec(gem)
uri = gem.metadata["source_code_uri"] || gem.homepage
uri = uri.sub(%r[\Ahttps://github\.com/[^/]+/[^/]+\K/tree/.*], "").chomp(".git")
- $F[3][$F[1]] = gem.version.to_s if $F[3] && $F[3].include?($F[1])
+ if $F[3]
+ if $F[3].include?($F[1])
+ $F[3][$F[1]] = gem.version.to_s
+ elsif $F[2] != gem.version and /\A\h+\z/ =~ $F[3]
+ $F[3..-1] = []
+ end
+ end
$_ = [gem.name, gem.version, uri, *$F[3..-1]].join(" ")
end