test-unit 2.4.8 → 2.4.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/test-unit.rb CHANGED
@@ -1,3 +1,13 @@
1
1
  module Test
2
- autoload :Unit, "test/unit"
2
+ module Unit
3
+ autoload :TestCase, "test/unit/testcase"
4
+ autoload :AutoRunner, "test/unit/autorunner"
5
+ end
6
+ end
7
+
8
+ # experimental. It is for "ruby -rtest-unit -e run test/test_*.rb".
9
+ # Is this API OK or dirty?
10
+ def run
11
+ self.class.send(:undef_method, :run)
12
+ require "test/unit"
3
13
  end
data/lib/test/unit.rb CHANGED
@@ -310,19 +310,23 @@ module Test # :nodoc:
310
310
  module Unit
311
311
  # Set true when Test::Unit has run. If set to true Test::Unit
312
312
  # will not automatically run at exit.
313
- def self.run=(flag)
314
- @run = flag
313
+ #
314
+ # @deprecated Use Test::Unit::AutoRunner.need_auto_run= instead.
315
+ def self.run=(have_run)
316
+ AutoRunner.need_auto_run = (not have_run)
315
317
  end
316
318
 
317
319
  # Already tests have run?
320
+ #
321
+ # @deprecated Use Test::Unit::AutoRunner.need_auto_run? instead.
318
322
  def self.run?
319
- @run ||= false
323
+ not AutoRunner.need_auto_run?
320
324
  end
321
325
  end
322
326
  end
323
327
 
324
328
  at_exit do
325
- unless $! || Test::Unit.run?
329
+ if $!.nil? and Test::Unit::AutoRunner.need_auto_run?
326
330
  exit Test::Unit::AutoRunner.run
327
331
  end
328
332
  end
@@ -1755,7 +1755,30 @@ EOT
1755
1755
  def result(parameters)
1756
1756
  raise "The number of parameters does not match the number of substitutions." if(parameters.size != count)
1757
1757
  params = parameters.dup
1758
- @parts.collect{|e| e == '?' ? params.shift : e.gsub(/\\\?/m, '?')}.join('')
1758
+ expanded_template = ""
1759
+ @parts.each do |part|
1760
+ if part == '?'
1761
+ encoding_safe_concat(expanded_template, params.shift)
1762
+ else
1763
+ expanded_template << part.gsub(/\\\?/m, '?')
1764
+ end
1765
+ end
1766
+ expanded_template
1767
+ end
1768
+
1769
+ private
1770
+ if Object.const_defined?(:Encoding)
1771
+ def encoding_safe_concat(buffer, parameter)
1772
+ if Encoding.compatible?(buffer.encoding, parameter.encoding)
1773
+ buffer << parameter
1774
+ else
1775
+ buffer << parameter.dup.force_encoding(buffer.encoding)
1776
+ end
1777
+ end
1778
+ else
1779
+ def encoding_safe_concat(buffer, parameter)
1780
+ buffer << parameter
1781
+ end
1759
1782
  end
1760
1783
  end
1761
1784
 
@@ -1,4 +1,5 @@
1
1
  require 'test/unit/color-scheme'
2
+ require 'test/unit/priority'
2
3
  require 'optparse'
3
4
 
4
5
  module Test
@@ -48,22 +49,31 @@ module Test
48
49
  def prepare(hook=Proc.new)
49
50
  PREPARE_HOOKS << hook
50
51
  end
51
- end
52
52
 
53
- def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
54
- r = new(force_standalone || standalone?, &block)
55
- r.base = default_dir
56
- r.prepare
57
- r.process_args(argv)
58
- r.run
59
- end
53
+ def run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
54
+ r = new(force_standalone || standalone?, &block)
55
+ r.base = default_dir
56
+ r.prepare
57
+ r.process_args(argv)
58
+ r.run
59
+ end
60
60
 
61
- def self.standalone?
62
- return false unless("-e" == $0)
63
- ObjectSpace.each_object(Class) do |klass|
64
- return false if(klass < TestCase)
61
+ def standalone?
62
+ return false unless("-e" == $0)
63
+ ObjectSpace.each_object(Class) do |klass|
64
+ return false if(klass < TestCase)
65
+ end
66
+ true
67
+ end
68
+
69
+ @@need_auto_run = true
70
+ def need_auto_run?
71
+ @@need_auto_run
72
+ end
73
+
74
+ def need_auto_run=(need)
75
+ @@need_auto_run = need
65
76
  end
66
- true
67
77
  end
68
78
 
69
79
  register_collector(:descendant) do |auto_runner|
@@ -117,7 +127,6 @@ module Test
117
127
  attr_writer :runner, :collector
118
128
 
119
129
  def initialize(standalone)
120
- Unit.run = true
121
130
  @standalone = standalone
122
131
  @runner = default_runner
123
132
  @collector = default_collector
@@ -144,7 +153,6 @@ module Test
144
153
  end
145
154
 
146
155
  def process_args(args=ARGV)
147
- args = args.dup
148
156
  begin
149
157
  args.unshift(*@default_arguments)
150
158
  options.order!(args) {|arg| @to_run << arg}
@@ -357,6 +365,7 @@ module Test
357
365
  end
358
366
 
359
367
  def run
368
+ self.class.need_auto_run = false
360
369
  suite = @collector[self]
361
370
  return false if suite.nil?
362
371
  return true if suite.empty?
@@ -365,8 +374,9 @@ module Test
365
374
  @runner_options[:color_scheme] ||= @color_scheme
366
375
  @runner_options[:listeners] ||= []
367
376
  @runner_options[:listeners].concat(@listeners)
368
- Dir.chdir(@workdir) if @workdir
369
- runner.run(suite, @runner_options).passed?
377
+ change_work_directory do
378
+ runner.run(suite, @runner_options).passed?
379
+ end
370
380
  end
371
381
 
372
382
  def load_config(file)
@@ -416,6 +426,14 @@ module Test
416
426
  file = global_config_file
417
427
  load_config(file) if file and File.exist?(file)
418
428
  end
429
+
430
+ def change_work_directory(&block)
431
+ if @workdir
432
+ Dir.chdir(@workdir, &block)
433
+ else
434
+ yield
435
+ end
436
+ end
419
437
  end
420
438
  end
421
439
  end
@@ -94,7 +94,7 @@ module Test
94
94
  256
95
95
  else
96
96
  case ENV["TERM"]
97
- when "xterm-256color"
97
+ when /-256color\z/
98
98
  256
99
99
  else
100
100
  8
@@ -104,6 +104,7 @@ module Test
104
104
 
105
105
  class << self
106
106
  def inherited(sub_class) # :nodoc:
107
+ require "test/unit"
107
108
  DESCENDANTS << sub_class
108
109
  end
109
110
 
@@ -8,6 +8,7 @@
8
8
 
9
9
  require 'test/unit/color-scheme'
10
10
  require 'test/unit/code-snippet-fetcher'
11
+ require 'test/unit/diff'
11
12
  require 'test/unit/ui/testrunner'
12
13
  require 'test/unit/ui/testrunnermediator'
13
14
  require 'test/unit/ui/console/outputlevel'
@@ -168,8 +169,7 @@ module Test
168
169
  end
169
170
 
170
171
  def output_fault_in_detail(fault)
171
- if @use_color and fault.is_a?(Failure) and
172
- fault.inspected_expected and fault.inspected_actual
172
+ if fault.is_a?(Failure)
173
173
  output_single(fault.label, fault_color(fault))
174
174
  output(":")
175
175
  output(fault.test_name)
@@ -429,7 +429,7 @@ module Test
429
429
  def guess_color_availability
430
430
  return false unless @output.tty?
431
431
  case ENV["TERM"]
432
- when /term(?:-color)?\z/, "screen"
432
+ when /term(?:-(?:256)?color)?\z/, "screen"
433
433
  true
434
434
  else
435
435
  return true if ENV["EMACS"] == "t"
@@ -37,7 +37,7 @@ module Test
37
37
  end
38
38
 
39
39
  def start_mediator
40
- @mediator.run_suite
40
+ @mediator.run
41
41
  end
42
42
 
43
43
  def diff_target_string?(string)
@@ -29,8 +29,8 @@ module Test
29
29
 
30
30
  # Runs the suite the TestRunnerMediator was created
31
31
  # with.
32
- def run_suite
33
- Unit.run = true
32
+ def run
33
+ AutoRunner.need_auto_run = false
34
34
 
35
35
  result = create_result
36
36
  finished_listener = result.add_listener(TestResult::FINISHED) do |*args|
@@ -51,9 +51,7 @@ module Test
51
51
  notify_listeners(RESET, @suite.size)
52
52
  notify_listeners(STARTED, result)
53
53
 
54
- @suite.run(result) do |channel, value|
55
- notify_listeners(channel, value)
56
- end
54
+ run_suite(result)
57
55
  ensure
58
56
  elapsed_time = Time.now - start_time
59
57
  result.remove_listener(TestResult::FAULT, fault_listener)
@@ -80,6 +78,12 @@ module Test
80
78
  yield
81
79
  Time.now - begin_time
82
80
  end
81
+
82
+ def run_suite(result)
83
+ @suite.run(result) do |channel, value|
84
+ notify_listeners(channel, value)
85
+ end
86
+ end
83
87
  end
84
88
  end
85
89
  end
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = '2.4.8'
3
+ VERSION = '2.4.9'
4
4
  end
5
5
  end
@@ -1907,5 +1907,20 @@ EOM
1907
1907
  end
1908
1908
  end
1909
1909
  end
1910
+
1911
+ class TestTemplate < Test::Unit::TestCase
1912
+ def test_incompatible_encoding_by_diff
1913
+ need_encoding
1914
+ assert_raise(AssertionFailedError) do
1915
+ assert_equal("UTF-8の日本語\n" * 3,
1916
+ ("Shift_JISの日本語\n" * 3).force_encoding("ASCII-8BIT"))
1917
+ end
1918
+ end
1919
+
1920
+ private
1921
+ def need_encoding
1922
+ omit("need Encoding") unless Object.const_defined?(:Encoding)
1923
+ end
1924
+ end
1910
1925
  end
1911
1926
  end
@@ -13,7 +13,7 @@ class TestUnitUIMediator < Test::Unit::TestCase
13
13
  finished = true
14
14
  end
15
15
  assert_raise(Interrupt) do
16
- mediator.run_suite
16
+ mediator.run
17
17
  end
18
18
  assert(finished)
19
19
  end
metadata CHANGED
@@ -1,81 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: test-unit
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.4.9
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 4
9
- - 8
10
- version: 2.4.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kouhei Sutou
14
9
  - Haruka Yoshihara
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-03-06 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
13
+ date: 2012-06-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
31
16
  name: rake
32
- prerelease: false
33
- type: :development
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
17
+ requirement: &3359000 !ruby/object:Gem::Requirement
37
18
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
45
- name: yard
46
- prerelease: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
47
23
  type: :development
48
- requirement: *id002
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ version_requirements: *3359000
26
+ - !ruby/object:Gem::Dependency
27
+ name: yard
28
+ requirement: &3371220 !ruby/object:Gem::Requirement
51
29
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
59
- name: jeweler
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
60
35
  prerelease: false
36
+ version_requirements: *3371220
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &3367460 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
61
45
  type: :development
62
- requirement: *id003
63
- description: |
64
- Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit
46
+ prerelease: false
47
+ version_requirements: *3367460
48
+ description: ! 'Ruby 1.9.x bundles minitest not Test::Unit. Test::Unit
49
+
65
50
  bundled in Ruby 1.8.x had not been improved but unbundled
51
+
66
52
  Test::Unit (test-unit) is improved actively.
67
53
 
68
- email:
54
+ '
55
+ email:
69
56
  - kou@cozmixng.org
70
57
  - yoshihara@clear-code.com
71
58
  executables: []
72
-
73
59
  extensions: []
74
-
75
- extra_rdoc_files:
60
+ extra_rdoc_files:
76
61
  - README.textile
77
62
  - TODO
78
- files:
63
+ files:
79
64
  - COPYING
80
65
  - GPL
81
66
  - PSFL
@@ -164,37 +149,28 @@ files:
164
149
  - test/util/test_observable.rb
165
150
  - test/util/test_procwrapper.rb
166
151
  homepage: http://test-unit.rubyforge.org/
167
- licenses:
152
+ licenses:
168
153
  - Ruby's and PSFL (lib/test/unit/diff.rb)
169
154
  post_install_message:
170
155
  rdoc_options: []
171
-
172
- require_paths:
156
+ require_paths:
173
157
  - lib
174
- required_ruby_version: !ruby/object:Gem::Requirement
158
+ required_ruby_version: !ruby/object:Gem::Requirement
175
159
  none: false
176
- requirements:
177
- - - ">="
178
- - !ruby/object:Gem::Version
179
- hash: 3
180
- segments:
181
- - 0
182
- version: "0"
183
- required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
165
  none: false
185
- requirements:
186
- - - ">="
187
- - !ruby/object:Gem::Version
188
- hash: 3
189
- segments:
190
- - 0
191
- version: "0"
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
192
170
  requirements: []
193
-
194
171
  rubyforge_project: test-unit
195
- rubygems_version: 1.8.15
172
+ rubygems_version: 1.8.11
196
173
  signing_key:
197
174
  specification_version: 3
198
175
  summary: test-unit - Improved version of Test::Unit bundled in Ruby 1.8.x.
199
176
  test_files: []
200
-