buildr 1.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/CHANGELOG +780 -0
  2. data/DISCLAIMER +7 -0
  3. data/KEYS +151 -0
  4. data/LICENSE +176 -0
  5. data/NOTICE +31 -0
  6. data/README +173 -0
  7. data/Rakefile +63 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +232 -0
  10. data/addon/buildr/hibernate.rb +142 -0
  11. data/addon/buildr/javacc.rb +85 -0
  12. data/addon/buildr/jdepend.rb +60 -0
  13. data/addon/buildr/jetty.rb +248 -0
  14. data/addon/buildr/nailgun.rb +892 -0
  15. data/addon/buildr/openjpa.rb +90 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  18. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  19. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  20. data/addon/buildr/xmlbeans.rb +93 -0
  21. data/bin/buildr +21 -0
  22. data/buildr.gemspec +50 -0
  23. data/doc/css/default.css +225 -0
  24. data/doc/css/print.css +95 -0
  25. data/doc/css/syntax.css +43 -0
  26. data/doc/images/apache-incubator-logo.png +0 -0
  27. data/doc/images/buildr-hires.png +0 -0
  28. data/doc/images/buildr.png +0 -0
  29. data/doc/images/note.png +0 -0
  30. data/doc/images/tip.png +0 -0
  31. data/doc/images/zbuildr.tif +0 -0
  32. data/doc/pages/artifacts.textile +317 -0
  33. data/doc/pages/building.textile +501 -0
  34. data/doc/pages/contributing.textile +178 -0
  35. data/doc/pages/download.textile +25 -0
  36. data/doc/pages/extending.textile +229 -0
  37. data/doc/pages/getting_started.textile +337 -0
  38. data/doc/pages/index.textile +63 -0
  39. data/doc/pages/mailing_lists.textile +17 -0
  40. data/doc/pages/more_stuff.textile +367 -0
  41. data/doc/pages/packaging.textile +592 -0
  42. data/doc/pages/projects.textile +449 -0
  43. data/doc/pages/recipes.textile +127 -0
  44. data/doc/pages/settings_profiles.textile +339 -0
  45. data/doc/pages/testing.textile +475 -0
  46. data/doc/pages/troubleshooting.textile +121 -0
  47. data/doc/pages/whats_new.textile +389 -0
  48. data/doc/print.haml +52 -0
  49. data/doc/print.toc.yaml +28 -0
  50. data/doc/scripts/buildr-git.rb +411 -0
  51. data/doc/scripts/install-jruby.sh +44 -0
  52. data/doc/scripts/install-linux.sh +64 -0
  53. data/doc/scripts/install-osx.sh +52 -0
  54. data/doc/site.haml +55 -0
  55. data/doc/site.toc.yaml +44 -0
  56. data/lib/buildr.rb +47 -0
  57. data/lib/buildr/core.rb +27 -0
  58. data/lib/buildr/core/application.rb +373 -0
  59. data/lib/buildr/core/application_cli.rb +134 -0
  60. data/lib/buildr/core/build.rb +262 -0
  61. data/lib/buildr/core/checks.rb +382 -0
  62. data/lib/buildr/core/common.rb +155 -0
  63. data/lib/buildr/core/compile.rb +594 -0
  64. data/lib/buildr/core/environment.rb +120 -0
  65. data/lib/buildr/core/filter.rb +258 -0
  66. data/lib/buildr/core/generate.rb +195 -0
  67. data/lib/buildr/core/help.rb +118 -0
  68. data/lib/buildr/core/progressbar.rb +156 -0
  69. data/lib/buildr/core/project.rb +890 -0
  70. data/lib/buildr/core/test.rb +690 -0
  71. data/lib/buildr/core/transports.rb +486 -0
  72. data/lib/buildr/core/util.rb +235 -0
  73. data/lib/buildr/ide.rb +19 -0
  74. data/lib/buildr/ide/eclipse.rb +181 -0
  75. data/lib/buildr/ide/idea.ipr.template +300 -0
  76. data/lib/buildr/ide/idea.rb +194 -0
  77. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  78. data/lib/buildr/ide/idea7x.rb +210 -0
  79. data/lib/buildr/java.rb +26 -0
  80. data/lib/buildr/java/ant.rb +71 -0
  81. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  82. data/lib/buildr/java/commands.rb +210 -0
  83. data/lib/buildr/java/compilers.rb +432 -0
  84. data/lib/buildr/java/deprecated.rb +141 -0
  85. data/lib/buildr/java/groovyc.rb +137 -0
  86. data/lib/buildr/java/jruby.rb +99 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  89. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  91. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  92. data/lib/buildr/java/packaging.rb +706 -0
  93. data/lib/buildr/java/pom.rb +178 -0
  94. data/lib/buildr/java/rjb.rb +142 -0
  95. data/lib/buildr/java/test_frameworks.rb +290 -0
  96. data/lib/buildr/java/version_requirement.rb +172 -0
  97. data/lib/buildr/packaging.rb +21 -0
  98. data/lib/buildr/packaging/artifact.rb +729 -0
  99. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  100. data/lib/buildr/packaging/artifact_search.rb +140 -0
  101. data/lib/buildr/packaging/gems.rb +102 -0
  102. data/lib/buildr/packaging/package.rb +233 -0
  103. data/lib/buildr/packaging/tar.rb +104 -0
  104. data/lib/buildr/packaging/zip.rb +719 -0
  105. data/rakelib/apache.rake +126 -0
  106. data/rakelib/changelog.rake +56 -0
  107. data/rakelib/doc.rake +103 -0
  108. data/rakelib/package.rake +44 -0
  109. data/rakelib/release.rake +53 -0
  110. data/rakelib/rspec.rake +81 -0
  111. data/rakelib/rubyforge.rake +45 -0
  112. data/rakelib/scm.rake +49 -0
  113. data/rakelib/setup.rake +59 -0
  114. data/rakelib/stage.rake +45 -0
  115. data/spec/application_spec.rb +316 -0
  116. data/spec/archive_spec.rb +494 -0
  117. data/spec/artifact_namespace_spec.rb +635 -0
  118. data/spec/artifact_spec.rb +738 -0
  119. data/spec/build_spec.rb +193 -0
  120. data/spec/checks_spec.rb +537 -0
  121. data/spec/common_spec.rb +579 -0
  122. data/spec/compile_spec.rb +561 -0
  123. data/spec/groovy_compilers_spec.rb +239 -0
  124. data/spec/java_bdd_frameworks_spec.rb +238 -0
  125. data/spec/java_compilers_spec.rb +446 -0
  126. data/spec/java_packaging_spec.rb +1042 -0
  127. data/spec/java_test_frameworks_spec.rb +414 -0
  128. data/spec/packaging_helper.rb +63 -0
  129. data/spec/packaging_spec.rb +589 -0
  130. data/spec/project_spec.rb +739 -0
  131. data/spec/sandbox.rb +116 -0
  132. data/spec/scala_compilers_spec.rb +239 -0
  133. data/spec/spec.opts +6 -0
  134. data/spec/spec_helpers.rb +283 -0
  135. data/spec/test_spec.rb +871 -0
  136. data/spec/transport_spec.rb +300 -0
  137. data/spec/version_requirement_spec.rb +115 -0
  138. metadata +324 -0
@@ -0,0 +1,871 @@
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
+ describe Buildr::TestTask do
21
+ def test_task
22
+ @test_task ||= define('foo').test
23
+ end
24
+
25
+ it 'should respond to :compile and return compile task' do
26
+ test_task.compile.should be_kind_of(Buildr::CompileTask)
27
+ end
28
+
29
+ it 'should respond to :compile and add sources to compile' do
30
+ test_task.compile 'sources'
31
+ test_task.compile.sources.should include('sources')
32
+ end
33
+
34
+ it 'should respond to :compile and add action for test:compile' do
35
+ write 'src/test/java/Test.java', 'class Test {}'
36
+ test_task.compile { task('action').invoke }
37
+ lambda { test_task.compile.invoke }.should run_tasks('action')
38
+ end
39
+
40
+ it 'should execute compile tasks first' do
41
+ write 'src/main/java/Nothing.java', 'class Nothing {}'
42
+ write 'src/test/java/Test.java', 'class Test {}'
43
+ define 'foo'
44
+ lambda { project('foo').test.compile.invoke }.should run_tasks(['foo:compile', 'foo:test:compile'])
45
+ end
46
+
47
+ it 'should respond to :resources and return resources task' do
48
+ test_task.resources.should be_kind_of(Buildr::ResourcesTask)
49
+ end
50
+
51
+ it 'should respond to :resources and add prerequisites to test:resources' do
52
+ file('prereq').should_receive :invoke_prerequisites
53
+ test_task.resources 'prereq'
54
+ test_task.compile.invoke
55
+ end
56
+
57
+ it 'should respond to :resources and add action for test:resources' do
58
+ task 'action'
59
+ test_task.resources { task('action').invoke }
60
+ lambda { test_task.resources.invoke }.should run_tasks('action')
61
+ end
62
+
63
+ it 'should respond to :setup and return setup task' do
64
+ test_task.setup.name.should =~ /test:setup$/
65
+ end
66
+
67
+ it 'should respond to :setup and add prerequisites to test:setup' do
68
+ test_task.setup 'prereq'
69
+ test_task.setup.prerequisites.should include('prereq')
70
+ end
71
+
72
+ it 'should respond to :setup and add action for test:setup' do
73
+ task 'action'
74
+ test_task.setup { task('action').invoke }
75
+ lambda { test_task.setup.invoke }.should run_tasks('action')
76
+ end
77
+
78
+ it 'should respond to :teardown and return teardown task' do
79
+ test_task.teardown.name.should =~ /test:teardown$/
80
+ end
81
+
82
+ it 'should respond to :teardown and add prerequisites to test:teardown' do
83
+ test_task.teardown 'prereq'
84
+ test_task.teardown.prerequisites.should include('prereq')
85
+ end
86
+
87
+ it 'should respond to :teardown and add action for test:teardown' do
88
+ task 'action'
89
+ test_task.teardown { task('action').invoke }
90
+ lambda { test_task.teardown.invoke }.should run_tasks('action')
91
+ end
92
+
93
+ it 'should respond to :with and return self' do
94
+ test_task.with.should be(test_task)
95
+ end
96
+
97
+ it 'should respond to :with and add artifacfs to compile task dependencies' do
98
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
99
+ test_task.compile.dependencies.should include(File.expand_path('test.jar'))
100
+ test_task.compile.dependencies.should include(artifact('acme:example:jar:1.0'))
101
+ end
102
+
103
+ it 'should respond to :with and add artifacfs to task dependencies' do
104
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
105
+ test_task.dependencies.should include(File.expand_path('test.jar'))
106
+ test_task.dependencies.should include(artifact('acme:example:jar:1.0'))
107
+ end
108
+
109
+ it 'should response to :options and return test framework options' do
110
+ test_task.using :foo=>'bar'
111
+ test_task.options[:foo].should eql('bar')
112
+ end
113
+
114
+ it 'should respond to :using and return self' do
115
+ test_task.using.should be(test_task)
116
+ end
117
+
118
+ it 'should respond to :using and set value options' do
119
+ test_task.using('foo'=>'FOO', 'bar'=>'BAR')
120
+ test_task.options[:foo].should eql('FOO')
121
+ test_task.options[:bar].should eql('BAR')
122
+ end
123
+
124
+ it 'should start without pre-selected test framework' do
125
+ test_task.framework.should be_nil
126
+ end
127
+
128
+ it 'should respond to :using and select test framework' do
129
+ test_task.using(:testng)
130
+ test_task.framework.should eql(:testng)
131
+ end
132
+
133
+ it 'should infer test framework from compiled language' do
134
+ lambda { test_task.compile.using(:javac) }.should change { test_task.framework }.to(:junit)
135
+ end
136
+
137
+ it 'should respond to :include and return self' do
138
+ test_task.include.should be(test_task)
139
+ end
140
+
141
+ it 'should respond to :include and add inclusion patterns' do
142
+ test_task.include 'Foo', 'Bar'
143
+ test_task.send(:include?, 'Foo').should be_true
144
+ test_task.send(:include?, 'Bar').should be_true
145
+ end
146
+
147
+ it 'should respond to :exclude and return self' do
148
+ test_task.exclude.should be(test_task)
149
+ end
150
+
151
+ it 'should respond to :exclude and add exclusion patterns' do
152
+ test_task.exclude 'FooTest', 'BarTest'
153
+ test_task.send(:include?, 'FooTest').should be_false
154
+ test_task.send(:include?, 'BarTest').should be_false
155
+ test_task.send(:include?, 'BazTest').should be_true
156
+ end
157
+
158
+ it 'should execute setup task before running tests' do
159
+ mock = mock('actions')
160
+ test_task.setup { mock.setup }
161
+ test_task.enhance { mock.tests }
162
+ mock.should_receive(:setup).ordered
163
+ mock.should_receive(:tests).ordered
164
+ test_task.invoke
165
+ end
166
+
167
+ it 'should execute teardown task after running tests' do
168
+ mock = mock('actions')
169
+ test_task.teardown { mock.teardown }
170
+ test_task.enhance { mock.tests }
171
+ mock.should_receive(:tests).ordered
172
+ mock.should_receive(:teardown).ordered
173
+ test_task.invoke
174
+ end
175
+
176
+ it 'should not execute teardown if setup failed' do
177
+ test_task.setup { fail }
178
+ lambda { test_task.invoke rescue nil }.should_not run_task(test_task.teardown)
179
+ end
180
+
181
+ it 'should use the main compile dependencies' do
182
+ define('foo') { compile.using(:javac).with 'group:id:jar:1.0' }
183
+ project('foo').test.dependencies.should include(artifact('group:id:jar:1.0'))
184
+ end
185
+
186
+ it 'should include the main compile target in its dependencies' do
187
+ define('foo') { compile.using(:javac) }
188
+ project('foo').test.dependencies.should include(project('foo').compile.target)
189
+ end
190
+
191
+ it 'should include the main resources target in its dependencies' do
192
+ write 'src/main/resources/test'
193
+ define('foo').test.dependencies.should include(project('foo').resources.target)
194
+ end
195
+
196
+ it 'should not use the test compile dependencies' do
197
+ define('foo') { test.compile.using(:javac).with 'group:id:jar:1.0' }
198
+ project('foo').test.dependencies.should_not include(artifact('group:id:jar:1.0'))
199
+ end
200
+
201
+ it 'should include the test compile target in its dependencies' do
202
+ define('foo') { test.compile.using(:javac) }
203
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
204
+ end
205
+
206
+ it 'should include the test resources target in its dependencies' do
207
+ write 'src/test/resources/test'
208
+ define('foo').test.dependencies.should include(project('foo').test.resources.target)
209
+ end
210
+
211
+ it 'should clean after itself (test files)' do
212
+ define('foo') { test.compile.using(:javac) }
213
+ mkpath project('foo').test.compile.target.to_s
214
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.compile.target.to_s) }.to(false)
215
+ end
216
+
217
+ it 'should clean after itself (reports)' do
218
+ define 'foo'
219
+ mkpath project('foo').test.report_to.to_s
220
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.report_to.to_s) }.to(false)
221
+ end
222
+ end
223
+
224
+
225
+ describe Buildr::TestTask, 'with no tests' do
226
+ it 'should pass' do
227
+ lambda { define('foo').test.invoke }.should_not raise_error
228
+ end
229
+
230
+ it 'should report no failed tests' do
231
+ lambda { verbose(true) { define('foo').test.invoke } }.should_not warn_that(/fail/i)
232
+ end
233
+
234
+ it 'should return no failed tests' do
235
+ define('foo') { test.using(:junit) }
236
+ project('foo').test.invoke
237
+ project('foo').test.failed_tests.should be_empty
238
+ end
239
+
240
+ it 'should return no passing tests' do
241
+ define('foo') { test.using(:junit) }
242
+ project('foo').test.invoke
243
+ project('foo').test.passed_tests.should be_empty
244
+ end
245
+
246
+ it 'should execute teardown task' do
247
+ lambda { define('foo').test.invoke }.should run_task('foo:test:teardown')
248
+ end
249
+ end
250
+
251
+
252
+ describe Buildr::TestTask, 'with passing tests' do
253
+ def test_task
254
+ @test_task ||= begin
255
+ define 'foo' do
256
+ test.using(:junit)
257
+ test.instance_eval do
258
+ @framework.stub!(:tests).and_return(['PassingTest1', 'PassingTest2'])
259
+ @framework.stub!(:run).and_return(['PassingTest1', 'PassingTest2'])
260
+ end
261
+ end
262
+ project('foo').test
263
+ end
264
+ end
265
+
266
+ it 'should pass' do
267
+ lambda { test_task.invoke }.should_not raise_error
268
+ end
269
+
270
+ it 'should report no failed tests' do
271
+ lambda { verbose(true) { test_task.invoke } }.should_not warn_that(/fail/i)
272
+ end
273
+
274
+ it 'should return passed tests' do
275
+ test_task.invoke
276
+ test_task.passed_tests.should == ['PassingTest1', 'PassingTest2']
277
+ end
278
+
279
+ it 'should return no failed tests' do
280
+ test_task.invoke
281
+ test_task.failed_tests.should be_empty
282
+ end
283
+
284
+ it 'should execute teardown task' do
285
+ lambda { test_task.invoke }.should run_task('foo:test:teardown')
286
+ end
287
+ end
288
+
289
+
290
+ describe Buildr::TestTask, 'with failed test' do
291
+ def test_task
292
+ @test_task ||= begin
293
+ define 'foo' do
294
+ test.using(:junit)
295
+ test.instance_eval do
296
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
297
+ @framework.stub!(:run).and_return(['PassingTest'])
298
+ end
299
+ end
300
+ project('foo').test
301
+ end
302
+ end
303
+
304
+ it 'should fail' do
305
+ lambda { test_task.invoke }.should raise_error(RuntimeError, /Tests failed/)
306
+ end
307
+
308
+ it 'should report failed tests' do
309
+ lambda { verbose(true) { test_task.invoke rescue nil } }.should warn_that(/FailingTest/)
310
+ end
311
+
312
+ it 'should return failed tests' do
313
+ test_task.invoke rescue nil
314
+ test_task.failed_tests.should == ['FailingTest']
315
+ end
316
+
317
+ it 'should return passing tests as well' do
318
+ test_task.invoke rescue nil
319
+ test_task.passed_tests.should == ['PassingTest']
320
+ end
321
+
322
+ it 'should not fail if fail_on_failure is false' do
323
+ test_task.using(:fail_on_failure=>false).invoke
324
+ lambda { test_task.invoke }.should_not raise_error
325
+ end
326
+
327
+ it 'should report failed tests even if fail_on_failure is false' do
328
+ test_task.using(:fail_on_failure=>false)
329
+ lambda { verbose(true) { test_task.invoke } }.should warn_that(/FailingTest/)
330
+ end
331
+
332
+ it 'should return failed tests even if fail_on_failure is false' do
333
+ test_task.using(:fail_on_failure=>false).invoke
334
+ test_task.failed_tests.should == ['FailingTest']
335
+ end
336
+
337
+ it 'should execute teardown task' do
338
+ lambda { test_task.invoke rescue nil }.should run_task('foo:test:teardown')
339
+ end
340
+ end
341
+
342
+
343
+ describe Buildr::Project, '#test' do
344
+ it 'should return the project\'s test task' do
345
+ define('foo') { test.should be(task('test')) }
346
+ end
347
+
348
+ it 'should accept prerequisites for task' do
349
+ define('foo') { test 'prereq' }
350
+ project('foo').test.prerequisites.should include('prereq')
351
+ end
352
+
353
+ it 'should accept actions for task' do
354
+ task 'action'
355
+ define('foo') { test { task('action').invoke } }
356
+ lambda { project('foo').test.invoke }.should run_tasks('action')
357
+ end
358
+
359
+ it 'should set fail_on_failure true by default' do
360
+ define('foo').test.options[:fail_on_failure].should be_true
361
+ end
362
+
363
+ it 'should set fork mode by default' do
364
+ define('foo').test.options[:fork].should == :once
365
+ end
366
+
367
+ it 'should set properties to empty hash by default' do
368
+ define('foo').test.options[:properties].should == {}
369
+ end
370
+
371
+ it 'should set environment variables to empty hash by default' do
372
+ define('foo').test.options[:environment].should == {}
373
+ end
374
+
375
+ it 'should inherit options from parent project' do
376
+ define 'foo' do
377
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }
378
+ define 'bar' do
379
+ test.options[:fail_on_failure].should be_false
380
+ test.options[:fork].should == :each
381
+ test.options[:properties][:foo].should == 'bar'
382
+ end
383
+ end
384
+ end
385
+
386
+ it 'should clone options from parent project' do
387
+ define 'foo' do
388
+ define 'bar' do
389
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }
390
+ end.invoke
391
+ test.options[:fail_on_failure].should be_true
392
+ test.options[:fork].should == :once
393
+ test.options[:other].should be_nil
394
+ end
395
+ end
396
+ end
397
+
398
+
399
+ describe Buildr::Project, '#test.compile' do
400
+ it 'should identify compiler from project' do
401
+ write 'src/test/java/com/example/Test.java'
402
+ define('foo') do
403
+ test.compile.compiler.should eql(:javac)
404
+ end
405
+ end
406
+
407
+ it 'should include identified sources' do
408
+ write 'src/test/java/Test.java'
409
+ define('foo') do
410
+ test.compile.sources.should include(_('src/test/java'))
411
+ end
412
+ end
413
+
414
+ it 'should compile to target/test/<code>' do
415
+ define 'foo', :target=>'targeted' do
416
+ test.compile.using(:javac)
417
+ test.compile.target.should eql(file('targeted/test/classes'))
418
+ end
419
+ end
420
+
421
+ it 'should use main compile dependencies' do
422
+ define 'foo' do
423
+ compile.using(:javac).with 'group:id:jar:1.0'
424
+ test.compile.using(:javac)
425
+ end
426
+ project('foo').test.compile.dependencies.should include(artifact('group:id:jar:1.0'))
427
+ end
428
+
429
+ it 'should include the main compiled target in its dependencies' do
430
+ define 'foo' do
431
+ compile.using(:javac).into 'bytecode'
432
+ test.compile.using(:javac)
433
+ end
434
+ project('foo').test.compile.dependencies.should include(file('bytecode'))
435
+ end
436
+
437
+ it 'should include the test framework dependencies' do
438
+ define 'foo' do
439
+ test.compile.using(:javac)
440
+ test.using(:junit)
441
+ end
442
+ project('foo').test.compile.dependencies.should include(*artifacts(JUnit.dependencies))
443
+ end
444
+
445
+ it 'should clean after itself' do
446
+ write 'src/test/java/Nothing.java', 'class Nothing {}'
447
+ define('foo') { test.compile.into 'bytecode' }
448
+ project('foo').test.compile.invoke
449
+ lambda { project('foo').clean.invoke }.should change { File.exist?('bytecode') }.to(false)
450
+ end
451
+ end
452
+
453
+
454
+ describe Buildr::Project, 'test:resources' do
455
+ it 'should ignore resources unless they exist' do
456
+ define('foo').test.resources.sources.should be_empty
457
+ end
458
+
459
+ it 'should pick resources from src/test/resources if found' do
460
+ mkpath 'src/test/resources'
461
+ define('foo') { test.resources.sources.should include(file('src/test/resources')) }
462
+ end
463
+
464
+ it 'should copy to the resources target directory' do
465
+ write 'src/test/resources/foo', 'Foo'
466
+ define('foo', :target=>'targeted').test.invoke
467
+ file('targeted/test/resources/foo').should contain('Foo')
468
+ end
469
+
470
+ it 'should execute alongside compile task' do
471
+ task 'action'
472
+ define('foo') { test.resources { task('action').invoke } }
473
+ lambda { project('foo').test.compile.invoke }.should run_tasks('action')
474
+ end
475
+ end
476
+
477
+
478
+ describe Rake::Task, 'test' do
479
+ it 'should be recursive' do
480
+ define('foo') { define 'bar' }
481
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:test')
482
+ end
483
+
484
+ it 'should be local task' do
485
+ define('foo') { define 'bar' }
486
+ lambda do
487
+ in_original_dir project('foo:bar').base_dir do
488
+ task('test').invoke
489
+ end
490
+ end.should run_task('foo:bar:test').but_not('foo:test')
491
+ end
492
+
493
+ it 'should stop at first failure' do
494
+ define('foo') { test { fail } }
495
+ define('bar') { test { fail } }
496
+ lambda { task('test').invoke rescue nil }.should run_tasks('bar:test').but_not('foo:test')
497
+ end
498
+
499
+ it 'should ignore failure if options.test is :all' do
500
+ define('foo') { test { fail } }
501
+ define('bar') { test { fail } }
502
+ options.test = :all
503
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
504
+ end
505
+
506
+ it 'should ignore failure if environment variable test is \'all\'' do
507
+ define('foo') { test { fail } }
508
+ define('bar') { test { fail } }
509
+ ENV['test'] = 'all'
510
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
511
+ end
512
+
513
+ it 'should ignore failure if environment variable TEST is \'all\'' do
514
+ define('foo') { test { fail } }
515
+ define('bar') { test { fail } }
516
+ ENV['TEST'] = 'all'
517
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
518
+ end
519
+
520
+ it 'should execute no tests if options.test is false' do
521
+ define('foo') { test { fail } }
522
+ define('bar') { test { fail } }
523
+ options.test = false
524
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
525
+ end
526
+
527
+ it 'should execute no tests if environment variable test is \'no\'' do
528
+ define('foo') { test { fail } }
529
+ define('bar') { test { fail } }
530
+ ENV['test'] = 'no'
531
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
532
+ end
533
+
534
+ it 'should execute no tests if environment variable TEST is \'no\'' do
535
+ define('foo') { test { fail } }
536
+ define('bar') { test { fail } }
537
+ ENV['TEST'] = 'no'
538
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
539
+ end
540
+ end
541
+
542
+
543
+ describe 'test rule' do
544
+ it 'should execute test task on local project' do
545
+ define('foo') { define 'bar' }
546
+ lambda { task('test:something').invoke }.should run_task('foo:test')
547
+ end
548
+
549
+ it 'should reset tasks to specific pattern' do
550
+ define 'foo' do
551
+ test.using(:junit)
552
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
553
+ define 'bar' do
554
+ test.using(:junit)
555
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
556
+ end
557
+ end
558
+ task('test:something').invoke
559
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
560
+ project.test.tests.should include('something')
561
+ project.test.tests.should_not include('nothing')
562
+ end
563
+ end
564
+
565
+ it 'should apply *name* pattern' do
566
+ define 'foo' do
567
+ test.using(:junit)
568
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
569
+ end
570
+ task('test:something').invoke
571
+ project('foo').test.tests.should include('prefix-something-suffix')
572
+ end
573
+
574
+ it 'should not apply *name* pattern if asterisks used' do
575
+ define 'foo' do
576
+ test.using(:junit)
577
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
578
+ end
579
+ task('test:*something').invoke
580
+ project('foo').test.tests.should include('prefix-something')
581
+ project('foo').test.tests.should_not include('prefix-something-suffix')
582
+ end
583
+
584
+ it 'should accept multiple tasks separated by commas' do
585
+ define 'foo' do
586
+ test.using(:junit)
587
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
588
+ end
589
+ task('test:foo,bar').invoke
590
+ project('foo').test.tests.should include('foo')
591
+ project('foo').test.tests.should include('bar')
592
+ project('foo').test.tests.should_not include('baz')
593
+ end
594
+
595
+ it 'should execute only the named tests' do
596
+ write 'src/test/java/TestSomething.java',
597
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
598
+ write 'src/test/java/TestFails.java', 'class TestFails {}'
599
+ define 'foo'
600
+ task('test:Something').invoke
601
+ end
602
+ end
603
+
604
+
605
+ describe Rake::Task, 'build' do
606
+ it 'should run test task if test option is on' do
607
+ Buildr.options.test = true
608
+ lambda { task('build').invoke }.should run_tasks('test')
609
+ end
610
+
611
+ it 'should not run test task if test option is off' do
612
+ Buildr.options.test = false
613
+ lambda { task('build').invoke }.should_not run_task('test')
614
+ end
615
+ end
616
+
617
+
618
+ describe Buildr::Options, 'test' do
619
+ it 'should be true by default' do
620
+ Buildr.options.test.should be_true
621
+ end
622
+
623
+ ['skip', 'no', 'off', 'false'].each do |value|
624
+ it "should be false if test environment variable is '#{value}'" do
625
+ lambda { ENV['test'] = value }.should change { Buildr.options.test }.to(false)
626
+ end
627
+ end
628
+
629
+ ['skip', 'no', 'off', 'false'].each do |value|
630
+ it "should be false if TEST environment variable is '#{value}'" do
631
+ lambda { ENV['TEST'] = value }.should change { Buildr.options.test }.to(false)
632
+ end
633
+ end
634
+
635
+ it 'should be :all if test environment variable is all' do
636
+ lambda { ENV['test'] = 'all' }.should change { Buildr.options.test }.to(:all)
637
+ end
638
+
639
+ it 'should be :all if TEST environment variable is all' do
640
+ lambda { ENV['TEST'] = 'all' }.should change { Buildr.options.test }.to(:all)
641
+ end
642
+
643
+ it 'should be true and warn for any other value' do
644
+ ENV['TEST'] = 'funky'
645
+ lambda { Buildr.options.test.should be(true) }.should warn_that(/expecting the environment variable/i)
646
+ end
647
+ end
648
+
649
+
650
+ describe Buildr, 'integration' do
651
+ it 'should return the same task from all contexts' do
652
+ task = task('integration')
653
+ define 'foo' do
654
+ integration.should be(task)
655
+ define 'bar' do
656
+ integration.should be(task)
657
+ end
658
+ end
659
+ integration.should be(task)
660
+ end
661
+
662
+ it 'should respond to :setup and return setup task' do
663
+ setup = integration.setup
664
+ define('foo') { integration.setup.should be(setup) }
665
+ end
666
+
667
+ it 'should respond to :setup and add prerequisites to integration:setup' do
668
+ define('foo') { integration.setup 'prereq' }
669
+ integration.setup.prerequisites.should include('prereq')
670
+ end
671
+
672
+ it 'should respond to :setup and add action for integration:setup' do
673
+ action = task('action')
674
+ define('foo') { integration.setup { action.invoke } }
675
+ lambda { integration.setup.invoke }.should run_tasks(action)
676
+ end
677
+
678
+ it 'should respond to :teardown and return teardown task' do
679
+ teardown = integration.teardown
680
+ define('foo') { integration.teardown.should be(teardown) }
681
+ end
682
+
683
+ it 'should respond to :teardown and add prerequisites to integration:teardown' do
684
+ define('foo') { integration.teardown 'prereq' }
685
+ integration.teardown.prerequisites.should include('prereq')
686
+ end
687
+
688
+ it 'should respond to :teardown and add action for integration:teardown' do
689
+ action = task('action')
690
+ define('foo') { integration.teardown { action.invoke } }
691
+ lambda { integration.teardown.invoke }.should run_tasks(action)
692
+ end
693
+ end
694
+
695
+
696
+ describe Rake::Task, 'integration' do
697
+ it 'should be a local task' do
698
+ define('foo') { test.using :integration }
699
+ define('bar', :base_dir=>'other') { test.using :integration }
700
+ lambda { task('integration').invoke }.should run_task('foo:test').but_not('bar:test')
701
+ end
702
+
703
+ it 'should be a recursive task' do
704
+ define 'foo' do
705
+ test.using :integration
706
+ define('bar') { test.using :integration }
707
+ end
708
+ lambda { task('integration').invoke }.should run_tasks('foo:test', 'foo:bar:test')
709
+ end
710
+
711
+ it 'should find nested integration tests' do
712
+ define 'foo' do
713
+ define('bar') { test.using :integration }
714
+ end
715
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test')
716
+ end
717
+
718
+ it 'should ignore nested regular tasks' do
719
+ define 'foo' do
720
+ test.using :integration
721
+ define('bar') { test.using :integration=>false }
722
+ end
723
+ lambda { task('integration').invoke }.should run_tasks('foo:test').but_not('foo:bar:test')
724
+ end
725
+
726
+ it 'should agree not to run the same tasks as test' do
727
+ define 'foo' do
728
+ define 'bar' do
729
+ test.using :integration
730
+ define('baz') { test.using :integration=>false }
731
+ end
732
+ end
733
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:baz:test').but_not('foo:bar:test')
734
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test', 'foo:bar:baz:test')
735
+ end
736
+
737
+ it 'should run setup task before any project integration tests' do
738
+ define('foo') { test.using :integration }
739
+ define('bar') { test.using :integration }
740
+ lambda { task('integration').invoke }.should run_tasks([integration.setup, 'bar:test', 'foo:test'])
741
+ end
742
+
743
+ it 'should run teardown task after all project integrations tests' do
744
+ define('foo') { test.using :integration }
745
+ define('bar') { test.using :integration }
746
+ lambda { task('integration').invoke }.should run_tasks(['bar:test', 'foo:test', integration.teardown])
747
+ end
748
+
749
+ it 'should run test cases marked for integration' do
750
+ write 'src/test/java/FailingTest.java',
751
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
752
+ define('foo') { test.using :integration }
753
+ lambda { task('test').invoke }.should_not raise_error
754
+ lambda { task('integration').invoke }.should raise_error(RuntimeError, /tests failed/i)
755
+ end
756
+
757
+ it 'should run setup and teardown tasks marked for integration' do
758
+ define('foo') { test.using :integration }
759
+ lambda { task('test').invoke }.should run_tasks().but_not('foo:test:setup', 'foo:test:teardown')
760
+ lambda { task('integration').invoke }.should run_tasks('foo:test:setup', 'foo:test:teardown')
761
+ end
762
+
763
+ it 'should run test actions marked for integration' do
764
+ task 'action'
765
+ define 'foo' do
766
+ test.using :integration, :junit
767
+ end
768
+ lambda { task('test').invoke }.should_not change { project('foo').test.passed_tests }
769
+ lambda { task('integration').invoke }.should change { project('foo').test.passed_tests }
770
+ project('foo').test.passed_tests.should be_empty
771
+ end
772
+
773
+ it 'should not fail if test=all' do
774
+ write 'src/test/java/FailingTest.java',
775
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
776
+ define('foo') { test.using :integration }
777
+ options.test = :all
778
+ lambda { task('integration').invoke }.should_not raise_error
779
+ end
780
+
781
+ it 'should execute by local package task' do
782
+ define 'foo', :version=>'1.0' do
783
+ test.using :integration
784
+ package :jar
785
+ end
786
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'])
787
+ end
788
+
789
+ it 'should execute by local package task along with unit tests' do
790
+ define 'foo', :version=>'1.0' do
791
+ test.using :integration
792
+ package :jar
793
+ define('bar') { test.using :integration=>false }
794
+ end
795
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'],
796
+ ['foo:bar:build', 'foo:bar:test', 'foo:bar:package'])
797
+ end
798
+
799
+ it 'should not execute by local package task if test=no' do
800
+ define 'foo', :version=>'1.0' do
801
+ test.using :integration
802
+ package :jar
803
+ end
804
+ options.test = false
805
+ lambda { task('package').invoke }.should run_task('foo:package').but_not('foo:test')
806
+ end
807
+ end
808
+
809
+
810
+ describe 'integration rule' do
811
+ it 'should execute integration tests on local project' do
812
+ define 'foo' do
813
+ test.using :junit, :integration
814
+ define 'bar'
815
+ end
816
+ lambda { task('integration:something').invoke }.should run_task('foo:test')
817
+ end
818
+
819
+ it 'should reset tasks to specific pattern' do
820
+ define 'foo' do
821
+ test.using :junit, :integration
822
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
823
+ define 'bar' do
824
+ test.using :junit, :integration
825
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
826
+ end
827
+ end
828
+ task('integration:something').invoke
829
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
830
+ project.test.tests.should include('something')
831
+ project.test.tests.should_not include('nothing')
832
+ end
833
+ end
834
+
835
+ it 'should apply *name* pattern' do
836
+ define 'foo' do
837
+ test.using :junit, :integration
838
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
839
+ end
840
+ task('integration:something').invoke
841
+ project('foo').test.tests.should include('prefix-something-suffix')
842
+ end
843
+
844
+ it 'should not apply *name* pattern if asterisks used' do
845
+ define 'foo' do
846
+ test.using :junit, :integration
847
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
848
+ end
849
+ task('integration:*something').invoke
850
+ project('foo').test.tests.should include('prefix-something')
851
+ project('foo').test.tests.should_not include('prefix-something-suffix')
852
+ end
853
+
854
+ it 'should accept multiple tasks separated by commas' do
855
+ define 'foo' do
856
+ test.using :junit, :integration
857
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
858
+ end
859
+ task('integration:foo,bar').invoke
860
+ project('foo').test.tests.should include('foo')
861
+ project('foo').test.tests.should include('bar')
862
+ project('foo').test.tests.should_not include('baz')
863
+ end
864
+
865
+ it 'should execute only the named tasts' do
866
+ write 'src/test/java/TestSomething.java',
867
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
868
+ write 'src/test/java/TestFails.java', 'class TestFails {}'
869
+ task('integration:Something').invoke
870
+ end
871
+ end