[DRE-commits] [ruby-test-unit] 01/03: New upstream version 3.2.5
Lucas Nussbaum
lucas at moszumanska.debian.org
Tue Jul 4 20:51:20 UTC 2017
This is an automated email from the git hooks/post-receive script.
lucas pushed a commit to branch master
in repository ruby-test-unit.
commit 83a7a0a6420939ffe7cebc24c4bb4a89db087640
Author: Lucas Nussbaum <lucas at debian.org>
Date: Mon Jul 3 21:28:55 2017 +0200
New upstream version 3.2.5
---
COPYING | 5 +-
README.md | 18 +--
Rakefile | 11 +-
doc/text/getting-started.md | 246 +++++++++++++++++++++++++++++
doc/text/news.md | 177 ++++++++++++++++++++-
lib/test/unit/assertions.rb | 148 +++++++++++-------
lib/test/unit/attribute.rb | 64 ++++++++
lib/test/unit/autorunner.rb | 30 +++-
lib/test/unit/collector/load.rb | 2 +
lib/test/unit/diff.rb | 22 +--
lib/test/unit/fixture.rb | 3 +
lib/test/unit/testcase.rb | 141 +++++++++++------
lib/test/unit/testresult.rb | 7 +
lib/test/unit/ui/console/testrunner.rb | 10 +-
lib/test/unit/ui/emacs/testrunner.rb | 10 +-
lib/test/unit/ui/testrunnermediator.rb | 16 +-
lib/test/unit/util/backtracefilter.rb | 4 +-
lib/test/unit/version.rb | 2 +-
metadata.yml | 277 ---------------------------------
test-unit.gemspec | 49 ++++++
test/collector/test-descendant.rb | 4 +
test/collector/test_dir.rb | 9 +-
test/collector/test_objectspace.rb | 12 +-
test/test-assertions.rb | 223 ++++++++++++++------------
test/test-test-case.rb | 113 +++++++++++++-
test/test-test-suite.rb | 1 +
26 files changed, 1065 insertions(+), 539 deletions(-)
diff --git a/COPYING b/COPYING
index 3205abf..1aa77da 100644
--- a/COPYING
+++ b/COPYING
@@ -61,4 +61,7 @@ version 2 (see the file GPL), or the conditions below:
Exceptions
----------
- * lib/test/unit/diff.rb: PSFL
+ * lib/test/unit/diff.rb: This license, PSF license and/or LGPLv2.1
+ or later
+
+ * lib/test-unit.rb: This license and/or LGPLv2.1 or later
diff --git a/README.md b/README.md
index 9308f7c..c60ab86 100644
--- a/README.md
+++ b/README.md
@@ -10,31 +10,31 @@
An xUnit family unit testing framework for Ruby.
-Test::Unit (test-unit) is unit testing framework for Ruby, based on xUnit
+test-unit (Test::Unit) is unit testing framework for Ruby, based on xUnit
principles. These were originally designed by Kent Beck, creator of extreme
programming software development methodology, for Smalltalk's SUnit. It allows
writing tests, checking results and automated testing in Ruby.
## Features
-* Test::Unit 1.2.3 is the original Test::Unit, taken
+* test-unit 1.2.3 is the original test-unit, taken
straight from the ruby distribution. It is being
distributed as a gem to allow tool builders to use it as a
stand-alone package. (The test framework in ruby is going
to radically change very soon).
* test-unit will be improved actively and may break
- compatiblity with Test::Unit 1.2.3. (We will not hope it
+ compatiblity with test-unit 1.2.3. (We will not hope it
if it isn't needed.)
* Some features exist as separated gems like GUI test
runner. (Tk, GTK+ and Fox) test-unit-full gem package
- provides for installing all Test::Unit related gems
+ provides for installing all test-unit related gems
easily.
## How To
-* [How To](doc/text/how-to.md) (link for GitHub)
+* [How To](https://github.com/test-unit/test-unit/blob/master/doc/text/how-to.md) (link for GitHub)
* {file:doc/text/how-to.md How To} (link for YARD)
## Install
@@ -43,7 +43,7 @@ writing tests, checking results and automated testing in Ruby.
% sudo gem install test-unit
</pre>
-If you want to use full Test::Unit features:
+If you want to use full test-unit features:
<pre>
% sudo gem install test-unit-full
@@ -57,8 +57,8 @@ This software is distributed under the same terms as ruby.
Exception:
- * lib/test/unit/diff.rb is a double license of the Ruby license and
- PSF license.
+ * lib/test/unit/diff.rb is a triple license of the Ruby license,
+ PSF license and LGPLv2.1 or later.
* lib/test-unit.rb is a dual license of the Ruby license and LGPLv2.1
or later.
@@ -77,7 +77,7 @@ Exception:
### Images
-* Mayu & Co.: kinotan icons: http://cocooooooon.com/kinotan/
+* Mayu & Co.: kinotan icons
## Thanks
diff --git a/Rakefile b/Rakefile
index 8d4fda1..1e045a9 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,6 +1,6 @@
# -*- ruby -*-
#
-# Copyright (C) 2008-2013 Kouhei Sutou <kou at clear-code.com>
+# Copyright (C) 2008-2017 Kouhei Sutou <kou at clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,15 @@
Encoding.default_internal = "UTF-8" if defined?(Encoding.default_internal)
+# TODO: Remove me when we drop Ruby 1.9 support.
+unless "".respond_to?(:b)
+ class String
+ def b
+ dup.force_encoding("ASCII-8BIT")
+ end
+ end
+end
+
require "erb"
require "yaml"
require "rubygems"
diff --git a/doc/text/getting-started.md b/doc/text/getting-started.md
new file mode 100644
index 0000000..f49bd65
--- /dev/null
+++ b/doc/text/getting-started.md
@@ -0,0 +1,246 @@
+## 1. First step of the `test-unit`
+
+Let's getting start `test-unit`.
+
+This document creates an example gem package called `sample` with the `test-unit` testing framework.
+
+## 2. Install bundler and test-unit.
+
+* First, install the `bundler` gem for generating gem template.
+* Second, install the `test-unit` itself.
+
+~~~
+!!!plain
+gem install bundler
+gem install test-unit
+~~~
+
+The `gem list` command output installed packages.
+You will find the following lines.
+
+~~~
+!!!plain
+gem list
+...
+bundler (1.14.6)
+...
+test-unit (3.2.3)
+~~~
+
+## 3. Create gem template.
+
+Next, create a gem template using `bundler` command.
+This command generates package skeleton with a testing framework.
+However, this command can't generate test templates for `test-unit`.
+
+So, First create gem template with the `minitest` testing framework.
+(It's similar to `unit-test`).
+After that, replace some files for `test-unit`.
+
+The `bundle gem -t minitest sample` command will generate the following files.
+
+~~~
+!!!plain
+.
+|-- Gemfile
+|-- README.md
+|-- Rakefile
+|-- bin
+| |-- console
+| `-- setup
+|-- lib
+| |-- sample
+| | `-- version.rb
+| `-- sample.rb
+|-- sample.gemspec # <- Modify
+`-- test
+ |-- sample_test.rb # <- Modify
+ `-- test_helper.rb # <- Modify
+~~~
+
+## 4. Edit files for `test-unit`
+
+### 4.1. Edit gemspec
+
+Edit `sample.gemspec` like the below.
+Replace `minitest` line to `test-unit`.
+
+Before
+
+~~~
+!!!ruby
+ spec.add_development_dependency "minitest", "~> 5.0"
+~~~
+
+After
+
+~~~
+!!!ruby
+ spec.add_development_dependency "test-unit", "~> 3.2.3"
+~~~
+
+### 4.2. Edit `test/test_helper.rb`
+
+Next, edit the `test/test_helper.rb` file.
+
+Before
+
+~~~
+!!!ruby
+$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+require 'sample'
+
+require 'minitest/autorun' # <-- Modify this line.
+~~~
+
+After
+
+~~~
+!!!ruby
+$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+require 'sample'
+
+require 'test/unit' # <-- After modification.
+~~~
+
+### 4.3 Rakefile (No edit)
+
+This file doesn't need to modify.
+The output is the below.
+
+~~~
+!!!ruby
+require "bundler/gem_tasks"
+require "rake/testtask"
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << "test"
+ t.libs << "lib"
+ t.test_files = FileList['test/**/*_test.rb']
+end
+
+task :default => :test
+~~~
+
+### 4.4 Edit `test/sample_test.rb`
+
+The bundler generate the file `test/sample_test.rb`.
+This file originally templates for `minitest`.
+
+Let's modify this file for `test-unit`
+
+before
+
+~~~
+!!!ruby
+require 'test_helper'
+
+class SampleTest < Minitest::Test # <- Modify here
+ def test_that_it_has_a_version_number
+ refute_nil ::Sample::VERSION
+ end
+
+ def test_it_does_something_useful
+ assert false
+ end
+end
+~~~
+
+After
+
+~~~
+!!!ruby
+require 'test_helper'
+
+class SampleTest < Test::Unit::TestCase # <- After modification
+ def test_that_it_has_a_version_number
+ refute_nil ::Sample::VERSION
+ end
+
+ def test_it_does_something_useful
+ assert false
+ end
+end
+~~~
+
+## 5. Execute test.
+
+The `rake test` command execute test scenarios in the `test` directory.
+Now it tries to two tests. One will success the other one fails.
+
+~~~
+!!!plain
+rake test
+Loaded suite
+/path/to/ruby/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_test_loader
+Started
+F
+================================================================================
+Failure: <false> is not true.
+test_it_does_something_useful(SampleTest)
+/path/to/sample/test/sample_test.rb:9:in `test_it_does_something_useful'
+ 6: end
+ 7:
+ 8: def test_it_does_something_useful
+ => 9: assert false
+ 10: end
+ 11: end
+================================================================================
+.
+
+Finished in 0.011521 seconds.
+--------------------------------------------------------------------------------
+2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
+50% passed
+--------------------------------------------------------------------------------
+173.60 tests/s, 173.60 assertions/s
+rake aborted!
+Command failed with status (1)
+
+Tasks: TOP => test
+(See full trace by running task with --trace)
+~~~
+
+## 6. Create original tests.
+
+Let's create your original tests with the following rules.
+
+* Create a test file in the `test` directory.
+* The file needs suffix `xxx_test.rb`.
+* You can put test file into the subdirectory like `test/sub`.
+
+Example directory layout.
+
+~~~
+!!!plain
+test
+|-- sample_test.rb
+|-- sub
+| `-- sample2_test.rb
+`-- test_helper.rb
+~~~
+
+Example test file in the sub directory.
+
+~~~
+!!!ruby
+require 'test_helper'
+
+module Sub
+ class Sample2Test < Test::Unit::TestCase
+ def test_that_it_has_a_version_number
+ refute_nil ::Sample::VERSION
+ end
+
+ def test_it_does_something_useful
+ assert false
+ end
+ end
+end
+~~~
+
+## 7. For more inforomation
+
+Let's read the official document.
+
+* [test-unit](http://test-unit.github.io/index.html)
diff --git a/doc/text/news.md b/doc/text/news.md
index 17468e4..c60c83c 100644
--- a/doc/text/news.md
+++ b/doc/text/news.md
@@ -1,5 +1,180 @@
# News
+## 3.2.5 - 2017-06-24 {#version-3-2-5}
+
+### Improvements
+
+ * Supported `--enable-frozen-string-literal` `ruby` option.
+ [GitHub#149][Reported by Pat Allan]
+
+### Thanks
+
+ * Pat Allan
+
+## 3.2.4 - 2017-05-23 {#version-3-2-4}
+
+### Improvements
+
+ * Updated tests for Ruby 2.4. [GitHUb#136][Patch by Kazuki Tsujimoto]
+
+ * Supported power\_assert 1.0.0. [GitHub#137][Patch by Kazuki Tsujimoto]
+
+ * Added the getting started document.
+ [GitHub#139][GitHub#141][Patch by Hiroyuki Sato]
+
+ * Added the document for `attribute`.
+ [GitHub#143][Patch by Fumiaki MATSUSHIMA]
+
+ * Improved a link for GitHub. [GitHub#144][Patch by rochefort]
+
+ * Updated `.travis.yml`. [GitHub#145][Patch by Jun Aruga]
+
+### Fixes
+
+ * Fixed a contributor name. [GitHub#131][Patch by Akira Matsuda]
+
+ * Fixed typos in document. [GitHub#132][Patch by Akira Matsuda]
+
+ * Fixed typos in document. [GitHub#134][Patch by Yuji Yaginuma]
+
+ * Fixed a bug that data label with "(" isn't supported.
+ [GitHub#135][Reported by Kazuki Tsujimoto]
+
+ * Fixed assertion message in English.
+ [GitHub#133][Reported by Khalil Fazal]
+
+ * Fixed a typo in typo fix. [GitHub#138][Patch by kami]
+
+ * Fixed a bug that target location finder may return wrong
+ location. [GitHub#146][Patch by Yuki Ito]
+
+ * Fixed a bug that `--no-show-detail-immediately` raises an error.
+ [GitHub#147][Reported by MSP-Greg]
+
+### Thanks
+
+ * Akira Matsuda
+
+ * Yuji Yaginuma
+
+ * Kazuki Tsujimoto
+
+ * Khalil Fazal
+
+ * kami
+
+ * Hiroyuki Sato
+
+ * Fumiaki MATSUSHIMA
+
+ * rochefort
+
+ * Jun Aruga
+
+ * Yuki Ito
+
+ * MSP-Greg
+
+## 3.2.3 - 2016-11-25 {#version-3-2-3}
+
+### Fixes
+
+ * Fixed a bug that `--order` isn't applied.
+ [GitHub#129][Reported by Vít Ondruch]
+
+### Thanks
+
+ * Vít Ondruch
+
+## 3.2.2 - 2016-11-02 {#version-3-2-2}
+
+### Improvements
+
+ * Improved Travis CI configuration.
+ [GitHub#123][Patch by Ryunosuke Sato]
+
+ * Supported Java native exception.
+ [GitHub#126][Reported by Bob Saveland]
+
+### Fixes
+
+ * doc: Fixed markup. [GitHub#127][Patch by Tomohiro Hashidate]
+
+ * Fixed a bug that `--location=LINE` may not detect a test when
+ fixtures are defined before any tests:
+
+ 1 class MyTestCase < Test::Unit::TestCase
+ 2 setup do
+ 3 end
+ 4
+ 5 test "xxx" do
+ 6 end
+ 7 end
+
+ `--location=5` couldn't find the `xxx` test.
+
+ [Reported by Ryota Sasabe]
+
+### Thanks
+
+ * Ryunosuke Sato
+
+ * Tomohiro Hashidate
+
+ * Bob Saveland
+
+ * Ryota Sasabe
+
+## 3.2.1 - 2016-07-19 {#version-3-2-1}
+
+### Improvements
+
+ * Clarified lib/test/unit/diff.rb license. It's a triple license of
+ the Ruby license, PSF license and LGPLv2.1 or later.
+ [Reported by Luisa Pace]
+
+ * Reported norification when data driven test doesn't have
+ parameter.
+ [GitHub#122][Reported by Satoshi "Moris" Tagomori]
+
+### Thanks
+
+ * Luisa Pace
+
+ * Satoshi "Moris" Tagomori
+
+## 3.2.0 - 2016-06-12 {#version-3-2-0}
+
+### Improvements
+
+ * Supported rxvt family terminals as color available terminals.
+ [GitHub#121][Reported by Ippei Kishida]
+
+### Thanks
+
+ * Ippei Kishida
+
+## 3.1.9 - 2016-05-20 {#version-3-1-9}
+
+### Fixes
+
+ * Fixed conflict with test-unit-power_assert.
+ [GitHub#120][Patch by Kazuki Tsujimoto]
+
+ * Fixed a bug that path in `$LOAD_PATH` may be removed.
+
+### Thanks
+
+ * Kazuki Tsujimoto
+
+## 3.1.8 - 2016-03-19 {#version-3-1-8}
+
+### Improvements
+
+ * Added `--stop-on-failure` command line option. With this option,
+ running test suite is stopped immediately when one test is failed
+ or an error is raised in one test.
+
## 3.1.7 - 2016-01-17 {#version-3-1-7}
### Fixes
@@ -473,7 +648,7 @@ It's a release for minitest compatibility and bug fix.
* Allowed use of test for inheritance in ActionController::TestCase.
[GitHub#42] [Patch by David Rasch]
- * Ensured evaluating at_exist block in top level.
+ * Ensured evaluating at_exit block in top level.
In IRB context, exit() specifies irb_exit().
[test-unit-users-en:00089] [Reported by Daniel Berger]
* Fixed a bug that decoration style description is ignored.
diff --git a/lib/test/unit/assertions.rb b/lib/test/unit/assertions.rb
index ce6525c..a71ac03 100644
--- a/lib/test/unit/assertions.rb
+++ b/lib/test/unit/assertions.rb
@@ -153,8 +153,8 @@ module Test
assertion_message = message
else
error_message = "assertion message must be String, Proc or "
- error_message << "#{AssertionMessage}: "
- error_message << "<#{message.inspect}>(<#{message.class}>)"
+ error_message += "#{AssertionMessage}: "
+ error_message += "<#{message.inspect}>(<#{message.class}>)"
raise ArgumentError, error_message, filter_backtrace(caller)
end
assertion_message ||= build_message(message,
@@ -192,8 +192,8 @@ module Test
assertion_message = message
else
error_message = "assertion message must be String, Proc or "
- error_message << "#{AssertionMessage}: "
- error_message << "<#{message.inspect}>(<#{message.class}>)"
+ error_message += "#{AssertionMessage}: "
+ error_message += "<#{message.inspect}>(<#{message.class}>)"
raise ArgumentError, error_message, filter_backtrace(caller)
end
assert_block("refute should not be called with a block.") do
@@ -334,7 +334,7 @@ EOT
"<#{value}>"
end
full_message = build_message(message, <<EOT, object, klass_message, object.class)
-<?> expected to be instance_of\\?
+<?> was expected to be instance_of\\?
? but was
<?>.
EOT
@@ -362,7 +362,7 @@ EOT
else
klasses = [klass]
end
- assert_block("The first parameter to assert_not_instance_of should be " <<
+ assert_block("The first parameter to assert_not_instance_of should be " +
"a Class or an Array of Class.") do
klasses.all? {|k| k.is_a?(Class)}
end
@@ -370,7 +370,7 @@ EOT
"<#{value}>"
end
full_message = build_message(message,
- "<?> expected to not be instance_of\\?\n" +
+ "<?> was expected to not be instance_of\\?\n" +
"? but was.",
object,
klass_message)
@@ -392,7 +392,7 @@ EOT
# assert_nil [1, 2].uniq!
def assert_nil(object, message="")
full_message = build_message(message, <<EOT, object)
-<?> expected to be nil.
+<?> was expected to be nil.
EOT
assert_block(full_message) { object.nil? }
end
@@ -421,7 +421,7 @@ EOT
"<#{value}>"
end
full_message = build_message(message,
- "<?> expected to be kind_of\\?\n" +
+ "<?> was expected to be kind_of\\?\n" +
"? but was\n" +
"<?>.",
object,
@@ -459,7 +459,7 @@ EOT
"<#{value}>"
end
full_message = build_message(message,
- "<?> expected to not be kind_of\\?\n" +
+ "<?> was expected to not be kind_of\\?\n" +
"? but was.",
object,
klass_message)
@@ -537,7 +537,8 @@ EOT
else
pattern
end
- full_message = build_message(message, "<?> expected to be =~\n<?>.",
+ full_message = build_message(message,
+ "<?> was expected to be =~\n<?>.",
pattern, string)
assert_block(full_message) { pattern =~ string }
end
@@ -553,7 +554,7 @@ EOT
def assert_same(expected, actual, message="")
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
<?>
-with id <?> expected to be equal\\? to
+with id <?> was expected to be equal\\? to
<?>
with id <?>.
EOT
@@ -572,7 +573,7 @@ EOT
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, <<EOT, object1, AssertionMessage.literal(operator), object2)
-<?> expected to be
+<?> was expected to be
?
<?>.
EOT
@@ -595,7 +596,7 @@ EOT
full_message = build_message(nil, "<?>\ngiven as the operator for #assert_not_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, <<EOT, object1, AssertionMessage.literal(operator), object2)
-<?> expected to not be
+<?> was expected to not be
?
<?>.
EOT
@@ -635,7 +636,6 @@ EOT
raise
end
end
- nil
end
end
@@ -656,7 +656,7 @@ EOT
def assert_not_same(expected, actual, message="")
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
<?>
-with id <?> expected to not be equal\\? to
+with id <?> was expected to not be equal\\? to
<?>
with id <?>.
EOT
@@ -674,7 +674,9 @@ EOT
# @example
# assert_not_equal 'some string', 5
def assert_not_equal(expected, actual, message="")
- full_message = build_message(message, "<?> expected to be != to\n<?>.", expected, actual)
+ full_message = build_message(message,
+ "<?> was expected to be != to\n<?>.",
+ expected, actual)
assert_block(full_message) { expected != actual }
end
@@ -689,7 +691,9 @@ EOT
# @example
# assert_not_nil '1 two 3'.sub!(/two/, '2')
def assert_not_nil(object, message="")
- full_message = build_message(message, "<?> expected to not be nil.", object)
+ full_message = build_message(message,
+ "<?> was expected to not be nil.",
+ object)
assert_block(full_message){!object.nil?}
end
@@ -710,7 +714,7 @@ EOT
"<REGEXP> in assert_not_match(<REGEXP>, ...) " +
"should be a Regexp.")
full_message = build_message(message,
- "<?> expected to not match\n<?>.",
+ "<?> was expected to not match\n<?>.",
regexp, string)
assert_block(full_message) { regexp !~ string }
end
@@ -814,7 +818,7 @@ EOT
tag = extractor.extract_tag
raise if tag.nil?
full_message = build_message(message,
- "<?> expected to be thrown but\n" +
+ "<?> was expected to be thrown but\n" +
"<?> was thrown.",
expected_object, tag)
flunk(full_message)
@@ -922,12 +926,12 @@ EOT
message, options={})
if options[:negative_assertion]
format = <<-EOT
-<?> -/+ <?> expected to not include
+<?> -/+ <?> was expected to not include
<?>.
EOT
else
format = <<-EOT
-<?> -/+ <?> expected to include
+<?> -/+ <?> was expected to include
<?>.
EOT
end
@@ -961,7 +965,7 @@ EOT
end
if relation_format
- format << <<-EOT
+ format += <<-EOT
Relation:
#{relation_format}
@@ -1061,12 +1065,12 @@ EOT
if options[:negative_assertion]
format = <<-EOT
-<?> -/+ (<?> * <?>)[?] expected to not include
+<?> -/+ (<?> * <?>)[?] was expected to not include
<?>.
EOT
else
format = <<-EOT
-<?> -/+ (<?> * <?>)[?] expected to include
+<?> -/+ (<?> * <?>)[?] was expected to include
<?>.
EOT
end
@@ -1099,7 +1103,7 @@ EOT
end
if relation_format
- format << <<-EOT
+ format += <<-EOT
Relation:
#{relation_format}
@@ -1131,7 +1135,7 @@ EOT
"assert_send requires at least a receiver " +
"and a message name")
format = <<EOT
-<?> expected to respond to
+<?> was expected to respond to
<?(*?)> with a true value but was
<?>.
EOT
@@ -1171,7 +1175,7 @@ EOT
"assert_not_send requires at least a receiver " +
"and a message name")
format = <<EOT
-<?> expected to respond to
+<?> was expected to respond to
<?(*?)> with not a true value but was
<?>.
EOT
@@ -1261,7 +1265,7 @@ EOT
end
template = <<-EOT
<?> #{operator} <?> should be true
-<?> expected #{operator_description}
+<?> was expected to be #{operator_description}
<?>.
EOT
full_message = build_message(message, template,
@@ -1306,7 +1310,7 @@ EOT
def assert_raise_message(expected, message=nil)
_wrap_assertion do
full_message = build_message(message,
- "<?> exception message expected " +
+ "<?> exception message was expected " +
"but none was thrown.",
expected)
exception = nil
@@ -1476,7 +1480,7 @@ EOT
def assert_path_exist(path, message=nil)
_wrap_assertion do
failure_message = build_message(message,
- "<?> expected to exist",
+ "<?> was expected to exist",
path)
assert_block(failure_message) do
File.exist?(path)
@@ -1494,7 +1498,7 @@ EOT
def assert_path_not_exist(path, message=nil)
_wrap_assertion do
failure_message = build_message(message,
- "<?> expected to not exist",
+ "<?> was expected to not exist",
path)
assert_block(failure_message) do
not File.exist?(path)
@@ -1515,7 +1519,7 @@ EOT
assert_respond_to(collection, :include?,
"The collection must respond to :include?.")
full_message = build_message(message,
- "<?> expected to include\n<?>.",
+ "<?> was expected to include\n<?>.",
collection,
object)
assert_block(full_message) do
@@ -1542,7 +1546,7 @@ EOT
assert_respond_to(collection, :include?,
"The collection must respond to :include?.")
full_message = build_message(message,
- "<?> expected to not include\n<?>.",
+ "<?> was expected to not include\n<?>.",
collection,
object)
assert_block(full_message) do
@@ -1576,7 +1580,7 @@ EOT
assert_respond_to(object, :empty?,
"The object must respond to :empty?.")
full_message = build_message(message,
- "<?> expected to be empty.",
+ "<?> was expected to be empty.",
object)
assert_block(full_message) do
object.empty?
@@ -1599,7 +1603,7 @@ EOT
assert_respond_to(object, :empty?,
"The object must respond to :empty?.")
full_message = build_message(message,
- "<?> expected to not be empty.",
+ "<?> was expected to not be empty.",
object)
assert_block(full_message) do
not object.empty?
@@ -1667,7 +1671,7 @@ EOT
expected = assert_exception_helper.expected_exceptions
actual_exception = nil
full_message = build_message(message,
- "<?> exception expected " +
+ "<?> exception was expected " +
"but none was thrown.",
expected)
assert_block(full_message) do
@@ -1776,7 +1780,7 @@ EOT
if Diff.need_fold?(diff)
folded_diff = Diff.folded_readable(from, to)
- diff << "\n\nfolded diff:\n#{folded_diff}"
+ diff += "\n\nfolded diff:\n#{folded_diff}"
end
diff
@@ -1790,9 +1794,9 @@ EOT
inspector = Inspector.new(object)
if use_pp
begin
- require 'pp' unless defined?(PP)
+ require "pp" unless defined?(PP)
begin
- return PP.pp(inspector, '').chomp
+ return PP.pp(inspector, String.new).chomp
rescue NameError
end
rescue LoadError
@@ -2041,26 +2045,26 @@ EOT
expanded_template = ""
@parts.each do |part|
if part == '?'
- encoding_safe_concat(expanded_template, params.shift)
+ param = params.shift
+ if Object.const_defined?(:Encoding)
+ expanded_template += concatenatable(param,
+ expanded_template.encoding)
+ else
+ expanded_template += param
+ end
else
- expanded_template << part.gsub(/\\\?/m, '?')
+ expanded_template += part.gsub(/\\\?/m, '?')
end
end
expanded_template
end
private
- if Object.const_defined?(:Encoding)
- def encoding_safe_concat(buffer, parameter)
- if Encoding.compatible?(buffer, parameter)
- buffer << parameter
- else
- buffer << parameter.dup.force_encoding(buffer.encoding)
- end
- end
- else
- def encoding_safe_concat(buffer, parameter)
- buffer << parameter
+ def concatenatable(text, encoding)
+ if Encoding.compatible?(text, encoding)
+ text
+ else
+ text.dup.force_encoding(encoding)
end
end
end
@@ -2170,19 +2174,45 @@ EOT
expected_exceptions.each do |exception_type|
if exception_type.instance_of?(Module)
exception_modules << exception_type
- elsif exception_type.is_a?(Exception)
+ elsif exception_object?(exception_type)
exception_objects << exception_type
- else
- @test_case.__send__(:assert,
- Exception >= exception_type,
- "Should expect a class of exception, " +
- "#{exception_type}")
+ elsif exception_class?(exception_type)
exception_classes << exception_type
+ else
+ full_message =
+ @test_case.__send__(:build_message,
+ nil,
+ "<?> must be " +
+ "a subclass of Exception, " +
+ "an object of Exception subclasses " +
+ "or a Module",
+ exception_type)
+ @test_case.flunk(full_message)
end
end
[exception_classes, exception_modules, exception_objects]
end
+ def exception_object?(exception_type)
+ return true if exception_type.is_a?(Exception)
+
+ if Object.const_defined?(:Java)
+ return true if exception_type.is_a?(Java::JavaLang::Throwable)
+ end
+
+ false
+ end
+
+ def exception_class?(exception_type)
+ return true if exception_type <= Exception
+
+ if Object.const_defined?(:Java)
+ return true if exception_type <= Java::JavaLang::Throwable
+ end
+
+ false
+ end
+
def expected_class?(actual_exception, equality)
@expected_classes.any? do |expected_class|
actual_exception.__send__(equality, expected_class)
diff --git a/lib/test/unit/attribute.rb b/lib/test/unit/attribute.rb
index cfc9e8d..2efbf8c 100644
--- a/lib/test/unit/attribute.rb
+++ b/lib/test/unit/attribute.rb
@@ -49,6 +49,70 @@ module Test
@current_attributes = kept_attributes
end
+ # Set an attribute to test methods.
+ #
+ # @overload attribute(name, value)
+ # @example
+ # attribute :speed, :slow
+ # def test_my_slow_method
+ # self[:speed] # => :slow
+ # end
+ #
+ # @param [Object] name the attribute name
+ # @param [Object] value the attribute value
+ # @return [void]
+ #
+ # @overload attribute(name, value, *method_names)
+ # @example
+ # def test_my_slow_method1
+ # self[:speed] # => :slow
+ # end
+ #
+ # attribute :speed, :slow, :test_my_slow_method1, :test_my_slow_method2
+ #
+ # def test_my_slow_method2
+ # self[:speed] # => :slow
+ # end
+ #
+ # @param [Object] name the attribute name
+ # @param [Object] value the attribute value
+ # @param [Array<Symbol, String>] method_names the test method names set the attribute
+ # @return [void]
+ #
+ # @overload attribute(name, value, options)
+ # @example
+ # attribute :speed, :slow, keep: true
+ # def test_my_slow_method1
+ # self[:speed] # => :slow
+ # end
+ #
+ # def test_my_slow_method2
+ # self[:speed] # => :slow
+ # end
+ #
+ # @param [Object] name the attribute name
+ # @param [Object] value the attribute value
+ # @option options [Boolean] :keep whether or not to set attribute to following test methods
+ # @return [void]
+ #
+ # @overload attribute(name, value, options, *method_names)
+ # @example
+ # def test_my_slow_method1
+ # self[:speed] # => :slow
+ # end
+ #
+ # # There are no valid options for now.
+ # attribute :speed, :slow, {}, :test_my_slow_method1
+ #
+ # def test_my_slow_method2
+ # self[:speed] # => nil
+ # end
+ #
+ # @param [Object] name the attribute name
+ # @param [Object] value the attribute value
+ # @param [Hash] options ignored
+ # @param [Array<Symbol, String>] method_names the test method names set the attribute
+ # @return [void]
def attribute(name, value, options={}, *method_names)
unless options.is_a?(Hash)
method_names << options
diff --git a/lib/test/unit/autorunner.rb b/lib/test/unit/autorunner.rb
index 624c599..f17cb42 100644
--- a/lib/test/unit/autorunner.rb
+++ b/lib/test/unit/autorunner.rb
@@ -139,6 +139,7 @@ module Test
attr_accessor :default_test_paths
attr_accessor :pattern, :exclude, :base, :workdir
attr_accessor :color_scheme, :listeners
+ attr_writer :stop_on_failuere
attr_writer :runner, :collector
def initialize(standalone)
@@ -153,6 +154,7 @@ module Test
@default_arguments = []
@workdir = nil
@listeners = []
+ @stop_on_failure = false
config_file = "test-unit.yml"
if File.exist?(config_file)
load_config(config_file)
@@ -162,6 +164,10 @@ module Test
yield(self) if block_given?
end
+ def stop_on_failure?
+ @stop_on_failure
+ end
+
def prepare
PREPARE_HOOKS.each do |handler|
handler.call(self)
@@ -183,7 +189,7 @@ module Test
def options
@options ||= OptionParser.new do |o|
o.banner = "Test::Unit automatic runner."
- o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]"
+ o.banner += "\nUsage: #{$0} [options] [-- untouched arguments]"
o.on("-r", "--runner=RUNNER", RUNNERS,
"Use the given RUNNER.",
@@ -240,10 +246,7 @@ module Test
name = (%r{\A/(.*)/\Z} =~ name ? Regexp.new($1) : name)
@filters << lambda do |test|
return true if name === test.method_name
- test_name_without_class_name = test.name.gsub(/\(.+?\)\z/, "")
- if test_name_without_class_name != test.method_name
- return true if name === test_name_without_class_name
- end
+ return true if name === test.local_name
false
end
end
@@ -361,6 +364,12 @@ module Test
assertion_message_class.max_diff_target_string_size = size
end
+ o.on("--[no-]stop-on-failure",
+ "Stops immediately on the first non success test",
+ "(#{@stop_on_failure})") do |boolean|
+ @stop_on_failure = boolean
+ end
+
ADDITIONAL_OPTIONS.each do |option_builder|
option_builder.call(self, o)
end
@@ -419,6 +428,9 @@ module Test
@runner_options[:color_scheme] ||= @color_scheme
@runner_options[:listeners] ||= []
@runner_options[:listeners].concat(@listeners)
+ if @stop_on_failure
+ @runner_options[:listeners] << StopOnFailureListener.new
+ end
change_work_directory do
runner.run(suite, @runner_options).passed?
end
@@ -504,6 +516,14 @@ module Test
:method_name => test.method_name)
end
end
+
+ class StopOnFailureListener
+ def attach_to_mediator(mediator)
+ mediator.add_listener(TestResult::FINISHED) do |result|
+ result.stop unless result.passed?
+ end
+ end
+ end
end
end
end
diff --git a/lib/test/unit/collector/load.rb b/lib/test/unit/collector/load.rb
index 9c0fcd0..a623ff1 100644
--- a/lib/test/unit/collector/load.rb
+++ b/lib/test/unit/collector/load.rb
@@ -131,6 +131,8 @@ module Test
return yield if path.nil?
path = path.to_s
+ return yield if $LOAD_PATH.index(path)
+
begin
$LOAD_PATH.unshift(path)
yield
diff --git a/lib/test/unit/diff.rb b/lib/test/unit/diff.rb
index 8e7ff56..ce2348e 100644
--- a/lib/test/unit/diff.rb
+++ b/lib/test/unit/diff.rb
@@ -3,9 +3,9 @@
# Copyright (c) 2001-2008 Python Software Foundation; All Rights Reserved
# Copyright (c) 2008-2011 Kouhei Sutou; All Rights Reserved
#
-# It is free software, and is distributed under the Ruby
-# license and/or the PSF license. See the COPYING file and
-# PSFL file.
+# It is free software, and is distributed under the Ruby license, the
+# PSF license and/or LGPLv2.1 or later. See the COPYING file, the PSFL
+# file and the LGPL file.
module Test
module Unit
@@ -269,7 +269,7 @@ module Test
private
def tag(mark, contents)
- contents.collect {|content| "#{mark}#{content}"}
+ contents.collect {|content| mark + content}
end
end
@@ -450,7 +450,7 @@ module Test
def tag(mark, contents)
contents.each do |content|
- @result << "#{mark}#{content}"
+ @result << (mark + content)
end
end
@@ -577,15 +577,15 @@ module Test
to_width = compute_width(to_line, to_start, to_end)
case tag
when :replace
- from_tags << "^" * from_width
- to_tags << "^" * to_width
+ from_tags += "^" * from_width
+ to_tags += "^" * to_width
when :delete
- from_tags << "-" * from_width
+ from_tags += "-" * from_width
when :insert
- to_tags << "+" * to_width
+ to_tags += "+" * to_width
when :equal
- from_tags << " " * from_width
- to_tags << " " * to_width
+ from_tags += " " * from_width
+ to_tags += " " * to_width
else
raise "unknown tag: #{tag}"
end
diff --git a/lib/test/unit/fixture.rb b/lib/test/unit/fixture.rb
index 59228f5..d41f25d 100644
--- a/lib/test/unit/fixture.rb
+++ b/lib/test/unit/fixture.rb
@@ -127,6 +127,9 @@ module Test
if method_name_or_callback.respond_to?(:call)
callback = method_name_or_callback
method_name = callback_method_name(callback)
+ @test_case.attribute(:source_location,
+ callback.source_location,
+ method_name)
@test_case.__send__(:define_method, method_name, &callback)
else
method_name = method_name_or_callback
diff --git a/lib/test/unit/testcase.rb b/lib/test/unit/testcase.rb
index 05e31f9..29b1fcd 100644
--- a/lib/test/unit/testcase.rb
+++ b/lib/test/unit/testcase.rb
@@ -37,49 +37,70 @@ module Test
# You can run two hooks before/after a TestCase run.
#
# Example:
- # class TestMyClass < Test::Unit::TestCase
- # class << self
- # def startup
+ #
+ # class TestMyClass < Test::Unit::TestCase
+ # class << self
+ # def startup
+ # ...
+ # end
+ #
+ # def shutdown
+ # ...
+ # end
+ # end
+ #
+ # def setup
# ...
# end
#
- # def shutdown
+ # def cleanup
# ...
# end
- # end
#
- # def setup
- # ...
- # end
+ # def teardown
+ # ...
+ # end
#
- # def cleanup
- # ...
- # end
+ # def test_my_method1
+ # ...
+ # end
#
- # def teardown
- # ...
+ # def test_my_method2
+ # ...
+ # end
# end
#
- # def test_my_method1
- # ...
- # end
+ # Here is a call order:
#
- # def test_my_method2
- # ...
- # end
- # end
+ # 1. startup
+ # 1. setup
+ # 1. test_my_method1
+ # 1. cleanup
+ # 1. teardown
+ # 1. setup
+ # 1. test_my_method2
+ # 1. cleanup
+ # 1. teardown
+ # 1. shutdown
#
- # Here is a call order:
- # * startup
- # * setup
- # * test_my_method1
- # * cleanup
- # * teardown
- # * setup
- # * test_my_method2
- # * cleanup
- # * teardown
- # * shutdown
+ # You can set an attribute to each test.
+ #
+ # Example:
+ #
+ # class TestMyClass < Test::Unit::TestCase
+ # attribute :speed, :fast
+ # def test_my_fast_method
+ # # You can get the attribute via `self[]`
+ # self[:speed] # => :fast
+ # ...
+ # end
+ #
+ # attribute :speed, :slow
+ # def test_my_slow_method
+ # self[:speed] # => :slow
+ # ...
+ # end
+ # end
class TestCase
include Attribute
include Fixture
@@ -228,7 +249,11 @@ module Test
# Returns the current test order. This returns
# +:alphabetic+ by default.
def test_order
- @@test_orders[self] || AVAILABLE_ORDERS.first
+ ancestors.each do |ancestor|
+ order = @@test_orders[ancestor]
+ return order if order
+ end
+ AVAILABLE_ORDERS.first
end
# Sets the current test order.
@@ -314,7 +339,7 @@ module Test
# the same in meaning:
#
# Standard:
- # class TestParent < Test::UnitTestCase
+ # class TestParent < Test::Unit::TestCase
# class TestChild < self
# def test_in_child
# end
@@ -322,7 +347,7 @@ module Test
# end
#
# Syntax sugar:
- # class TestParent < Test::UnitTestCase
+ # class TestParent < Test::Unit::TestCase
# sub_test_case("TestChild") do
# def test_in_child
# end
@@ -365,6 +390,11 @@ module Test
# @option query [String] :method_name (nil)
# the method name for a test.
def test_defined?(query)
+ locations = find_locations(query)
+ not locations.empty?
+ end
+
+ def find_locations(query)
query_path = query[:path]
query_line = query[:line]
query_method_name = query[:method_name]
@@ -377,19 +407,20 @@ module Test
available_location = available_locations.find do |location|
query_line >= location[:line]
end
- return false if available_location.nil?
- return false if available_location[:test_case] != self
+ return [] if available_location.nil?
+ return [] if available_location[:test_case] != self
available_locations = [available_location]
end
if query_method_name
available_location = available_locations.find do |location|
- query_method_name == location[:method_name]
+ location[:test_case] == self and
+ query_method_name == location[:method_name]
end
- return false if available_location.nil?
+ return [] if available_location.nil?
available_locations = [available_location]
end
- not available_locations.empty?
+ available_locations
end
private
@@ -441,9 +472,7 @@ module Test
def valid? # :nodoc:
return false unless respond_to?(@method_name)
test_method = method(@method_name)
- if @internal_data.have_test_data?
- return false unless test_method.arity == 1
- else
+ unless @internal_data.have_test_data?
return false unless test_method.arity <= 0
end
owner = Util::MethodOwnerFinder.find(self, @method_name)
@@ -652,10 +681,19 @@ module Test
# Returns a human-readable name for the specific test that
# this instance of TestCase represents.
def name
+ "#{local_name}(#{self.class.name})"
+ end
+
+ # Returns a human-readable name for the specific test that this
+ # instance of TestCase represents.
+ #
+ # `#local_name` doesn't include class name. `#name` includes
+ # class name.
+ def local_name
if @internal_data.have_test_data?
- "#{@method_name}[#{data_label}](#{self.class.name})"
+ "#{@method_name}[#{data_label}]"
else
- "#{@method_name}(#{self.class.name})"
+ @method_name.to_s
end
end
@@ -733,13 +771,24 @@ module Test
end
def run_test
+ signature = "#{self.class}\##{@method_name}"
redefined_info = self[:redefined]
if redefined_info
- notify("#{self.class}\##{@method_name} was redefined",
+ notify("<#{signature}> was redefined",
:backtrace => redefined_info[:backtrace])
end
if @internal_data.have_test_data?
- __send__(@method_name, @internal_data.test_data)
+ test_method = method(@method_name)
+ if test_method.arity == 1 or test_method.arity < 0
+ __send__(@method_name, @internal_data.test_data)
+ else
+ locations = self.class.find_locations(:method_name => @method_name)
+ backtrace = locations.collect do |location|
+ "#{location[:path]}:#{location[:line]}"
+ end
+ notify("<#{signature}> misses a parameter to take test data",
+ :backtrace => backtrace)
+ end
else
__send__(@method_name)
end
diff --git a/lib/test/unit/testresult.rb b/lib/test/unit/testresult.rb
index 3177528..5afb3be 100644
--- a/lib/test/unit/testresult.rb
+++ b/lib/test/unit/testresult.rb
@@ -38,12 +38,15 @@ module Test
attr_reader :run_count, :pass_count, :assertion_count, :faults
+ attr_accessor :stop_tag
+
# Constructs a new, empty TestResult.
def initialize
@run_count, @pass_count, @assertion_count = 0, 0, 0
@summary_generators = []
@problem_checkers = []
@faults = []
+ @stop_tag = nil
initialize_containers
end
@@ -92,6 +95,10 @@ module Test
end
end
+ def stop
+ throw @stop_tag
+ end
+
def to_s
summary
end
diff --git a/lib/test/unit/ui/console/testrunner.rb b/lib/test/unit/ui/console/testrunner.rb
index 3612c45..3394326 100644
--- a/lib/test/unit/ui/console/testrunner.rb
+++ b/lib/test/unit/ui/console/testrunner.rb
@@ -342,7 +342,7 @@ module Test
def test_started(test)
return unless output?(VERBOSE)
- name = test.name.sub(/\(.+?\)\z/, '')
+ name = test.local_name
right_space = 8 * 2
left_space = @progress_row_max - right_space
left_space = left_space - indent.size - name.size
@@ -473,8 +473,12 @@ module Test
fault_class.name.split(/::/).last.downcase
end
+ def fault_class_color(fault_class)
+ color(fault_class_color_name(fault_class))
+ end
+
def fault_color(fault)
- color(fault_class_color_name(fault.class))
+ fault_class_color(fault.class)
end
def fault_marker_color(fault)
@@ -491,6 +495,8 @@ module Test
case ENV["TERM"]
when /(?:term|screen)(?:-(?:256)?color)?\z/
true
+ when /\Arxvt/
+ true
else
return true if ENV["EMACS"] == "t"
false
diff --git a/lib/test/unit/ui/emacs/testrunner.rb b/lib/test/unit/ui/emacs/testrunner.rb
index cde06a8..c3aad42 100644
--- a/lib/test/unit/ui/emacs/testrunner.rb
+++ b/lib/test/unit/ui/emacs/testrunner.rb
@@ -30,16 +30,16 @@ module Test
location_display = "\n" + failure.location.join("\n")
end
result = "#{failure.label}:\n"
- result << "#{failure.test_name}#{location_display}:\n"
- result << failure.message
+ result += "#{failure.test_name}#{location_display}:\n"
+ result += failure.message
result
end
def format_fault_error(error)
result = "#{error.label}:\n"
- result << "#{error.test_name}:\n"
- result << "#{error.message}\n"
- result << error.backtrace.join("\n")
+ result += "#{error.test_name}:\n"
+ result += "#{error.message}\n"
+ result += error.backtrace.join("\n")
result
end
end
diff --git a/lib/test/unit/ui/testrunnermediator.rb b/lib/test/unit/ui/testrunnermediator.rb
index 5c8bd03..21a1d7e 100644
--- a/lib/test/unit/ui/testrunnermediator.rb
+++ b/lib/test/unit/ui/testrunnermediator.rb
@@ -4,7 +4,6 @@
# 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'
@@ -18,9 +17,9 @@ module Test
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)
@@ -37,11 +36,14 @@ module Test
Test::Unit.run_at_start_hooks
start_time = Time.now
begin
- with_listener(result) do
- notify_listeners(RESET, @suite.size)
- notify_listeners(STARTED, result)
+ catch do |stop_tag|
+ result.stop_tag = stop_tag
+ with_listener(result) do
+ notify_listeners(RESET, @suite.size)
+ notify_listeners(STARTED, result)
- run_suite(result)
+ run_suite(result)
+ end
end
ensure
elapsed_time = Time.now - start_time
diff --git a/lib/test/unit/util/backtracefilter.rb b/lib/test/unit/util/backtracefilter.rb
index c8c2993..15db727 100644
--- a/lib/test/unit/util/backtracefilter.rb
+++ b/lib/test/unit/util/backtracefilter.rb
@@ -12,8 +12,8 @@ module Test
TESTUNIT_RB_FILE = /\.rb\Z/
POWERASSERT_PREFIX =
- defined?(PowerAssert) ?
- PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] :
+ defined?(::PowerAssert) ?
+ ::PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] :
nil
module_function
diff --git a/lib/test/unit/version.rb b/lib/test/unit/version.rb
index 8e541fa..bd0332e 100644
--- a/lib/test/unit/version.rb
+++ b/lib/test/unit/version.rb
@@ -1,5 +1,5 @@
module Test
module Unit
- VERSION = '3.1.7'
+ VERSION = "3.2.5"
end
end
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index 0ba6aaf..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,277 +0,0 @@
---- !ruby/object:Gem::Specification
-name: test-unit
-version: !ruby/object:Gem::Version
- version: 3.1.7
-platform: ruby
-authors:
-- Kouhei Sutou
-- Haruka Yoshihara
-autorequire:
-bindir: bin
-cert_chain: []
-date: 2016-01-17 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
- name: power_assert
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :runtime
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-- !ruby/object:Gem::Dependency
- name: bundler
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-- !ruby/object:Gem::Dependency
- name: rake
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-- !ruby/object:Gem::Dependency
- name: yard
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-- !ruby/object:Gem::Dependency
- name: kramdown
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-- !ruby/object:Gem::Dependency
- name: packnga
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-description: |
- Test::Unit (test-unit) is unit testing framework for Ruby, based on xUnit
- principles. These were originally designed by Kent Beck, creator of extreme
- programming software development methodology, for Smalltalk's SUnit. It allows
- writing tests, checking results and automated testing in Ruby.
-email:
-- kou at cozmixng.org
-- yoshihara at clear-code.com
-executables: []
-extensions: []
-extra_rdoc_files: []
-files:
-- COPYING
-- GPL
-- LGPL
-- PSFL
-- README.md
-- Rakefile
-- doc/text/how-to.md
-- doc/text/news.md
-- lib/test-unit.rb
-- lib/test/unit.rb
-- lib/test/unit/assertion-failed-error.rb
-- lib/test/unit/assertions.rb
-- lib/test/unit/attribute-matcher.rb
-- lib/test/unit/attribute.rb
-- lib/test/unit/auto-runner-loader.rb
-- lib/test/unit/autorunner.rb
-- lib/test/unit/code-snippet-fetcher.rb
-- lib/test/unit/collector.rb
-- lib/test/unit/collector/descendant.rb
-- lib/test/unit/collector/dir.rb
-- lib/test/unit/collector/load.rb
-- lib/test/unit/collector/objectspace.rb
-- lib/test/unit/collector/xml.rb
-- lib/test/unit/color-scheme.rb
-- lib/test/unit/color.rb
-- lib/test/unit/data.rb
-- lib/test/unit/diff.rb
-- lib/test/unit/error.rb
-- lib/test/unit/exception-handler.rb
-- lib/test/unit/failure.rb
-- lib/test/unit/fault-location-detector.rb
-- lib/test/unit/fixture.rb
-- lib/test/unit/notification.rb
-- lib/test/unit/omission.rb
-- lib/test/unit/pending.rb
-- lib/test/unit/priority.rb
-- lib/test/unit/runner/console.rb
-- lib/test/unit/runner/emacs.rb
-- lib/test/unit/runner/xml.rb
-- lib/test/unit/test-suite-creator.rb
-- lib/test/unit/testcase.rb
-- lib/test/unit/testresult.rb
-- lib/test/unit/testsuite.rb
-- lib/test/unit/ui/console/outputlevel.rb
-- lib/test/unit/ui/console/testrunner.rb
-- lib/test/unit/ui/emacs/testrunner.rb
-- lib/test/unit/ui/testrunner.rb
-- lib/test/unit/ui/testrunnermediator.rb
-- lib/test/unit/ui/testrunnerutilities.rb
-- lib/test/unit/ui/xml/testrunner.rb
-- lib/test/unit/util/backtracefilter.rb
-- lib/test/unit/util/method-owner-finder.rb
-- lib/test/unit/util/observable.rb
-- lib/test/unit/util/output.rb
-- lib/test/unit/util/procwrapper.rb
-- lib/test/unit/version.rb
-- sample/adder.rb
-- sample/subtracter.rb
-- sample/test_adder.rb
-- sample/test_subtracter.rb
-- sample/test_user.rb
-- test/collector/test-descendant.rb
-- test/collector/test-load.rb
-- test/collector/test_dir.rb
-- test/collector/test_objectspace.rb
-- test/fixtures/header-label.csv
-- test/fixtures/header-label.tsv
-- test/fixtures/header.csv
-- test/fixtures/header.tsv
-- test/fixtures/no-header.csv
-- test/fixtures/no-header.tsv
-- test/fixtures/plus.csv
-- test/run-test.rb
-- test/test-assertions.rb
-- test/test-attribute-matcher.rb
-- test/test-attribute.rb
-- test/test-code-snippet.rb
-- test/test-color-scheme.rb
-- test/test-color.rb
-- test/test-data.rb
-- test/test-diff.rb
-- test/test-emacs-runner.rb
-- test/test-error.rb
-- test/test-failure.rb
-- test/test-fault-location-detector.rb
-- test/test-fixture.rb
-- test/test-notification.rb
-- test/test-omission.rb
-- test/test-pending.rb
-- test/test-priority.rb
-- test/test-test-case.rb
-- test/test-test-result.rb
-- test/test-test-suite-creator.rb
-- test/test-test-suite.rb
-- test/testunit-test-util.rb
-- test/ui/test_testrunmediator.rb
-- test/util/test-method-owner-finder.rb
-- test/util/test-output.rb
-- test/util/test_backtracefilter.rb
-- test/util/test_observable.rb
-- test/util/test_procwrapper.rb
-homepage: http://test-unit.github.io/
-licenses:
-- Ruby
-- PSFL
-metadata: {}
-post_install_message:
-rdoc_options: []
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: '0'
-requirements: []
-rubyforge_project:
-rubygems_version: 2.4.5.1
-signing_key:
-specification_version: 4
-summary: An xUnit family unit testing framework for Ruby.
-test_files:
-- test/test-code-snippet.rb
-- test/test-fault-location-detector.rb
-- test/test-attribute.rb
-- test/test-priority.rb
-- test/test-color-scheme.rb
-- test/test-failure.rb
-- test/test-color.rb
-- test/ui/test_testrunmediator.rb
-- test/test-attribute-matcher.rb
-- test/test-test-suite.rb
-- test/test-test-suite-creator.rb
-- test/test-diff.rb
-- test/test-emacs-runner.rb
-- test/test-data.rb
-- test/fixtures/header.csv
-- test/fixtures/header.tsv
-- test/fixtures/no-header.tsv
-- test/fixtures/plus.csv
-- test/fixtures/no-header.csv
-- test/fixtures/header-label.tsv
-- test/fixtures/header-label.csv
-- test/test-assertions.rb
-- test/test-test-result.rb
-- test/testunit-test-util.rb
-- test/collector/test-load.rb
-- test/collector/test_dir.rb
-- test/collector/test_objectspace.rb
-- test/collector/test-descendant.rb
-- test/test-error.rb
-- test/run-test.rb
-- test/test-pending.rb
-- test/test-fixture.rb
-- test/util/test-output.rb
-- test/util/test-method-owner-finder.rb
-- test/util/test_observable.rb
-- test/util/test_procwrapper.rb
-- test/util/test_backtracefilter.rb
-- test/test-notification.rb
-- test/test-omission.rb
-- test/test-test-case.rb
-has_rdoc:
diff --git a/test-unit.gemspec b/test-unit.gemspec
new file mode 100644
index 0000000..8847412
--- /dev/null
+++ b/test-unit.gemspec
@@ -0,0 +1,49 @@
+#########################################################
+# This file has been automatically generated by gem2tgz #
+#########################################################
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "test-unit"
+ s.version = "3.2.5"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Kouhei Sutou", "Haruka Yoshihara"]
+ s.date = "2017-06-24"
+ s.description = "test-unit (Test::Unit) is unit testing framework for Ruby, based on xUnit\nprinciples. These were originally designed by Kent Beck, creator of extreme\nprogramming software development methodology, for Smalltalk's SUnit. It allows\nwriting tests, checking results and automated testing in Ruby.\n"
+ s.email = ["kou at cozmixng.org", "yoshihara at clear-code.com"]
+ s.files = ["COPYING", "GPL", "LGPL", "PSFL", "README.md", "Rakefile", "doc/text/getting-started.md", "doc/text/how-to.md", "doc/text/news.md", "lib/test-unit.rb", "lib/test/unit.rb", "lib/test/unit/assertion-failed-error.rb", "lib/test/unit/assertions.rb", "lib/test/unit/attribute-matcher.rb", "lib/test/unit/attribute.rb", "lib/test/unit/auto-runner-loader.rb", "lib/test/unit/autorunner.rb", "lib/test/unit/code-snippet-fetcher.rb", "lib/test/unit/collector.rb", "lib/test/unit/collector [...]
+ s.homepage = "http://test-unit.github.io/"
+ s.licenses = ["Ruby", "PSFL"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.23"
+ s.summary = "An xUnit family unit testing framework for Ruby."
+ s.test_files = ["test/collector/test-descendant.rb", "test/collector/test-load.rb", "test/collector/test_dir.rb", "test/collector/test_objectspace.rb", "test/fixtures/header-label.csv", "test/fixtures/header-label.tsv", "test/fixtures/header.csv", "test/fixtures/header.tsv", "test/fixtures/no-header.csv", "test/fixtures/no-header.tsv", "test/fixtures/plus.csv", "test/run-test.rb", "test/test-assertions.rb", "test/test-attribute-matcher.rb", "test/test-attribute.rb", "test/test-code-sni [...]
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 4
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<bundler>, [">= 0"])
+ s.add_development_dependency(%q<kramdown>, [">= 0"])
+ s.add_development_dependency(%q<packnga>, [">= 0"])
+ s.add_runtime_dependency(%q<power_assert>, [">= 0"])
+ s.add_development_dependency(%q<rake>, [">= 0"])
+ s.add_development_dependency(%q<yard>, [">= 0"])
+ else
+ s.add_dependency(%q<bundler>, [">= 0"])
+ s.add_dependency(%q<kramdown>, [">= 0"])
+ s.add_dependency(%q<packnga>, [">= 0"])
+ s.add_dependency(%q<power_assert>, [">= 0"])
+ s.add_dependency(%q<rake>, [">= 0"])
+ s.add_dependency(%q<yard>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<bundler>, [">= 0"])
+ s.add_dependency(%q<kramdown>, [">= 0"])
+ s.add_dependency(%q<packnga>, [">= 0"])
+ s.add_dependency(%q<power_assert>, [">= 0"])
+ s.add_dependency(%q<rake>, [">= 0"])
+ s.add_dependency(%q<yard>, [">= 0"])
+ end
+end
diff --git a/test/collector/test-descendant.rb b/test/collector/test-descendant.rb
index 9404851..3f72e0b 100644
--- a/test/collector/test-descendant.rb
+++ b/test/collector/test-descendant.rb
@@ -31,6 +31,8 @@ class TestUnitCollectorDescendant < Test::Unit::TestCase
super
@test_case1 = Class.new(Test::Unit::TestCase) do
+ self.test_order = :alphabetic
+
def self.name
"test-case1"
end
@@ -43,6 +45,8 @@ class TestUnitCollectorDescendant < Test::Unit::TestCase
end
@test_case2 = Class.new(Test::Unit::TestCase) do
+ self.test_order = :alphabetic
+
def self.name
"test-case2"
end
diff --git a/test/collector/test_dir.rb b/test/collector/test_dir.rb
index 2de802c..c257938 100644
--- a/test/collector/test_dir.rb
+++ b/test/collector/test_dir.rb
@@ -15,7 +15,7 @@ module Test
@contents = {'.' => self, '..' => parent}
instance_eval(&block) if(block)
end
-
+
def file(name, contents)
@contents[name] = contents
end
@@ -74,7 +74,7 @@ module Test
end
attr_reader :object_space
-
+
def initialize(&block)
@root = Directory.new('/', self, &block)
@pwd = @root
@@ -295,7 +295,7 @@ module Test
assert_raises(LoadError) do
fs.require('bogus')
end
-
+
assert(fs.require('test_class1.rb'))
assert(!fs.require('test_class1.rb'))
c = []
@@ -345,6 +345,7 @@ module Test
def create_test(name)
t = Class.new(TestCase)
t.class_eval <<-EOC
+ self.test_order = :alphabetic
def self.name
"T\#{#{name}}"
end
@@ -373,7 +374,7 @@ module Test
expected = TestSuite.new('test_1.rb')
expected << @t1.suite
assert_equal(expected, @c.collect('test_1.rb'))
-
+
expected = TestSuite.new('t4.rb')
expected << @t4.suite
assert_equal(expected, @c.collect('t4.rb'))
diff --git a/test/collector/test_objectspace.rb b/test/collector/test_objectspace.rb
index 9a51b80..b63b5a3 100644
--- a/test/collector/test_objectspace.rb
+++ b/test/collector/test_objectspace.rb
@@ -11,6 +11,7 @@ module Test
class TC_ObjectSpace < TestCase
def setup
@tc1 = Class.new(TestCase) do
+ self.test_order = :alphabetic
def self.name
"tc_1"
end
@@ -21,6 +22,7 @@ module Test
end
@tc2 = Class.new(TestCase) do
+ self.test_order = :alphabetic
def self.name
"tc_2"
end
@@ -32,7 +34,7 @@ module Test
def test_4
end
end
-
+
@object_space = {Class => [@tc1, @tc2, @no_tc], String => ['']}
def @object_space.each_object(type)
self[type].each{|item| yield(item) }
@@ -50,14 +52,14 @@ module Test
def empty_suite
TestSuite.new(ObjectSpace::NAME)
end
-
+
def test_basic_collection
assert_equal(full_suite("name"), @c.collect("name"))
@c.filter = []
assert_equal(full_suite("name"), @c.collect("name"))
end
-
+
def test_filtered_collection
@c.filter = proc{false}
assert_equal(empty_suite, @c.collect)
@@ -76,10 +78,10 @@ module Test
@c.filter = [proc{nil}, proc{false}]
assert_equal(empty_suite, @c.collect)
-
+
@c.filter = [proc{nil}, proc{true}]
assert_equal(full_suite, @c.collect)
-
+
expected = TestSuite.new(ObjectSpace::NAME)
expected << (TestSuite.new(@tc1.name) << @tc1.new('test_1'))
expected << (TestSuite.new(@tc2.name) << @tc2.new('test_0'))
diff --git a/test/test-assertions.rb b/test/test-assertions.rb
index e00aac5..8af4071 100644
--- a/test/test-assertions.rb
+++ b/test/test-assertions.rb
@@ -68,7 +68,10 @@ module Test
"Incorrect expected message type in assert_nothing_failed")
end
else
- if return_value_expected
+ case return_value_expected
+ when :dont_care
+ # do nothing
+ when true
check(!return_value.nil?, "Should return a value")
else
check(return_value.nil?,
@@ -298,8 +301,8 @@ EOM
def test_multi_lines_result
message = <<-EOM.chomp
-<#{"a\nb".inspect}> expected but was
-<#{"x".inspect}>.
+<#{AssertionMessage.convert("a\nb")}> expected but was
+<#{AssertionMessage.convert("x")}>.
diff:
+ x
@@ -313,8 +316,8 @@ EOM
def test_large_string
message = <<-EOM.chomp
-<#{("a\n" + "x" * 997).inspect}> expected but was
-<#{"x".inspect}>.
+<#{AssertionMessage.convert("a\n" + "x" * 997)}> expected but was
+<#{AssertionMessage.convert("x")}>.
diff:
+ x
@@ -332,8 +335,8 @@ EOM
end
message = <<-EOM.chomp
-<#{("a\n" + "x" * 998).inspect}> expected but was
-<#{"x".inspect}>.
+<#{AssertionMessage.convert("a\n" + "x" * 998)}> expected but was
+<#{AssertionMessage.convert("x")}>.
EOM
check_fail(message) do
assert_equal("a\n" + "x" * 998, "x")
@@ -346,8 +349,8 @@ EOM
ENV[key] = "100"
begin
message = <<-EOM.chomp
-<#{("a\n" + "x" * 97).inspect}> expected but was
-<#{"x".inspect}>.
+<#{AssertionMessage.convert("a\n" + "x" * 97)}> expected but was
+<#{AssertionMessage.convert("x")}>.
diff:
+ x
@@ -365,8 +368,8 @@ EOM
end
message = <<-EOM.chomp
-<#{("a\n" + "x" * 98).inspect}> expected but was
-<#{"x".inspect}>.
+<#{AssertionMessage.convert("a\n" + "x" * 98)}> expected but was
+<#{AssertionMessage.convert("x")}>.
EOM
check_fail(message) do
assert_equal("a\n" + "x" * 98, "x")
@@ -492,7 +495,7 @@ EOM
end
def test_assert_raise_fail
- check_fail("<RuntimeError> exception expected but none was thrown.") do
+ check_fail("<RuntimeError> exception was expected but none was thrown.") do
assert_raise(RuntimeError) do
1 + 1
end
@@ -510,8 +513,7 @@ EOM
end
message = <<-EOM
-Should expect a class of exception, Object.
-<false> is not true.
+<Object> must be a subclass of Exception, an object of Exception subclasses or a Module.
EOM
check_fail(message.chomp) do
assert_nothing_raised(Object) do
@@ -554,7 +556,7 @@ EOM
end
check_fail("<[ArgumentError, TypeError, Math, Comparable]> exception " +
- "expected but none was thrown.") do
+ "was expected but none was thrown.") do
assert_raise(*rescues) do
1 + 1
end
@@ -636,6 +638,21 @@ EOM
end
end
+ def test_assert_raise_jruby
+ omit("For JRuby") unless Object.const_defined?(:Java)
+
+ exception = Java::JavaLang::StringIndexOutOfBoundsException
+
+ return_value = nil
+ check_nothing_fails(true) do
+ return_value = assert_raise(exception) do
+ Java::JavaLang::String.new("abc").char_at(4)
+ end
+ end
+ check(return_value.instance_of?(exception),
+ "Should have returned #{exception} but was #{return_value.class}")
+ end
+
def test_assert_instance_of
check_nothing_fails {
assert_instance_of(String, "string")
@@ -646,21 +663,21 @@ EOM
check_nothing_fails {
assert_instance_of(String, "string", "successful assert_instance_of")
}
- check_fail(%Q{<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
+ check_fail(%Q{<"string"> was expected to be instance_of?\n<Hash> but was\n<String>.}) {
assert_instance_of(Hash, "string")
}
- check_fail(%Q{failed assert_instance_of.\n<"string"> expected to be instance_of?\n<Hash> but was\n<String>.}) {
+ check_fail(%Q{failed assert_instance_of.\n<"string"> was expected to be instance_of?\n<Hash> but was\n<String>.}) {
assert_instance_of(Hash, "string", "failed assert_instance_of")
}
check_nothing_fails do
- assert_instance_of([Fixnum, NilClass], 100)
+ assert_instance_of([Class, NilClass], Array)
end
- check_fail(%Q{<"string"> expected to be instance_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
- assert_instance_of([Fixnum, NilClass], "string")
+ check_fail(%Q{<"string"> was expected to be instance_of?\n[<Class>, <NilClass>] but was\n<String>.}) do
+ assert_instance_of([Class, NilClass], "string")
end
- check_fail(%Q{<100> expected to be instance_of?\n[<Numeric>, <NilClass>] but was\n<Fixnum>.}) do
- assert_instance_of([Numeric, NilClass], 100)
+ check_fail(%Q{<Array> was expected to be instance_of?\n[<Module>, <NilClass>] but was\n<Class>.}) do
+ assert_instance_of([Module, NilClass], Array)
end
end
@@ -671,20 +688,20 @@ EOM
check_nothing_fails {
assert_not_instance_of(NilClass, "string", "successful assert_instance_of")
}
- check_fail(%Q{<"string"> expected to not be instance_of?\n<String> but was.}) {
+ check_fail(%Q{<"string"> was expected to not be instance_of?\n<String> but was.}) {
assert_not_instance_of(String, "string")
}
- check_fail(%Q{failed assert.\n<"string"> expected to not be instance_of?\n<String> but was.}) {
+ check_fail(%Q{failed assert.\n<"string"> was expected to not be instance_of?\n<String> but was.}) {
assert_not_instance_of(String, "string", "failed assert")
}
check_nothing_fails do
- assert_not_instance_of([Numeric, NilClass], 100)
+ assert_not_instance_of([Module, NilClass], Array)
end
- check_fail(%Q{<100> expected to not be instance_of?\n[<Fixnum>, <NilClass>] but was.}) do
- assert_not_instance_of([Fixnum, NilClass], 100)
+ check_fail(%Q{<Array> was expected to not be instance_of?\n[<Class>, <NilClass>] but was.}) do
+ assert_not_instance_of([Class, NilClass], Array)
end
- check_fail(%Q{<"str"> expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
+ check_fail(%Q{<"str"> was expected to not be instance_of?\n[<Numeric>, <String>] but was.}) do
assert_not_instance_of([Numeric, String], 'str')
end
end
@@ -699,10 +716,10 @@ EOM
check_nothing_fails {
assert_nil(nil, "successful assert_nil")
}
- check_fail(%Q{<"string"> expected to be nil.}) {
+ check_fail(%Q{<"string"> was expected to be nil.}) {
assert_nil("string")
}
- check_fail(%Q{failed assert_nil.\n<"string"> expected to be nil.}) {
+ check_fail(%Q{failed assert_nil.\n<"string"> was expected to be nil.}) {
assert_nil("string", "failed assert_nil")
}
end
@@ -710,8 +727,8 @@ EOM
def test_assert_not_nil
check_nothing_fails{assert_not_nil(false)}
check_nothing_fails{assert_not_nil(false, "message")}
- check_fail("<nil> expected to not be nil."){assert_not_nil(nil)}
- check_fail("message.\n<nil> expected to not be nil.") {assert_not_nil(nil, "message")}
+ check_fail("<nil> was expected to not be nil."){assert_not_nil(nil)}
+ check_fail("message.\n<nil> was expected to not be nil.") {assert_not_nil(nil, "message")}
end
def test_assert_kind_of
@@ -727,18 +744,18 @@ EOM
check_nothing_fails {
assert_kind_of(Comparable, 1)
}
- check_fail(%Q{<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
+ check_fail(%Q{<"string"> was expected to be kind_of?\n<Class> but was\n<String>.}) {
assert_kind_of(Class, "string")
}
- check_fail(%Q{failed assert_kind_of.\n<"string"> expected to be kind_of?\n<Class> but was\n<String>.}) {
+ check_fail(%Q{failed assert_kind_of.\n<"string"> was expected to be kind_of?\n<Class> but was\n<String>.}) {
assert_kind_of(Class, "string", "failed assert_kind_of")
}
check_nothing_fails do
- assert_kind_of([Fixnum, NilClass], 100)
+ assert_kind_of([Class, NilClass], Array)
end
- check_fail(%Q{<"string"> expected to be kind_of?\n[<Fixnum>, <NilClass>] but was\n<String>.}) do
- assert_kind_of([Fixnum, NilClass], "string")
+ check_fail(%Q{<"string"> was expected to be kind_of?\n[<Class>, <NilClass>] but was\n<String>.}) do
+ assert_kind_of([Class, NilClass], "string")
end
end
@@ -752,18 +769,18 @@ EOM
check_nothing_fails {
assert_not_kind_of(Integer, 1.1)
}
- check_fail(%Q{<1> expected to not be kind_of?\n<Integer> but was.}) {
+ check_fail(%Q{<1> was expected to not be kind_of?\n<Integer> but was.}) {
assert_not_kind_of(Integer, 1)
}
- check_fail(%Q{failed assert_not_kind_of.\n<"string"> expected to not be kind_of?\n<String> but was.}) {
+ check_fail(%Q{failed assert_not_kind_of.\n<"string"> was expected to not be kind_of?\n<String> but was.}) {
assert_not_kind_of(String, "string", "failed assert_not_kind_of")
}
check_nothing_fails do
assert_not_kind_of([String, NilClass], 100)
end
- check_fail(%Q{<100> expected to not be kind_of?\n[<Fixnum>, <NilClass>] but was.}) do
- assert_not_kind_of([Fixnum, NilClass], 100)
+ check_fail(%Q{<Array> was expected to not be kind_of?\n[<Class>, <NilClass>] but was.}) do
+ assert_not_kind_of([Class, NilClass], Array)
end
end
@@ -780,13 +797,13 @@ EOM
check_nothing_fails {
assert_match(/strin./, "string", "successful assert_match")
}
- check_fail(%Q{</slin./> expected to be =~\n<"string">.}) {
+ check_fail(%Q{</slin./> was expected to be =~\n<"string">.}) {
assert_match(/slin./, "string")
}
- check_fail(%Q{</strin\\./> expected to be =~\n<"string">.}) {
+ check_fail(%Q{</strin\\./> was expected to be =~\n<"string">.}) {
assert_match("strin.", "string")
}
- check_fail(%Q{failed assert_match.\n</slin./> expected to be =~\n<"string">.}) {
+ check_fail(%Q{failed assert_match.\n</slin./> was expected to be =~\n<"string">.}) {
assert_match(/slin./, "string", "failed assert_match")
}
end
@@ -802,32 +819,32 @@ EOM
check_nothing_fails {
assert_same(thing, thing, "successful assert_same")
}
- thing2 = "thing"
- check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
+ thing2 = thing.dup
+ check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> was expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
assert_same(thing, thing2)
}
- check_fail(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
+ check_fail(%Q{failed assert_same.\n<"thing">\nwith id <#{thing.__id__}> was expected to be equal? to\n<"thing">\nwith id <#{thing2.__id__}>.}) {
assert_same(thing, thing2, "failed assert_same")
}
end
def test_assert_nothing_raised
- check_nothing_fails {
+ check_nothing_fails(:dont_care) {
assert_nothing_raised {
1 + 1
}
}
- check_nothing_fails {
+ check_nothing_fails(:dont_care) {
assert_nothing_raised("successful assert_nothing_raised") {
1 + 1
}
}
- check_nothing_fails {
+ check_nothing_fails(:dont_care) {
assert_nothing_raised("successful assert_nothing_raised") {
1 + 1
}
}
- check_nothing_fails {
+ check_nothing_fails(:dont_care) {
begin
assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") {
raise ZeroDivisionError.new("ArgumentError")
@@ -835,7 +852,10 @@ EOM
rescue ZeroDivisionError
end
}
- check_fail("Should expect a class of exception, Object.\n<false> is not true.") {
+ expected_message =
+ "<Object> must be a subclass of Exception, " +
+ "an object of Exception subclasses or a Module."
+ check_fail(expected_message) {
assert_nothing_raised(Object) {
1 + 1
}
@@ -886,17 +906,17 @@ EOM
def test_assert_not_same
thing = "thing"
- thing2 = "thing"
+ thing2 = thing.dup
check_nothing_fails {
assert_not_same(thing, thing2)
}
check_nothing_fails {
assert_not_same(thing, thing2, "message")
}
- check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
+ check_fail(%Q{<"thing">\nwith id <#{thing.__id__}> was expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
assert_not_same(thing, thing)
}
- check_fail(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
+ check_fail(%Q{message.\n<"thing">\nwith id <#{thing.__id__}> was expected to not be equal? to\n<"thing">\nwith id <#{thing.__id__}>.}) {
assert_not_same(thing, thing, "message")
}
end
@@ -908,10 +928,10 @@ EOM
check_nothing_fails {
assert_not_equal("string1", "string2", "message")
}
- check_fail(%Q{<"string"> expected to be != to\n<"string">.}) {
+ check_fail(%Q{<"string"> was expected to be != to\n<"string">.}) {
assert_not_equal("string", "string")
}
- check_fail(%Q{message.\n<"string"> expected to be != to\n<"string">.}) {
+ check_fail(%Q{message.\n<"string"> was expected to be != to\n<"string">.}) {
assert_not_equal("string", "string", "message")
}
end
@@ -931,7 +951,7 @@ EOM
def test_assert_not_match_fail_not_regexp
check_fail("<REGEXP> in assert_not_match(<REGEXP>, ...) " +
"should be a Regexp.\n" +
- "<\"asdf\"> expected to be instance_of?\n" +
+ "<\"asdf\"> was expected to be instance_of?\n" +
"<Regexp> but was\n" +
"<String>.") do
assert_not_match("asdf", "asdf")
@@ -939,7 +959,7 @@ EOM
end
def test_assert_not_match_fail_match
- check_fail("</string/> expected to not match\n" +
+ check_fail("</string/> was expected to not match\n" +
"<\"string\">.") do
assert_not_match(/string/, "string")
end
@@ -947,7 +967,7 @@ EOM
def test_assert_not_match_fail_match_with_message
check_fail("message.\n" +
- "</string/> expected to not match\n" +
+ "</string/> was expected to not match\n" +
"<\"string\">.") do
assert_not_match(/string/, "string", "message")
end
@@ -956,13 +976,13 @@ EOM
def test_assert_no_match
check_nothing_fails{assert_no_match(/sling/, "string")}
check_nothing_fails{assert_no_match(/sling/, "string", "message")}
- check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> expected to be instance_of?\n<Regexp> but was\n<String>.}) do
+ check_fail(%Q{The first argument to assert_no_match should be a Regexp.\n<"asdf"> was expected to be instance_of?\n<Regexp> but was\n<String>.}) do
assert_no_match("asdf", "asdf")
end
- check_fail(%Q{</string/> expected to not match\n<"string">.}) do
+ check_fail(%Q{</string/> was expected to not match\n<"string">.}) do
assert_no_match(/string/, "string")
end
- check_fail(%Q{message.\n</string/> expected to not match\n<"string">.}) do
+ check_fail(%Q{message.\n</string/> was expected to not match\n<"string">.}) do
assert_no_match(/string/, "string", "message")
end
end
@@ -976,7 +996,7 @@ EOM
tag = :thing2
check_fail("message.\n" +
- "<:thing> expected to be thrown but\n" +
+ "<:thing> was expected to be thrown but\n" +
"<#{inspect_tag(tag)}> was thrown.") do
assert_throw(:thing, "message") do
throw :thing2
@@ -1014,7 +1034,7 @@ EOM
check_fail(%Q{<0.15>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to?(:to_str).}) do
assert_operator("thing", 0.15, "thing")
end
- check_fail(%Q{message.\n<"thing1"> expected to be\n==\n<"thing2">.}) {
+ check_fail(%Q{message.\n<"thing1"> was expected to be\n==\n<"thing2">.}) {
assert_operator("thing1", :==, "thing2", "message")
}
end
@@ -1026,7 +1046,7 @@ EOM
check_fail(%Q{<42>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to?(:to_str).}) do
assert_not_operator("thing", 42, "message")
end
- check_fail(%Q{message.\n<0> expected to not be\n==\n<0.0>.}) {
+ check_fail(%Q{message.\n<0> was expected to not be\n==\n<0.0>.}) {
assert_not_operator(0, :==, 0.0, "message")
}
end
@@ -1091,7 +1111,7 @@ EOM
inspected_object = AssertionMessage.convert(object)
expected_message = <<-EOM
message.
-<#{inspected_object}> expected to respond to
+<#{inspected_object}> was expected to respond to
<return_argument(*[false, "bogus"])> with a true value but was
<false>.
EOM
@@ -1190,7 +1210,7 @@ EOM
expected_message = <<-EOM
<15> < <10> should be true
-<15> expected less than
+<15> was expected to be less than
<10>.
EOM
check_fail(expected_message.chomp) do
@@ -1199,7 +1219,7 @@ EOM
expected_message = <<-EOM
<15> <= <10> should be true
-<15> expected less than or equal to
+<15> was expected to be less than or equal to
<10>.
EOM
check_fail(expected_message.chomp) do
@@ -1208,7 +1228,7 @@ EOM
expected_message = <<-EOM
<10> > <15> should be true
-<10> expected greater than
+<10> was expected to be greater than
<15>.
EOM
check_fail(expected_message.chomp) do
@@ -1217,7 +1237,7 @@ EOM
expected_message = <<-EOM
<10> >= <15> should be true
-<10> expected greater than or equal to
+<10> was expected to be greater than or equal to
<15>.
EOM
check_fail(expected_message.chomp) do
@@ -1268,7 +1288,7 @@ EOM
end
expected_message = <<-EOM
-<"Expected message"> exception message expected but none was thrown.
+<"Expected message"> exception message was expected but none was thrown.
EOM
check_fail(expected_message.chomp) do
assert_raise_message("Expected message") do
@@ -1394,7 +1414,7 @@ EOM
end
nonexistent_file = __FILE__ + ".nonexistent"
- check_fail("<#{nonexistent_file.inspect}> expected to exist") do
+ check_fail("<#{nonexistent_file.inspect}> was expected to exist") do
assert_path_exist(nonexistent_file)
end
end
@@ -1405,7 +1425,7 @@ EOM
assert_path_not_exist(nonexistent_file)
end
- check_fail("<#{__FILE__.inspect}> expected to not exist") do
+ check_fail("<#{__FILE__.inspect}> was expected to not exist") do
assert_path_not_exist(__FILE__)
end
end
@@ -1501,15 +1521,18 @@ EOM
class TestBlock < self
def test_with_message
if defined?(PowerAssert)
- system_message = <<-MESSAGE
- 1 == 2
+ system_message = <<-MESSAGE.chomp
+ 1.to_s == "2"
+ | |
+ | false
+ "1"
MESSAGE
else
system_message = "<false> is not true."
end
check_fail("user message.\n#{system_message}") do
assert("user message") do
- 1 == 2
+ 1.to_s == "2"
end
end
end
@@ -1615,7 +1638,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
- "<0.5> -/+ <0.05> expected to include\n" +
+ "<0.5> -/+ <0.05> was expected to include\n" +
"<0.4>.\n" +
"\n" +
"Relation:\n" +
@@ -1637,13 +1660,13 @@ MESSAGE
def test_fail_because_negaitve_delta
check_fail("The delta should not be negative.\n" +
- "<-0.1> expected to be\n>=\n<0.0>.") do
+ "<-0.1> was expected to be\n>=\n<0.0>.") do
assert_in_delta(0.5, 0.4, -0.1, "message")
end
end
def test_fail_without_delta
- check_fail("<1.402> -/+ <0.001> expected to include\n" +
+ check_fail("<1.402> -/+ <0.001> was expected to include\n" +
"<1.404>.\n" +
"\n" +
"Relation:\n" +
@@ -1695,7 +1718,7 @@ MESSAGE
end
def test_fail
- check_fail("<1.4> -/+ <0.11> expected to not include\n" +
+ check_fail("<1.4> -/+ <0.11> was expected to not include\n" +
"<1.5>.\n" +
"\n" +
"Relation:\n" +
@@ -1709,7 +1732,7 @@ MESSAGE
end
def test_fail_without_delta
- check_fail("<1.402> -/+ <0.001> expected to not include\n" +
+ check_fail("<1.402> -/+ <0.001> was expected to not include\n" +
"<1.4021>.\n" +
"\n" +
"Relation:\n" +
@@ -1724,7 +1747,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
- "<0.5> -/+ <0.11> expected to not include\n" +
+ "<0.5> -/+ <0.11> was expected to not include\n" +
"<0.4>.\n" +
"\n" +
"Relation:\n" +
@@ -1750,7 +1773,7 @@ MESSAGE
def test_fail_because_negaitve_delta
check_fail("The delta should not be negative.\n" +
- "<-0.11> expected to be\n>=\n<0.0>.") do
+ "<-0.11> was expected to be\n>=\n<0.0>.") do
assert_not_in_delta(0.5, 0.4, -0.11, "message")
end
end
@@ -1808,7 +1831,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
- "expected to include\n" +
+ "was expected to include\n" +
"<8999>.\n" +
"\n" +
"Relation:\n" +
@@ -1834,14 +1857,14 @@ MESSAGE
def test_fail_because_negaitve_epsilon
check_fail("The epsilon should not be negative.\n" +
- "<-0.1> expected to be\n>=\n<0.0>.") do
+ "<-0.1> was expected to be\n>=\n<0.0>.") do
assert_in_epsilon(10000, 9000, -0.1, "message")
end
end
def test_fail_without_epsilon
check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
- "expected to include\n" +
+ "was expected to include\n" +
"<10011>.\n" +
"\n" +
"Relation:\n" +
@@ -1894,7 +1917,7 @@ MESSAGE
def test_fail
check_fail("<10000> -/+ (<10000> * <0.1>)[1000.0] " +
- "expected to not include\n" +
+ "was expected to not include\n" +
"<9000>.\n" +
"\n" +
"Relation:\n" +
@@ -1909,7 +1932,7 @@ MESSAGE
def test_fail_without_epsilon
check_fail("<10000> -/+ (<10000> * <0.001>)[10.0] " +
- "expected to not include\n" +
+ "was expected to not include\n" +
"<9990>.\n" +
"\n" +
"Relation:\n" +
@@ -1925,7 +1948,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
"<10000> -/+ (<10000> * <0.1>)[1000.0] " +
- "expected to not include\n" +
+ "was expected to not include\n" +
"<9000>.\n" +
"\n" +
"Relation:\n" +
@@ -1951,7 +1974,7 @@ MESSAGE
def test_fail_because_negaitve_epsilon
check_fail("The epsilon should not be negative.\n" +
- "<-0.1> expected to be\n>=\n<0.0>.") do
+ "<-0.1> was expected to be\n>=\n<0.0>.") do
assert_not_in_epsilon(10000, 9000, -0.1, "message")
end
end
@@ -1973,7 +1996,7 @@ MESSAGE
end
def test_fail
- check_fail("<[1, 2, 3]> expected to include\n" +
+ check_fail("<[1, 2, 3]> was expected to include\n" +
"<4>.") do
assert_include([1, 2, 3], 4)
end
@@ -1981,7 +2004,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
- "<[1, 2, 3]> expected to include\n" +
+ "<[1, 2, 3]> was expected to include\n" +
"<4>.") do
assert_include([1, 2, 3], 4, "message")
end
@@ -2014,7 +2037,7 @@ MESSAGE
end
def test_fail
- check_fail("<[1, 2, 3]> expected to not include\n" +
+ check_fail("<[1, 2, 3]> was expected to not include\n" +
"<2>.") do
assert_not_include([1, 2, 3], 2)
end
@@ -2022,7 +2045,7 @@ MESSAGE
def test_fail_with_message
check_fail("message.\n" +
- "<[1, 2, 3]> expected to not include\n" +
+ "<[1, 2, 3]> was expected to not include\n" +
"<2>.") do
assert_not_include([1, 2, 3], 2, "message")
end
@@ -2055,14 +2078,14 @@ MESSAGE
end
def test_fail
- check_fail("<[1]> expected to be empty.") do
+ check_fail("<[1]> was expected to be empty.") do
assert_empty([1])
end
end
def test_fail_with_message
check_fail("message.\n" +
- "<[1]> expected to be empty.") do
+ "<[1]> was expected to be empty.") do
assert_empty([1], "message")
end
end
@@ -2094,14 +2117,14 @@ MESSAGE
end
def test_fail
- check_fail("<[]> expected to not be empty.") do
+ check_fail("<[]> was expected to not be empty.") do
assert_not_empty([])
end
end
def test_fail_with_message
check_fail("message.\n" +
- "<[]> expected to not be empty.") do
+ "<[]> was expected to not be empty.") do
assert_not_empty([], "message")
end
end
@@ -2129,7 +2152,7 @@ MESSAGE
def test_fail
expected_message = <<-EOM
message.
-<[1, 2]> expected to respond to
+<[1, 2]> was expected to respond to
<member?(*[2])> with not a true value but was
<true>.
EOM
diff --git a/test/test-test-case.rb b/test/test-test-case.rb
index 2096148..54614ed 100644
--- a/test/test-test-case.rb
+++ b/test/test-test-case.rb
@@ -465,9 +465,6 @@ module Test
end
end
- assert_equal(["test_1", "test_a", "test_z"],
- test_case.suite.tests.collect {|test| test.method_name})
-
test_case.test_order = :defined
assert_equal(["test_z", "test_1", "test_a"],
test_case.suite.tests.collect {|test| test.method_name})
@@ -513,6 +510,8 @@ module Test
def test_redefine_method
test_case = Class.new(Test::Unit::TestCase) do
+ self.test_order = :alphabetic
+
def test_name
end
alias_method :test_name2, :test_name
@@ -543,6 +542,23 @@ module Test
assert_predicate(test, :valid?)
end
+ def test_data_driven_test_without_parameter
+ test_case = Class.new(TestCase) do
+ data("label" => "value")
+ def test_without_parameter
+ end
+ end
+
+ suite = test_case.suite
+ assert_equal(["test_without_parameter"],
+ suite.tests.collect {|test| test.method_name})
+ result = TestResult.new
+ suite.run(result) {}
+ assert_equal("1 tests, 0 assertions, 0 failures, " +
+ "0 errors, 0 pendings, 0 omissions, 1 notifications",
+ result.summary)
+ end
+
private
def check(message, passed)
add_assertion
@@ -735,6 +751,21 @@ module Test
child_test_case.test_defined?(:line => line_child),
])
end
+
+ def test_with_setup
+ line = nil
+ test_case = Class.new(TestCase) do
+ setup do
+ end
+
+ line = __LINE__; test "with setup" do
+ end
+ end
+ assert do
+ test_case.test_defined?(:line => line,
+ :method_name => "test: with setup")
+ end
+ end
end
end
@@ -980,6 +1011,8 @@ module Test
@parent_test_case = Class.new(TestCase) do
extend CallLogger
+ self.test_order = :alphabetic
+
class << self
def startup
called << :startup_parent
@@ -1164,6 +1197,80 @@ module Test
assert_equal([:startup, :shutdown],
test_case.called)
end
+
+ class TestName < self
+ def test_no_data
+ test_case = Class.new(TestCase) do
+ class << self
+ def name
+ "TestCase"
+ end
+ end
+
+ def test_nothing
+ end
+ end
+
+ test = test_case.new("test_nothing")
+ assert_equal("test_nothing(TestCase)",
+ test.name)
+ end
+
+ def test_data
+ test_case = Class.new(TestCase) do
+ class << self
+ def name
+ "TestCase"
+ end
+ end
+
+ def test_nothing
+ end
+ end
+
+ test = test_case.new("test_nothing")
+ test.assign_test_data("(nil)", nil)
+ assert_equal("test_nothing[(nil)](TestCase)",
+ test.name)
+ end
+ end
+
+ class TestLocalName < self
+ def test_no_data
+ test_case = Class.new(TestCase) do
+ class << self
+ def name
+ "TestCase"
+ end
+ end
+
+ def test_nothing
+ end
+ end
+
+ test = test_case.new("test_nothing")
+ assert_equal("test_nothing",
+ test.local_name)
+ end
+
+ def test_data
+ test_case = Class.new(TestCase) do
+ class << self
+ def name
+ "TestCase"
+ end
+ end
+
+ def test_nothing
+ end
+ end
+
+ test = test_case.new("test_nothing")
+ test.assign_test_data("(nil)", nil)
+ assert_equal("test_nothing[(nil)]",
+ test.local_name)
+ end
+ end
end
end
end
diff --git a/test/test-test-suite.rb b/test/test-test-suite.rb
index 5ccf741..08bf04f 100644
--- a/test/test-test-suite.rb
+++ b/test/test-test-suite.rb
@@ -67,6 +67,7 @@ module Test
def test_run
progress = []
+ @testcase1.test_order = :alphabetic
suite = @testcase1.suite
tests = suite.tests.dup
result = TestResult.new
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-test-unit.git
More information about the Pkg-ruby-extras-commits
mailing list