rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
@@ -0,0 +1,48 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ module Test
8
+ module Unit
9
+ module Util
10
+
11
+ # Allows the storage of a Proc passed through '&' in a
12
+ # hash.
13
+ #
14
+ # Note: this may be inefficient, since the hash being
15
+ # used is not necessarily very good. In Observable,
16
+ # efficiency is not too important, since the hash is
17
+ # only accessed when adding and removing listeners,
18
+ # not when notifying.
19
+
20
+ class ProcWrapper
21
+
22
+ # Creates a new wrapper for a_proc.
23
+ def initialize(a_proc)
24
+ @a_proc = a_proc
25
+ @hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
26
+ end
27
+
28
+ def hash
29
+ return @hash
30
+ end
31
+
32
+ def ==(other)
33
+ case(other)
34
+ when ProcWrapper
35
+ return @a_proc == other.to_proc
36
+ else
37
+ return super
38
+ end
39
+ end
40
+ alias :eql? :==
41
+
42
+ def to_proc
43
+ return @a_proc
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+
2
+ # HACK: quick and dirty to get integrated into the new project - ryan
3
+ module Test
4
+ module Unit
5
+ VERSION = '2.0.8'
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ class Adder
6
+ def initialize(number)
7
+ @number = number
8
+ end
9
+ def add(number)
10
+ return @number + number
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ class Subtracter
6
+ def initialize(number)
7
+ @number = number
8
+ end
9
+ def subtract(number)
10
+ return @number - number
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit'
6
+ require 'adder'
7
+
8
+ class TestAdder < Test::Unit::TestCase
9
+ def setup
10
+ @adder = Adder.new(5)
11
+ end
12
+
13
+ def test_add
14
+ assert_equal(7, @adder.add(2), "Should have added correctly")
15
+ end
16
+
17
+ def teardown
18
+ @adder = nil
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit'
6
+ require 'subtracter'
7
+
8
+ class TestSubtracter < Test::Unit::TestCase
9
+ def setup
10
+ @subtracter = Subtracter.new(5)
11
+ end
12
+
13
+ def test_subtract
14
+ assert_equal(3, @subtracter.subtract(2), "Should have subtracted correctly")
15
+ end
16
+
17
+ def teardown
18
+ @subtracter = nil
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # nested test case example.
2
+ require 'test/unit'
3
+
4
+ class UserTest < Test::Unit::TestCase
5
+ def setup
6
+ @user = "me"
7
+ end
8
+
9
+ def test_full_name
10
+ assert_equal("me", @user)
11
+ end
12
+
13
+ class ProfileTest < UserTest
14
+ setup
15
+ def setup_profile
16
+ @user += ": profile"
17
+ end
18
+
19
+ def test_has_profile
20
+ assert_match(/: profile/, @user)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,133 @@
1
+ require 'test/unit'
2
+ require 'test/unit/collector/descendant'
3
+
4
+ class TestUnitCollectorDescendant < Test::Unit::TestCase
5
+ def setup
6
+ @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
7
+ Test::Unit::TestCase::DESCENDANTS.clear
8
+
9
+ @test_case1 = Class.new(Test::Unit::TestCase) do
10
+ def self.name
11
+ "test-case1"
12
+ end
13
+
14
+ def test_1
15
+ end
16
+
17
+ def test_2
18
+ end
19
+ end
20
+
21
+ @test_case2 = Class.new(Test::Unit::TestCase) do
22
+ def self.name
23
+ "test-case2"
24
+ end
25
+
26
+ def test_0
27
+ end
28
+ end
29
+
30
+ @no_test_case = Class.new do
31
+ def self.name
32
+ "no-test-case"
33
+ end
34
+
35
+ def test_4
36
+ end
37
+ end
38
+ end
39
+
40
+ def teardown
41
+ Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
42
+ end
43
+
44
+ def test_basic_collection
45
+ assert_collect(full_suite("name"), "name")
46
+
47
+ assert_collect(full_suite("name"), "name") do |collector|
48
+ collector.filter = []
49
+ end
50
+ end
51
+
52
+ def test_filtered_collection
53
+ assert_collect(empty_suite) do |collector|
54
+ collector.filter = Proc.new {false}
55
+ end
56
+
57
+ assert_collect(full_suite) do |collector|
58
+ collector.filter = Proc.new {true}
59
+ end
60
+
61
+ assert_collect(full_suite) do |collector|
62
+ collector.filter = Proc.new {nil}
63
+ end
64
+
65
+ assert_collect(empty_suite) do |collector|
66
+ collector.filter = [Proc.new {false}, Proc.new {true}]
67
+ end
68
+
69
+ assert_collect(empty_suite) do |collector|
70
+ collector.filter = [Proc.new {true}, Proc.new {false}]
71
+ end
72
+
73
+ assert_collect(empty_suite) do |collector|
74
+ collector.filter = [Proc.new {nil}, Proc.new {false}]
75
+ end
76
+
77
+ assert_collect(full_suite) do |collector|
78
+ collector.filter = [Proc.new {nil}, Proc.new {true}]
79
+ end
80
+
81
+ expected = empty_suite
82
+ suite1 = Test::Unit::TestSuite.new(@test_case1.name)
83
+ suite1 << @test_case1.new("test_1")
84
+ suite2 = Test::Unit::TestSuite.new(@test_case2.name)
85
+ suite2 << @test_case2.new("test_0")
86
+ expected << suite1 << suite2
87
+ assert_collect(expected) do |collector|
88
+ collector.filter = Proc.new do |test|
89
+ ['test_1', 'test_0'].include?(test.method_name)
90
+ end
91
+ end
92
+
93
+ suite1 = Test::Unit::TestSuite.new(@test_case1.name)
94
+ suite1 << @test_case1.new("test_1")
95
+ suite2 = Test::Unit::TestSuite.new(@test_case2.name)
96
+ suite2 << @test_case2.new("test_0")
97
+ assert_collect(empty_suite) do |collector|
98
+ filters = [Proc.new {|test| test.method_name == 'test_1' ? true : nil},
99
+ Proc.new {|test| test.method_name == 'test_0' ? true : nil},
100
+ Proc.new {false}]
101
+ collector.filter = filters
102
+ end
103
+ end
104
+
105
+ private
106
+ def assert_collect(expected, *collect_args)
107
+ collector = Test::Unit::Collector::Descendant.new
108
+ yield(collector) if block_given?
109
+ assert_equal(expected, collector.send(:collect, *collect_args))
110
+ end
111
+
112
+ def default_name
113
+ Test::Unit::Collector::Descendant::NAME
114
+ end
115
+
116
+ def empty_suite(name=nil)
117
+ Test::Unit::TestSuite.new(name || default_name)
118
+ end
119
+
120
+ def full_suite(name=nil)
121
+ sub_suite1 = Test::Unit::TestSuite.new(@test_case1.name)
122
+ sub_suite1 << @test_case1.new('test_1')
123
+ sub_suite1 << @test_case1.new('test_2')
124
+
125
+ sub_suite2 = Test::Unit::TestSuite.new(@test_case2.name)
126
+ sub_suite2 << @test_case2.new('test_0')
127
+
128
+ suite = empty_suite(name)
129
+ suite << sub_suite1
130
+ suite << sub_suite2
131
+ suite
132
+ end
133
+ end
@@ -0,0 +1,348 @@
1
+ require 'tmpdir'
2
+ require 'pathname'
3
+
4
+ require 'test/unit'
5
+ require 'test/unit/collector/load'
6
+
7
+ class TestUnitCollectorLoad < Test::Unit::TestCase
8
+ def setup
9
+ @previous_descendants = Test::Unit::TestCase::DESCENDANTS.dup
10
+ Test::Unit::TestCase::DESCENDANTS.clear
11
+
12
+ @temporary_test_cases_module_name = "TempTestCases"
13
+ ::Object.const_set(@temporary_test_cases_module_name, Module.new)
14
+
15
+ @test_dir = Pathname(Dir.tmpdir) + "test-unit"
16
+ @test_dir.rmtree if @test_dir.exist?
17
+ @test_dir.mkpath
18
+ end
19
+
20
+ setup
21
+ def setup_top_level_test_cases
22
+ @test_case1 = @test_dir + "test_case1.rb"
23
+ @test_case2 = @test_dir + "test_case2.rb"
24
+ @no_load_test_case3 = @test_dir + "case3.rb"
25
+
26
+ @test_case1.open("w") do |test_case|
27
+ test_case.puts(<<-EOT)
28
+ module #{@temporary_test_cases_module_name}
29
+ class TestCase1 < Test::Unit::TestCase
30
+ def test1_1
31
+ end
32
+
33
+ def test1_2
34
+ end
35
+ end
36
+ end
37
+ EOT
38
+ end
39
+
40
+ @test_case2.open("w") do |test_case|
41
+ test_case.puts(<<-EOT)
42
+ module #{@temporary_test_cases_module_name}
43
+ class TestCase2 < Test::Unit::TestCase
44
+ def test2
45
+ end
46
+ end
47
+ end
48
+ EOT
49
+ end
50
+
51
+ @no_load_test_case3.open("w") do |test_case|
52
+ test_case.puts(<<-EOT)
53
+ module #{@temporary_test_cases_module_name}
54
+ class NoLoadTestCase3 < Test::Unit::TestCase
55
+ def test3
56
+ end
57
+ end
58
+ end
59
+ EOT
60
+ end
61
+ end
62
+
63
+ setup
64
+ def setup_sub_level_test_cases
65
+ @sub_test_dir = @test_dir + "sub"
66
+ @sub_test_dir.mkpath
67
+
68
+ @sub_test_case4 = @sub_test_dir + "test_case4.rb"
69
+ @no_load_sub_test_case5 = @sub_test_dir + "case5.rb"
70
+ @sub_test_case6 = @sub_test_dir + "test_case6.rb"
71
+
72
+ @sub_test_case4.open("w") do |test_case|
73
+ test_case.puts(<<-EOT)
74
+ module #{@temporary_test_cases_module_name}
75
+ class SubTestCase4 < Test::Unit::TestCase
76
+ def test4_1
77
+ end
78
+
79
+ def test4_2
80
+ end
81
+ end
82
+ end
83
+ EOT
84
+ end
85
+
86
+ @no_load_sub_test_case5.open("w") do |test_case|
87
+ test_case.puts(<<-EOT)
88
+ module #{@temporary_test_cases_module_name}
89
+ class NoLoadSubTestCase5 < Test::Unit::TestCase
90
+ def test5_1
91
+ end
92
+
93
+ def test5_2
94
+ end
95
+ end
96
+ end
97
+ EOT
98
+ end
99
+
100
+ @sub_test_case6.open("w") do |test_case|
101
+ test_case.puts(<<-EOT)
102
+ module #{@temporary_test_cases_module_name}
103
+ class SubTestCase6 < Test::Unit::TestCase
104
+ def test6
105
+ end
106
+ end
107
+ end
108
+ EOT
109
+ end
110
+ end
111
+
112
+ setup
113
+ def setup_sub_level_test_cases2
114
+ @sub2_test_dir = @test_dir + "sub2"
115
+ @sub2_test_dir.mkpath
116
+
117
+ @no_load_sub2_test_case7 = @sub2_test_dir + "case7.rb"
118
+ @sub2_test_case8 = @sub2_test_dir + "test_case8.rb"
119
+ @sub2_test_case9 = @sub2_test_dir + "test_case9.rb"
120
+
121
+ @no_load_sub2_test_case7.open("w") do |test_case|
122
+ test_case.puts(<<-EOT)
123
+ module #{@temporary_test_cases_module_name}
124
+ class NoLoadSub2TestCase7 < Test::Unit::TestCase
125
+ def test7_1
126
+ end
127
+
128
+ def test7_2
129
+ end
130
+ end
131
+ end
132
+ EOT
133
+ end
134
+
135
+ @sub2_test_case8.open("w") do |test_case|
136
+ test_case.puts(<<-EOT)
137
+ module #{@temporary_test_cases_module_name}
138
+ class Sub2TestCase8 < Test::Unit::TestCase
139
+ def test8_1
140
+ end
141
+
142
+ def test8_2
143
+ end
144
+ end
145
+ end
146
+ EOT
147
+ end
148
+
149
+ @sub2_test_case9.open("w") do |test_case|
150
+ test_case.puts(<<-EOT)
151
+ module #{@temporary_test_cases_module_name}
152
+ class Sub2TestCase9 < Test::Unit::TestCase
153
+ def test9
154
+ end
155
+ end
156
+ end
157
+ EOT
158
+ end
159
+ end
160
+
161
+ setup
162
+ def setup_svn_test_cases
163
+ @svn_test_dir = @test_dir + ".svn"
164
+ @svn_test_dir.mkpath
165
+
166
+ @svn_test_case10 = @svn_test_dir + "test_case10.rb"
167
+
168
+ @svn_test_case10.open("w") do |test_case|
169
+ test_case.puts(<<-EOT)
170
+ module #{@temporary_test_cases_module_name}
171
+ class SvnTestCase10 < Test::Unit::TestCase
172
+ def test7
173
+ end
174
+ end
175
+ end
176
+ EOT
177
+ end
178
+ end
179
+
180
+ setup
181
+ def setup_sub_cvs_test_cases
182
+ @sub_cvs_test_dir = @sub_test_dir + "CVS"
183
+ @sub_cvs_test_dir.mkpath
184
+
185
+ @sub_cvs_test_case11 = @sub_cvs_test_dir + "test_case11.rb"
186
+
187
+ @sub_cvs_test_case11.open("w") do |test_case|
188
+ test_case.puts(<<-EOT)
189
+ module #{@temporary_test_cases_module_name}
190
+ class SubCVSTestCase11 < Test::Unit::TestCase
191
+ def test11
192
+ end
193
+ end
194
+ end
195
+ EOT
196
+ end
197
+ end
198
+
199
+ setup
200
+ def setup_sub_git_test_cases
201
+ @sub_git_test_dir = @sub_test_dir + ".git"
202
+ @sub_git_test_dir.mkpath
203
+
204
+ @sub_git_test_case11 = @sub_git_test_dir + "test_case11.rb"
205
+
206
+ @sub_git_test_case11.open("w") do |test_case|
207
+ test_case.puts(<<-EOT)
208
+ module #{@temporary_test_cases_module_name}
209
+ class SubGitTestCase11 < Test::Unit::TestCase
210
+ def test11
211
+ end
212
+ end
213
+ end
214
+ EOT
215
+ end
216
+ end
217
+
218
+ def teardown
219
+ @test_dir.rmtree if @test_dir.exist?
220
+ ::Object.send(:remove_const, @temporary_test_cases_module_name)
221
+ Test::Unit::TestCase::DESCENDANTS.replace(@previous_descendants)
222
+ end
223
+
224
+ def test_simple_collect
225
+ assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
226
+ [:suite, {:name => _test_case_name("SubTestCase4")},
227
+ [:test, {:name => "test4_1"}],
228
+ [:test, {:name => "test4_2"}]],
229
+ [:suite, {:name => _test_case_name("SubTestCase6")},
230
+ [:test, {:name => "test6"}]]],
231
+ @sub_test_dir.to_s)
232
+ end
233
+
234
+ def test_multilevel_collect
235
+ assert_collect([:suite, {:name => "."},
236
+ [:suite, {:name => _test_case_name("TestCase1")},
237
+ [:test, {:name => "test1_1"}],
238
+ [:test, {:name => "test1_2"}]],
239
+ [:suite, {:name => _test_case_name("TestCase2")},
240
+ [:test, {:name => "test2"}]],
241
+ [:suite, {:name => @sub_test_dir.basename.to_s},
242
+ [:suite, {:name => _test_case_name("SubTestCase4")},
243
+ [:test, {:name => "test4_1"}],
244
+ [:test, {:name => "test4_2"}]],
245
+ [:suite, {:name => _test_case_name("SubTestCase6")},
246
+ [:test, {:name => "test6"}]]],
247
+ [:suite, {:name => @sub2_test_dir.basename.to_s},
248
+ [:suite, {:name => _test_case_name("Sub2TestCase8")},
249
+ [:test, {:name => "test8_1"}],
250
+ [:test, {:name => "test8_2"}]],
251
+ [:suite, {:name => _test_case_name("Sub2TestCase9")},
252
+ [:test, {:name => "test9"}]]]])
253
+ end
254
+
255
+ def test_collect_file
256
+ assert_collect([:suite, {:name => @test_case1.basename.to_s},
257
+ [:suite, {:name => _test_case_name("TestCase1")},
258
+ [:test, {:name => "test1_1"}],
259
+ [:test, {:name => "test1_2"}]]],
260
+ @test_case1.to_s)
261
+
262
+ assert_collect(nil, @no_load_sub_test_case5.to_s)
263
+ end
264
+
265
+ def test_nil_pattern
266
+ assert_collect([:suite, {:name => @sub_test_dir.basename.to_s},
267
+ [:suite, {:name => _test_case_name("NoLoadSubTestCase5")},
268
+ [:test, {:name => "test5_1"}],
269
+ [:test, {:name => "test5_2"}]],
270
+ [:suite, {:name => _test_case_name("SubTestCase4")},
271
+ [:test, {:name => "test4_1"}],
272
+ [:test, {:name => "test4_2"}]],
273
+ [:suite, {:name => _test_case_name("SubTestCase6")},
274
+ [:test, {:name => "test6"}]]],
275
+ @sub_test_dir.to_s) do |collector|
276
+ collector.patterns.clear
277
+ end
278
+ end
279
+
280
+ def test_filtering
281
+ assert_collect([:suite, {:name => "."},
282
+ [:suite, {:name => _test_case_name("TestCase1")},
283
+ [:test, {:name => "test1_1"}],
284
+ [:test, {:name => "test1_2"}]]]) do |collector|
285
+ collector.filter = Proc.new do |test|
286
+ !/\Atest1/.match(test.method_name).nil?
287
+ end
288
+ end
289
+ end
290
+
291
+ def test_collect_multi
292
+ test_dirs = [@sub_test_dir.to_s, @sub2_test_dir.to_s]
293
+ assert_collect([:suite, {:name => "[#{test_dirs.join(', ')}]"},
294
+ [:suite, {:name => @sub_test_dir.basename.to_s},
295
+ [:suite, {:name => _test_case_name("SubTestCase4")},
296
+ [:test, {:name => "test4_1"}],
297
+ [:test, {:name => "test4_2"}]],
298
+ [:suite, {:name => _test_case_name("SubTestCase6")},
299
+ [:test, {:name => "test6"}]]],
300
+ [:suite, {:name => @sub2_test_dir.basename.to_s},
301
+ [:suite, {:name => _test_case_name("Sub2TestCase8")},
302
+ [:test, {:name => "test8_1"}],
303
+ [:test, {:name => "test8_2"}]],
304
+ [:suite, {:name => _test_case_name("Sub2TestCase9")},
305
+ [:test, {:name => "test9"}]]]],
306
+ *test_dirs)
307
+ end
308
+
309
+ private
310
+ def assert_collect(expected, *collect_args)
311
+ keep_required_files do
312
+ Dir.chdir(@test_dir.to_s) do
313
+ collector = Test::Unit::Collector::Load.new
314
+ yield(collector) if block_given?
315
+ actual = inspect_test_object(collector.send(:collect, *collect_args))
316
+ assert_equal(expected, actual)
317
+ end
318
+ end
319
+ end
320
+
321
+ def keep_required_files
322
+ required_files = $".dup
323
+ yield
324
+ ensure
325
+ $".replace(required_files)
326
+ end
327
+
328
+ def _test_case_name(test_case_class_name)
329
+ "#{@temporary_test_cases_module_name}::#{test_case_class_name}"
330
+ end
331
+
332
+ def inspect_test_object(test_object)
333
+ return nil if test_object.nil?
334
+ case test_object
335
+ when Test::Unit::TestSuite
336
+ sub_tests = test_object.tests.collect do |test|
337
+ inspect_test_object(test)
338
+ end.sort_by do |type, attributes, *children|
339
+ attributes[:name]
340
+ end
341
+ [:suite, {:name => test_object.name}, *sub_tests]
342
+ when Test::Unit::TestCase
343
+ [:test, {:name => test_object.method_name}]
344
+ else
345
+ raise "unexpected test object: #{test_object.inspect}"
346
+ end
347
+ end
348
+ end