[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / spec / default.mspec
blobcae5fa374f5844694781f0190f1079130351a054
1 # -*- ruby -*-
2 $VERBOSE = false
3 if (opt = ENV["RUBYOPT"]) and (opt = opt.dup).sub!(/(?:\A|\s)-w(?=\z|\s)/, '')
4   ENV["RUBYOPT"] = opt
5 end
7 # Enable constant leak checks by ruby/mspec
8 ENV["CHECK_CONSTANT_LEAKS"] ||= "true"
10 require "./rbconfig" unless defined?(RbConfig)
11 require_relative "../tool/test-coverage" if ENV.key?("COVERAGE")
12 load File.dirname(__FILE__) + '/ruby/default.mspec'
13 OBJDIR = File.expand_path("spec/ruby/optional/capi/ext") unless defined?(OBJDIR)
14 class MSpecScript
15   @testing_ruby = true
17   builddir = Dir.pwd
18   srcdir = ENV['SRCDIR']
19   srcdir ||= File.read("Makefile", encoding: "US-ASCII")[/^\s*srcdir\s*=\s*(.+)/i, 1] rescue nil
20   config = RbConfig::CONFIG
22   # The default implementation to run the specs.
23   set :target, File.join(builddir, "miniruby#{config['exeext']}")
24   set :prefix, File.expand_path('ruby', File.dirname(__FILE__))
25   if srcdir
26     srcdir = File.expand_path(srcdir)
27     set :flags, %W[
28       -I#{srcdir}/lib
29       #{srcdir}/tool/runruby.rb --archdir=#{builddir} --extout=#{config['EXTOUT']}
30       --
31     ]
32   end
34   # Disable to run for bundled gems in test-spec
35   set :bundled_gems, (File.readlines("#{srcdir}/gems/bundled_gems").map do |line|
36     next if /^\s*(?:#|$)/ =~ line
37     "#{srcdir}/spec/ruby/library/" + line.split.first
38   end.compact)
39   set :stdlibs, Dir.glob("#{srcdir}/spec/ruby/library/*")
40   set :library, get(:stdlibs).to_a - get(:bundled_gems).to_a
42   set :files, get(:command_line) + get(:language) + get(:core) + get(:library) + get(:security) + get(:optional)
44   if ENV.key?("COVERAGE")
45     set :excludes, ["Coverage"]
46   end
47 end
49 module MSpecScript::JobServer
50   def cores(max = 1)
51     if max > 1 and /(?:\A|\s)--jobserver-(?:auth|fds)=(\d+),(\d+)/ =~ ENV["MAKEFLAGS"]
52       cores = 1
53       begin
54         r = IO.for_fd($1.to_i(10), "rb", autoclose: false)
55         w = IO.for_fd($2.to_i(10), "wb", autoclose: false)
56         jobtokens = r.read_nonblock(max - 1)
57         cores = jobtokens.size
58         if cores > 0
59           cores += 1
60           jobserver = w
61           w = nil
62           at_exit {
63             jobserver.print(jobtokens)
64             jobserver.close
65           }
66           MSpecScript::JobServer.module_eval do
67             remove_method :cores
68             define_method(:cores) do
69               cores
70             end
71           end
72           return cores
73         end
74       rescue Errno::EBADF
75       ensure
76         r&.close
77         w&.close
78       end
79     end
80     super
81   end
82 end
84 class MSpecScript
85   prepend JobServer
86 end
88 require 'mspec/runner/formatters/dotted'
90 class DottedFormatter
91   prepend Module.new {
92     BASE = __dir__ + "/ruby/" unless defined?(BASE)
94     def initialize(out = nil)
95       super
96       if out
97         @columns = nil
98       else
99         columns = ENV["COLUMNS"]&.to_i
100         @columns = columns&.nonzero? || 80
101       end
102       @dotted = 0
103       @loaded = false
104       @count = 0
105     end
107     def register
108       super
109       MSpec.register :load, self
110       MSpec.register :unload, self
111     end
113     def after(*)
114       if @columns
115         if @dotted == 0
116           s = sprintf("%6d ", @count)
117           print(s)
118           @dotted += s.size
119         end
120         @count +=1
121       end
122       super
123       if @columns and (@dotted += 1) >= @columns
124         print "\n"
125         @dotted = 0
126       end
127     end
129     def load(*)
130       file = MSpec.file || MSpec.files_array.first
131       @loaded = true
132       s = "#{file.delete_prefix(BASE)}:"
133       print s
134       if @columns
135         if (@dotted += s.size) >= @columns
136           print "\n"
137           @dotted = 0
138         else
139           print " "
140           @dotted += 1
141         end
142       end
143       @count = 0
144     end
146     def unload
147       super
148       if @loaded
149         print "\n" if @dotted > 0
150         @dotted = 0
151         @loaded = nil
152       end
153     end
154   }