From a68ddf42879005905176bc38285906fe01707aff Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 2 May 2020 16:03:12 +0200 Subject: Update to ruby/mspec@ee29a34 --- spec/mspec/lib/mspec/helpers/ruby_exe.rb | 4 +- spec/mspec/lib/mspec/helpers/tmp.rb | 18 ++------ spec/mspec/lib/mspec/runner/formatters.rb | 1 + spec/mspec/lib/mspec/runner/formatters/stats.rb | 57 +++++++++++++++++++++++++ spec/mspec/lib/mspec/utils/options.rb | 6 ++- spec/mspec/spec/utils/options_spec.rb | 19 +++++++++ spec/mspec/tool/sync/sync-rubyspec.rb | 4 +- 7 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 spec/mspec/lib/mspec/runner/formatters/stats.rb (limited to 'spec/mspec') diff --git a/spec/mspec/lib/mspec/helpers/ruby_exe.rb b/spec/mspec/lib/mspec/helpers/ruby_exe.rb index 6d5470bbb5..075a8aaef5 100644 --- a/spec/mspec/lib/mspec/helpers/ruby_exe.rb +++ b/spec/mspec/lib/mspec/helpers/ruby_exe.rb @@ -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 diff --git a/spec/mspec/lib/mspec/helpers/tmp.rb b/spec/mspec/lib/mspec/helpers/tmp.rb index df242f73c1..5062991d63 100644 --- a/spec/mspec/lib/mspec/helpers/tmp.rb +++ b/spec/mspec/lib/mspec/helpers/tmp.rb @@ -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 diff --git a/spec/mspec/lib/mspec/runner/formatters.rb b/spec/mspec/lib/mspec/runner/formatters.rb index d085031a12..66f515ddff 100644 --- a/spec/mspec/lib/mspec/runner/formatters.rb +++ b/spec/mspec/lib/mspec/runner/formatters.rb @@ -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' diff --git a/spec/mspec/lib/mspec/runner/formatters/stats.rb b/spec/mspec/lib/mspec/runner/formatters/stats.rb new file mode 100644 index 0000000000..8cff96d145 --- /dev/null +++ b/spec/mspec/lib/mspec/runner/formatters/stats.rb @@ -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 diff --git a/spec/mspec/lib/mspec/utils/options.rb b/spec/mspec/lib/mspec/utils/options.rb index 886707e0c4..cb466f6a83 100644 --- a/spec/mspec/lib/mspec/utils/options.rb +++ b/spec/mspec/lib/mspec/utils/options.rb @@ -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 diff --git a/spec/mspec/spec/utils/options_spec.rb b/spec/mspec/spec/utils/options_spec.rb index ef85c41246..f3a7046526 100644 --- a/spec/mspec/spec/utils/options_spec.rb +++ b/spec/mspec/spec/utils/options_spec.rb @@ -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 diff --git a/spec/mspec/tool/sync/sync-rubyspec.rb b/spec/mspec/tool/sync/sync-rubyspec.rb index c1218bb02c..8a66217e4e 100644 --- a/spec/mspec/tool/sync/sync-rubyspec.rb +++ b/spec/mspec/tool/sync/sync-rubyspec.rb @@ -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 -- cgit v1.2.1