From 9d0e8d9c53b58543eb4af3ec86e08c4e0474ff88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 18 Jan 2020 16:54:39 +0100 Subject: [PATCH 1/3] Drop ruby 1.8 and ruby 1.9 support --- .travis.yml | 4 - Gemfile | 13 +- README.markdown | 2 +- README_INDEX.rdoc | 2 +- coderay.gemspec | 2 +- lib/coderay/duo.rb | 2 +- lib/coderay/encoders/html/numbering.rb | 2 +- lib/coderay/scanners/java.rb | 2 +- rake_tasks/documentation.rake | 8 +- rake_tasks/test.rake | 14 +- spec/spec_helper.rb | 2 +- test/executable/suite.rb | 2 +- test/functional/for_redcloth.rb | 4 +- test/functional/suite.rb | 2 +- test/lib/README | 2 - test/lib/test/unit.rb | 280 --------- test/lib/test/unit/assertionfailederror.rb | 14 - test/lib/test/unit/assertions.rb | 622 ------------------- test/lib/test/unit/autorunner.rb | 219 ------- test/lib/test/unit/collector.rb | 43 -- test/lib/test/unit/collector/dir.rb | 107 ---- test/lib/test/unit/error.rb | 56 -- test/lib/test/unit/failure.rb | 51 -- test/lib/test/unit/testcase.rb | 160 ----- test/lib/test/unit/testresult.rb | 80 --- test/lib/test/unit/testsuite.rb | 76 --- test/lib/test/unit/ui/console/testrunner.rb | 127 ---- test/lib/test/unit/ui/testrunnermediator.rb | 68 -- test/lib/test/unit/ui/testrunnerutilities.rb | 46 -- test/lib/test/unit/util/backtracefilter.rb | 40 -- test/lib/test/unit/util/observable.rb | 90 --- test/lib/test/unit/util/procwrapper.rb | 48 -- test/unit/suite.rb | 2 +- 33 files changed, 23 insertions(+), 2169 deletions(-) delete mode 100644 test/lib/README delete mode 100644 test/lib/test/unit.rb delete mode 100644 test/lib/test/unit/assertionfailederror.rb delete mode 100644 test/lib/test/unit/assertions.rb delete mode 100644 test/lib/test/unit/autorunner.rb delete mode 100644 test/lib/test/unit/collector.rb delete mode 100644 test/lib/test/unit/collector/dir.rb delete mode 100644 test/lib/test/unit/error.rb delete mode 100644 test/lib/test/unit/failure.rb delete mode 100644 test/lib/test/unit/testcase.rb delete mode 100644 test/lib/test/unit/testresult.rb delete mode 100644 test/lib/test/unit/testsuite.rb delete mode 100644 test/lib/test/unit/ui/console/testrunner.rb delete mode 100644 test/lib/test/unit/ui/testrunnermediator.rb delete mode 100644 test/lib/test/unit/ui/testrunnerutilities.rb delete mode 100644 test/lib/test/unit/util/backtracefilter.rb delete mode 100644 test/lib/test/unit/util/observable.rb delete mode 100644 test/lib/test/unit/util/procwrapper.rb diff --git a/.travis.yml b/.travis.yml index a8f407e5..dbeb2957 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,6 @@ env: - "CC_TEST_REPORTER_ID=faa393209ff0a104cf37511a9a03510bcee37951971b1ca4ffc2af217851d47e" language: ruby rvm: - - 1.8.7 - - ree - - 1.9.3 - 2.0 - 2.1 - 2.2 @@ -19,7 +16,6 @@ rvm: - jruby matrix: allow_failures: - - rvm: 1.8.7 - rvm: ruby-head - rvm: jruby branches: diff --git a/Gemfile b/Gemfile index 49ac338d..655342f5 100644 --- a/Gemfile +++ b/Gemfile @@ -7,14 +7,13 @@ gemspec # Include everything needed to run rake, tests, features, etc. group :development do gem 'bundler' - gem 'json', '~> 1.8' if RUBY_VERSION < '2.0' - gem 'rake', RUBY_VERSION < '1.9' ? '~> 10.5' : '>= 10.5' - gem 'rdoc', Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3') ? '~> 4.2.2' : Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2') ? '< 6' : '>= 6' + gem 'rake', '>= 10.5' + gem 'rdoc', Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2') ? '< 6' : '>= 6' gem 'RedCloth', RUBY_PLATFORM == 'java' ? '= 4.2.9' : '>= 4.0.3' gem 'rspec', '~> 3.9.0' - gem 'shoulda-context', RUBY_VERSION < '1.9' ? '= 1.2.1' : '>= 1.2.1' + gem 'shoulda-context', '>= 1.2.1' gem 'simplecov', RUBY_VERSION < '2.7' ? '~> 0.17.1' : '>= 0.18.5' - gem 'term-ansicolor', RUBY_VERSION < '2.0' ? '~> 1.3.2' : '>= 1.3.2' - gem 'test-unit', RUBY_VERSION < '1.9' ? '~> 2.0' : '>= 3.0' - gem 'tins', RUBY_VERSION < '2.0' ? '~> 1.6.0' : '>= 1.6.0' + gem 'term-ansicolor', '>= 1.3.2' + gem 'test-unit', '>= 3.0' + gem 'tins', '>= 1.6.0' end diff --git a/README.markdown b/README.markdown index 410d1bff..6ff6893e 100644 --- a/README.markdown +++ b/README.markdown @@ -15,7 +15,7 @@ You put your code in, and you get it back colored; Keywords, strings, floats, co ### Dependencies -CodeRay needs Ruby 1.8.7, 1.9.3 or 2.0+. It also runs on JRuby. +CodeRay needs Ruby 2.0+. It also runs on JRuby. ## Example Usage diff --git a/README_INDEX.rdoc b/README_INDEX.rdoc index 7332653c..b6d0215b 100644 --- a/README_INDEX.rdoc +++ b/README_INDEX.rdoc @@ -26,7 +26,7 @@ floats, comments - all in different colors. And with line numbers. === Dependencies -CodeRay needs Ruby 1.8.7+ or 1.9.2+. It also runs on Rubinius and JRuby. +CodeRay needs Ruby 2.0+. It also runs on Rubinius and JRuby. == Example Usage diff --git a/coderay.gemspec b/coderay.gemspec index 14500ad9..d93d0a81 100644 --- a/coderay.gemspec +++ b/coderay.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.license = 'MIT' s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 1.8.6' + s.required_ruby_version = '>= 2.0.0' readme_file = 'README_INDEX.rdoc' diff --git a/lib/coderay/duo.rb b/lib/coderay/duo.rb index cb3f8ee8..b6886f6c 100644 --- a/lib/coderay/duo.rb +++ b/lib/coderay/duo.rb @@ -71,7 +71,7 @@ def encode code, options = {} # # CodeRay::Duo[:python => :yaml].call(code) # - # or, in Ruby 1.9 and later: + # or: # # CodeRay::Duo[:python => :yaml].(code) alias call encode diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb index a1b9c04a..151c1518 100644 --- a/lib/coderay/encoders/html/numbering.rb +++ b/lib/coderay/encoders/html/numbering.rb @@ -56,7 +56,7 @@ def self.number! output, mode = :table, options = {} raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every end - if position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n) + if position_of_last_newline = output.rindex(/\n/) after_last_newline = output[position_of_last_newline + 1 .. -1] ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/] diff --git a/lib/coderay/scanners/java.rb b/lib/coderay/scanners/java.rb index 7dd1919e..503c834d 100644 --- a/lib/coderay/scanners/java.rb +++ b/lib/coderay/scanners/java.rb @@ -44,7 +44,7 @@ class Java < Scanner '"' => /[^\\"]+/, '/' => /[^\\\/]+/, } # :nodoc: - IDENT = RUBY_VERSION < '1.9' ? /[a-zA-Z_][A-Za-z_0-9]*/ : Regexp.new('[[[:alpha:]]_][[[:alnum:]]_]*') # :nodoc: + IDENT = Regexp.new('[[[:alpha:]]_][[[:alnum:]]_]*') # :nodoc: protected diff --git a/rake_tasks/documentation.rake b/rake_tasks/documentation.rake index 4f7cef7a..d3723a60 100644 --- a/rake_tasks/documentation.rake +++ b/rake_tasks/documentation.rake @@ -1,10 +1,6 @@ begin - if RUBY_VERSION >= '1.8.7' - gem 'rdoc' if defined? gem - require 'rdoc/task' - else - require 'rake/rdoctask' - end + gem 'rdoc' if defined? gem + require 'rdoc/task' rescue LoadError warn 'Please gem install rdoc.' end diff --git a/rake_tasks/test.rake b/rake_tasks/test.rake index e72c96b2..61e50a6c 100644 --- a/rake_tasks/test.rake +++ b/rake_tasks/test.rake @@ -69,19 +69,11 @@ Please rename or remove it and run again to use the GitHub repository: desc 'test the CodeRay executable' task :exe do - if RUBY_VERSION >= '1.8.7' - ruby './test/executable/suite.rb' - else - puts - puts "Can't run executable tests because shoulda-context requires Ruby 1.8.7+." - puts "Skipping." - end + ruby './test/executable/suite.rb' end end -if RUBY_VERSION >= '1.9' - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) -end +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) task :test => %w(test:functional test:units test:exe spec) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4e2dac6e..5dfe5328 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,7 @@ # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end if RUBY_VERSION >= '1.9' + end # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. diff --git a/test/executable/suite.rb b/test/executable/suite.rb index a6f40972..4eb86c1c 100644 --- a/test/executable/suite.rb +++ b/test/executable/suite.rb @@ -1,4 +1,4 @@ -require 'simplecov' if RUBY_VERSION >= '1.9' +require 'simplecov' require 'test/unit' require 'rubygems' unless defined? Gem require 'shoulda-context' diff --git a/test/functional/for_redcloth.rb b/test/functional/for_redcloth.rb index 32a1a1b3..bda3f260 100644 --- a/test/functional/for_redcloth.rb +++ b/test/functional/for_redcloth.rb @@ -1,4 +1,4 @@ -require 'simplecov' if RUBY_VERSION >= '1.9' +require 'simplecov' require 'test/unit' $:.unshift File.expand_path('../../../lib', __FILE__) @@ -76,4 +76,4 @@ def test_for_redcloth_false_positive BLOCKCODE end -end if defined? RedCloth \ No newline at end of file +end if defined? RedCloth diff --git a/test/functional/suite.rb b/test/functional/suite.rb index 2bbc29c5..f87ca0fe 100644 --- a/test/functional/suite.rb +++ b/test/functional/suite.rb @@ -1,4 +1,4 @@ -require 'simplecov' if RUBY_VERSION >= '1.9' +require 'simplecov' require 'test/unit' $VERBOSE = $CODERAY_DEBUG = true diff --git a/test/lib/README b/test/lib/README deleted file mode 100644 index 7c416487..00000000 --- a/test/lib/README +++ /dev/null @@ -1,2 +0,0 @@ -Contents: -- test/unit: We need the old Test::Unit for the scanner test suite to work with Ruby 1.9. diff --git a/test/lib/test/unit.rb b/test/lib/test/unit.rb deleted file mode 100644 index b71f6445..00000000 --- a/test/lib/test/unit.rb +++ /dev/null @@ -1,280 +0,0 @@ -require 'test/unit/testcase' -require 'test/unit/autorunner' - -module Test # :nodoc: - # - # = Test::Unit - Ruby Unit Testing Framework - # - # == Introduction - # - # Unit testing is making waves all over the place, largely due to the - # fact that it is a core practice of XP. While XP is great, unit testing - # has been around for a long time and has always been a good idea. One - # of the keys to good unit testing, though, is not just writing tests, - # but having tests. What's the difference? Well, if you just _write_ a - # test and throw it away, you have no guarantee that something won't - # change later which breaks your code. If, on the other hand, you _have_ - # tests (obviously you have to write them first), and run them as often - # as possible, you slowly build up a wall of things that cannot break - # without you immediately knowing about it. This is when unit testing - # hits its peak usefulness. - # - # Enter Test::Unit, a framework for unit testing in Ruby, helping you to - # design, debug and evaluate your code by making it easy to write and - # have tests for it. - # - # - # == Notes - # - # Test::Unit has grown out of and superceded Lapidary. - # - # - # == Feedback - # - # I like (and do my best to practice) XP, so I value early releases, - # user feedback, and clean, simple, expressive code. There is always - # room for improvement in everything I do, and Test::Unit is no - # exception. Please, let me know what you think of Test::Unit as it - # stands, and what you'd like to see expanded/changed/improved/etc. If - # you find a bug, let me know ASAP; one good way to let me know what the - # bug is is to submit a new test that catches it :-) Also, I'd love to - # hear about any successes you have with Test::Unit, and any - # documentation you might add will be greatly appreciated. My contact - # info is below. - # - # - # == Contact Information - # - # A lot of discussion happens about Ruby in general on the ruby-talk - # mailing list (http://www.ruby-lang.org/en/ml.html), and you can ask - # any questions you might have there. I monitor the list, as do many - # other helpful Rubyists, and you're sure to get a quick answer. Of - # course, you're also welcome to email me (Nathaniel Talbott) directly - # at mailto:testunit@talbott.ws, and I'll do my best to help you out. - # - # - # == Credits - # - # I'd like to thank... - # - # Matz, for a great language! - # - # Masaki Suketa, for his work on RubyUnit, which filled a vital need in - # the Ruby world for a very long time. I'm also grateful for his help in - # polishing Test::Unit and getting the RubyUnit compatibility layer - # right. His graciousness in allowing Test::Unit to supercede RubyUnit - # continues to be a challenge to me to be more willing to defer my own - # rights. - # - # Ken McKinlay, for his interest and work on unit testing, and for his - # willingness to dialog about it. He was also a great help in pointing - # out some of the holes in the RubyUnit compatibility layer. - # - # Dave Thomas, for the original idea that led to the extremely simple - # "require 'test/unit'", plus his code to improve it even more by - # allowing the selection of tests from the command-line. Also, without - # RDoc, the documentation for Test::Unit would stink a lot more than it - # does now. - # - # Everyone who's helped out with bug reports, feature ideas, - # encouragement to continue, etc. It's a real privilege to be a part of - # the Ruby community. - # - # The guys at RoleModel Software, for putting up with me repeating, "But - # this would be so much easier in Ruby!" whenever we're coding in Java. - # - # My Creator, for giving me life, and giving it more abundantly. - # - # - # == License - # - # Test::Unit is copyright (c) 2000-2003 Nathaniel Talbott. It is free - # software, and is distributed under the Ruby license. See the COPYING - # file in the standard Ruby distribution for details. - # - # - # == Warranty - # - # This software is provided "as is" and without any express or - # implied warranties, including, without limitation, the implied - # warranties of merchantibility and fitness for a particular - # purpose. - # - # - # == Author - # - # Nathaniel Talbott. - # Copyright (c) 2000-2003, Nathaniel Talbott - # - # ---- - # - # = Usage - # - # The general idea behind unit testing is that you write a _test_ - # _method_ that makes certain _assertions_ about your code, working - # against a _test_ _fixture_. A bunch of these _test_ _methods_ are - # bundled up into a _test_ _suite_ and can be run any time the - # developer wants. The results of a run are gathered in a _test_ - # _result_ and displayed to the user through some UI. So, lets break - # this down and see how Test::Unit provides each of these necessary - # pieces. - # - # - # == Assertions - # - # These are the heart of the framework. Think of an assertion as a - # statement of expected outcome, i.e. "I assert that x should be equal - # to y". If, when the assertion is executed, it turns out to be - # correct, nothing happens, and life is good. If, on the other hand, - # your assertion turns out to be false, an error is propagated with - # pertinent information so that you can go back and make your - # assertion succeed, and, once again, life is good. For an explanation - # of the current assertions, see Test::Unit::Assertions. - # - # - # == Test Method & Test Fixture - # - # Obviously, these assertions have to be called within a context that - # knows about them and can do something meaningful with their - # pass/fail value. Also, it's handy to collect a bunch of related - # tests, each test represented by a method, into a common test class - # that knows how to run them. The tests will be in a separate class - # from the code they're testing for a couple of reasons. First of all, - # it allows your code to stay uncluttered with test code, making it - # easier to maintain. Second, it allows the tests to be stripped out - # for deployment, since they're really there for you, the developer, - # and your users don't need them. Third, and most importantly, it - # allows you to set up a common test fixture for your tests to run - # against. - # - # What's a test fixture? Well, tests do not live in a vacuum; rather, - # they're run against the code they are testing. Often, a collection - # of tests will run against a common set of data, also called a - # fixture. If they're all bundled into the same test class, they can - # all share the setting up and tearing down of that data, eliminating - # unnecessary duplication and making it much easier to add related - # tests. - # - # Test::Unit::TestCase wraps up a collection of test methods together - # and allows you to easily set up and tear down the same test fixture - # for each test. This is done by overriding #setup and/or #teardown, - # which will be called before and after each test method that is - # run. The TestCase also knows how to collect the results of your - # assertions into a Test::Unit::TestResult, which can then be reported - # back to you... but I'm getting ahead of myself. To write a test, - # follow these steps: - # - # * Make sure Test::Unit is in your library path. - # * require 'test/unit' in your test script. - # * Create a class that subclasses Test::Unit::TestCase. - # * Add a method that begins with "test" to your class. - # * Make assertions in your test method. - # * Optionally define #setup and/or #teardown to set up and/or tear - # down your common test fixture. - # * You can now run your test as you would any other Ruby - # script... try it and see! - # - # A really simple test might look like this (#setup and #teardown are - # commented out to indicate that they are completely optional): - # - # require 'test/unit' - # - # class TC_MyTest < Test::Unit::TestCase - # # def setup - # # end - # - # # def teardown - # # end - # - # def test_fail - # assert(false, 'Assertion was false.') - # end - # end - # - # - # == Test Runners - # - # So, now you have this great test class, but you still need a way to - # run it and view any failures that occur during the run. This is - # where Test::Unit::UI::Console::TestRunner (and others, such as - # Test::Unit::UI::GTK::TestRunner) comes into play. The console test - # runner is automatically invoked for you if you require 'test/unit' - # and simply run the file. To use another runner, or to manually - # invoke a runner, simply call its run class method and pass in an - # object that responds to the suite message with a - # Test::Unit::TestSuite. This can be as simple as passing in your - # TestCase class (which has a class suite method). It might look - # something like this: - # - # require 'test/unit/ui/console/testrunner' - # Test::Unit::UI::Console::TestRunner.run(TC_MyTest) - # - # - # == Test Suite - # - # As more and more unit tests accumulate for a given project, it - # becomes a real drag running them one at a time, and it also - # introduces the potential to overlook a failing test because you - # forget to run it. Suddenly it becomes very handy that the - # TestRunners can take any object that returns a Test::Unit::TestSuite - # in response to a suite method. The TestSuite can, in turn, contain - # other TestSuites or individual tests (typically created by a - # TestCase). In other words, you can easily wrap up a group of - # TestCases and TestSuites like this: - # - # require 'test/unit/testsuite' - # require 'tc_myfirsttests' - # require 'tc_moretestsbyme' - # require 'ts_anothersetoftests' - # - # class TS_MyTests - # def self.suite - # suite = Test::Unit::TestSuite.new - # suite << TC_MyFirstTests.suite - # suite << TC_MoreTestsByMe.suite - # suite << TS_AnotherSetOfTests.suite - # return suite - # end - # end - # Test::Unit::UI::Console::TestRunner.run(TS_MyTests) - # - # Now, this is a bit cumbersome, so Test::Unit does a little bit more - # for you, by wrapping these up automatically when you require - # 'test/unit'. What does this mean? It means you could write the above - # test case like this instead: - # - # require 'test/unit' - # require 'tc_myfirsttests' - # require 'tc_moretestsbyme' - # require 'ts_anothersetoftests' - # - # Test::Unit is smart enough to find all the test cases existing in - # the ObjectSpace and wrap them up into a suite for you. It then runs - # the dynamic suite using the console TestRunner. - # - # - # == Questions? - # - # I'd really like to get feedback from all levels of Ruby - # practitioners about typos, grammatical errors, unclear statements, - # missing points, etc., in this document (or any other). - # - - module Unit - # If set to false Test::Unit will not automatically run at exit. - def self.run=(flag) - @run = flag - end - - # Automatically run tests at exit? - def self.run? - @run ||= false - end - end -end - -at_exit do - unless $! || Test::Unit.run? - exit Test::Unit::AutoRunner.run - end -end diff --git a/test/lib/test/unit/assertionfailederror.rb b/test/lib/test/unit/assertionfailederror.rb deleted file mode 100644 index a21e4b58..00000000 --- a/test/lib/test/unit/assertionfailederror.rb +++ /dev/null @@ -1,14 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - - # Thrown by Test::Unit::Assertions when an assertion fails. - class AssertionFailedError < StandardError - end - end -end diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb deleted file mode 100644 index aa97799d..00000000 --- a/test/lib/test/unit/assertions.rb +++ /dev/null @@ -1,622 +0,0 @@ -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/assertionfailederror' -require 'test/unit/util/backtracefilter' - -module Test - module Unit - - ## - # Test::Unit::Assertions contains the standard Test::Unit assertions. - # Assertions is included in Test::Unit::TestCase. - # - # To include it in your own code and use its functionality, you simply - # need to rescue Test::Unit::AssertionFailedError. Additionally you may - # override add_assertion to get notified whenever an assertion is made. - # - # Notes: - # * The message to each assertion, if given, will be propagated with the - # failure. - # * It is easy to add your own assertions based on assert_block(). - # - # = Example Custom Assertion - # - # def deny(boolean, message = nil) - # message = build_message message, ' is not false or nil.', boolean - # assert_block message do - # not boolean - # end - # end - - module Assertions - - ## - # The assertion upon which all other assertions are based. Passes if the - # block yields true. - # - # Example: - # assert_block "Couldn't do the thing" do - # do_the_thing - # end - - public - def assert_block(message="assert_block failed.") # :yields: - _wrap_assertion do - if (! yield) - raise AssertionFailedError.new(message.to_s) - end - end - end - - ## - # Asserts that +boolean+ is not false or nil. - # - # Example: - # assert [1, 2].include?(5) - - public - def assert(boolean, message=nil) - _wrap_assertion do - assert_block("assert should not be called with a block.") { !block_given? } - assert_block(build_message(message, " is not true.", boolean)) { boolean } - end - end - - ## - # Passes if +expected+ == +actual. - # - # Note that the ordering of arguments is important, since a helpful - # error message is generated when this one fails that tells you the - # values of expected and actual. - # - # Example: - # assert_equal 'MY STRING', 'my string'.upcase - - public - def assert_equal(expected, actual, message=nil) - full_message = build_message(message, < expected but was -. -EOT - assert_block(full_message) { expected == actual } - end - - private - def _check_exception_class(args) # :nodoc: - args.partition do |klass| - next if klass.instance_of?(Module) - assert(Exception >= klass, "Should expect a class of exception, #{klass}") - true - end - end - - private - def _expected_exception?(actual_exception, exceptions, modules) # :nodoc: - exceptions.include?(actual_exception.class) or - modules.any? {|mod| actual_exception.is_a?(mod)} - end - - ## - # Passes if the block raises one of the given exceptions. - # - # Example: - # assert_raise RuntimeError, LoadError do - # raise 'Boom!!!' - # end - - public - def assert_raise(*args) - _wrap_assertion do - if Module === args.last - message = "" - else - message = args.pop - end - exceptions, modules = _check_exception_class(args) - expected = args.size == 1 ? args.first : args - actual_exception = nil - full_message = build_message(message, " exception expected but none was thrown.", expected) - assert_block(full_message) do - begin - yield - rescue Exception => actual_exception - break - end - false - end - full_message = build_message(message, " exception expected but was\n?", expected, actual_exception) - assert_block(full_message) {_expected_exception?(actual_exception, exceptions, modules)} - actual_exception - end - end - - ## - # Alias of assert_raise. - # - # Will be deprecated in 1.9, and removed in 2.0. - - public - def assert_raises(*args, &block) - assert_raise(*args, &block) - end - - ## - # Passes if +object+ .instance_of? +klass+ - # - # Example: - # assert_instance_of String, 'foo' - - public - def assert_instance_of(klass, object, message="") - _wrap_assertion do - assert_equal(Class, klass.class, "assert_instance_of takes a Class as its first argument") - full_message = build_message(message, < expected to be an instance of - but was -. -EOT - assert_block(full_message){object.instance_of?(klass)} - end - end - - ## - # Passes if +object+ is nil. - # - # Example: - # assert_nil [1, 2].uniq! - - public - def assert_nil(object, message="") - assert_equal(nil, object, message) - end - - ## - # Passes if +object+ .kind_of? +klass+ - # - # Example: - # assert_kind_of Object, 'foo' - - public - def assert_kind_of(klass, object, message="") - _wrap_assertion do - assert(klass.kind_of?(Module), "The first parameter to assert_kind_of should be a kind_of Module.") - full_message = build_message(message, "\nexpected to be kind_of\\?\n but was\n.", object, klass, object.class) - assert_block(full_message){object.kind_of?(klass)} - end - end - - ## - # Passes if +object+ .respond_to? +method+ - # - # Example: - # assert_respond_to 'bugbear', :slice - - public - def assert_respond_to(object, method, message="") - _wrap_assertion do - full_message = build_message(nil, "\ngiven as the method name argument to #assert_respond_to must be a Symbol or #respond_to\\?(:to_str).", method) - - assert_block(full_message) do - method.kind_of?(Symbol) || method.respond_to?(:to_str) - end - full_message = build_message(message, < -of type -expected to respond_to\\?. -EOT - assert_block(full_message) { object.respond_to?(method) } - end - end - - ## - # Passes if +string+ =~ +pattern+. - # - # Example: - # assert_match(/\d+/, 'five, 6, seven') - - public - def assert_match(pattern, string, message="") - _wrap_assertion do - pattern = case(pattern) - when String - Regexp.new(Regexp.escape(pattern)) - else - pattern - end - full_message = build_message(message, " expected to be =~\n.", string, pattern) - assert_block(full_message) { string =~ pattern } - end - end - - ## - # Passes if +actual+ .equal? +expected+ (i.e. they are the same - # instance). - # - # Example: - # o = Object.new - # assert_same o, o - - public - def assert_same(expected, actual, message="") - full_message = build_message(message, < -with id expected to be equal\\? to - -with id . -EOT - assert_block(full_message) { actual.equal?(expected) } - end - - ## - # Compares the +object1+ with +object2+ using +operator+. - # - # Passes if object1.__send__(operator, object2) is true. - # - # Example: - # assert_operator 5, :>=, 4 - - public - def assert_operator(object1, operator, object2, message="") - _wrap_assertion do - full_message = build_message(nil, "\ngiven as the operator for #assert_operator must be a Symbol or #respond_to\\?(:to_str).", operator) - assert_block(full_message){operator.kind_of?(Symbol) || operator.respond_to?(:to_str)} - full_message = build_message(message, < expected to be -? -. -EOT - assert_block(full_message) { object1.__send__(operator, object2) } - end - end - - ## - # Passes if block does not raise an exception. - # - # Example: - # assert_nothing_raised do - # [1, 2].uniq - # end - - public - def assert_nothing_raised(*args) - _wrap_assertion do - if Module === args.last - message = "" - else - message = args.pop - end - exceptions, modules = _check_exception_class(args) - begin - yield - rescue Exception => e - if ((args.empty? && !e.instance_of?(AssertionFailedError)) || - _expected_exception?(e, exceptions, modules)) - assert_block(build_message(message, "Exception raised:\n?", e)){false} - else - raise - end - end - nil - end - end - - ## - # Flunk always fails. - # - # Example: - # flunk 'Not done testing yet.' - - public - def flunk(message="Flunked") - assert_block(build_message(message)){false} - end - - ## - # Passes if ! +actual+ .equal? +expected+ - # - # Example: - # assert_not_same Object.new, Object.new - - public - def assert_not_same(expected, actual, message="") - full_message = build_message(message, < -with id expected to not be equal\\? to - -with id . -EOT - assert_block(full_message) { !actual.equal?(expected) } - end - - ## - # Passes if +expected+ != +actual+ - # - # Example: - # assert_not_equal 'some string', 5 - - public - def assert_not_equal(expected, actual, message="") - full_message = build_message(message, " expected to be != to\n.", expected, actual) - assert_block(full_message) { expected != actual } - end - - ## - # Passes if ! +object+ .nil? - # - # Example: - # assert_not_nil '1 two 3'.sub!(/two/, '2') - - public - def assert_not_nil(object, message="") - full_message = build_message(message, " expected to not be nil.", object) - assert_block(full_message){!object.nil?} - end - - ## - # Passes if +regexp+ !~ +string+ - # - # Example: - # assert_no_match(/two/, 'one 2 three') - - public - def assert_no_match(regexp, string, message="") - _wrap_assertion do - assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.") - full_message = build_message(message, " expected to not match\n.", regexp, string) - assert_block(full_message) { regexp !~ string } - end - end - - UncaughtThrow = {NameError => /^uncaught throw \`(.+)\'$/, - ThreadError => /^uncaught throw \`(.+)\' in thread /} #` - - ## - # Passes if the block throws +expected_symbol+ - # - # Example: - # assert_throws :done do - # throw :done - # end - - public - def assert_throws(expected_symbol, message="", &proc) - _wrap_assertion do - assert_instance_of(Symbol, expected_symbol, "assert_throws expects the symbol that should be thrown for its first argument") - assert_block("Should have passed a block to assert_throws."){block_given?} - caught = true - begin - catch(expected_symbol) do - proc.call - caught = false - end - full_message = build_message(message, " should have been thrown.", expected_symbol) - assert_block(full_message){caught} - rescue NameError, ThreadError => error - if UncaughtThrow[error.class] !~ error.message - raise error - end - full_message = build_message(message, " expected to be thrown but\n was thrown.", expected_symbol, $1.intern) - flunk(full_message) - end - end - end - - ## - # Passes if block does not throw anything. - # - # Example: - # assert_nothing_thrown do - # [1, 2].uniq - # end - - public - def assert_nothing_thrown(message="", &proc) - _wrap_assertion do - assert(block_given?, "Should have passed a block to assert_nothing_thrown") - begin - proc.call - rescue NameError, ThreadError => error - if UncaughtThrow[error.class] !~ error.message - raise error - end - full_message = build_message(message, " was thrown when nothing was expected", $1.intern) - flunk(full_message) - end - assert(true, "Expected nothing to be thrown") - end - end - - ## - # Passes if +expected_float+ and +actual_float+ are equal - # within +delta+ tolerance. - # - # Example: - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - - public - def assert_in_delta(expected_float, actual_float, delta, message="") - _wrap_assertion do - {expected_float => "first float", actual_float => "second float", delta => "delta"}.each do |float, name| - assert_respond_to(float, :to_f, "The arguments must respond to to_f; the #{name} did not") - end - assert_operator(delta, :>=, 0.0, "The delta should not be negative") - full_message = build_message(message, < and - expected to be within - of each other. -EOT - assert_block(full_message) { (expected_float.to_f - actual_float.to_f).abs <= delta.to_f } - end - end - - ## - # Passes if the method send returns a true value. - # - # +send_array+ is composed of: - # * A receiver - # * A method - # * Arguments to the method - # - # Example: - # assert_send [[1, 2], :include?, 4] - - public - def assert_send(send_array, message="") - _wrap_assertion do - assert_instance_of(Array, send_array, "assert_send requires an array of send information") - assert(send_array.size >= 2, "assert_send requires at least a receiver and a message name") - full_message = build_message(message, < expected to respond to - with a true value. -EOT - assert_block(full_message) { send_array[0].__send__(send_array[1], *send_array[2..-1]) } - end - end - - ## - # Builds a failure message. +head+ is added before the +template+ and - # +arguments+ replaces the '?'s positionally in the template. - - public - def build_message(head, template=nil, *arguments) - template &&= template.chomp - return AssertionMessage.new(head, template, arguments) - end - - private - def _wrap_assertion - @_assertion_wrapped ||= false - unless (@_assertion_wrapped) - @_assertion_wrapped = true - begin - add_assertion - return yield - ensure - @_assertion_wrapped = false - end - else - return yield - end - end - - ## - # Called whenever an assertion is made. Define this in classes that - # include Test::Unit::Assertions to record assertion counts. - - private - def add_assertion - end - - ## - # Select whether or not to use the pretty-printer. If this option is set - # to false before any assertions are made, pp.rb will not be required. - - public - def self.use_pp=(value) - AssertionMessage.use_pp = value - end - - # :stopdoc: - - class AssertionMessage - @use_pp = true - class << self - attr_accessor :use_pp - end - - class Literal - def initialize(value) - @value = value - end - - def inspect - @value.to_s - end - end - - class Template - def self.create(string) - parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : []) - self.new(parts) - end - - attr_reader :count - - def initialize(parts) - @parts = parts - @count = parts.find_all{|e| e == '?'}.size - end - - def result(parameters) - raise "The number of parameters does not match the number of substitutions." if(parameters.size != count) - params = parameters.dup - @parts.collect{|e| e == '?' ? params.shift : e.gsub(/\\\?/m, '?')}.join('') - end - end - - def self.literal(value) - Literal.new(value) - end - - include Util::BacktraceFilter - - def initialize(head, template_string, parameters) - @head = head - @template_string = template_string - @parameters = parameters - end - - def convert(object) - case object - when Exception - < -Message: <#{convert(object.message)}> ----Backtrace--- -#{filter_backtrace(object.backtrace).join("\n")} ---------------- -EOM - else - if(self.class.use_pp) - begin - require 'pp' - rescue LoadError - self.class.use_pp = false - return object.inspect - end unless(defined?(PP)) - PP.pp(object, '').chomp - else - object.inspect - end - end - end - - def template - @template ||= Template.create(@template_string) - end - - def add_period(string) - (string =~ /\.\Z/ ? string : string + '.') - end - - def to_s - message_parts = [] - if (@head) - head = @head.to_s - unless(head.empty?) - message_parts << add_period(head) - end - end - tail = template.result(@parameters.collect{|e| convert(e)}) - message_parts << tail unless(tail.empty?) - message_parts.join("\n") - end - end - - # :startdoc: - - end - end -end diff --git a/test/lib/test/unit/autorunner.rb b/test/lib/test/unit/autorunner.rb deleted file mode 100644 index 0dfc01c3..00000000 --- a/test/lib/test/unit/autorunner.rb +++ /dev/null @@ -1,219 +0,0 @@ -require 'test/unit/ui/testrunnerutilities' -require 'optparse' - -module Test - module Unit - class AutoRunner - def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block) - r = new(force_standalone || standalone?, &block) - r.base = default_dir - r.process_args(argv) - r.run - end - - def self.standalone? - return false unless("-e" == $0) - ObjectSpace.each_object(Class) do |klass| - return false if(klass < TestCase) - end - true - end - - RUNNERS = { - :console => proc do |r| - require 'test/unit/ui/console/testrunner' - Test::Unit::UI::Console::TestRunner - end, - :gtk => proc do |r| - require 'test/unit/ui/gtk/testrunner' - Test::Unit::UI::GTK::TestRunner - end, - :gtk2 => proc do |r| - require 'test/unit/ui/gtk2/testrunner' - Test::Unit::UI::GTK2::TestRunner - end, - :fox => proc do |r| - require 'test/unit/ui/fox/testrunner' - Test::Unit::UI::Fox::TestRunner - end, - :tk => proc do |r| - require 'test/unit/ui/tk/testrunner' - Test::Unit::UI::Tk::TestRunner - end, - } - - OUTPUT_LEVELS = [ - [:silent, UI::SILENT], - [:progress, UI::PROGRESS_ONLY], - [:normal, UI::NORMAL], - [:verbose, UI::VERBOSE], - ] - - COLLECTORS = { - :objectspace => proc do |r| - require 'test/unit/collector/objectspace' - c = Collector::ObjectSpace.new - c.filter = r.filters - c.collect($0.sub(/\.rb\Z/, '')) - end, - :dir => proc do |r| - require 'test/unit/collector/dir' - c = Collector::Dir.new - c.filter = r.filters - c.pattern.concat(r.pattern) if(r.pattern) - c.exclude.concat(r.exclude) if(r.exclude) - c.base = r.base - $:.push(r.base) if r.base - c.collect(*(r.to_run.empty? ? ['.'] : r.to_run)) - end, - } - - attr_reader :suite - attr_accessor :output_level, :filters, :to_run, :pattern, :exclude, :base, :workdir - attr_writer :runner, :collector - - def initialize(standalone) - Unit.run = true - @standalone = standalone - @runner = RUNNERS[:console] - @collector = COLLECTORS[(standalone ? :dir : :objectspace)] - @filters = [] - @to_run = [] - @output_level = UI::NORMAL - @workdir = nil - yield(self) if(block_given?) - end - - def process_args(args = ARGV) - begin - options.order!(args) {|arg| @to_run << arg} - rescue OptionParser::ParseError => e - puts e - puts options - $! = nil - abort - else - @filters << proc{false} unless(@filters.empty?) - end - not @to_run.empty? - end - - def options - @options ||= OptionParser.new do |o| - o.banner = "Test::Unit automatic runner." - o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]" - - o.on - o.on('-r', '--runner=RUNNER', RUNNERS, - "Use the given RUNNER.", - "(" + keyword_display(RUNNERS) + ")") do |r| - @runner = r - end - - if(@standalone) - o.on('-b', '--basedir=DIR', "Base directory of test suites.") do |b| - @base = b - end - - o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w| - @workdir = w - end - - o.on('-a', '--add=TORUN', Array, - "Add TORUN to the list of things to run;", - "can be a file or a directory.") do |a| - @to_run.concat(a) - end - - @pattern = [] - o.on('-p', '--pattern=PATTERN', Regexp, - "Match files to collect against PATTERN.") do |e| - @pattern << e - end - - @exclude = [] - o.on('-x', '--exclude=PATTERN', Regexp, - "Ignore files to collect against PATTERN.") do |e| - @exclude << e - end - end - - o.on('-n', '--name=NAME', String, - "Runs tests matching NAME.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.method_name ? true : nil} - else - @filters << proc{|t| n == t.method_name ? true : nil} - end - end - - o.on('-t', '--testcase=TESTCASE', String, - "Runs tests in TestCases matching TESTCASE.", - "(patterns may be used).") do |n| - n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) - case n - when Regexp - @filters << proc{|t| n =~ t.class.name ? true : nil} - else - @filters << proc{|t| n == t.class.name ? true : nil} - end - end - - o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]", - "Appends directory list to $LOAD_PATH.") do |dirs| - $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR)) - end - - o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS, - "Set the output level (default is verbose).", - "(" + keyword_display(OUTPUT_LEVELS) + ")") do |l| - @output_level = l || UI::VERBOSE - end - - o.on('--', - "Stop processing options so that the", - "remaining options will be passed to the", - "test."){o.terminate} - - o.on('-h', '--help', 'Display this help.'){puts o; exit} - - o.on_tail - o.on_tail('Deprecated options:') - - o.on_tail('--console', 'Console runner (use --runner).') do - warn("Deprecated option (--console).") - @runner = RUNNERS[:console] - end - - o.on_tail('--gtk', 'GTK runner (use --runner).') do - warn("Deprecated option (--gtk).") - @runner = RUNNERS[:gtk] - end - - o.on_tail('--fox', 'Fox runner (use --runner).') do - warn("Deprecated option (--fox).") - @runner = RUNNERS[:fox] - end - - o.on_tail - end - end - - def keyword_display(array) - list = array.collect {|e, *| e.to_s} - Array === array or list.sort! - list.collect {|e| e.sub(/^(.)([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')}.join(", ") - end - - def run - @suite = @collector[self] - result = @runner[self] or return false - Dir.chdir(@workdir) if @workdir - result.run(@suite, @output_level).passed? - end - end - end -end diff --git a/test/lib/test/unit/collector.rb b/test/lib/test/unit/collector.rb deleted file mode 100644 index 9e9e6541..00000000 --- a/test/lib/test/unit/collector.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Test - module Unit - module Collector - def initialize - @filters = [] - end - - def filter=(filters) - @filters = case(filters) - when Proc - [filters] - when Array - filters - end - end - - def add_suite(destination, suite) - to_delete = suite.tests.find_all{|t| !include?(t)} - to_delete.each{|t| suite.delete(t)} - destination << suite unless(suite.size == 0) - end - - def include?(test) - return true if(@filters.empty?) - @filters.each do |filter| - result = filter[test] - if(result.nil?) - next - elsif(!result) - return false - else - return true - end - end - true - end - - def sort(suites) - suites.sort_by{|s| s.name} - end - end - end -end diff --git a/test/lib/test/unit/collector/dir.rb b/test/lib/test/unit/collector/dir.rb deleted file mode 100644 index 97c8d284..00000000 --- a/test/lib/test/unit/collector/dir.rb +++ /dev/null @@ -1,107 +0,0 @@ -require 'test/unit/testsuite' -require 'test/unit/collector' - -module Test - module Unit - module Collector - class Dir - include Collector - - attr_reader :pattern, :exclude - attr_accessor :base - - def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil) - super() - @dir = dir - @file = file - @object_space = object_space - @req = req - @pattern = [/\btest_.*\.rb\Z/m] - @exclude = [] - end - - def collect(*from) - basedir = @base - $:.push(basedir) if basedir - if(from.empty?) - recursive_collect('.', find_test_cases) - elsif(from.size == 1) - recursive_collect(from.first, find_test_cases) - else - suites = [] - from.each do |f| - suite = recursive_collect(f, find_test_cases) - suites << suite unless(suite.tests.empty?) - end - suite = TestSuite.new("[#{from.join(', ')}]") - sort(suites).each{|s| suite << s} - suite - end - ensure - $:.delete_at($:.rindex(basedir)) if basedir - end - - def find_test_cases(ignore=[]) - cases = [] - @object_space.each_object(Class) do |c| - cases << c if(c < TestCase && !ignore.include?(c)) - end - ignore.concat(cases) - cases - end - - def recursive_collect(name, already_gathered) - sub_suites = [] - path = realdir(name) - if @file.directory?(path) - dir_name = name unless name == '.' - @dir.entries(path).each do |e| - next if(e == '.' || e == '..') - e_name = dir_name ? @file.join(dir_name, e) : e - if @file.directory?(realdir(e_name)) - next if /\ACVS\z/ =~ e - sub_suite = recursive_collect(e_name, already_gathered) - sub_suites << sub_suite unless(sub_suite.empty?) - else - next if /~\z/ =~ e_name or /\A\.\#/ =~ e - if @pattern and !@pattern.empty? - next unless @pattern.any? {|pat| pat =~ e_name} - end - if @exclude and !@exclude.empty? - next if @exclude.any? {|pat| pat =~ e_name} - end - collect_file(e_name, sub_suites, already_gathered) - end - end - else - collect_file(name, sub_suites, already_gathered) - end - suite = TestSuite.new(@file.basename(name)) - sort(sub_suites).each{|s| suite << s} - suite - end - - def collect_file(name, suites, already_gathered) - dir = @file.dirname(@file.expand_path(name, @base)) - $:.unshift(dir) - if(@req) - @req.require(name) - else - require(name) - end - find_test_cases(already_gathered).each{|t| add_suite(suites, t.suite)} - ensure - $:.delete_at($:.rindex(dir)) if(dir) - end - - def realdir(path) - if @base - @file.join(@base, path) - else - path - end - end - end - end - end -end diff --git a/test/lib/test/unit/error.rb b/test/lib/test/unit/error.rb deleted file mode 100644 index 43a813f7..00000000 --- a/test/lib/test/unit/error.rb +++ /dev/null @@ -1,56 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/backtracefilter' - -module Test - module Unit - - # Encapsulates an error in a test. Created by - # Test::Unit::TestCase when it rescues an exception thrown - # during the processing of a test. - class Error - include Util::BacktraceFilter - - attr_reader(:test_name, :exception) - - SINGLE_CHARACTER = 'E' - - # Creates a new Error with the given test_name and - # exception. - def initialize(test_name, exception) - @test_name = test_name - @exception = exception - end - - # Returns a single character representation of an error. - def single_character_display - SINGLE_CHARACTER - end - - # Returns the message associated with the error. - def message - "#{@exception.class.name}: #{@exception.message}" - end - - # Returns a brief version of the error description. - def short_display - "#@test_name: #{message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - backtrace = filter_backtrace(@exception.backtrace).join("\n ") - "Error:\n#@test_name:\n#{message}\n #{backtrace}" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - end -end diff --git a/test/lib/test/unit/failure.rb b/test/lib/test/unit/failure.rb deleted file mode 100644 index 832c9985..00000000 --- a/test/lib/test/unit/failure.rb +++ /dev/null @@ -1,51 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - - # Encapsulates a test failure. Created by Test::Unit::TestCase - # when an assertion fails. - class Failure - attr_reader :test_name, :location, :message - - SINGLE_CHARACTER = 'F' - - # Creates a new Failure with the given location and - # message. - def initialize(test_name, location, message) - @test_name = test_name - @location = location - @message = message - end - - # Returns a single character representation of a failure. - def single_character_display - SINGLE_CHARACTER - end - - # Returns a brief version of the error description. - def short_display - "#@test_name: #{@message.split("\n")[0]}" - end - - # Returns a verbose version of the error description. - def long_display - location_display = if(location.size == 1) - location[0].sub(/\A(.+:\d+).*/, ' [\\1]') - else - "\n [#{location.join("\n ")}]" - end - "Failure:\n#@test_name#{location_display}:\n#@message" - end - - # Overridden to return long_display. - def to_s - long_display - end - end - end -end diff --git a/test/lib/test/unit/testcase.rb b/test/lib/test/unit/testcase.rb deleted file mode 100644 index f53b460c..00000000 --- a/test/lib/test/unit/testcase.rb +++ /dev/null @@ -1,160 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/assertions' -require 'test/unit/failure' -require 'test/unit/error' -require 'test/unit/testsuite' -require 'test/unit/assertionfailederror' -require 'test/unit/util/backtracefilter' - -module Test - module Unit - - # Ties everything together. If you subclass and add your own - # test methods, it takes care of making them into tests and - # wrapping those tests into a suite. It also does the - # nitty-gritty of actually running an individual test and - # collecting its results into a Test::Unit::TestResult object. - class TestCase - include Assertions - include Util::BacktraceFilter - - attr_reader :method_name - - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - ## - # These exceptions are not caught by #run. - - PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException, Interrupt, - SystemExit] - - # Creates a new instance of the fixture for running the - # test represented by test_method_name. - def initialize(test_method_name) - unless(respond_to?(test_method_name) and - (method(test_method_name).arity == 0 || - method(test_method_name).arity == -1)) - throw :invalid_test - end - @method_name = test_method_name - @test_passed = true - end - - # Rolls up all of the test* methods in the fixture into - # one suite, creating a new instance of the fixture for - # each method. - def self.suite - method_names = public_instance_methods(true) - tests = method_names.delete_if {|method_name| method_name !~ /^test./} - suite = TestSuite.new(name) - tests.sort.each do - |test| - catch(:invalid_test) do - suite << new(test) - end - end - if (suite.empty?) - catch(:invalid_test) do - suite << new("default_test") - end - end - return suite - end - - # Runs the individual test method represented by this - # instance of the fixture, collecting statistics, failures - # and errors in result. - def run(result) - yield(STARTED, name) - @_result = result - begin - setup - __send__(@method_name) - rescue AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue Exception - raise if PASSTHROUGH_EXCEPTIONS.include? $!.class - add_error($!) - ensure - begin - teardown - rescue AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue Exception - raise if PASSTHROUGH_EXCEPTIONS.include? $!.class - add_error($!) - end - end - result.add_run - yield(FINISHED, name) - end - - # Called before every test method runs. Can be used - # to set up fixture information. - def setup - end - - # Called after every test method runs. Can be used to tear - # down fixture information. - def teardown - end - - def default_test - flunk("No tests were specified") - end - - # Returns whether this individual test passed or - # not. Primarily for use in teardown so that artifacts - # can be left behind if the test fails. - def passed? - return @test_passed - end - private :passed? - - def size - 1 - end - - def add_assertion - @_result.add_assertion - end - private :add_assertion - - def add_failure(message, all_locations=caller()) - @test_passed = false - @_result.add_failure(Failure.new(name, filter_backtrace(all_locations), message)) - end - private :add_failure - - def add_error(exception) - @test_passed = false - @_result.add_error(Error.new(name, exception)) - end - private :add_error - - # Returns a human-readable name for the specific test that - # this instance of TestCase represents. - def name - "#{@method_name}(#{self.class.name})" - end - - # Overridden to return #name. - def to_s - name - end - - # It's handy to be able to compare TestCase instances. - def ==(other) - return false unless(other.kind_of?(self.class)) - return false unless(@method_name == other.method_name) - self.class == other.class - end - end - end -end diff --git a/test/lib/test/unit/testresult.rb b/test/lib/test/unit/testresult.rb deleted file mode 100644 index e3a472ef..00000000 --- a/test/lib/test/unit/testresult.rb +++ /dev/null @@ -1,80 +0,0 @@ -#-- -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/observable' - -module Test - module Unit - - # Collects Test::Unit::Failure and Test::Unit::Error so that - # they can be displayed to the user. To this end, observers - # can be added to it, allowing the dynamic updating of, say, a - # UI. - class TestResult - include Util::Observable - - CHANGED = "CHANGED" - FAULT = "FAULT" - - attr_reader(:run_count, :assertion_count) - - # Constructs a new, empty TestResult. - def initialize - @run_count, @assertion_count = 0, 0 - @failures, @errors = Array.new, Array.new - end - - # Records a test run. - def add_run - @run_count += 1 - notify_listeners(CHANGED, self) - end - - # Records a Test::Unit::Failure. - def add_failure(failure) - @failures << failure - notify_listeners(FAULT, failure) - notify_listeners(CHANGED, self) - end - - # Records a Test::Unit::Error. - def add_error(error) - @errors << error - notify_listeners(FAULT, error) - notify_listeners(CHANGED, self) - end - - # Records an individual assertion. - def add_assertion - @assertion_count += 1 - notify_listeners(CHANGED, self) - end - - # Returns a string contain the recorded runs, assertions, - # failures and errors in this TestResult. - def to_s - "#{run_count} tests, #{assertion_count} assertions, #{failure_count} failures, #{error_count} errors" - end - - # Returns whether or not this TestResult represents - # successful completion. - def passed? - return @failures.empty? && @errors.empty? - end - - # Returns the number of failures this TestResult has - # recorded. - def failure_count - return @failures.size - end - - # Returns the number of errors this TestResult has - # recorded. - def error_count - return @errors.size - end - end - end -end diff --git a/test/lib/test/unit/testsuite.rb b/test/lib/test/unit/testsuite.rb deleted file mode 100644 index 6fea976c..00000000 --- a/test/lib/test/unit/testsuite.rb +++ /dev/null @@ -1,76 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - - # A collection of tests which can be #run. - # - # Note: It is easy to confuse a TestSuite instance with - # something that has a static suite method; I know because _I_ - # have trouble keeping them straight. Think of something that - # has a suite method as simply providing a way to get a - # meaningful TestSuite instance. - class TestSuite - attr_reader :name, :tests - - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - # Creates a new TestSuite with the given name. - def initialize(name="Unnamed TestSuite") - @name = name - @tests = [] - end - - # Runs the tests and/or suites contained in this - # TestSuite. - def run(result, &progress_block) - yield(STARTED, name) - @tests.each do |test| - test.run(result, &progress_block) - end - yield(FINISHED, name) - end - - # Adds the test to the suite. - def <<(test) - @tests << test - self - end - - def delete(test) - @tests.delete(test) - end - - # Retuns the rolled up number of tests in this suite; - # i.e. if the suite contains other suites, it counts the - # tests within those suites, not the suites themselves. - def size - total_size = 0 - @tests.each { |test| total_size += test.size } - total_size - end - - def empty? - tests.empty? - end - - # Overridden to return the name given the suite at - # creation. - def to_s - @name - end - - # It's handy to be able to compare TestSuite instances. - def ==(other) - return false unless(other.kind_of?(self.class)) - return false unless(@name == other.name) - @tests == other.tests - end - end - end -end diff --git a/test/lib/test/unit/ui/console/testrunner.rb b/test/lib/test/unit/ui/console/testrunner.rb deleted file mode 100644 index 6b600e31..00000000 --- a/test/lib/test/unit/ui/console/testrunner.rb +++ /dev/null @@ -1,127 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/ui/testrunnermediator' -require 'test/unit/ui/testrunnerutilities' - -module Test - module Unit - module UI - module Console - - # Runs a Test::Unit::TestSuite on the console. - class TestRunner - extend TestRunnerUtilities - - # Creates a new TestRunner for running the passed - # suite. If quiet_mode is true, the output while - # running is limited to progress dots, errors and - # failures, and the final result. io specifies - # where runner output should go to; defaults to - # STDOUT. - def initialize(suite, output_level=NORMAL, io=STDOUT) - if (suite.respond_to?(:suite)) - @suite = suite.suite - else - @suite = suite - end - @output_level = output_level - @io = io - @already_outputted = false - @faults = [] - end - - # Begins the test run. - def start - setup_mediator - attach_to_mediator - return start_mediator - end - - private - def setup_mediator - @mediator = create_mediator(@suite) - suite_name = @suite.to_s - if ( @suite.kind_of?(Module) ) - suite_name = @suite.name - end - output("Loaded suite #{suite_name}") - end - - def create_mediator(suite) - return TestRunnerMediator.new(suite) - end - - def attach_to_mediator - @mediator.add_listener(TestResult::FAULT, &method(:add_fault)) - @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started)) - @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished)) - @mediator.add_listener(TestCase::STARTED, &method(:test_started)) - @mediator.add_listener(TestCase::FINISHED, &method(:test_finished)) - end - - def start_mediator - return @mediator.run_suite - end - - def add_fault(fault) - @faults << fault - output_single(fault.single_character_display, PROGRESS_ONLY) - @already_outputted = true - end - - def started(result) - @result = result - output("Started") - end - - def finished(elapsed_time) - nl - output("Finished in #{elapsed_time} seconds.") - @faults.each_with_index do |fault, index| - nl - output("%3d) %s" % [index + 1, fault.long_display]) - end - nl - output(@result) - end - - def test_started(name) - output_single(name + ": ", VERBOSE) - end - - def test_finished(name) - output_single(".", PROGRESS_ONLY) unless (@already_outputted) - nl(VERBOSE) - @already_outputted = false - end - - def nl(level=NORMAL) - output("", level) - end - - def output(something, level=NORMAL) - @io.puts(something) if (output?(level)) - @io.flush - end - - def output_single(something, level=NORMAL) - @io.write(something) if (output?(level)) - @io.flush - end - - def output?(level) - level <= @output_level - end - end - end - end - end -end - -if __FILE__ == $0 - Test::Unit::UI::Console::TestRunner.start_command_line_test -end diff --git a/test/lib/test/unit/ui/testrunnermediator.rb b/test/lib/test/unit/ui/testrunnermediator.rb deleted file mode 100644 index d34510d1..00000000 --- a/test/lib/test/unit/ui/testrunnermediator.rb +++ /dev/null @@ -1,68 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit' -require 'test/unit/util/observable' -require 'test/unit/testresult' - -module Test - module Unit - module UI - - # Provides an interface to write any given UI against, - # hopefully making it easy to write new UIs. - class TestRunnerMediator - RESET = name + "::RESET" - STARTED = name + "::STARTED" - FINISHED = name + "::FINISHED" - - include Util::Observable - - # Creates a new TestRunnerMediator initialized to run - # the passed suite. - def initialize(suite) - @suite = suite - end - - # Runs the suite the TestRunnerMediator was created - # with. - def run_suite - Unit.run = true - begin_time = Time.now - notify_listeners(RESET, @suite.size) - result = create_result - notify_listeners(STARTED, result) - result_listener = result.add_listener(TestResult::CHANGED) do |updated_result| - notify_listeners(TestResult::CHANGED, updated_result) - end - - fault_listener = result.add_listener(TestResult::FAULT) do |fault| - notify_listeners(TestResult::FAULT, fault) - end - - @suite.run(result) do |channel, value| - notify_listeners(channel, value) - end - - result.remove_listener(TestResult::FAULT, fault_listener) - result.remove_listener(TestResult::CHANGED, result_listener) - end_time = Time.now - elapsed_time = end_time - begin_time - notify_listeners(FINISHED, elapsed_time) #"Finished in #{elapsed_time} seconds.") - return result - end - - private - # A factory method to create the result the mediator - # should run with. Can be overridden by subclasses if - # one wants to use a different result. - def create_result - return TestResult.new - end - end - end - end -end diff --git a/test/lib/test/unit/ui/testrunnerutilities.rb b/test/lib/test/unit/ui/testrunnerutilities.rb deleted file mode 100644 index 70b885bd..00000000 --- a/test/lib/test/unit/ui/testrunnerutilities.rb +++ /dev/null @@ -1,46 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - module UI - - SILENT = 0 - PROGRESS_ONLY = 1 - NORMAL = 2 - VERBOSE = 3 - - # Provides some utilities common to most, if not all, - # TestRunners. - # - #-- - # - # Perhaps there ought to be a TestRunner superclass? There - # seems to be a decent amount of shared code between test - # runners. - - module TestRunnerUtilities - - # Creates a new TestRunner and runs the suite. - def run(suite, output_level=NORMAL) - return new(suite, output_level).start - end - - # Takes care of the ARGV parsing and suite - # determination necessary for running one of the - # TestRunners from the command line. - def start_command_line_test - if ARGV.empty? - puts "You should supply the name of a test suite file to the runner" - exit - end - require ARGV[0].gsub(/.+::/, '') - new(eval(ARGV[0])).start - end - end - end - end -end diff --git a/test/lib/test/unit/util/backtracefilter.rb b/test/lib/test/unit/util/backtracefilter.rb deleted file mode 100644 index 7ebec2df..00000000 --- a/test/lib/test/unit/util/backtracefilter.rb +++ /dev/null @@ -1,40 +0,0 @@ -module Test - module Unit - module Util - module BacktraceFilter - TESTUNIT_FILE_SEPARATORS = %r{[\\/:]} - TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3] - TESTUNIT_RB_FILE = /\.rb\Z/ - - def filter_backtrace(backtrace, prefix=nil) - return ["No backtrace"] unless(backtrace) - split_p = if(prefix) - prefix.split(TESTUNIT_FILE_SEPARATORS) - else - TESTUNIT_PREFIX - end - match = proc do |e| - split_e = e.split(TESTUNIT_FILE_SEPARATORS)[0, split_p.size] - next false unless(split_e[0..-2] == split_p[0..-2]) - split_e[-1].sub(TESTUNIT_RB_FILE, '') == split_p[-1] - end - return backtrace unless(backtrace.detect(&match)) - found_prefix = false - new_backtrace = backtrace.reverse.reject do |e| - if(match[e]) - found_prefix = true - true - elsif(found_prefix) - false - else - true - end - end.reverse - new_backtrace = (new_backtrace.empty? ? backtrace : new_backtrace) - new_backtrace = new_backtrace.reject(&match) - new_backtrace.empty? ? backtrace : new_backtrace - end - end - end - end -end diff --git a/test/lib/test/unit/util/observable.rb b/test/lib/test/unit/util/observable.rb deleted file mode 100644 index 3567d342..00000000 --- a/test/lib/test/unit/util/observable.rb +++ /dev/null @@ -1,90 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -require 'test/unit/util/procwrapper' - -module Test - module Unit - module Util - - # This is a utility class that allows anything mixing - # it in to notify a set of listeners about interesting - # events. - module Observable - # We use this for defaults since nil might mean something - NOTHING = "NOTHING/#{__id__}" - - # Adds the passed proc as a listener on the - # channel indicated by channel_name. listener_key - # is used to remove the listener later; if none is - # specified, the proc itself is used. - # - # Whatever is used as the listener_key is - # returned, making it very easy to use the proc - # itself as the listener_key: - # - # listener = add_listener("Channel") { ... } - # remove_listener("Channel", listener) - def add_listener(channel_name, listener_key=NOTHING, &listener) # :yields: value - unless(block_given?) - raise ArgumentError.new("No callback was passed as a listener") - end - - key = listener_key - if (listener_key == NOTHING) - listener_key = listener - key = ProcWrapper.new(listener) - end - - channels[channel_name] ||= {} - channels[channel_name][key] = listener - return listener_key - end - - # Removes the listener indicated by listener_key - # from the channel indicated by - # channel_name. Returns the registered proc, or - # nil if none was found. - def remove_listener(channel_name, listener_key) - channel = channels[channel_name] - return nil unless (channel) - key = listener_key - if (listener_key.instance_of?(Proc)) - key = ProcWrapper.new(listener_key) - end - if (channel.has_key?(key)) - return channel.delete(key) - end - return nil - end - - # Calls all the procs registered on the channel - # indicated by channel_name. If value is - # specified, it is passed in to the procs, - # otherwise they are called with no arguments. - # - #-- - # - # Perhaps this should be private? Would it ever - # make sense for an external class to call this - # method directly? - def notify_listeners(channel_name, *arguments) - channel = channels[channel_name] - return 0 unless (channel) - listeners = channel.values - listeners.each { |listener| listener.call(*arguments) } - return listeners.size - end - - private - def channels - @channels ||= {} - return @channels - end - end - end - end -end diff --git a/test/lib/test/unit/util/procwrapper.rb b/test/lib/test/unit/util/procwrapper.rb deleted file mode 100644 index ad725218..00000000 --- a/test/lib/test/unit/util/procwrapper.rb +++ /dev/null @@ -1,48 +0,0 @@ -#-- -# -# Author:: Nathaniel Talbott. -# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. -# License:: Ruby license. - -module Test - module Unit - module Util - - # Allows the storage of a Proc passed through '&' in a - # hash. - # - # Note: this may be inefficient, since the hash being - # used is not necessarily very good. In Observable, - # efficiency is not too important, since the hash is - # only accessed when adding and removing listeners, - # not when notifying. - - class ProcWrapper - - # Creates a new wrapper for a_proc. - def initialize(a_proc) - @a_proc = a_proc - @hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex - end - - def hash - return @hash - end - - def ==(other) - case(other) - when ProcWrapper - return @a_proc == other.to_proc - else - return super - end - end - alias :eql? :== - - def to_proc - return @a_proc - end - end - end - end -end diff --git a/test/unit/suite.rb b/test/unit/suite.rb index 7d20dc0c..26ebe1b5 100755 --- a/test/unit/suite.rb +++ b/test/unit/suite.rb @@ -1,4 +1,4 @@ -require 'simplecov' if RUBY_VERSION >= '1.9' +require 'simplecov' require 'test/unit' require 'rubygems' From bbf267cbc24ae96a746c2b77493bb2431601d722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 18 Jan 2020 18:05:07 +0100 Subject: [PATCH 2/3] Drop support for the rest of EOL'd rubies --- .travis.yml | 4 ---- Gemfile | 2 +- README.markdown | 2 +- README_INDEX.rdoc | 2 +- coderay.gemspec | 2 +- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index dbeb2957..9ca7b13a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,6 @@ env: - "CC_TEST_REPORTER_ID=faa393209ff0a104cf37511a9a03510bcee37951971b1ca4ffc2af217851d47e" language: ruby rvm: - - 2.0 - - 2.1 - - 2.2 - - 2.3 - 2.4 - 2.5 - 2.6 diff --git a/Gemfile b/Gemfile index 655342f5..12ec0a91 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gemspec group :development do gem 'bundler' gem 'rake', '>= 10.5' - gem 'rdoc', Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2') ? '< 6' : '>= 6' + gem 'rdoc', '>= 6' gem 'RedCloth', RUBY_PLATFORM == 'java' ? '= 4.2.9' : '>= 4.0.3' gem 'rspec', '~> 3.9.0' gem 'shoulda-context', '>= 1.2.1' diff --git a/README.markdown b/README.markdown index 6ff6893e..46d7080e 100644 --- a/README.markdown +++ b/README.markdown @@ -15,7 +15,7 @@ You put your code in, and you get it back colored; Keywords, strings, floats, co ### Dependencies -CodeRay needs Ruby 2.0+. It also runs on JRuby. +CodeRay needs Ruby 2.4+. It also runs on JRuby. ## Example Usage diff --git a/README_INDEX.rdoc b/README_INDEX.rdoc index b6d0215b..1539d992 100644 --- a/README_INDEX.rdoc +++ b/README_INDEX.rdoc @@ -26,7 +26,7 @@ floats, comments - all in different colors. And with line numbers. === Dependencies -CodeRay needs Ruby 2.0+. It also runs on Rubinius and JRuby. +CodeRay needs Ruby 2.4+. It also runs on Rubinius and JRuby. == Example Usage diff --git a/coderay.gemspec b/coderay.gemspec index d93d0a81..29ee8276 100644 --- a/coderay.gemspec +++ b/coderay.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.license = 'MIT' s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 2.0.0' + s.required_ruby_version = '>= 2.4.0' readme_file = 'README_INDEX.rdoc' From a5d9fe7220759ac9984a5c04baeccccdbbe90ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 30 May 2020 11:46:08 +0200 Subject: [PATCH 3/3] Whitespace --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 12ec0a91..1183154f 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ group :development do gem 'RedCloth', RUBY_PLATFORM == 'java' ? '= 4.2.9' : '>= 4.0.3' gem 'rspec', '~> 3.9.0' gem 'shoulda-context', '>= 1.2.1' - gem 'simplecov', RUBY_VERSION < '2.7' ? '~> 0.17.1' : '>= 0.18.5' + gem 'simplecov', RUBY_VERSION < '2.7' ? '~> 0.17.1' : '>= 0.18.5' gem 'term-ansicolor', '>= 1.3.2' gem 'test-unit', '>= 3.0' gem 'tins', '>= 1.6.0'