rroonga 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/NEWS.ja.rdoc +46 -0
  2. data/NEWS.rdoc +46 -0
  3. data/README.ja.rdoc +2 -2
  4. data/README.rdoc +2 -3
  5. data/Rakefile +148 -11
  6. data/example/bookmark.rb +94 -91
  7. data/ext/groonga/extconf.rb +25 -25
  8. data/ext/groonga/groonga.def +2 -0
  9. data/ext/groonga/mkmf.log +7 -7
  10. data/ext/groonga/rb-grn-column.c +66 -0
  11. data/ext/groonga/rb-grn-context.c +92 -5
  12. data/ext/groonga/rb-grn-database.c +24 -1
  13. data/ext/groonga/rb-grn-exception.c +15 -0
  14. data/ext/groonga/rb-grn-hash.c +2 -2
  15. data/ext/groonga/rb-grn-index-column.c +8 -4
  16. data/ext/groonga/rb-grn-object.c +4 -2
  17. data/ext/groonga/rb-grn-patricia-trie.c +2 -2
  18. data/ext/groonga/rb-grn-snippet.c +1 -0
  19. data/ext/groonga/rb-grn-table-key-support.c +22 -19
  20. data/ext/groonga/rb-grn-table.c +63 -5
  21. data/ext/groonga/rb-grn.h +1 -1
  22. data/ext/groonga/rb-groonga.c +1 -0
  23. data/extconf.rb +1 -1
  24. data/html/developer.html +8 -2
  25. data/html/favicon.ico +0 -0
  26. data/html/favicon.svg +591 -0
  27. data/html/index.html +71 -8
  28. data/html/logo.svg +612 -0
  29. data/html/ranguba.css +92 -7
  30. data/html/readme.svg +256 -0
  31. data/lib/groonga/expression-builder.rb +8 -4
  32. data/lib/groonga/record.rb +77 -7
  33. data/lib/groonga/schema.rb +429 -100
  34. data/rroonga-build.rb +1 -1
  35. data/test/run-test.rb +1 -1
  36. data/test/test-array.rb +4 -0
  37. data/test/test-context.rb +8 -0
  38. data/test/test-database.rb +8 -1
  39. data/test/test-expression-builder.rb +14 -0
  40. data/test/test-fix-size-column.rb +4 -0
  41. data/test/test-hash.rb +10 -4
  42. data/test/test-index-column.rb +11 -0
  43. data/test/test-patricia-trie.rb +7 -1
  44. data/test/test-record.rb +14 -0
  45. data/test/test-remote.rb +3 -2
  46. data/test/test-schema-create-table.rb +32 -2
  47. data/test/test-schema.rb +108 -11
  48. data/test/test-table-select-normalize.rb +7 -3
  49. data/test/test-table-select.rb +12 -0
  50. data/test/test-table.rb +7 -0
  51. data/test/test-variable-size-column.rb +4 -0
  52. data/test-unit/Rakefile +40 -0
  53. data/test-unit/TODO +5 -0
  54. data/test-unit/bin/testrb +5 -0
  55. data/test-unit/html/classic.html +15 -0
  56. data/test-unit/html/index.html +25 -0
  57. data/test-unit/html/index.html.ja +27 -0
  58. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  59. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  60. data/test-unit/lib/test/unit/attribute.rb +125 -0
  61. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  62. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  63. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  64. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  65. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  66. data/test-unit/lib/test/unit/collector.rb +36 -0
  67. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  68. data/test-unit/lib/test/unit/color.rb +96 -0
  69. data/test-unit/lib/test/unit/diff.rb +724 -0
  70. data/test-unit/lib/test/unit/error.rb +130 -0
  71. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  72. data/test-unit/lib/test/unit/failure.rb +136 -0
  73. data/test-unit/lib/test/unit/fixture.rb +176 -0
  74. data/test-unit/lib/test/unit/notification.rb +129 -0
  75. data/test-unit/lib/test/unit/omission.rb +191 -0
  76. data/test-unit/lib/test/unit/pending.rb +150 -0
  77. data/test-unit/lib/test/unit/priority.rb +180 -0
  78. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  79. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  80. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  81. data/test-unit/lib/test/unit/testcase.rb +476 -0
  82. data/test-unit/lib/test/unit/testresult.rb +89 -0
  83. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  84. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  85. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  86. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  87. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  88. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  89. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  90. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  91. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  92. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  93. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  94. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  95. data/test-unit/lib/test/unit/version.rb +7 -0
  96. data/test-unit/lib/test/unit.rb +323 -0
  97. data/test-unit/sample/adder.rb +13 -0
  98. data/test-unit/sample/subtracter.rb +12 -0
  99. data/test-unit/sample/test_adder.rb +20 -0
  100. data/test-unit/sample/test_subtracter.rb +20 -0
  101. data/test-unit/sample/test_user.rb +23 -0
  102. data/test-unit/test/collector/test-descendant.rb +133 -0
  103. data/test-unit/test/collector/test-load.rb +442 -0
  104. data/test-unit/test/collector/test_dir.rb +406 -0
  105. data/test-unit/test/collector/test_objectspace.rb +100 -0
  106. data/test-unit/test/run-test.rb +15 -0
  107. data/test-unit/test/test-attribute.rb +86 -0
  108. data/test-unit/test/test-color-scheme.rb +67 -0
  109. data/test-unit/test/test-color.rb +47 -0
  110. data/test-unit/test/test-diff.rb +518 -0
  111. data/test-unit/test/test-emacs-runner.rb +60 -0
  112. data/test-unit/test/test-fixture.rb +287 -0
  113. data/test-unit/test/test-notification.rb +33 -0
  114. data/test-unit/test/test-omission.rb +81 -0
  115. data/test-unit/test/test-pending.rb +70 -0
  116. data/test-unit/test/test-priority.rb +119 -0
  117. data/test-unit/test/test-testcase.rb +544 -0
  118. data/test-unit/test/test_assertions.rb +1151 -0
  119. data/test-unit/test/test_error.rb +26 -0
  120. data/test-unit/test/test_failure.rb +33 -0
  121. data/test-unit/test/test_testresult.rb +113 -0
  122. data/test-unit/test/test_testsuite.rb +129 -0
  123. data/test-unit/test/testunit-test-util.rb +14 -0
  124. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  125. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  126. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  127. data/test-unit/test/util/test_observable.rb +102 -0
  128. data/test-unit/test/util/test_procwrapper.rb +36 -0
  129. data/text/{TUTORIAL.ja.rdoc → tutorial.ja.rdoc} +165 -126
  130. metadata +106 -16
  131. data/html/favicon.xcf +0 -0
  132. data/html/logo.xcf +0 -0
  133. data/license/GPL +0 -340
  134. data/license/RUBY +0 -59
  135. data/pkg-config.rb +0 -333
@@ -0,0 +1,466 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright::
5
+ # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
+ # * Copyright (c) 2008-2009 Kouhei Sutou <kou@clear-code.com>
7
+ # License:: Ruby license.
8
+
9
+ require 'test/unit/color-scheme'
10
+ require 'test/unit/ui/testrunner'
11
+ require 'test/unit/ui/testrunnermediator'
12
+ require 'test/unit/ui/console/outputlevel'
13
+
14
+ module Test
15
+ module Unit
16
+ module UI
17
+ module Console
18
+
19
+ # Runs a Test::Unit::TestSuite on the console.
20
+ class TestRunner < UI::TestRunner
21
+ include OutputLevel
22
+
23
+ # Creates a new TestRunner for running the passed
24
+ # suite. If quiet_mode is true, the output while
25
+ # running is limited to progress dots, errors and
26
+ # failures, and the final result. io specifies
27
+ # where runner output should go to; defaults to
28
+ # STDOUT.
29
+ def initialize(suite, options={})
30
+ super
31
+ @output_level = @options[:output_level] || NORMAL
32
+ @output = @options[:output] || STDOUT
33
+ @use_color = @options[:use_color]
34
+ @use_color = guess_color_availability if @use_color.nil?
35
+ @color_scheme = @options[:color_scheme] || ColorScheme.default
36
+ @reset_color = Color.new("reset")
37
+ @progress_row = 0
38
+ @progress_row_max = @options[:progress_row_max]
39
+ @progress_row_max ||= guess_progress_row_max
40
+ @already_outputted = false
41
+ @n_successes = 0
42
+ @n_omissions = 0
43
+ @indent = 0
44
+ @top_level = true
45
+ @faults = []
46
+ end
47
+
48
+ # Begins the test run.
49
+ def start
50
+ setup_mediator
51
+ attach_to_mediator
52
+ return start_mediator
53
+ end
54
+
55
+ private
56
+ def setup_mediator
57
+ @mediator = create_mediator(@suite)
58
+ output_setup_end
59
+ end
60
+
61
+ def output_setup_end
62
+ suite_name = @suite.to_s
63
+ suite_name = @suite.name if @suite.kind_of?(Module)
64
+ output("Loaded suite #{suite_name}")
65
+ end
66
+
67
+ def create_mediator(suite)
68
+ return TestRunnerMediator.new(suite)
69
+ end
70
+
71
+ def attach_to_mediator
72
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
73
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
74
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
75
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
76
+ @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
77
+ @mediator.add_listener(TestSuite::STARTED, &method(:test_suite_started))
78
+ @mediator.add_listener(TestSuite::FINISHED, &method(:test_suite_finished))
79
+ end
80
+
81
+ def start_mediator
82
+ return @mediator.run_suite
83
+ end
84
+
85
+ def add_fault(fault)
86
+ @faults << fault
87
+ output_progress(fault.single_character_display, fault_color(fault))
88
+ @n_omissions += 1 if fault.is_a?(Omission)
89
+ @already_outputted = true if fault.critical?
90
+ end
91
+
92
+ def started(result)
93
+ @result = result
94
+ output_started
95
+ end
96
+
97
+ def output_started
98
+ output("Started")
99
+ end
100
+
101
+ def finished(elapsed_time)
102
+ nl if output?(NORMAL) and !output?(VERBOSE)
103
+ @faults.each_with_index do |fault, index|
104
+ nl
105
+ output_single("%3d) " % (index + 1))
106
+ output_fault(fault)
107
+ end
108
+ nl
109
+ output("Finished in #{elapsed_time} seconds.")
110
+ nl
111
+ output(@result, result_color)
112
+ n_tests = @result.run_count - @n_omissions
113
+ if n_tests.zero?
114
+ pass_percentage = 0
115
+ else
116
+ pass_percentage = 100.0 * (@n_successes / n_tests.to_f)
117
+ end
118
+ output("%g%% passed" % pass_percentage, result_color)
119
+ end
120
+
121
+ def output_fault(fault)
122
+ if @use_color and fault.is_a?(Failure) and
123
+ fault.inspected_expected and fault.inspected_actual
124
+ output_single(fault.label, fault_color(fault))
125
+ output(":")
126
+ output_fault_backtrace(fault)
127
+ output_fault_message(fault)
128
+ else
129
+ label, detail = format_fault(fault).split(/\r?\n/, 2)
130
+ output(label, fault_color(fault))
131
+ output(detail)
132
+ end
133
+ end
134
+
135
+ def output_fault_backtrace(fault)
136
+ backtrace = fault.location
137
+ if backtrace.size == 1
138
+ output(fault.test_name +
139
+ backtrace[0].sub(/\A(.+:\d+).*/, ' [\\1]') +
140
+ ":")
141
+ else
142
+ output(fault.test_name)
143
+ backtrace.each_with_index do |entry, i|
144
+ if i.zero?
145
+ prefix = "["
146
+ postfix = ""
147
+ elsif i == backtrace.size - 1
148
+ prefix = " "
149
+ postfix = "]:"
150
+ else
151
+ prefix = " "
152
+ postfix = ""
153
+ end
154
+ output(" #{prefix}#{entry}#{postfix}")
155
+ end
156
+ end
157
+ end
158
+
159
+ def output_fault_message(fault)
160
+ output(fault.user_message) if fault.user_message
161
+ output_single("<")
162
+ output_single(fault.inspected_expected, color("success"))
163
+ output("> expected but was")
164
+ output_single("<")
165
+ output_single(fault.inspected_actual, color("failure"))
166
+ output(">")
167
+ from, to = prepare_for_diff(fault.expected, fault.actual)
168
+ if from and to
169
+ differ = ColorizedReadableDiffer.new(from.split(/\r?\n/),
170
+ to.split(/\r?\n/),
171
+ self)
172
+ if differ.need_diff?
173
+ output("")
174
+ output("diff:")
175
+ differ.diff
176
+ end
177
+ end
178
+ end
179
+
180
+ def format_fault(fault)
181
+ fault.long_display
182
+ end
183
+
184
+ def test_started(name)
185
+ return unless output?(VERBOSE)
186
+
187
+ name = name.sub(/\(.+?\)\z/, '')
188
+ right_space = 8 * 2
189
+ left_space = @progress_row_max - right_space
190
+ left_space = left_space - indent.size - name.size
191
+ tab_stop = "\t" * ([left_space - 1, 0].max / 8)
192
+ output_single("#{indent}#{name}:#{tab_stop}", nil, VERBOSE)
193
+ @test_start = Time.now
194
+ end
195
+
196
+ def test_finished(name)
197
+ unless @already_outputted
198
+ @n_successes += 1
199
+ output_progress(".", color("success"))
200
+ end
201
+ @already_outputted = false
202
+
203
+ return unless output?(VERBOSE)
204
+
205
+ output(": (%f)" % (Time.now - @test_start), nil, VERBOSE)
206
+ end
207
+
208
+ def test_suite_started(name)
209
+ if @top_level
210
+ @top_level = false
211
+ return
212
+ end
213
+
214
+ output_single(indent, nil, VERBOSE)
215
+ if /\A[A-Z]/ =~ name
216
+ _color = color("case")
217
+ else
218
+ _color = color("suite")
219
+ end
220
+ output_single(name, _color, VERBOSE)
221
+ output(": ", nil, VERBOSE)
222
+ @indent += 2
223
+ end
224
+
225
+ def test_suite_finished(name)
226
+ @indent -= 2
227
+ end
228
+
229
+ def indent
230
+ if output?(VERBOSE)
231
+ " " * @indent
232
+ else
233
+ ""
234
+ end
235
+ end
236
+
237
+ def nl(level=NORMAL)
238
+ output("", nil, level)
239
+ end
240
+
241
+ def output(something, color=nil, level=NORMAL)
242
+ return unless output?(level)
243
+ output_single(something, color, level)
244
+ @output.puts
245
+ end
246
+
247
+ def output_single(something, color=nil, level=NORMAL)
248
+ return false unless output?(level)
249
+ if @use_color and color
250
+ something = "%s%s%s" % [color.escape_sequence,
251
+ something,
252
+ @reset_color.escape_sequence]
253
+ end
254
+ @output.write(something)
255
+ @output.flush
256
+ true
257
+ end
258
+
259
+ def output_progress(mark, color=nil)
260
+ if output_single(mark, color, PROGRESS_ONLY)
261
+ return unless @progress_row_max > 0
262
+ @progress_row += mark.size
263
+ if @progress_row >= @progress_row_max
264
+ nl unless @output_level == VERBOSE
265
+ @progress_row = 0
266
+ end
267
+ end
268
+ end
269
+
270
+ def output?(level)
271
+ level <= @output_level
272
+ end
273
+
274
+ def color(name)
275
+ @color_scheme[name] || ColorScheme.default[name]
276
+ end
277
+
278
+ def fault_color(fault)
279
+ color(fault.class.name.split(/::/).last.downcase)
280
+ end
281
+
282
+ def result_color
283
+ if @result.passed?
284
+ if @result.pending_count > 0
285
+ color("pending")
286
+ elsif @result.omission_count > 0
287
+ color("omission")
288
+ elsif @result.notification_count > 0
289
+ color("notification")
290
+ else
291
+ color("success")
292
+ end
293
+ elsif @result.error_count > 0
294
+ color("error")
295
+ elsif @result.failure_count > 0
296
+ color("failure")
297
+ end
298
+ end
299
+
300
+ def guess_color_availability
301
+ return false unless @output.tty?
302
+ case ENV["TERM"]
303
+ when /term(?:-color)?\z/, "screen"
304
+ true
305
+ else
306
+ return true if ENV["EMACS"] == "t"
307
+ false
308
+ end
309
+ end
310
+
311
+ def guess_progress_row_max
312
+ term_width = guess_term_width
313
+ if term_width.zero?
314
+ if ENV["EMACS"] == "t"
315
+ -1
316
+ else
317
+ 79
318
+ end
319
+ else
320
+ term_width
321
+ end
322
+ end
323
+
324
+ def guess_term_width
325
+ Integer(ENV["TERM_WIDTH"] || 0)
326
+ rescue ArgumentError
327
+ 0
328
+ end
329
+ end
330
+
331
+ class ColorizedReadableDiffer < Diff::ReadableDiffer
332
+ def initialize(from, to, runner)
333
+ @runner = runner
334
+ super(from, to)
335
+ end
336
+
337
+ def need_diff?(options={})
338
+ operations.each do |tag,|
339
+ return true if [:replace, :equal].include?(tag)
340
+ end
341
+ false
342
+ end
343
+
344
+ private
345
+ def output_single(something, color=nil)
346
+ @runner.send(:output_single, something, color)
347
+ end
348
+
349
+ def output(something, color=nil)
350
+ @runner.send(:output, something, color)
351
+ end
352
+
353
+ def color(name)
354
+ @runner.send(:color, name)
355
+ end
356
+
357
+ def cut_off_ratio
358
+ 0
359
+ end
360
+
361
+ def default_ratio
362
+ 0
363
+ end
364
+
365
+ def tag(mark, color_name, contents)
366
+ _color = color(color_name)
367
+ contents.each do |content|
368
+ output_single(mark, _color)
369
+ output_single(" ")
370
+ output(content)
371
+ end
372
+ end
373
+
374
+ def tag_deleted(contents)
375
+ tag("-", "diff-deleted-tag", contents)
376
+ end
377
+
378
+ def tag_inserted(contents)
379
+ tag("+", "diff-inserted-tag", contents)
380
+ end
381
+
382
+ def tag_equal(contents)
383
+ tag(" ", "normal", contents)
384
+ end
385
+
386
+ def tag_difference(contents)
387
+ tag("?", "diff-difference-tag", contents)
388
+ end
389
+
390
+ def diff_line(from_line, to_line)
391
+ to_operations = []
392
+ from_line, to_line, _operations = line_operations(from_line, to_line)
393
+
394
+ no_replace = true
395
+ _operations.each do |tag,|
396
+ if tag == :replace
397
+ no_replace = false
398
+ break
399
+ end
400
+ end
401
+
402
+ output_single("?", color("diff-difference-tag"))
403
+ output_single(" ")
404
+ _operations.each do |tag, from_start, from_end, to_start, to_end|
405
+ from_width = compute_width(from_line, from_start, from_end)
406
+ to_width = compute_width(to_line, to_start, to_end)
407
+ case tag
408
+ when :replace
409
+ output_single(from_line[from_start...from_end],
410
+ color("diff-deleted"))
411
+ if (from_width < to_width)
412
+ output_single(" " * (to_width - from_width))
413
+ end
414
+ to_operations << Proc.new do
415
+ output_single(to_line[to_start...to_end],
416
+ color("diff-inserted"))
417
+ if (to_width < from_width)
418
+ output_single(" " * (from_width - to_width))
419
+ end
420
+ end
421
+ when :delete
422
+ output_single(from_line[from_start...from_end],
423
+ color("diff-deleted"))
424
+ unless no_replace
425
+ to_operations << Proc.new {output_single(" " * from_width)}
426
+ end
427
+ when :insert
428
+ if no_replace
429
+ output_single(to_line[to_start...to_end],
430
+ color("diff-inserted"))
431
+ else
432
+ output_single(" " * to_width)
433
+ to_operations << Proc.new do
434
+ output_single(to_line[to_start...to_end],
435
+ color("diff-inserted"))
436
+ end
437
+ end
438
+ when :equal
439
+ output_single(from_line[from_start...from_end])
440
+ unless no_replace
441
+ to_operations << Proc.new {output_single(" " * to_width)}
442
+ end
443
+ else
444
+ raise "unknown tag: #{tag}"
445
+ end
446
+ end
447
+ output("")
448
+
449
+ unless to_operations.empty?
450
+ output_single("?", color("diff-difference-tag"))
451
+ output_single(" ")
452
+ to_operations.each do |operation|
453
+ operation.call
454
+ end
455
+ output("")
456
+ end
457
+ end
458
+ end
459
+ end
460
+ end
461
+ end
462
+ end
463
+
464
+ if __FILE__ == $0
465
+ Test::Unit::UI::Console::TestRunner.start_command_line_test
466
+ end
@@ -0,0 +1,63 @@
1
+ require 'test/unit/ui/console/testrunner'
2
+
3
+ module Test
4
+ module Unit
5
+ module UI
6
+ module Emacs
7
+ class TestRunner < Console::TestRunner
8
+ private
9
+ def output_setup_end
10
+ end
11
+
12
+ def output_started
13
+ end
14
+
15
+ def format_fault(fault)
16
+ return super unless fault.respond_to?(:label)
17
+ format_method_name = "format_fault_#{fault.label.downcase}"
18
+ if respond_to?(format_method_name, true)
19
+ send(format_method_name, fault)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def output_fault_backtrace(fault)
26
+ backtrace = fault.location
27
+ if backtrace.size == 1
28
+ output(fault.test_name +
29
+ backtrace[0].sub(/\A(.+:\d+).*/, ' [\\1]') +
30
+ ":")
31
+ else
32
+ output(fault.test_name)
33
+ backtrace.each do |entry|
34
+ output(entry)
35
+ end
36
+ end
37
+ end
38
+
39
+ def format_fault_failure(failure)
40
+ if failure.location.size == 1
41
+ location = failure.location[0]
42
+ location_display = location.sub(/\A(.+:\d+).*/, ' [\\1]')
43
+ else
44
+ location_display = "\n" + failure.location.join("\n")
45
+ end
46
+ result = "#{failure.label}:\n"
47
+ result << "#{failure.test_name}#{location_display}:\n"
48
+ result << failure.message
49
+ result
50
+ end
51
+
52
+ def format_fault_error(error)
53
+ result = "#{error.label}:\n"
54
+ result << "#{error.test_name}:\n"
55
+ result << "#{error.message}\n"
56
+ result << error.backtrace.join("\n")
57
+ result
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,92 @@
1
+ #--
2
+ #
3
+ # Author:: Kouhei Sutou.
4
+ # Copyright:: Copyright (c) 2009 Kouhei Sutou <kou@clear-code.com>.
5
+ # License:: Ruby license.
6
+
7
+ require 'test/unit/ui/testrunner'
8
+ require 'test/unit/ui/testrunnermediator'
9
+
10
+ module Test
11
+ module Unit
12
+ module UI
13
+ module Tap
14
+
15
+ # Runs a Test::Unit::TestSuite and outputs result
16
+ # as TAP format.
17
+ class TestRunner < UI::TestRunner
18
+ def initialize(suite, options={})
19
+ super
20
+ @output = @options[:output] || STDOUT
21
+ @n_tests = 0
22
+ @already_outputted = false
23
+ end
24
+
25
+ # Begins the test run.
26
+ def start
27
+ setup_mediator
28
+ result = start_mediator
29
+ def result.passed?
30
+ true # for prove commend :<
31
+ end
32
+ result
33
+ end
34
+
35
+ private
36
+ def setup_mediator
37
+ @mediator = TestRunnerMediator.new(@suite)
38
+ attach_to_mediator
39
+ end
40
+
41
+ def attach_to_mediator
42
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
43
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
44
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
45
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
46
+ @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
47
+ end
48
+
49
+ def start_mediator
50
+ @mediator.run_suite
51
+ end
52
+
53
+ def add_fault(fault)
54
+ puts("not ok #{@n_tests} - #{fault.short_display}")
55
+ fault.long_display.each_line do |line|
56
+ puts("# #{line}")
57
+ end
58
+ @already_outputted = true
59
+ end
60
+
61
+ def started(result)
62
+ @result = result
63
+ puts("1..#{@suite.size}")
64
+ end
65
+
66
+ def finished(elapsed_time)
67
+ puts("# Finished in #{elapsed_time} seconds.")
68
+ @result.to_s.each_line do |line|
69
+ puts("# #{line}")
70
+ end
71
+ end
72
+
73
+ def test_started(name)
74
+ @n_tests += 1
75
+ end
76
+
77
+ def test_finished(name)
78
+ unless @already_outputted
79
+ puts("ok #{@n_tests} - #{name}")
80
+ end
81
+ @already_outputted = false
82
+ end
83
+
84
+ def puts(*args)
85
+ @output.puts(*args)
86
+ @output.flush
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,28 @@
1
+ require 'test/unit/ui/testrunnerutilities'
2
+
3
+ module Test
4
+ module Unit
5
+ module UI
6
+ class TestRunner
7
+ extend TestRunnerUtilities
8
+
9
+ def initialize(suite, options={})
10
+ if suite.respond_to?(:suite)
11
+ @suite = suite.suite
12
+ else
13
+ @suite = suite
14
+ end
15
+ @options = options
16
+ end
17
+
18
+ def diff_target_string?(string)
19
+ Assertions::AssertionMessage.diff_target_string?(string)
20
+ end
21
+
22
+ def prepare_for_diff(from, to)
23
+ Assertions::AssertionMessage.prepare_for_diff(from, to)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end