summaryrefslogtreecommitdiff
path: root/test/ruby/test_require_lib.rb
blob: a88279727e896d5afcd1c5cd06825de3d31dac9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
require 'test/unit'

class TestRequireLib < Test::Unit::TestCase
  libdir = __dir__ + '/../../lib'

  # .rb files at lib
  scripts = Dir.glob('*.rb', base: libdir).map {|f| f.chomp('.rb')}

  # .rb files in subdirectories of lib without same name script
  dirs = Dir.glob('*/', base: libdir).map {|d| d.chomp('/')}
  dirs -= scripts
  scripts.concat(Dir.glob(dirs.map {|d| d + '/*.rb'}, base: libdir).map {|f| f.chomp('.rb')})

  # skip some problems
  scripts -= %w[bundler bundled_gems rubygems mkmf]

  scripts.each do |lib|
    define_method "test_thread_size:#{lib}" do
      assert_separately(['-W0'], "#{<<~"begin;"}\n#{<<~"end;"}")
      begin;
        n = Thread.list.size
        require #{lib.dump}
        assert_equal n, Thread.list.size
      end;
    end
  end
end