summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
Diffstat (limited to 'tool')
-rw-r--r--tool/fake.rb1
-rw-r--r--tool/gem-unpack.rb1
-rw-r--r--tool/lib/test/unit/core_assertions.rb33
3 files changed, 35 insertions, 0 deletions
diff --git a/tool/fake.rb b/tool/fake.rb
index 42174052e2..4946fd6234 100644
--- a/tool/fake.rb
+++ b/tool/fake.rb
@@ -43,6 +43,7 @@ prehook = proc do |extmk|
$extout_prefix = '$(extout)$(target_prefix)/'
config = RbConfig::CONFIG
mkconfig = RbConfig::MAKEFILE_CONFIG
+ $builtruby ||= File.join(builddir, config['RUBY_INSTALL_NAME'] + config['EXEEXT'])
RbConfig.fire_update!("builddir", builddir)
RbConfig.fire_update!("buildlibdir", builddir)
RbConfig.fire_update!("libdir", builddir)
diff --git a/tool/gem-unpack.rb b/tool/gem-unpack.rb
index 0ddcea0704..08faec9355 100644
--- a/tool/gem-unpack.rb
+++ b/tool/gem-unpack.rb
@@ -1,3 +1,4 @@
+require 'fileutils'
require 'rubygems'
require 'rubygems/package'
diff --git a/tool/lib/test/unit/core_assertions.rb b/tool/lib/test/unit/core_assertions.rb
index 00555d6e32..c25fc4e983 100644
--- a/tool/lib/test/unit/core_assertions.rb
+++ b/tool/lib/test/unit/core_assertions.rb
@@ -398,6 +398,39 @@ eom
end
alias all_assertions assert_all_assertions
+ # Expect +seq+ to respond to +first+ and +each+ methods, e.g.,
+ # Array, Range, Enumerator::ArithmeticSequence and other
+ # Enumerable-s, and each elements should be size factors.
+ #
+ # :yield: each elements of +seq+.
+ def assert_linear_performance(seq, rehearsal: nil, pre: ->(n) {n})
+ first = seq.first
+ *arg = pre.call(first)
+ times = (0..(rehearsal || (2 * first))).map do
+ st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ yield(*arg)
+ t = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st)
+ assert_operator 0, :<=, t
+ t.nonzero?
+ end
+ times.compact!
+ tmin, tmax = times.minmax
+ tmax *= tmax / tmin
+ tmax = 10**Math.log10(tmax).ceil
+
+ seq.each do |i|
+ next if i == first
+ t = tmax * i.fdiv(first)
+ *arg = pre.call(i)
+ message = "[#{i}]: in #{t}s"
+ Timeout.timeout(t, Timeout::Error, message) do
+ st = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ yield(*arg)
+ assert_operator (Process.clock_gettime(Process::CLOCK_MONOTONIC) - st), :<=, t, message
+ end
+ end
+ end
+
def message(msg = nil, *args, &default) # :nodoc:
if Proc === msg
super(nil, *args) do