Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

! Updates to use #record method from newer MiniTest. Removes copied c…

…ode, yay!
  • Loading branch information...
commit a414a96204f18bed63e53e73f025267105da0cb7 1 parent f0f27c0
bhenderson authored
View
17 .autotest
@@ -1,26 +1,11 @@
# -*- ruby -*-
require 'autotest/restart'
+require 'autotest/isolate'
Autotest.add_hook :initialize do |at|
at.add_exception 'test/reports'
-# at.extra_files << "../some/external/dependency.rb"
-#
-# at.libs << ":../some/external"
-#
-# at.add_exception 'vendor'
-#
-# at.add_mapping(/dependency.rb/) do |f, _|
-# at.files_matching(/test_.*rb$/)
-# end
-#
-# %w(TestA TestB).each do |klass|
-# at.extra_class_map[klass] = "test/test_misc.rb"
-# end
false
end
-# Autotest.add_hook :run_command do |at|
-# system "rake build"
-# end
# vim: syntax=ruby
View
3  README.txt
@@ -5,11 +5,12 @@
== DESCRIPTION:
CI reporter plugin for MiniTest
+
This gem was made possible by ATT Interactive.
== FEATURES/PROBLEMS:
-* Monkeypatches MiniTest::Unit#_run_suite so I have to fix the version of MiniTest I support.
+* Uses MiniTest::Unit#record which is only available since version 2.12.0
== SYNOPSIS:
View
2  Rakefile
@@ -10,7 +10,7 @@ Hoe.spec 'minitest-ci' do
self.testlib = :none
- extra_deps << ['minitest', '2.6.0']
+ extra_deps << ['minitest', '~> 2.12.0']
extra_dev_deps << ['nokogiri', '~> 1.5.0']
extra_dev_deps << ['rdoc', '>= 2.4.2']
end
View
128 lib/minitest/ci.rb
@@ -1,12 +1,7 @@
-begin
- gem 'minitest', '2.6.0'
- require "minitest/unit"
-rescue Gem::LoadError => e
- msg = [
- 'minitest version 2.6.0 required',
- 'try: gem install minitest -v 2.6.0'
- ]
- raise e.exception msg.join("\n")
+require 'minitest/unit'
+#unless MiniTest::Unit::VERSION >= '2.12.0'
+unless MiniTest::Unit.public_method_defined? :record
+ abort 'you are running an unsupported version of MiniTest. try upgrading.'
end
require 'fileutils'
@@ -14,44 +9,20 @@
module MiniTest
module Ci
- ###
- # copied
- file = if RUBY_VERSION =~ /^1\.9/ then # bt's expanded, but __FILE__ isn't :(
- File.expand_path __FILE__
- elsif __FILE__ =~ /^[^\.]/ then # assume both relative
- require 'pathname'
- pwd = Pathname.new Dir.pwd
- pn = Pathname.new File.expand_path(__FILE__)
- pn = File.join(".", pn.relative_path_from(pwd)) unless pn.relative?
- pn.to_s
- else # assume both are expanded
- __FILE__
- end
- # end of copy
- ###
- CI_MINI_DIR = File.dirname(File.dirname(file))
VERSION = '1.0.4'
- @test_dir = nil #'test/reports'
- @error = nil
+ @report_dir = nil
@suites = Hash.new {|h,k| h[k] = []}
class << self
- attr_accessor :test_dir
+ # Accessor method to change the report dir if you don't like the
+ # defaults.
+ attr_accessor :report_dir
end
- def add_error e
- @error = e
- end
-
- def push suite, method, num, time
- a = [method, time, num]
- if @error
- a << @error
- @error = nil
- end
- @suites[suite] << a
+ def push suite, method, num_assertions, time, error
+ @suites[suite] << [method, num_assertions, time, error]
end
def finish io
@@ -60,7 +31,7 @@ def finish io
clean
- Dir.chdir @test_dir do
+ Dir.chdir report_dir do
@suites.each do |name, suite|
generate_suite name, suite
end
@@ -70,31 +41,17 @@ def finish io
private
def clean
- FileUtils.rm_rf @test_dir
- FileUtils.mkdir_p @test_dir
+ FileUtils.rm_rf report_dir
+ FileUtils.mkdir_p report_dir
end
def escape o
CGI.escapeHTML(o.to_s)
end
- # use original as well as filtering this file.
- def filter_backtrace bt
- bt = MiniTest::filter_backtrace bt
- orig_mini_dir = MiniTest::MINI_DIR
-
- orig_verbose, $VERBOSE = $VERBOSE, nil
-
- MiniTest.const_set :MINI_DIR, CI_MINI_DIR
- MiniTest::filter_backtrace bt
- ensure
- MiniTest.const_set :MINI_DIR, orig_mini_dir
- $VERBOSE = orig_verbose
- end
-
def generate_suite name, suite
total_time, assertions, errors, failures, skips = 0, 0, 0, 0, 0
- suite.each do |_, t, a, e|
+ suite.each do |_, a, t, e|
total_time += t
assertions += a
case e
@@ -111,12 +68,12 @@ def generate_suite name, suite
f.puts '<?xml version="1.0" encoding="UTF-8"?>'
f.puts "<testsuite time='#{"%6f" % total_time}' skipped='#{skips}' failures='#{failures}' errors='#{errors}' name='#{name}' assertions='#{assertions}' tests='#{suite.count}'>"
- suite.each do |method, time, asserts, error|
+ suite.each do |method, asserts, time, error|
f.puts " <testcase time='#{"%6f" % time}' name='#{method}' assertions='#{asserts}'>"
if error
- bt = filter_backtrace(error.backtrace).join "\n"
+ bt = MiniTest::filter_backtrace error.backtrace
f.write " <#{type error} type='#{escape error.class}' message=#{escape( error.message ).inspect}>"
- f.puts escape bt
+ f.puts escape bt.join "\n"
f.puts " </#{type error}>"
end
f.puts " </testcase>"
@@ -138,55 +95,10 @@ def type e
extend self
end
- class Unit
- # pull this out of _run_suite to make it easier to grab stuff
- def _run_suite_method suite, method
- inst = suite.new method
- inst._assertions = 0
-
- print "#{suite}##{method} = " if @verbose
-
- @start_time = Time.now
- result = inst.run self
- time = Time.now - @start_time
-
- print "%.2f s = " % time if @verbose
- print result
- puts if @verbose
-
- [inst._assertions, time]
- end
-
- # copied out of MiniTest::Unit
- def _run_suite suite, type
- header = "#{type}_suite_header"
- puts send(header, suite) if respond_to? header
-
- filter = options[:filter] || '/./'
- filter = Regexp.new $1 if filter =~ /\/(.*)\//
-
- assertions = suite.send("#{type}_methods").grep(filter).map { |method|
- a_count, _ = _run_suite_method suite, method
-
- a_count
- }
-
- return assertions.size, assertions.inject(0) { |sum, n| sum + n }
- end
- end
-
class CiUnit < Unit
- def _run_suite_method suite, method
- res = super
-
- MiniTest::Ci.push suite, method, *res
-
- res
- end
-
- def puke klass, meth, e
- MiniTest::Ci.add_error e
+ def record suite, method, assertions, time, error
+ MiniTest::Ci.push suite, method, assertions, time, error
super
end
@@ -199,5 +111,5 @@ def status io = self.output
end
# set defaults
-MiniTest::Ci.test_dir = 'test/reports'
+MiniTest::Ci.report_dir = 'test/reports'
MiniTest::Unit.runner = MiniTest::CiUnit.new
View
14 test/test_minitest_ci.rb
@@ -49,14 +49,14 @@ class TestMinitest::TestCi < MiniTest::Unit::TestCase
ensure
MiniTest::Unit.output = old_out
end
+ MiniTest::Unit.runner = nil # reset
def self.output
@output
end
def setup
- file = "#{MiniTest::Ci.test_dir}/TEST-MockTestSuite.xml"
- assert File.exists?( file ), 'expected xml file to exists'
+ file = "#{MiniTest::Ci.report_dir}/TEST-MockTestSuite.xml"
@file = File.read file
@doc = Nokogiri.parse @file
@doc = @doc.at_xpath('/testsuite')
@@ -113,12 +113,8 @@ def test_output
assert_match( /generating ci files/, self.class.output.read )
end
- def test_filter_backtrace
- bt = begin; raise; rescue => e; e.backtrace; end
-
- bt = MiniTest::Ci.send :filter_backtrace, bt
-
- assert_equal 1, bt.size
- assert_match( /#{__FILE__}/, bt.first )
+ def test_filtering_backtraces
+ error = @doc.at_xpath('/testsuite/testcase[@name="test_raise_error"]')
+ refute_match /lib\/minitest/, error.inner_text
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.