buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,1098 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+
19
+
20
+ module TestHelper
21
+ def touch_last_successful_test_run(test_task, timestamp = Time.now)
22
+ test_task.instance_eval do
23
+ record_successful_run
24
+ File.utime(timestamp, timestamp, last_successful_run_file)
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ describe Buildr::TestTask do
31
+ def test_task
32
+ @test_task ||= define('foo').test
33
+ end
34
+
35
+ it 'should respond to :compile and return compile task' do
36
+ test_task.compile.should be_kind_of(Buildr::CompileTask)
37
+ end
38
+
39
+ it 'should respond to :compile and add sources to compile' do
40
+ test_task.compile 'sources'
41
+ test_task.compile.sources.should include('sources')
42
+ end
43
+
44
+ it 'should respond to :compile and add action for test:compile' do
45
+ write 'src/test/java/Test.java', 'class Test {}'
46
+ test_task.compile { task('action').invoke }
47
+ lambda { test_task.compile.invoke }.should run_tasks('action')
48
+ end
49
+
50
+ it 'should execute compile tasks first' do
51
+ write 'src/main/java/Nothing.java', 'class Nothing {}'
52
+ write 'src/test/java/Test.java', 'class Test {}'
53
+ define 'foo'
54
+ lambda { project('foo').test.compile.invoke }.should run_tasks(['foo:compile', 'foo:test:compile'])
55
+ end
56
+
57
+ it 'should respond to :resources and return resources task' do
58
+ test_task.resources.should be_kind_of(Buildr::ResourcesTask)
59
+ end
60
+
61
+ it 'should respond to :resources and add prerequisites to test:resources' do
62
+ file('prereq').should_receive :invoke_prerequisites
63
+ test_task.resources 'prereq'
64
+ test_task.compile.invoke
65
+ end
66
+
67
+ it 'should respond to :resources and add action for test:resources' do
68
+ task 'action'
69
+ test_task.resources { task('action').invoke }
70
+ lambda { test_task.resources.invoke }.should run_tasks('action')
71
+ end
72
+
73
+ it 'should respond to :setup and return setup task' do
74
+ test_task.setup.name.should =~ /test:setup$/
75
+ end
76
+
77
+ it 'should respond to :setup and add prerequisites to test:setup' do
78
+ test_task.setup 'prereq'
79
+ test_task.setup.prerequisites.should include('prereq')
80
+ end
81
+
82
+ it 'should respond to :setup and add action for test:setup' do
83
+ task 'action'
84
+ test_task.setup { task('action').invoke }
85
+ lambda { test_task.setup.invoke }.should run_tasks('action')
86
+ end
87
+
88
+ it 'should respond to :teardown and return teardown task' do
89
+ test_task.teardown.name.should =~ /test:teardown$/
90
+ end
91
+
92
+ it 'should respond to :teardown and add prerequisites to test:teardown' do
93
+ test_task.teardown 'prereq'
94
+ test_task.teardown.prerequisites.should include('prereq')
95
+ end
96
+
97
+ it 'should respond to :teardown and add action for test:teardown' do
98
+ task 'action'
99
+ test_task.teardown { task('action').invoke }
100
+ lambda { test_task.teardown.invoke }.should run_tasks('action')
101
+ end
102
+
103
+ it 'should respond to :with and return self' do
104
+ test_task.with.should be(test_task)
105
+ end
106
+
107
+ it 'should respond to :with and add artifacfs to compile task dependencies' do
108
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
109
+ test_task.compile.dependencies.should include(File.expand_path('test.jar'))
110
+ test_task.compile.dependencies.should include(artifact('acme:example:jar:1.0'))
111
+ end
112
+
113
+ it 'should respond to :with and add artifacfs to task dependencies' do
114
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
115
+ test_task.dependencies.should include(File.expand_path('test.jar'))
116
+ test_task.dependencies.should include(artifact('acme:example:jar:1.0'))
117
+ end
118
+
119
+ it 'should response to :options and return test framework options' do
120
+ test_task.using :foo=>'bar'
121
+ test_task.options[:foo].should eql('bar')
122
+ end
123
+
124
+ it 'should respond to :using and return self' do
125
+ test_task.using.should be(test_task)
126
+ end
127
+
128
+ it 'should respond to :using and set value options' do
129
+ test_task.using('foo'=>'FOO', 'bar'=>'BAR')
130
+ test_task.options[:foo].should eql('FOO')
131
+ test_task.options[:bar].should eql('BAR')
132
+ end
133
+
134
+ it 'should respond to :using with deprecated parameter style and set value options to true, up to version 1.5 since this usage was deprecated in version 1.3' do
135
+ Buildr::VERSION.should < '1.5'
136
+ test_task.using('foo', 'bar')
137
+ test_task.options[:foo].should eql(true)
138
+ test_task.options[:bar].should eql(true)
139
+ end
140
+
141
+ it 'should start without pre-selected test framework' do
142
+ test_task.framework.should be_nil
143
+ end
144
+
145
+ it 'should respond to :using and select test framework' do
146
+ test_task.using(:testng)
147
+ test_task.framework.should eql(:testng)
148
+ end
149
+
150
+ it 'should infer test framework from compiled language' do
151
+ lambda { test_task.compile.using(:javac) }.should change { test_task.framework }.to(:junit)
152
+ end
153
+
154
+ it 'should respond to :include and return self' do
155
+ test_task.include.should be(test_task)
156
+ end
157
+
158
+ it 'should respond to :include and add inclusion patterns' do
159
+ test_task.include 'Foo', 'Bar'
160
+ test_task.send(:include?, 'Foo').should be_true
161
+ test_task.send(:include?, 'Bar').should be_true
162
+ end
163
+
164
+ it 'should respond to :exclude and return self' do
165
+ test_task.exclude.should be(test_task)
166
+ end
167
+
168
+ it 'should respond to :exclude and add exclusion patterns' do
169
+ test_task.exclude 'FooTest', 'BarTest'
170
+ test_task.send(:include?, 'FooTest').should be_false
171
+ test_task.send(:include?, 'BarTest').should be_false
172
+ test_task.send(:include?, 'BazTest').should be_true
173
+ end
174
+
175
+ it 'should execute setup task before running tests' do
176
+ mock = mock('actions')
177
+ test_task.setup { mock.setup }
178
+ test_task.enhance { mock.tests }
179
+ mock.should_receive(:setup).ordered
180
+ mock.should_receive(:tests).ordered
181
+ test_task.invoke
182
+ end
183
+
184
+ it 'should execute teardown task after running tests' do
185
+ mock = mock('actions')
186
+ test_task.teardown { mock.teardown }
187
+ test_task.enhance { mock.tests }
188
+ mock.should_receive(:tests).ordered
189
+ mock.should_receive(:teardown).ordered
190
+ test_task.invoke
191
+ end
192
+
193
+ it 'should not execute teardown if setup failed' do
194
+ test_task.setup { fail }
195
+ lambda { test_task.invoke rescue nil }.should_not run_task(test_task.teardown)
196
+ end
197
+
198
+ it 'should use the main compile dependencies' do
199
+ define('foo') { compile.using(:javac).with 'group:id:jar:1.0' }
200
+ project('foo').test.dependencies.should include(artifact('group:id:jar:1.0'))
201
+ end
202
+
203
+ it 'should include the main compile target in its dependencies' do
204
+ define('foo') { compile.using(:javac) }
205
+ project('foo').test.dependencies.should include(project('foo').compile.target)
206
+ end
207
+
208
+ it 'should include the main compile target in its dependencies, even when using non standard directories' do
209
+ write 'src/java/Nothing.java', 'class Nothing {}'
210
+ define('foo') { compile path_to('src/java') }
211
+ project('foo').test.dependencies.should include(project('foo').compile.target)
212
+ end
213
+
214
+ it 'should include the main resources target in its dependencies' do
215
+ write 'src/main/resources/config.xml'
216
+ define('foo').test.dependencies.should include(project('foo').resources.target)
217
+ end
218
+
219
+ it 'should not use the test compile dependencies' do
220
+ define('foo') { test.compile.using(:javac).with 'group:id:jar:1.0' }
221
+ project('foo').test.dependencies.should_not include(artifact('group:id:jar:1.0'))
222
+ end
223
+
224
+ it 'should include the test compile target in its dependencies' do
225
+ define('foo') { test.compile.using(:javac) }
226
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
227
+ end
228
+
229
+ it 'should include the test compile target in its dependencies, even when using non standard directories' do
230
+ write 'src/test/Test.java', 'class Test {}'
231
+ define('foo') { test.compile path_to('src/test') }
232
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
233
+ end
234
+
235
+ it 'should add test compile target ahead of regular compile target' do
236
+ write 'src/main/java/Code.java'
237
+ write 'src/test/java/Test.java'
238
+ define 'foo'
239
+ depends = project('foo').test.dependencies
240
+ depends.index(project('foo').test.compile.target).should < depends.index(project('foo').compile.target)
241
+ end
242
+
243
+ it 'should include the test resources target in its dependencies' do
244
+ write 'src/test/resources/config.xml'
245
+ define('foo').test.dependencies.should include(project('foo').test.resources.target)
246
+ end
247
+
248
+ it 'should add test resource target ahead of regular resource target' do
249
+ write 'src/main/resources/config.xml'
250
+ write 'src/test/resources/config.xml'
251
+ define 'foo'
252
+ depends = project('foo').test.dependencies
253
+ depends.index(project('foo').test.resources.target).should < depends.index(project('foo').resources.target)
254
+ end
255
+
256
+ it 'should not have a last successful run timestamp before the tests are run' do
257
+ test_task.timestamp.should == Rake::EARLY
258
+ end
259
+
260
+ it 'should clean after itself (test files)' do
261
+ define('foo') { test.compile.using(:javac) }
262
+ mkpath project('foo').test.compile.target.to_s
263
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.compile.target.to_s) }.to(false)
264
+ end
265
+
266
+ it 'should clean after itself (reports)' do
267
+ define 'foo'
268
+ mkpath project('foo').test.report_to.to_s
269
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.report_to.to_s) }.to(false)
270
+ end
271
+ end
272
+
273
+
274
+ describe Buildr::TestTask, 'with no tests' do
275
+ it 'should pass' do
276
+ lambda { define('foo').test.invoke }.should_not raise_error
277
+ end
278
+
279
+ it 'should report no failed tests' do
280
+ lambda { verbose(true) { define('foo').test.invoke } }.should_not show_error(/fail/i)
281
+ end
282
+
283
+ it 'should return no failed tests' do
284
+ define('foo') { test.using(:junit) }
285
+ project('foo').test.invoke
286
+ project('foo').test.failed_tests.should be_empty
287
+ end
288
+
289
+ it 'should return no passing tests' do
290
+ define('foo') { test.using(:junit) }
291
+ project('foo').test.invoke
292
+ project('foo').test.passed_tests.should be_empty
293
+ end
294
+
295
+ it 'should execute teardown task' do
296
+ lambda { define('foo').test.invoke }.should run_task('foo:test:teardown')
297
+ end
298
+ end
299
+
300
+
301
+ describe Buildr::TestTask, 'with passing tests' do
302
+ def test_task
303
+ @test_task ||= begin
304
+ define 'foo' do
305
+ test.using(:junit)
306
+ test.instance_eval do
307
+ @framework.stub!(:tests).and_return(['PassingTest1', 'PassingTest2'])
308
+ @framework.stub!(:run).and_return(['PassingTest1', 'PassingTest2'])
309
+ end
310
+ end
311
+ project('foo').test
312
+ end
313
+ end
314
+
315
+ it 'should pass' do
316
+ lambda { test_task.invoke }.should_not raise_error
317
+ end
318
+
319
+ it 'should report no failed tests' do
320
+ lambda { verbose(true) { test_task.invoke } }.should_not show_error(/fail/i)
321
+ end
322
+
323
+ it 'should return passed tests' do
324
+ test_task.invoke
325
+ test_task.passed_tests.should == ['PassingTest1', 'PassingTest2']
326
+ end
327
+
328
+ it 'should return no failed tests' do
329
+ test_task.invoke
330
+ test_task.failed_tests.should be_empty
331
+ end
332
+
333
+ it 'should execute teardown task' do
334
+ lambda { test_task.invoke }.should run_task('foo:test:teardown')
335
+ end
336
+
337
+ it 'should update the last successful run timestamp' do
338
+ before = Time.now ; test_task.invoke ; after = Time.now
339
+ (before-1..after+1).should cover(test_task.timestamp)
340
+ end
341
+ end
342
+
343
+
344
+ describe Buildr::TestTask, 'with failed test' do
345
+ include TestHelper
346
+
347
+ def test_task
348
+ @test_task ||= begin
349
+ define 'foo' do
350
+ test.using(:junit)
351
+ test.instance_eval do
352
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
353
+ @framework.stub!(:run).and_return(['PassingTest'])
354
+ end
355
+ end
356
+ project('foo').test
357
+ end
358
+ end
359
+
360
+ it 'should fail' do
361
+ lambda { test_task.invoke }.should raise_error(RuntimeError, /Tests failed/)
362
+ end
363
+
364
+ it 'should report failed tests' do
365
+ lambda { verbose(true) { test_task.invoke rescue nil } }.should show_error(/FailingTest/)
366
+ end
367
+
368
+ it 'should return failed tests' do
369
+ test_task.invoke rescue nil
370
+ test_task.failed_tests.should == ['FailingTest']
371
+ end
372
+
373
+ it 'should return passing tests as well' do
374
+ test_task.invoke rescue nil
375
+ test_task.passed_tests.should == ['PassingTest']
376
+ end
377
+
378
+ it 'should not fail if fail_on_failure is false' do
379
+ test_task.using(:fail_on_failure=>false).invoke
380
+ lambda { test_task.invoke }.should_not raise_error
381
+ end
382
+
383
+ it 'should report failed tests even if fail_on_failure is false' do
384
+ test_task.using(:fail_on_failure=>false)
385
+ lambda { verbose(true) { test_task.invoke } }.should show_error(/FailingTest/)
386
+ end
387
+
388
+ it 'should return failed tests even if fail_on_failure is false' do
389
+ test_task.using(:fail_on_failure=>false).invoke
390
+ test_task.failed_tests.should == ['FailingTest']
391
+ end
392
+
393
+ it 'should execute teardown task' do
394
+ lambda { test_task.invoke rescue nil }.should run_task('foo:test:teardown')
395
+ end
396
+
397
+ it 'should not update the last successful run timestamp' do
398
+ a_second_ago = Time.now - 1
399
+ touch_last_successful_test_run test_task, a_second_ago
400
+ test_task.invoke rescue nil
401
+ test_task.timestamp.should <= a_second_ago
402
+ end
403
+ end
404
+
405
+
406
+ describe Buildr::Project, '#test' do
407
+ it 'should return the project\'s test task' do
408
+ define('foo') { test.should be(task('test')) }
409
+ end
410
+
411
+ it 'should accept prerequisites for task' do
412
+ define('foo') { test 'prereq' }
413
+ project('foo').test.prerequisites.should include('prereq')
414
+ end
415
+
416
+ it 'should accept actions for task' do
417
+ task 'action'
418
+ define('foo') { test { task('action').invoke } }
419
+ lambda { project('foo').test.invoke }.should run_tasks('action')
420
+ end
421
+
422
+ it 'should set fail_on_failure true by default' do
423
+ define('foo').test.options[:fail_on_failure].should be_true
424
+ end
425
+
426
+ it 'should set fork mode by default' do
427
+ define('foo').test.options[:fork].should == :once
428
+ end
429
+
430
+ it 'should set properties to empty hash by default' do
431
+ define('foo').test.options[:properties].should == {}
432
+ end
433
+
434
+ it 'should set environment variables to empty hash by default' do
435
+ define('foo').test.options[:environment].should == {}
436
+ end
437
+
438
+ it 'should inherit options from parent project' do
439
+ define 'foo' do
440
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
441
+ define 'bar' do
442
+ test.using :junit
443
+ test.options[:fail_on_failure].should be_false
444
+ test.options[:fork].should == :each
445
+ test.options[:properties][:foo].should == 'bar'
446
+ test.options[:environment]['config'].should == 'config.yaml'
447
+ end
448
+ end
449
+ end
450
+
451
+ it 'should clone options from parent project when using #using' do
452
+ define 'foo' do
453
+ define 'bar' do
454
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
455
+ test.using :junit
456
+ end.invoke
457
+ test.options[:fail_on_failure].should be_true
458
+ test.options[:fork].should == :once
459
+ test.options[:properties].should == {}
460
+ test.options[:environment].should == {}
461
+ end
462
+ end
463
+
464
+ it 'should clone options from parent project when using #options' do
465
+ define 'foo' do
466
+ define 'bar' do
467
+ test.options[:fail_on_failure] = false
468
+ test.options[:fork] = :each
469
+ test.options[:properties][:foo] = 'bar'
470
+ test.options[:environment]['config'] = 'config.yaml'
471
+ test.using :junit
472
+ end.invoke
473
+ test.options[:fail_on_failure].should be_true
474
+ test.options[:fork].should == :once
475
+ test.options[:properties].should == {}
476
+ test.options[:environment].should == {}
477
+ end
478
+ end
479
+
480
+ it 'should accept to set a test property in the top project' do
481
+ define 'foo' do
482
+ test.options[:properties][:foo] = 'bar'
483
+ end
484
+ project('foo').test.options[:properties][:foo].should == 'bar'
485
+ end
486
+
487
+ it 'should accept to set a test property in a subproject' do
488
+ define 'foo' do
489
+ define 'bar' do
490
+ test.options[:properties][:bar] = 'baz'
491
+ end
492
+ end
493
+ project('foo:bar').test.options[:properties][:bar].should == 'baz'
494
+ end
495
+
496
+ it 'should not change options of unrelated projects when using #options' do
497
+ define 'foo' do
498
+ test.options[:properties][:foo] = 'bar'
499
+ end
500
+ define 'bar' do
501
+ test.options[:properties].should == {}
502
+ end
503
+ end
504
+
505
+ it "should run from project's build task" do
506
+ write 'src/main/java/Foo.java'
507
+ write 'src/test/java/FooTest.java'
508
+ define('foo')
509
+ lambda { task('foo:build').invoke }.should run_task('foo:test')
510
+ end
511
+ end
512
+
513
+
514
+ describe Buildr::Project, '#test.compile' do
515
+ it 'should identify compiler from project' do
516
+ write 'src/test/java/com/example/Test.java'
517
+ define('foo') do
518
+ test.compile.compiler.should eql(:javac)
519
+ end
520
+ end
521
+
522
+ it 'should include identified sources' do
523
+ write 'src/test/java/Test.java'
524
+ define('foo') do
525
+ test.compile.sources.should include(_('src/test/java'))
526
+ end
527
+ end
528
+
529
+ it 'should compile to target/test/<code>' do
530
+ define 'foo', :target=>'targeted' do
531
+ test.compile.using(:javac)
532
+ test.compile.target.should eql(file('targeted/test/classes'))
533
+ end
534
+ end
535
+
536
+ it 'should use main compile dependencies' do
537
+ define 'foo' do
538
+ compile.using(:javac).with 'group:id:jar:1.0'
539
+ test.compile.using(:javac)
540
+ end
541
+ project('foo').test.compile.dependencies.should include(artifact('group:id:jar:1.0'))
542
+ end
543
+
544
+ it 'should include the main compiled target in its dependencies' do
545
+ define 'foo' do
546
+ compile.using(:javac).into 'bytecode'
547
+ test.compile.using(:javac)
548
+ end
549
+ project('foo').test.compile.dependencies.should include(file('bytecode'))
550
+ end
551
+
552
+ it 'should include the test framework dependencies' do
553
+ define 'foo' do
554
+ test.compile.using(:javac)
555
+ test.using(:junit)
556
+ end
557
+ project('foo').test.compile.dependencies.should include(*artifacts(JUnit.dependencies))
558
+ end
559
+
560
+ it 'should clean after itself' do
561
+ write 'src/test/java/Nothing.java', 'class Nothing {}'
562
+ define('foo') { test.compile.into 'bytecode' }
563
+ project('foo').test.compile.invoke
564
+ lambda { project('foo').clean.invoke }.should change { File.exist?('bytecode') }.to(false)
565
+ end
566
+ end
567
+
568
+
569
+ describe Buildr::Project, '#test.resources' do
570
+ it 'should ignore resources unless they exist' do
571
+ define('foo').test.resources.sources.should be_empty
572
+ project('foo').test.resources.target.should be_nil
573
+ end
574
+
575
+ it 'should pick resources from src/test/resources if found' do
576
+ mkpath 'src/test/resources'
577
+ define('foo') { test.resources.sources.should include(file('src/test/resources')) }
578
+ end
579
+
580
+ it 'should copy to the resources target directory' do
581
+ write 'src/test/resources/config.xml', '</xml>'
582
+ define('foo', :target=>'targeted').test.invoke
583
+ file('targeted/test/resources/config.xml').should contain('</xml>')
584
+ end
585
+
586
+ it 'should create target directory even if no files to copy' do
587
+ define('foo').test.resources.filter.into('resources')
588
+ lambda { file(File.expand_path('resources')).invoke }.should change { File.exist?('resources') }.to(true)
589
+ end
590
+
591
+ it 'should execute alongside compile task' do
592
+ task 'action'
593
+ define('foo') { test.resources { task('action').invoke } }
594
+ lambda { project('foo').test.compile.invoke }.should run_tasks('action')
595
+ end
596
+ end
597
+
598
+
599
+ describe Buildr::TestTask, '#invoke' do
600
+ include TestHelper
601
+
602
+ def test_task
603
+ @test_task ||= define('foo') {
604
+ test.using(:junit)
605
+ test.instance_eval do
606
+ @framework.stub!(:tests).and_return(['PassingTest'])
607
+ @framework.stub!(:run).and_return(['PassingTest'])
608
+ end
609
+ }.test
610
+ end
611
+
612
+ it 'should require dependencies to exist' do
613
+ lambda { test_task.with('no-such.jar').invoke }.should \
614
+ raise_error(RuntimeError, /Don't know how to build/)
615
+ end
616
+
617
+ it 'should run all dependencies as prerequisites' do
618
+ file(File.expand_path('no-such.jar')) { task('prereq').invoke }
619
+ lambda { test_task.with('no-such.jar').invoke }.should run_tasks(['prereq', 'foo:test'])
620
+ end
621
+
622
+ it 'should run tests if they have never run' do
623
+ lambda { test_task.invoke }.should run_task('foo:test')
624
+ end
625
+
626
+ it 'should not run tests if test option is off' do
627
+ Buildr.options.test = false
628
+ lambda { test_task.invoke }.should_not run_task('foo:test')
629
+ end
630
+
631
+ describe 'when there was a successful test run already' do
632
+ before do
633
+ @a_second_ago = Time.now - 1
634
+ src = ['main/java/Foo.java', 'main/resources/config.xml', 'test/java/FooTest.java', 'test/resources/config-test.xml'].map { |f| File.join('src', f) }
635
+ target = ['classes/Foo.class', 'resources/config.xml', 'test/classes/FooTest.class', 'test/resources/config-test.xml'].map { |f| File.join('target', f) }
636
+ files = ['buildfile'] + src + target
637
+ files.each { |file| write file }
638
+ (files + files.map { |file| file.pathmap('%d') }).each { |file| File.utime(@a_second_ago, @a_second_ago, file) }
639
+ touch_last_successful_test_run test_task, @a_second_ago
640
+ end
641
+
642
+ it 'should not run tests if nothing changed' do
643
+ lambda { test_task.invoke }.should_not run_task('foo:test')
644
+ end
645
+
646
+ it 'should run tests if options.test is :all' do
647
+ Buildr.options.test = :all
648
+ lambda { test_task.invoke }.should run_task('foo:test')
649
+ end
650
+
651
+ it 'should run tests if main compile target changed' do
652
+ touch project('foo').compile.target.to_s
653
+ lambda { test_task.invoke }.should run_task('foo:test')
654
+ end
655
+
656
+ it 'should run tests if test compile target changed' do
657
+ touch test_task.compile.target.to_s
658
+ lambda { test_task.invoke }.should run_task('foo:test')
659
+ end
660
+
661
+ it 'should run tests if main resources changed' do
662
+ touch project('foo').resources.target.to_s
663
+ lambda { test_task.invoke }.should run_task('foo:test')
664
+ end
665
+
666
+ it 'should run tests if test resources changed' do
667
+ touch test_task.resources.target.to_s
668
+ lambda { test_task.invoke }.should run_task('foo:test')
669
+ end
670
+
671
+ it 'should run tests if compile-dependent project changed' do
672
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
673
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
674
+ project('foo').compile.with project('bar')
675
+ lambda { test_task.invoke }.should run_task('foo:test')
676
+ end
677
+
678
+ it 'should run tests if test-dependent project changed' do
679
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
680
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
681
+ test_task.with project('bar')
682
+ lambda { test_task.invoke }.should run_task('foo:test')
683
+ end
684
+
685
+ it 'should run tests if buildfile changed' do
686
+ touch 'buildfile'
687
+ lambda { test_task.invoke }.should run_task('foo:test')
688
+ end
689
+ end
690
+ end
691
+
692
+ describe Rake::Task, 'test' do
693
+ it 'should be recursive' do
694
+ define('foo') { define 'bar' }
695
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:test')
696
+ end
697
+
698
+ it 'should be local task' do
699
+ define('foo') { define 'bar' }
700
+ lambda do
701
+ in_original_dir project('foo:bar').base_dir do
702
+ task('test').invoke
703
+ end
704
+ end.should run_task('foo:bar:test').but_not('foo:test')
705
+ end
706
+
707
+ it 'should stop at first failure' do
708
+ define('foo') { test { fail } }
709
+ define('bar') { test { fail } }
710
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test').but_not('bar:test')
711
+ end
712
+
713
+ it 'should ignore failure if options.test is :all' do
714
+ define('foo') { test { fail } }
715
+ define('bar') { test { fail } }
716
+ options.test = :all
717
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
718
+ end
719
+
720
+ it 'should ignore failure if environment variable test is \'all\'' do
721
+ define('foo') { test { fail } }
722
+ define('bar') { test { fail } }
723
+ ENV['test'] = 'all'
724
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
725
+ end
726
+
727
+ it 'should ignore failure if environment variable TEST is \'all\'' do
728
+ define('foo') { test { fail } }
729
+ define('bar') { test { fail } }
730
+ ENV['TEST'] = 'all'
731
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
732
+ end
733
+
734
+ it 'should execute no tests if options.test is false' do
735
+ define('foo') { test { fail } }
736
+ define('bar') { test { fail } }
737
+ options.test = false
738
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
739
+ end
740
+
741
+ it 'should execute no tests if environment variable test is \'no\'' do
742
+ define('foo') { test { fail } }
743
+ define('bar') { test { fail } }
744
+ ENV['test'] = 'no'
745
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
746
+ end
747
+
748
+ it 'should execute no tests if environment variable TEST is \'no\'' do
749
+ define('foo') { test { fail } }
750
+ define('bar') { test { fail } }
751
+ ENV['TEST'] = 'no'
752
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
753
+ end
754
+ end
755
+
756
+
757
+ describe 'test rule' do
758
+ include TestHelper
759
+
760
+ it 'should execute test task on local project' do
761
+ define('foo') { define 'bar' }
762
+ lambda { task('test:something').invoke }.should run_task('foo:test')
763
+ end
764
+
765
+ it 'should reset tasks to specific pattern' do
766
+ define 'foo' do
767
+ test.using(:junit)
768
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
769
+ define 'bar' do
770
+ test.using(:junit)
771
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
772
+ end
773
+ end
774
+ task('test:something').invoke
775
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
776
+ project.test.tests.should include('something')
777
+ project.test.tests.should_not include('nothing')
778
+ end
779
+ end
780
+
781
+ it 'should apply *name* pattern' do
782
+ define 'foo' do
783
+ test.using(:junit)
784
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
785
+ end
786
+ task('test:something').invoke
787
+ project('foo').test.tests.should include('prefix-something-suffix')
788
+ end
789
+
790
+ it 'should not apply *name* pattern if asterisks used' do
791
+ define 'foo' do
792
+ test.using(:junit)
793
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
794
+ end
795
+ task('test:*something').invoke
796
+ project('foo').test.tests.should include('prefix-something')
797
+ project('foo').test.tests.should_not include('prefix-something-suffix')
798
+ end
799
+
800
+ it 'should accept multiple tasks separated by commas' do
801
+ define 'foo' do
802
+ test.using(:junit)
803
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
804
+ end
805
+ task('test:foo,bar').invoke
806
+ project('foo').test.tests.should include('foo')
807
+ project('foo').test.tests.should include('bar')
808
+ project('foo').test.tests.should_not include('baz')
809
+ end
810
+
811
+ it 'should execute only the named tests' do
812
+ write 'src/test/java/TestSomething.java',
813
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
814
+ write 'src/test/java/TestFails.java',
815
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
816
+ define 'foo'
817
+ task('test:Something').invoke
818
+ end
819
+
820
+ it 'should execute the named tests even if the test task is not needed' do
821
+ define 'foo' do
822
+ test.using(:junit)
823
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
824
+ end
825
+ touch_last_successful_test_run project('foo').test
826
+ task('test:something').invoke
827
+ project('foo').test.tests.should include('something')
828
+ end
829
+
830
+ it 'should not update the last successful test run timestamp' do
831
+ define 'foo' do
832
+ test.using(:junit)
833
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
834
+ end
835
+ a_second_ago = Time.now - 1
836
+ touch_last_successful_test_run project('foo').test, a_second_ago
837
+ task('test:something').invoke
838
+ project('foo').test.timestamp.should <= a_second_ago
839
+ end
840
+ end
841
+
842
+
843
+ describe Buildr::Options, 'test' do
844
+ it 'should be true by default' do
845
+ Buildr.options.test.should be_true
846
+ end
847
+
848
+ ['skip', 'no', 'off', 'false'].each do |value|
849
+ it "should be false if test environment variable is '#{value}'" do
850
+ lambda { ENV['test'] = value }.should change { Buildr.options.test }.to(false)
851
+ end
852
+ end
853
+
854
+ ['skip', 'no', 'off', 'false'].each do |value|
855
+ it "should be false if TEST environment variable is '#{value}'" do
856
+ lambda { ENV['TEST'] = value }.should change { Buildr.options.test }.to(false)
857
+ end
858
+ end
859
+
860
+ it 'should be :all if test environment variable is all' do
861
+ lambda { ENV['test'] = 'all' }.should change { Buildr.options.test }.to(:all)
862
+ end
863
+
864
+ it 'should be :all if TEST environment variable is all' do
865
+ lambda { ENV['TEST'] = 'all' }.should change { Buildr.options.test }.to(:all)
866
+ end
867
+
868
+ it 'should be true and warn for any other value' do
869
+ ENV['TEST'] = 'funky'
870
+ lambda { Buildr.options.test.should be(true) }.should show_warning(/expecting the environment variable/i)
871
+ end
872
+ end
873
+
874
+
875
+ describe Buildr, 'integration' do
876
+ it 'should return the same task from all contexts' do
877
+ task = task('integration')
878
+ define 'foo' do
879
+ integration.should be(task)
880
+ define 'bar' do
881
+ integration.should be(task)
882
+ end
883
+ end
884
+ integration.should be(task)
885
+ end
886
+
887
+ it 'should respond to :setup and return setup task' do
888
+ setup = integration.setup
889
+ define('foo') { integration.setup.should be(setup) }
890
+ end
891
+
892
+ it 'should respond to :setup and add prerequisites to integration:setup' do
893
+ define('foo') { integration.setup 'prereq' }
894
+ integration.setup.prerequisites.should include('prereq')
895
+ end
896
+
897
+ it 'should respond to :setup and add action for integration:setup' do
898
+ action = task('action')
899
+ define('foo') { integration.setup { action.invoke } }
900
+ lambda { integration.setup.invoke }.should run_tasks(action)
901
+ end
902
+
903
+ it 'should respond to :teardown and return teardown task' do
904
+ teardown = integration.teardown
905
+ define('foo') { integration.teardown.should be(teardown) }
906
+ end
907
+
908
+ it 'should respond to :teardown and add prerequisites to integration:teardown' do
909
+ define('foo') { integration.teardown 'prereq' }
910
+ integration.teardown.prerequisites.should include('prereq')
911
+ end
912
+
913
+ it 'should respond to :teardown and add action for integration:teardown' do
914
+ action = task('action')
915
+ define('foo') { integration.teardown { action.invoke } }
916
+ lambda { integration.teardown.invoke }.should run_tasks(action)
917
+ end
918
+ end
919
+
920
+
921
+ describe Rake::Task, 'integration' do
922
+ it 'should be a local task' do
923
+ define('foo') { test.using :integration }
924
+ define('bar', :base_dir=>'other') { test.using :integration }
925
+ lambda { task('integration').invoke }.should run_task('foo:test').but_not('bar:test')
926
+ end
927
+
928
+ it 'should be a recursive task' do
929
+ define 'foo' do
930
+ test.using :integration
931
+ define('bar') { test.using :integration }
932
+ end
933
+ lambda { task('integration').invoke }.should run_tasks('foo:test', 'foo:bar:test')
934
+ end
935
+
936
+ it 'should find nested integration tests' do
937
+ define 'foo' do
938
+ define('bar') { test.using :integration }
939
+ end
940
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test')
941
+ end
942
+
943
+ it 'should ignore nested regular tasks' do
944
+ define 'foo' do
945
+ test.using :integration
946
+ define('bar') { test.using :integration=>false }
947
+ end
948
+ lambda { task('integration').invoke }.should run_tasks('foo:test').but_not('foo:bar:test')
949
+ end
950
+
951
+ it 'should agree not to run the same tasks as test' do
952
+ define 'foo' do
953
+ define 'bar' do
954
+ test.using :integration
955
+ define('baz') { test.using :integration=>false }
956
+ end
957
+ end
958
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:baz:test').but_not('foo:bar:test')
959
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test', 'foo:bar:baz:test')
960
+ end
961
+
962
+ it 'should run setup task before any project integration tests' do
963
+ define('foo') { test.using :integration }
964
+ define('bar') { test.using :integration }
965
+ lambda { task('integration').invoke }.should run_tasks([integration.setup, 'bar:test'], [integration.setup, 'foo:test'])
966
+ end
967
+
968
+ it 'should run teardown task after all project integrations tests' do
969
+ define('foo') { test.using :integration }
970
+ define('bar') { test.using :integration }
971
+ lambda { task('integration').invoke }.should run_tasks(['bar:test', integration.teardown], ['foo:test', integration.teardown])
972
+ end
973
+
974
+ it 'should run test cases marked for integration' do
975
+ write 'src/test/java/FailingTest.java',
976
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
977
+ define('foo') { test.using :integration }
978
+ lambda { task('test').invoke }.should_not raise_error
979
+ lambda { task('integration').invoke }.should raise_error(RuntimeError, /tests failed/i)
980
+ end
981
+
982
+ it 'should run setup and teardown tasks marked for integration' do
983
+ define('foo') { test.using :integration }
984
+ lambda { task('test').invoke }.should run_tasks().but_not('foo:test:setup', 'foo:test:teardown')
985
+ lambda { task('integration').invoke }.should run_tasks('foo:test:setup', 'foo:test:teardown')
986
+ end
987
+
988
+ it 'should run test actions marked for integration' do
989
+ task 'action'
990
+ define 'foo' do
991
+ test.using :integration, :junit
992
+ end
993
+ lambda { task('test').invoke }.should_not change { project('foo').test.passed_tests }
994
+ lambda { task('integration').invoke }.should change { project('foo').test.passed_tests }
995
+ project('foo').test.passed_tests.should be_empty
996
+ end
997
+
998
+ it 'should not fail if test=all' do
999
+ write 'src/test/java/FailingTest.java',
1000
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
1001
+ define('foo') { test.using :integration }
1002
+ options.test = :all
1003
+ lambda { task('integration').invoke }.should_not raise_error
1004
+ end
1005
+
1006
+ it 'should execute by local package task' do
1007
+ define 'foo', :version=>'1.0' do
1008
+ test.using :integration
1009
+ package :jar
1010
+ end
1011
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'])
1012
+ end
1013
+
1014
+ it 'should execute by local package task along with unit tests' do
1015
+ define 'foo', :version=>'1.0' do
1016
+ test.using :integration
1017
+ package :jar
1018
+ define('bar') { test.using :integration=>false }
1019
+ end
1020
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'],
1021
+ ['foo:bar:test', 'foo:bar:package'])
1022
+ end
1023
+
1024
+ it 'should not execute by local package task if test=no' do
1025
+ define 'foo', :version=>'1.0' do
1026
+ test.using :integration
1027
+ package :jar
1028
+ end
1029
+ options.test = false
1030
+ lambda { task('package').invoke }.should run_task('foo:package').but_not('foo:test')
1031
+ end
1032
+ end
1033
+
1034
+
1035
+ describe 'integration rule' do
1036
+ it 'should execute integration tests on local project' do
1037
+ define 'foo' do
1038
+ test.using :junit, :integration
1039
+ define 'bar'
1040
+ end
1041
+ lambda { task('integration:something').invoke }.should run_task('foo:test')
1042
+ end
1043
+
1044
+ it 'should reset tasks to specific pattern' do
1045
+ define 'foo' do
1046
+ test.using :junit, :integration
1047
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1048
+ define 'bar' do
1049
+ test.using :junit, :integration
1050
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1051
+ end
1052
+ end
1053
+ task('integration:something').invoke
1054
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
1055
+ project.test.tests.should include('something')
1056
+ project.test.tests.should_not include('nothing')
1057
+ end
1058
+ end
1059
+
1060
+ it 'should apply *name* pattern' do
1061
+ define 'foo' do
1062
+ test.using :junit, :integration
1063
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
1064
+ end
1065
+ task('integration:something').invoke
1066
+ project('foo').test.tests.should include('prefix-something-suffix')
1067
+ end
1068
+
1069
+ it 'should not apply *name* pattern if asterisks used' do
1070
+ define 'foo' do
1071
+ test.using :junit, :integration
1072
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
1073
+ end
1074
+ task('integration:*something').invoke
1075
+ project('foo').test.tests.should include('prefix-something')
1076
+ project('foo').test.tests.should_not include('prefix-something-suffix')
1077
+ end
1078
+
1079
+ it 'should accept multiple tasks separated by commas' do
1080
+ define 'foo' do
1081
+ test.using :junit, :integration
1082
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
1083
+ end
1084
+ task('integration:foo,bar').invoke
1085
+ project('foo').test.tests.should include('foo')
1086
+ project('foo').test.tests.should include('bar')
1087
+ project('foo').test.tests.should_not include('baz')
1088
+ end
1089
+
1090
+ it 'should execute only the named tests' do
1091
+ write 'src/test/java/TestSomething.java',
1092
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
1093
+ write 'src/test/java/TestFails.java',
1094
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
1095
+ define('foo') { test.using :junit, :integration }
1096
+ task('integration:Something').invoke
1097
+ end
1098
+ end