This commit is contained in:
Benoit Daloze 2020-05-02 16:03:12 +02:00
Родитель b78fba447a
Коммит a68ddf4287
7 изменённых файлов: 89 добавлений и 20 удалений

Просмотреть файл

@ -153,5 +153,7 @@ def ruby_cmd(code, opts = {})
body = "-e #{code.inspect}"
end
[RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
command = [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
STDERR.puts "\nruby_cmd: #{command}" if ENV["DEBUG_MSPEC_RUBY_CMD"] == "true"
command
end

Просмотреть файл

@ -4,25 +4,13 @@
# directory is empty when the process exits.
SPEC_TEMP_DIR_PID = Process.pid
SPEC_TEMP_DIR_LIST = []
if tmpdir = ENV['SPEC_TEMP_DIR']
temppath = File.realdirpath(tmpdir) + "/"
else
tmpdir = File.realdirpath("rubyspec_temp")
temppath = tmpdir + "/#{SPEC_TEMP_DIR_PID}"
SPEC_TEMP_DIR_LIST << tmpdir
end
SPEC_TEMP_DIR_LIST << temppath
SPEC_TEMP_DIR = temppath
SPEC_TEMP_DIR = File.expand_path(ENV["SPEC_TEMP_DIR"] || "rubyspec_temp/#{SPEC_TEMP_DIR_PID}")
SPEC_TEMP_UNIQUIFIER = "0"
at_exit do
begin
if SPEC_TEMP_DIR_PID == Process.pid
while temppath = SPEC_TEMP_DIR_LIST.pop
next unless File.directory? temppath
Dir.delete temppath
end
Dir.delete SPEC_TEMP_DIR if File.directory? SPEC_TEMP_DIR
end
rescue SystemCallError
STDERR.puts <<-EOM
@ -30,7 +18,7 @@ at_exit do
-----------------------------------------------------
The rubyspec temp directory is not empty. Ensure that
all specs are cleaning up temporary files:
#{temppath}
#{SPEC_TEMP_DIR}
-----------------------------------------------------
EOM

Просмотреть файл

@ -7,6 +7,7 @@ require 'mspec/runner/formatters/summary'
require 'mspec/runner/formatters/unit'
require 'mspec/runner/formatters/spinner'
require 'mspec/runner/formatters/method'
require 'mspec/runner/formatters/stats'
require 'mspec/runner/formatters/yaml'
require 'mspec/runner/formatters/profile'
require 'mspec/runner/formatters/junit'

Просмотреть файл

@ -0,0 +1,57 @@
require 'mspec/runner/formatters/base'
class StatsPerFileFormatter < BaseFormatter
def initialize(out = nil)
super(out)
@data = {}
@root = File.expand_path(MSpecScript.get(:prefix) || '.')
end
def register
super
MSpec.register :load, self
MSpec.register :unload, self
end
# Resets the tallies so the counts are only for this file.
def load
tally.counter.examples = 0
tally.counter.errors = 0
tally.counter.failures = 0
tally.counter.tagged = 0
end
def unload
file = format_file MSpec.file
raise if @data.key?(file)
@data[file] = {
examples: tally.counter.examples,
errors: tally.counter.errors,
failures: tally.counter.failures,
tagged: tally.counter.tagged,
}
end
def finish
width = @data.keys.max_by(&:size).size
f = "%3d"
@data.each_pair do |file, data|
total = data[:examples]
passing = total - data[:errors] - data[:failures] - data[:tagged]
puts "#{file.ljust(width)} #{f % passing}/#{f % total}"
end
require 'yaml'
yaml = YAML.dump(@data)
File.write "results-#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}.yml", yaml
end
private def format_file(file)
if file.start_with?(@root)
file[@root.size+1..-1]
else
raise file
end
end
end

Просмотреть файл

@ -274,6 +274,8 @@ class MSpecOptions
config[:formatter] = SpinnerFormatter
when 't', 'method'
config[:formatter] = MethodFormatter
when 'e', 'stats'
config[:formatter] = StatsPerFileFormatter
when 'y', 'yaml'
config[:formatter] = YamlFormatter
when 'p', 'profile'
@ -300,6 +302,7 @@ class MSpecOptions
doc " m, summary SummaryFormatter"
doc " a, *, spin SpinnerFormatter"
doc " t, method MethodFormatter"
doc " e, stats StatsPerFileFormatter"
doc " y, yaml YamlFormatter"
doc " p, profile ProfileFormatter"
doc " j, junit JUnitFormatter\n"
@ -467,8 +470,6 @@ class MSpecOptions
end
def all
# Generated with:
# puts File.read(__FILE__).scan(/def (\w+).*\n\s*on\(/)
configure {}
targets
formatters
@ -481,6 +482,7 @@ class MSpecOptions
repeat
verbose
interrupt
timeout
verify
action_filters
actions

Просмотреть файл

@ -1283,3 +1283,22 @@ describe "The -d, --debug option" do
end
end
end
describe "MSpecOptions#all" do
it "includes all options" do
meth = MSpecOptions.instance_method(:all)
file, line = meth.source_location
contents = File.read(file)
lines = contents.lines
from = line
to = from
to += 1 until /^\s*end\s*$/ =~ lines[to]
calls = lines[from...to].map(&:strip)
option_methods = contents.scan(/def (\w+).*\n\s*on\(/).map(&:first)
option_methods[0].sub!("configure", "configure {}")
calls.should == option_methods
end
end

Просмотреть файл

@ -18,7 +18,7 @@ IMPLS = {
MSPEC = ARGV.delete('--mspec')
CHECK_LAST_MERGE = ENV['CHECK_LAST_MERGE'] != 'false'
TEST_TRUNK = ENV['TEST_TRUNK'] != 'false'
TEST_MASTER = ENV['TEST_MASTER'] != 'false'
MSPEC_REPO = File.expand_path("../../..", __FILE__)
raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git")
@ -172,7 +172,7 @@ def test_new_specs
run_test[min_version]
run_test[max_version]
run_test["trunk"] if TEST_TRUNK
run_test["master"] if TEST_MASTER
end
end