pione 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. data/.gitignore +16 -13
  2. data/.travis.yml +1 -1
  3. data/History.txt +11 -0
  4. data/Rakefile +13 -0
  5. data/bin/pione-package +5 -0
  6. data/example/AbstractRule/package.yml +6 -0
  7. data/example/AbstractRule/scenario/a/output/message.txt +1 -0
  8. data/example/AbstractRule/scenario/a/scenario.yml +4 -0
  9. data/example/AbstractRule/scenario/b/output/message.txt +1 -0
  10. data/example/AbstractRule/scenario/b/scenario.yml +4 -0
  11. data/example/AbstractRule/scenario/c/output/message.txt +1 -0
  12. data/example/AbstractRule/scenario/c/scenario.yml +4 -0
  13. data/example/HelloWorld/package.yml +5 -1
  14. data/example/HelloWorld/scenario/scenario.yml +2 -1
  15. data/example/LoopByTouch/package.yml +4 -1
  16. data/example/MakePair/package.yml +6 -0
  17. data/example/MakePair/scenario/{input → case1/input}/1.i +0 -0
  18. data/example/MakePair/scenario/{input → case1/input}/2.i +0 -0
  19. data/example/MakePair/scenario/{input → case1/input}/3.i +0 -0
  20. data/example/MakePair/scenario/{input → case1/input}/4.i +0 -0
  21. data/example/MakePair/scenario/{input → case1/input}/5.i +0 -0
  22. data/example/MakePair/scenario/{output → case1/output}/comb-1-2.pair +0 -0
  23. data/example/MakePair/scenario/{output → case1/output}/comb-1-3.pair +0 -0
  24. data/example/MakePair/scenario/{output → case1/output}/comb-1-4.pair +0 -0
  25. data/example/MakePair/scenario/{output → case1/output}/comb-1-5.pair +0 -0
  26. data/example/MakePair/scenario/{output → case1/output}/comb-2-3.pair +0 -0
  27. data/example/MakePair/scenario/{output → case1/output}/comb-2-4.pair +0 -0
  28. data/example/MakePair/scenario/{output → case1/output}/comb-2-5.pair +0 -0
  29. data/example/MakePair/scenario/{output → case1/output}/comb-3-4.pair +0 -0
  30. data/example/MakePair/scenario/{output → case1/output}/comb-3-5.pair +0 -0
  31. data/example/MakePair/scenario/{output → case1/output}/comb-4-5.pair +0 -0
  32. data/example/MakePair/scenario/{output → case1/output}/perm-1-2.pair +0 -0
  33. data/example/MakePair/scenario/{output → case1/output}/perm-1-3.pair +0 -0
  34. data/example/MakePair/scenario/{output → case1/output}/perm-1-4.pair +0 -0
  35. data/example/MakePair/scenario/{output → case1/output}/perm-1-5.pair +0 -0
  36. data/example/MakePair/scenario/{output → case1/output}/perm-2-1.pair +0 -0
  37. data/example/MakePair/scenario/{output → case1/output}/perm-2-3.pair +0 -0
  38. data/example/MakePair/scenario/{output → case1/output}/perm-2-4.pair +0 -0
  39. data/example/MakePair/scenario/{output → case1/output}/perm-2-5.pair +0 -0
  40. data/example/MakePair/scenario/{output → case1/output}/perm-3-1.pair +0 -0
  41. data/example/MakePair/scenario/{output → case1/output}/perm-3-2.pair +0 -0
  42. data/example/MakePair/scenario/{output → case1/output}/perm-3-4.pair +0 -0
  43. data/example/MakePair/scenario/{output → case1/output}/perm-3-5.pair +0 -0
  44. data/example/MakePair/scenario/{output → case1/output}/perm-4-1.pair +0 -0
  45. data/example/MakePair/scenario/{output → case1/output}/perm-4-2.pair +0 -0
  46. data/example/MakePair/scenario/{output → case1/output}/perm-4-3.pair +0 -0
  47. data/example/MakePair/scenario/{output → case1/output}/perm-4-5.pair +0 -0
  48. data/example/MakePair/scenario/{output → case1/output}/perm-5-1.pair +0 -0
  49. data/example/MakePair/scenario/{output → case1/output}/perm-5-2.pair +0 -0
  50. data/example/MakePair/scenario/{output → case1/output}/perm-5-3.pair +0 -0
  51. data/example/MakePair/scenario/{output → case1/output}/perm-5-4.pair +0 -0
  52. data/example/MakePair/scenario/{output → case1/output}/succ-1-2.pair +0 -0
  53. data/example/MakePair/scenario/{output → case1/output}/succ-2-3.pair +0 -0
  54. data/example/MakePair/scenario/{output → case1/output}/succ-3-4.pair +0 -0
  55. data/example/MakePair/scenario/{output → case1/output}/succ-4-5.pair +0 -0
  56. data/example/MakePair/scenario/case1/scenario.yml +42 -0
  57. data/example/MakePair/scenario/case2/input/10.i +0 -0
  58. data/example/MakePair/scenario/case2/input/11.i +0 -0
  59. data/example/MakePair/scenario/case2/input/9.i +0 -0
  60. data/example/MakePair/scenario/case2/output/comb-10-11.pair +0 -0
  61. data/example/MakePair/scenario/case2/output/comb-9-10.pair +0 -0
  62. data/example/MakePair/scenario/case2/output/comb-9-11.pair +0 -0
  63. data/example/MakePair/scenario/case2/output/perm-10-11.pair +0 -0
  64. data/example/MakePair/scenario/case2/output/perm-10-9.pair +0 -0
  65. data/example/MakePair/scenario/case2/output/perm-11-10.pair +0 -0
  66. data/example/MakePair/scenario/case2/output/perm-11-9.pair +0 -0
  67. data/example/MakePair/scenario/case2/output/perm-9-10.pair +0 -0
  68. data/example/MakePair/scenario/case2/output/perm-9-11.pair +0 -0
  69. data/example/MakePair/scenario/case2/output/succ-10-11.pair +0 -0
  70. data/example/MakePair/scenario/case2/output/succ-9-10.pair +0 -0
  71. data/example/MakePair/scenario/case2/scenario.yml +17 -0
  72. data/example/MakePair/scenario/case3/input/1.i +0 -0
  73. data/example/MakePair/scenario/case3/input/3.i +0 -0
  74. data/example/MakePair/scenario/case3/input/5.i +0 -0
  75. data/example/MakePair/scenario/case3/input/7.i +0 -0
  76. data/example/MakePair/scenario/case3/input/9.i +0 -0
  77. data/example/MakePair/scenario/case3/output/comb-1-3.pair +0 -0
  78. data/example/MakePair/scenario/case3/output/comb-1-5.pair +0 -0
  79. data/example/MakePair/scenario/case3/output/comb-1-7.pair +0 -0
  80. data/example/MakePair/scenario/case3/output/comb-1-9.pair +0 -0
  81. data/example/MakePair/scenario/case3/output/comb-3-5.pair +0 -0
  82. data/example/MakePair/scenario/case3/output/comb-3-7.pair +0 -0
  83. data/example/MakePair/scenario/case3/output/comb-3-9.pair +0 -0
  84. data/example/MakePair/scenario/case3/output/comb-5-7.pair +0 -0
  85. data/example/MakePair/scenario/case3/output/comb-5-9.pair +0 -0
  86. data/example/MakePair/scenario/case3/output/comb-7-9.pair +0 -0
  87. data/example/MakePair/scenario/case3/output/perm-1-3.pair +0 -0
  88. data/example/MakePair/scenario/case3/output/perm-1-5.pair +0 -0
  89. data/example/MakePair/scenario/case3/output/perm-1-7.pair +0 -0
  90. data/example/MakePair/scenario/case3/output/perm-1-9.pair +0 -0
  91. data/example/MakePair/scenario/case3/output/perm-3-1.pair +0 -0
  92. data/example/MakePair/scenario/case3/output/perm-3-5.pair +0 -0
  93. data/example/MakePair/scenario/case3/output/perm-3-7.pair +0 -0
  94. data/example/MakePair/scenario/case3/output/perm-3-9.pair +0 -0
  95. data/example/MakePair/scenario/case3/output/perm-5-1.pair +0 -0
  96. data/example/MakePair/scenario/case3/output/perm-5-3.pair +0 -0
  97. data/example/MakePair/scenario/case3/output/perm-5-7.pair +0 -0
  98. data/example/MakePair/scenario/case3/output/perm-5-9.pair +0 -0
  99. data/example/MakePair/scenario/case3/output/perm-7-1.pair +0 -0
  100. data/example/MakePair/scenario/case3/output/perm-7-3.pair +0 -0
  101. data/example/MakePair/scenario/case3/output/perm-7-5.pair +0 -0
  102. data/example/MakePair/scenario/case3/output/perm-7-9.pair +0 -0
  103. data/example/MakePair/scenario/case3/output/perm-9-1.pair +0 -0
  104. data/example/MakePair/scenario/case3/output/perm-9-3.pair +0 -0
  105. data/example/MakePair/scenario/case3/output/perm-9-5.pair +0 -0
  106. data/example/MakePair/scenario/case3/output/perm-9-7.pair +0 -0
  107. data/example/MakePair/scenario/case3/scenario.yml +39 -0
  108. data/example/PegasusWMS/Merge/Merge.pione +21 -0
  109. data/example/PegasusWMS/Merge/package.yml +2 -0
  110. data/example/PegasusWMS/Pipeline/Pipeline.pione +20 -0
  111. data/example/PegasusWMS/Pipeline/package.yml +2 -0
  112. data/example/PegasusWMS/Split/Split.pione +27 -0
  113. data/example/PegasusWMS/Split/package.yml +2 -0
  114. data/example/ScoreAggregation/package.yml +4 -0
  115. data/example/ScoreAggregation/scenario/case1/scenario.yml +27 -1
  116. data/example/SerialProcessing/package.yml +5 -1
  117. data/example/SerialProcessing/scenario/scenario.yml +10 -0
  118. data/lib/pione.rb +20 -71
  119. data/lib/pione/agent.rb +17 -0
  120. data/lib/pione/agent/basic-agent.rb +2 -4
  121. data/lib/pione/command.rb +1 -0
  122. data/lib/pione/command/option.rb +4 -1
  123. data/lib/pione/command/pione-package.rb +97 -0
  124. data/lib/pione/command/pione-task-worker.rb +11 -7
  125. data/lib/pione/component.rb +5 -0
  126. data/lib/pione/component/document.rb +22 -5
  127. data/lib/pione/component/package-archiver.rb +92 -0
  128. data/lib/pione/component/package-expander.rb +37 -0
  129. data/lib/pione/component/package-filename.rb +38 -0
  130. data/lib/pione/component/package-reader.rb +276 -0
  131. data/lib/pione/component/package.rb +50 -162
  132. data/lib/pione/front.rb +14 -0
  133. data/lib/pione/location.rb +5 -0
  134. data/lib/pione/location/basic-location.rb +47 -274
  135. data/lib/pione/location/data-location.rb +328 -0
  136. data/lib/pione/location/dropbox-location.rb +30 -7
  137. data/lib/pione/location/exception.rb +38 -0
  138. data/lib/pione/location/ftp-location.rb +24 -13
  139. data/lib/pione/location/git-repository-location.rb +153 -0
  140. data/lib/pione/location/http-location.rb +65 -0
  141. data/lib/pione/location/https-location.rb +37 -0
  142. data/lib/pione/location/local-location.rb +24 -5
  143. data/lib/pione/parser.rb +14 -0
  144. data/lib/pione/patch.rb +10 -0
  145. data/lib/pione/patch/drb-patch.rb +2 -2
  146. data/lib/pione/relay.rb +11 -0
  147. data/lib/pione/system/file-cache.rb +1 -1
  148. data/lib/pione/system/global.rb +15 -0
  149. data/lib/pione/tuple-space.rb +11 -0
  150. data/lib/pione/tuple-space/tuple-space-server.rb +1 -1
  151. data/lib/pione/util.rb +1 -0
  152. data/lib/pione/util/error-report.rb +7 -0
  153. data/lib/pione/util/misc.rb +2 -2
  154. data/lib/pione/util/zip.rb +60 -0
  155. data/lib/pione/version.rb +1 -1
  156. data/pione.gemspec +5 -1
  157. data/test/agent/spec_rule-provider.rb +2 -2
  158. data/test/command/spec_pione-package.rb +15 -0
  159. data/test/component/spec_document.rb +2 -2
  160. data/test/component/spec_package-archiver.rb +27 -0
  161. data/test/component/spec_package-expander.rb +11 -0
  162. data/test/component/spec_package-filename.rb +79 -0
  163. data/test/component/spec_package-reader.rb +100 -0
  164. data/test/component/spec_package.rb +50 -33
  165. data/test/location/http-behavior.rb +59 -0
  166. data/test/location/location-behavior.rb +8 -0
  167. data/test/location/spec_basic-location.rb +5 -1
  168. data/test/location/spec_git-repository-location.rb +143 -0
  169. data/test/location/spec_http-location.rb +28 -0
  170. data/test/location/spec_http-location/a.txt +1 -0
  171. data/test/location/spec_http-location/b.txt +1 -0
  172. data/test/location/spec_http-location/c.txt +1 -0
  173. data/test/location/spec_http-location/dir/d.txt +1 -0
  174. data/test/location/spec_https-location.rb +37 -0
  175. data/test/rule-handler/spec_flow-handler.rb +1 -1
  176. data/test/rule-handler/spec_update-criteria.rb +1 -1
  177. data/test/test-data/package/HelloWorld+v0.1.0.ppg +0 -0
  178. data/test/test-data/package/HelloWorld-gitrepos.zip +0 -0
  179. data/test/test-data/package/HelloWorld/HelloWorld.pione +5 -0
  180. data/test/test-data/package/HelloWorld/package.yml +6 -0
  181. data/test/test-data/package/HelloWorld/scenario/output/message.txt +1 -0
  182. data/test/test-data/package/HelloWorld/scenario/scenario.yml +3 -0
  183. data/test/test-data/package/TestPackage1+v0.1.0.ppg +0 -0
  184. data/test/{component/spec_package/TestPackage → test-data/package/TestPackage1}/Test.pione +3 -1
  185. data/test/test-data/package/TestPackage1/bin/count +11 -0
  186. data/test/test-data/package/TestPackage1/package.yml +9 -0
  187. data/test/{component/spec_package/TestPackage → test-data/package/TestPackage1}/scenario/case1/input/1.txt +0 -0
  188. data/test/test-data/package/TestPackage1/scenario/case1/output/1.count +1 -0
  189. data/test/test-data/package/TestPackage1/scenario/case1/scenario.yml +6 -0
  190. data/test/test-data/package/TestPackage1/scenario/case2/input/1.txt +2 -0
  191. data/test/test-data/package/TestPackage1/scenario/case2/input/2.txt +1 -0
  192. data/test/test-data/package/TestPackage1/scenario/case2/input/3.txt +3 -0
  193. data/test/test-data/package/TestPackage1/scenario/case2/output/1.count +1 -0
  194. data/test/test-data/package/TestPackage1/scenario/case2/output/2.count +1 -0
  195. data/test/test-data/package/TestPackage1/scenario/case2/output/3.count +1 -0
  196. data/test/test-data/package/TestPackage1/scenario/case2/scenario.yml +10 -0
  197. data/test/test-data/package/TestPackage1/scenario/case3/input/a.txt +1 -0
  198. data/test/test-data/package/TestPackage1/scenario/case3/input/b.txt +1 -0
  199. data/test/test-data/package/TestPackage1/scenario/case3/output/a.count +1 -0
  200. data/test/test-data/package/TestPackage1/scenario/case3/output/b.count +1 -0
  201. data/test/test-data/package/TestPackage1/scenario/case3/scenario.yml +8 -0
  202. data/test/test-util.rb +10 -146
  203. data/test/test-util/command.rb +53 -0
  204. data/test/test-util/package.rb +9 -0
  205. data/test/test-util/parser.rb +45 -0
  206. data/test/test-util/transformer.rb +50 -0
  207. data/test/test-util/webserver.rb +43 -0
  208. data/test/util/spec_error-report.rb +12 -3
  209. data/test/util/spec_zip.rb +36 -0
  210. metadata +282 -54
  211. data/example/MakePair/scenario/scenario.yml +0 -1
  212. data/test/component/spec_package/TestPackage/bin/count +0 -3
  213. data/test/component/spec_package/TestPackage/package.yml +0 -7
  214. data/test/component/spec_package/TestPackage/scenario/case1/scenario.yml +0 -1
@@ -0,0 +1,8 @@
1
+ ScenarioName: Case3
2
+ Params: '{WORD: " "}'
3
+ Inputs:
4
+ - "a.txt"
5
+ - "b.txt"
6
+ Outputs:
7
+ - "a.count"
8
+ - "b.count"
@@ -1,10 +1,14 @@
1
1
  require 'bacon'
2
2
  require 'pione'
3
3
 
4
+ Global.git_package_directory = Location[Temppath.mkdir]
5
+
4
6
  module TestUtil
5
7
  include Pione::TupleSpaceServerInterface
6
8
 
7
9
  DIR = Location[File.dirname(__FILE__)]
10
+ TEST_DATA_DIR = DIR + "test-data"
11
+ TEST_PACKAGE_DIR = TEST_DATA_DIR + "package"
8
12
 
9
13
  def write_and_wait_to_be_taken(tuple, sec=5)
10
14
  observer = notify('take', tuple)
@@ -73,152 +77,6 @@ module TestUtil
73
77
  end
74
78
  end
75
79
 
76
- module TestUtil
77
- class CommandResult < StructX
78
- member :exception
79
- member :stdout
80
- member :stderr
81
-
82
- def success?
83
- exception.kind_of?(SystemExit) and exception.success?
84
- end
85
-
86
- def report
87
- unless success?
88
- puts "ERROR: %s" % exception.message
89
- exception.backtrace.each do |line|
90
- puts "TRACE: %s" % line
91
- end
92
- puts stdout.string[0..100] if stdout.string.size > 0
93
- puts stderr.string[0..100] if stderr.string.size > 0
94
- end
95
- end
96
- end
97
-
98
- module Command
99
- class << self
100
- def execute(&b)
101
- res = CommandResult.new(stdout: StringIO.new("", "w"), stderr: StringIO.new("", "w"))
102
- $stdout = res.stdout
103
- $stderr = res.stderr
104
- begin
105
- b.call
106
- rescue Object => e
107
- res.exception = e
108
- end
109
- $stdout = STDOUT
110
- $stderr = STDERR
111
- return res
112
- end
113
-
114
- def succeed(&b)
115
- res = execute(&b)
116
- res.report
117
- res.should.success
118
- return res
119
- end
120
-
121
- def fail(&b)
122
- res = execute(&b)
123
- res.should.not.success
124
- return res
125
- end
126
- end
127
- end
128
- end
129
-
130
- module TestUtil::Parser
131
- # Makes a test parser class by the sub-parser module.
132
- def make_test_parser(parser_module)
133
- klass = Class.new(Parslet::Parser)
134
- klass.instance_eval do
135
- include parser_module
136
- end
137
- return klass
138
- end
139
- module_function :make_test_parser
140
-
141
- def spec(mod, rb, context)
142
- #parser = make_test_parser(mod)
143
- parser = Pione::Parser::DocumentParser
144
- basename = File.basename(rb, ".rb")
145
- path = File.join(File.dirname(rb), basename + ".yml")
146
- YAML.load(File.read(path)).each do |name, testcase|
147
- context.describe name do
148
- if strings = testcase["valid"]
149
- strings.each do |string|
150
- it "should parse as %s:%s%s" % [name, string.include?("\n") ? "\n" : " ", string.chomp] do
151
- should.not.raise(Parslet::ParseFailed) do
152
- parser.new.send(name).parse(string)
153
- end
154
- end
155
- end
156
- end
157
-
158
- if strings = testcase["invalid"]
159
- strings.each do |string|
160
- it "should fail when parsing as %s:%s%s" % [name, string.include?("\n") ? "\n" : "", string.chomp] do
161
- should.raise(Parslet::ParseFailed) do
162
- parser.new.send(name).parse(string)
163
- end
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
170
- module_function :spec
171
- end
172
-
173
- module TestUtil::Transformer
174
- class TestCase < StructX
175
- member :string
176
- member :expected
177
- end
178
-
179
- class TestCaseEq < StructX
180
- member :string
181
- member :expected
182
- end
183
-
184
- def spec(name, parser, context, &b)
185
- testcases = Array.new
186
-
187
- def testcases.tc(obj)
188
- case obj
189
- when Hash
190
- obj.each do |key, val|
191
- push(TestCaseEq.new(key, val))
192
- end
193
- else
194
- push(TestCaseEq.new(obj, yield))
195
- end
196
- end
197
-
198
- def testcases.transform(obj, &b)
199
- push(TestCase.new(obj, b))
200
- end
201
-
202
- testcases.instance_eval(&b)
203
- context.describe name do
204
- testcases.each do |tc|
205
- it "should get %s:%s%s" % [name, tc.string.include?("\n") ? "\n" : " ", tc.string.chomp] do
206
- res = DocumentTransformer.new.apply(
207
- DocumentParser.new.send(parser).parse(tc.string)
208
- )
209
- case tc
210
- when TestCaseEq
211
- res.should == tc.expected
212
- when TestCase
213
- tc.expected.call(res)
214
- end
215
- end
216
- end
217
- end
218
- end
219
- module_function :spec
220
- end
221
-
222
80
  # Hash extension.
223
81
  class Hash
224
82
  # Symbolizes hash's keys recuirsively. This is convinient for YAML handling.
@@ -339,6 +197,12 @@ module Pione::Agent
339
197
  end
340
198
  end
341
199
 
200
+ require_relative "test-util/command"
201
+ require_relative "test-util/parser"
202
+ require_relative "test-util/transformer"
203
+ require_relative "test-util/package"
204
+ require_relative "test-util/webserver"
205
+
342
206
  def setup_for_test
343
207
  include Pione
344
208
  Thread.abort_on_exception = true
@@ -0,0 +1,53 @@
1
+ module TestUtil
2
+ class CommandResult < StructX
3
+ member :exception
4
+ member :stdout
5
+ member :stderr
6
+
7
+ def success?
8
+ exception.kind_of?(SystemExit) and exception.success?
9
+ end
10
+
11
+ def report
12
+ unless success?
13
+ puts "ERROR: %s" % exception.message
14
+ exception.backtrace.each do |line|
15
+ puts "TRACE: %s" % line
16
+ end
17
+ puts stdout.string[0..100] if stdout.string.size > 0
18
+ puts stderr.string[0..100] if stderr.string.size > 0
19
+ end
20
+ end
21
+ end
22
+
23
+ module Command
24
+ class << self
25
+ def execute(&b)
26
+ res = CommandResult.new(stdout: StringIO.new("", "w"), stderr: StringIO.new("", "w"))
27
+ $stdout = res.stdout
28
+ $stderr = res.stderr
29
+ begin
30
+ b.call
31
+ rescue Object => e
32
+ res.exception = e
33
+ end
34
+ $stdout = STDOUT
35
+ $stderr = STDERR
36
+ return res
37
+ end
38
+
39
+ def succeed(&b)
40
+ res = execute(&b)
41
+ res.report
42
+ res.should.success
43
+ return res
44
+ end
45
+
46
+ def fail(&b)
47
+ res = execute(&b)
48
+ res.should.not.success
49
+ return res
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module TestUtil
2
+ module Package
3
+ class << self
4
+ def get(name)
5
+ TEST_PACKAGE_DIR + name
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ module TestUtil
2
+ module Parser
3
+ # Makes a test parser class by the sub-parser module.
4
+ def make_test_parser(parser_module)
5
+ klass = Class.new(Parslet::Parser)
6
+ klass.instance_eval do
7
+ include parser_module
8
+ end
9
+ return klass
10
+ end
11
+ module_function :make_test_parser
12
+
13
+ def spec(mod, rb, context)
14
+ #parser = make_test_parser(mod)
15
+ parser = Pione::Parser::DocumentParser
16
+ basename = File.basename(rb, ".rb")
17
+ path = File.join(File.dirname(rb), basename + ".yml")
18
+ YAML.load(File.read(path)).each do |name, testcase|
19
+ context.describe name do
20
+ if strings = testcase["valid"]
21
+ strings.each do |string|
22
+ it "should parse as %s:%s%s" % [name, string.include?("\n") ? "\n" : " ", string.chomp] do
23
+ should.not.raise(Parslet::ParseFailed) do
24
+ parser.new.send(name).parse(string)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ if strings = testcase["invalid"]
31
+ strings.each do |string|
32
+ it "should fail when parsing as %s:%s%s" % [name, string.include?("\n") ? "\n" : "", string.chomp] do
33
+ should.raise(Parslet::ParseFailed) do
34
+ parser.new.send(name).parse(string)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ module_function :spec
43
+ end
44
+ end
45
+
@@ -0,0 +1,50 @@
1
+ module TestUtil
2
+ module Transformer
3
+ class TestCase < StructX
4
+ member :string
5
+ member :expected
6
+ end
7
+
8
+ class TestCaseEq < StructX
9
+ member :string
10
+ member :expected
11
+ end
12
+
13
+ def spec(name, parser, context, &b)
14
+ testcases = Array.new
15
+
16
+ def testcases.tc(obj)
17
+ case obj
18
+ when Hash
19
+ obj.each do |key, val|
20
+ push(TestCaseEq.new(key, val))
21
+ end
22
+ else
23
+ push(TestCaseEq.new(obj, yield))
24
+ end
25
+ end
26
+
27
+ def testcases.transform(obj, &b)
28
+ push(TestCase.new(obj, b))
29
+ end
30
+
31
+ testcases.instance_eval(&b)
32
+ context.describe name do
33
+ testcases.each do |tc|
34
+ it "should get %s:%s%s" % [name, tc.string.include?("\n") ? "\n" : " ", tc.string.chomp] do
35
+ res = DocumentTransformer.new.apply(
36
+ DocumentParser.new.send(parser).parse(tc.string)
37
+ )
38
+ case tc
39
+ when TestCaseEq
40
+ res.should == tc.expected
41
+ when TestCase
42
+ tc.expected.call(res)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ module_function :spec
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ require 'webrick'
2
+
3
+ module TestUtil
4
+ class WebServer
5
+ class << self
6
+ def start(*args)
7
+ new(*args).tap {|x| x.start}
8
+ end
9
+ end
10
+
11
+ def initialize(document_root, option={})
12
+ logger = WEBrick::Log.new(StringIO.new("", "w"))
13
+ # modify document root
14
+ document_root = document_root.local.path if document_root.kind_of?(Location::DataLocation)
15
+
16
+ # setup options
17
+ _option = {DocumentRoot: document_root}
18
+ _option[:Port] = 54673 unless option[:Port]
19
+ _option[:Logger] = logger unless option[:Logger]
20
+ _option[:AccessLog] = logger unless option[:AccessLog]
21
+
22
+ # make webrick
23
+ @server = WEBrick::HTTPServer.new(_option)
24
+ end
25
+
26
+ def root
27
+ Location["http://localhost:%s/" % port]
28
+ end
29
+
30
+ def port
31
+ @server.config[:Port]
32
+ end
33
+
34
+ def start
35
+ @thread = Thread.new { @server.start }
36
+ end
37
+
38
+ def terminate
39
+ @server.shutdown
40
+ @thread.kill
41
+ end
42
+ end
43
+ end
@@ -29,12 +29,21 @@ describe "Pione::Util::ErrorReport" do
29
29
  end
30
30
  end
31
31
 
32
+ it "should show debug message in debug mode" do
33
+ Pione.debug_mode {Util::ErrorReport.debug("test debug message", @rec, @file, @line)}
34
+ $stderr.string.tap do |s|
35
+ s.should.include "test debug message"
36
+ s.should.include @rec.to_s
37
+ s.should.include @file.to_s
38
+ s.should.include @line.to_s
39
+ end
40
+ end
41
+
32
42
  it "should not warn in normal mode" do
33
- Util::ErrorReport.warn("test warning", @rec, @exc, @file, @line)
43
+ Util::ErrorReport.debug("test debug message", @rec, @file, @line)
34
44
  $stderr.string.tap do |s|
35
- s.should.not.include "test warning"
45
+ s.should.not.include "test debug message"
36
46
  s.should.not.include @rec.to_s
37
- s.should.not.include @exc.to_s
38
47
  s.should.not.include @file.to_s
39
48
  s.should.not.include @line.to_s
40
49
  end
@@ -0,0 +1,36 @@
1
+ require_relative '../test-util'
2
+
3
+ shared "archiver" do
4
+ it "should compress and uncompress" do
5
+ Util::Zip.compress(@src, @archive)
6
+ @archive.should.exist
7
+ @archive.size.should > 0
8
+ Util::Zip.uncompress(@archive, @dest)
9
+ (@dest + "A").read.should == "A"
10
+ (@dest + "B").read.should == "B"
11
+ (@dest + "C/1").read.should == "C"
12
+ (@dest + "D/2").read.should == "D"
13
+ (@dest+ "E/1/2").read.should == "E"
14
+ end
15
+ end
16
+
17
+ describe "Pione::Util::Zip" do
18
+ def create_files(src)
19
+ (src + "A").create("A")
20
+ (src + "B").create("B")
21
+ (src + "C/1").create("C")
22
+ (src + "D/2").create("D")
23
+ (src + "E/1/2").create("E")
24
+ end
25
+
26
+ describe "local -> local -> local" do
27
+ before do
28
+ @src = Location[Temppath.mkdir]
29
+ create_files(@src)
30
+ @archive = Location[Temppath.create]
31
+ @dest = Location[Temppath.mkdir]
32
+ end
33
+
34
+ behaves_like "archiver"
35
+ end
36
+ end