mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,93 @@
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
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
+
18
+ describe Project, :run do
19
+
20
+ it 'should return the project\'s run task' do
21
+ define('foo')
22
+ project('foo').run.name.should eql('foo:run')
23
+ end
24
+
25
+ it 'should return a RunTask' do
26
+ define('foo')
27
+ project('foo').run.should be_kind_of(Run::RunTask)
28
+ end
29
+
30
+ it 'should include compile and test.compile dependencies' do
31
+ define('foo') do
32
+ compile.using(:javac).with 'group:compile:jar:1.0'
33
+ test.compile.using(:javac).with 'group:test:jar:1.0'
34
+ end
35
+ project('foo').run.classpath.should include(artifact('group:compile:jar:1.0'))
36
+ project('foo').run.classpath.should include(artifact('group:test:jar:1.0'))
37
+ end
38
+
39
+ it 'should respond to using() and return self' do
40
+ define 'foo' do
41
+ run.using(:foo=>'Fooing').should be(run)
42
+ end
43
+ end
44
+
45
+ it 'should respond to using() and accept options' do
46
+ define 'foo' do
47
+ run.using :foo=>'Fooing'
48
+ end
49
+ project('foo').run.options[:foo].should eql('Fooing')
50
+ end
51
+
52
+ it 'should select runner using run.using' do
53
+ define 'foo' do
54
+ run.using :java
55
+ end
56
+ project('foo').run.runner.should be_a(Run::JavaRunner)
57
+ end
58
+
59
+ it 'should select runner based on compile language' do
60
+ write 'src/main/java/Test.java', 'class Test {}'
61
+ define 'foo' do
62
+ # compile language detected as :java
63
+ end
64
+ project('foo').run.runner.should be_a(Run::JavaRunner)
65
+ end
66
+
67
+ it 'should depend on project''s compile and test.compile task' do
68
+ define 'foo'
69
+ project('foo').run.prerequisites.should include(project('foo').compile)
70
+ project('foo').run.prerequisites.should include(project('foo').test)
71
+ end
72
+
73
+ it 'should be local task' do
74
+ define 'foo' do
75
+ define('bar')
76
+ end
77
+ project('foo:bar').run.should_receive(:invoke_prerequisites)
78
+ project('foo:bar').run.should_receive(:run)
79
+ in_original_dir(project('foo:bar').base_dir) { task('run').invoke }
80
+ end
81
+
82
+ it 'should not recurse' do
83
+ define 'foo' do
84
+ define('bar') { run.using :java, :main => 'foo' }
85
+ end
86
+ project('foo:bar').run.should_not_receive(:invoke_prerequisites)
87
+ project('foo:bar').run.should_not_receive(:run)
88
+ project('foo').run.should_receive(:run)
89
+ project('foo').run.invoke
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,146 @@
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
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
+
18
+ describe Project, '.shell' do
19
+
20
+ it 'should return the project\'s shell task' do
21
+ define('foo')
22
+ project('foo').shell.name.should eql('foo:shell')
23
+ end
24
+
25
+ it 'should return a ShellTask' do
26
+ define('foo')
27
+ project('foo').shell.should be_kind_of(Shell::ShellTask)
28
+ end
29
+
30
+ it 'should include compile and test.compile dependencies' do
31
+ define('foo') do
32
+ compile.using(:javac).with 'group:compile:jar:1.0'
33
+ test.compile.using(:javac).with 'group:test:jar:1.0'
34
+ end
35
+ project('foo').shell.classpath.should include(artifact('group:compile:jar:1.0'))
36
+ project('foo').shell.classpath.should include(artifact('group:test:jar:1.0'))
37
+ end
38
+
39
+ it 'should respond to using() and return self' do
40
+ define 'foo' do
41
+ shell.using(:foo=>'Fooing').should be(shell)
42
+ end
43
+ end
44
+
45
+ it 'should respond to using() and accept options' do
46
+ define 'foo' do
47
+ shell.using :foo=>'Fooing'
48
+ end
49
+ project('foo').shell.options[:foo].should eql('Fooing')
50
+ end
51
+
52
+ it 'should select provider using shell.using' do
53
+ define 'foo' do
54
+ shell.using :bsh
55
+ end
56
+ project('foo').shell.provider.should be_a(Shell::BeanShell)
57
+ end
58
+
59
+ it 'should select runner based on compile language' do
60
+ write 'src/main/java/Test.java', 'class Test {}'
61
+ define 'foo' do
62
+ # compile language detected as :java
63
+ end
64
+ project('foo').shell.provider.should be_a(Shell::BeanShell)
65
+ end
66
+
67
+ it 'should depend on project''s compile task' do
68
+ define 'foo'
69
+ project('foo').shell.prerequisites.should include(project('foo').compile)
70
+ end
71
+
72
+ it 'should be local task' do
73
+ define 'foo' do
74
+ define('bar') do
75
+ shell.using :bsh
76
+ end
77
+ end
78
+ task = project('foo:bar').shell
79
+ task.should_receive(:invoke_prerequisites)
80
+ task.should_receive(:run)
81
+ in_original_dir(project('foo:bar').base_dir) { task('shell').invoke }
82
+ end
83
+
84
+ it 'should not recurse' do
85
+ define 'foo' do
86
+ shell.using :bsh
87
+ define('bar') { shell.using :bsh }
88
+ end
89
+ project('foo:bar').shell.should_not_receive(:invoke_prerequisites)
90
+ project('foo:bar').shell.should_not_receive(:run)
91
+ project('foo').shell.should_receive(:run)
92
+ project('foo').shell.invoke
93
+ end
94
+
95
+ it 'should call shell provider with task configuration' do
96
+ define 'foo' do
97
+ shell.using :bsh
98
+ end
99
+ shell = project('foo').shell
100
+ shell.provider.should_receive(:launch).with(shell)
101
+ project('foo').shell.invoke
102
+ end
103
+ end
104
+
105
+ shared_examples_for "shell provider" do
106
+
107
+ it 'should have launch method accepting shell task' do
108
+ @instance.method(:launch).should_not be_nil
109
+ @instance.method(:launch).arity.should === 1
110
+ end
111
+
112
+ end
113
+
114
+ Shell.providers.each do |provider|
115
+ describe provider do
116
+ before do
117
+ @provider = provider
118
+ @project = define('foo') {}
119
+ @instance = provider.new(@project)
120
+ @project.shell.using @provider.to_sym
121
+ end
122
+
123
+ it_should_behave_like "shell provider"
124
+
125
+ it 'should call Java::Commands.java with :java_args' do
126
+ @project.shell.using :java_args => ["-Xx"]
127
+ Java::Commands.should_receive(:java).with do |*args|
128
+ args.last.should be_a(Hash)
129
+ args.last.keys.should include(:java_args)
130
+ args.last[:java_args].should include('-Xx')
131
+ end
132
+ project('foo').shell.invoke
133
+ end
134
+
135
+ it 'should call Java::Commands.java with :properties' do
136
+ @project.shell.using :properties => {:foo => "bar"}
137
+ Java::Commands.should_receive(:java).with do |*args|
138
+ args.last.should be_a(Hash)
139
+ args.last.keys.should include(:properties)
140
+ args.last[:properties][:foo].should == "bar"
141
+ end
142
+ project('foo').shell.invoke
143
+ end
144
+ end
145
+ end
146
+
@@ -0,0 +1,1320 @@
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.expand_path(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 deprecated classpath' do
114
+ test_task.classpath = artifact('acme:example:jar:1.0')
115
+ test_task.classpath.should be(artifact('acme:example:jar:1.0'))
116
+ end
117
+
118
+ it 'should respond to dependencies' do
119
+ test_task.dependencies = artifact('acme:example:jar:1.0')
120
+ test_task.dependencies.should be(artifact('acme:example:jar:1.0'))
121
+ end
122
+
123
+ it 'should respond to :with and add artifacfs to task dependencies' do
124
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
125
+ test_task.dependencies.should include(File.expand_path('test.jar'))
126
+ test_task.dependencies.should include(artifact('acme:example:jar:1.0'))
127
+ end
128
+
129
+ it 'should response to :options and return test framework options' do
130
+ test_task.using :foo=>'bar'
131
+ test_task.options[:foo].should eql('bar')
132
+ end
133
+
134
+ it 'should respond to :using and return self' do
135
+ test_task.using.should be(test_task)
136
+ end
137
+
138
+ it 'should respond to :using and set value options' do
139
+ test_task.using('foo'=>'FOO', 'bar'=>'BAR')
140
+ test_task.options[:foo].should eql('FOO')
141
+ test_task.options[:bar].should eql('BAR')
142
+ end
143
+
144
+ 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
145
+ Buildr::VERSION.should < '1.5'
146
+ test_task.using('foo', 'bar')
147
+ test_task.options[:foo].should eql(true)
148
+ test_task.options[:bar].should eql(true)
149
+ end
150
+
151
+ it 'should start without pre-selected test framework' do
152
+ test_task.framework.should be_nil
153
+ end
154
+
155
+ it 'should respond to :using and select test framework' do
156
+ test_task.using(:testng)
157
+ test_task.framework.should eql(:testng)
158
+ end
159
+
160
+ it 'should infer test framework from compiled language' do
161
+ lambda { test_task.compile.using(:javac) }.should change { test_task.framework }.to(:junit)
162
+ end
163
+
164
+ it 'should respond to :include and return self' do
165
+ test_task.include.should be(test_task)
166
+ end
167
+
168
+ it 'should respond to :include and add inclusion patterns' do
169
+ test_task.include 'Foo', 'Bar'
170
+ test_task.send(:include?, 'Foo').should be_true
171
+ test_task.send(:include?, 'Bar').should be_true
172
+ end
173
+
174
+ it 'should respond to :exclude and return self' do
175
+ test_task.exclude.should be(test_task)
176
+ end
177
+
178
+ it 'should respond to :exclude and add exclusion patterns' do
179
+ test_task.exclude 'FooTest', 'BarTest'
180
+ test_task.send(:include?, 'FooTest').should be_false
181
+ test_task.send(:include?, 'BarTest').should be_false
182
+ test_task.send(:include?, 'BazTest').should be_true
183
+ end
184
+
185
+ it 'should execute setup task before running tests' do
186
+ mock = mock('actions')
187
+ test_task.setup { mock.setup }
188
+ test_task.enhance { mock.tests }
189
+ mock.should_receive(:setup).ordered
190
+ mock.should_receive(:tests).ordered
191
+ test_task.invoke
192
+ end
193
+
194
+ it 'should execute teardown task after running tests' do
195
+ mock = mock('actions')
196
+ test_task.teardown { mock.teardown }
197
+ test_task.enhance { mock.tests }
198
+ mock.should_receive(:tests).ordered
199
+ mock.should_receive(:teardown).ordered
200
+ test_task.invoke
201
+ end
202
+
203
+ it 'should not execute teardown if setup failed' do
204
+ test_task.setup { fail }
205
+ lambda { test_task.invoke rescue nil }.should_not run_task(test_task.teardown)
206
+ end
207
+
208
+ it 'should use the main compile dependencies' do
209
+ define('foo') { compile.using(:javac).with 'group:id:jar:1.0' }
210
+ project('foo').test.dependencies.should include(artifact('group:id:jar:1.0'))
211
+ end
212
+
213
+ it 'should include the main compile target in its dependencies' do
214
+ define('foo') { compile.using(:javac) }
215
+ project('foo').test.dependencies.should include(project('foo').compile.target)
216
+ end
217
+
218
+ it 'should include the main compile target in its dependencies, even when using non standard directories' do
219
+ write 'src/java/Nothing.java', 'class Nothing {}'
220
+ define('foo') { compile path_to('src/java') }
221
+ project('foo').test.dependencies.should include(project('foo').compile.target)
222
+ end
223
+
224
+ it 'should include the main resources target in its dependencies' do
225
+ write 'src/main/resources/config.xml'
226
+ define('foo').test.dependencies.should include(project('foo').resources.target)
227
+ end
228
+
229
+ it 'should use the test compile dependencies' do
230
+ define('foo') { test.compile.using(:javac).with 'group:id:jar:1.0' }
231
+ project('foo').test.dependencies.should include(artifact('group:id:jar:1.0'))
232
+ end
233
+
234
+ it 'should include the test compile target in its dependencies' do
235
+ define('foo') { test.compile.using(:javac) }
236
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
237
+ end
238
+
239
+ it 'should include the test compile target in its dependencies, even when using non standard directories' do
240
+ write 'src/test/Test.java', 'class Test {}'
241
+ define('foo') { test.compile path_to('src/test') }
242
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
243
+ end
244
+
245
+ it 'should add test compile target ahead of regular compile target' do
246
+ write 'src/main/java/Code.java'
247
+ write 'src/test/java/Test.java'
248
+ define 'foo'
249
+ depends = project('foo').test.dependencies
250
+ depends.index(project('foo').test.compile.target).should < depends.index(project('foo').compile.target)
251
+ end
252
+
253
+ it 'should include the test resources target in its dependencies' do
254
+ write 'src/test/resources/config.xml'
255
+ define('foo').test.dependencies.should include(project('foo').test.resources.target)
256
+ end
257
+
258
+ it 'should add test resource target ahead of regular resource target' do
259
+ write 'src/main/resources/config.xml'
260
+ write 'src/test/resources/config.xml'
261
+ define 'foo'
262
+ depends = project('foo').test.dependencies
263
+ depends.index(project('foo').test.resources.target).should < depends.index(project('foo').resources.target)
264
+ end
265
+
266
+ it 'should not have a last successful run timestamp before the tests are run' do
267
+ test_task.timestamp.should == Rake::EARLY
268
+ end
269
+
270
+ it 'should clean after itself (test files)' do
271
+ define('foo') { test.compile.using(:javac) }
272
+ mkpath project('foo').test.compile.target.to_s
273
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.compile.target.to_s) }.to(false)
274
+ end
275
+
276
+ it 'should clean after itself (reports)' do
277
+ define 'foo'
278
+ mkpath project('foo').test.report_to.to_s
279
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.report_to.to_s) }.to(false)
280
+ end
281
+
282
+ it 'should only run tests explicitly specified if options.test is :only' do
283
+ Buildr.options.test = :only
284
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
285
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
286
+ define('foo') { compile.with project('bar') }
287
+ lambda { task('foo:test').invoke rescue nil }.should_not run_tasks('bar:test')
288
+ end
289
+ end
290
+
291
+
292
+ describe Buildr::TestTask, 'with no tests' do
293
+ it 'should pass' do
294
+ lambda { define('foo').test.invoke }.should_not raise_error
295
+ end
296
+
297
+ it 'should report no failed tests' do
298
+ lambda { verbose(true) { define('foo').test.invoke } }.should_not show_error(/fail/i)
299
+ end
300
+
301
+ it 'should return no failed tests' do
302
+ define('foo') { test.using(:junit) }
303
+ project('foo').test.invoke
304
+ project('foo').test.failed_tests.should be_empty
305
+ end
306
+
307
+ it 'should return no passing tests' do
308
+ define('foo') { test.using(:junit) }
309
+ project('foo').test.invoke
310
+ project('foo').test.passed_tests.should be_empty
311
+ end
312
+
313
+ it 'should execute teardown task' do
314
+ lambda { define('foo').test.invoke }.should run_task('foo:test:teardown')
315
+ end
316
+ end
317
+
318
+
319
+ describe Buildr::TestTask, 'with passing tests' do
320
+ def test_task
321
+ @test_task ||= begin
322
+ define 'foo' do
323
+ test.using(:junit)
324
+ test.instance_eval do
325
+ @framework.stub!(:tests).and_return(['PassingTest1', 'PassingTest2'])
326
+ @framework.stub!(:run).and_return(['PassingTest1', 'PassingTest2'])
327
+ end
328
+ end
329
+ project('foo').test
330
+ end
331
+ end
332
+
333
+ it 'should pass' do
334
+ lambda { test_task.invoke }.should_not raise_error
335
+ end
336
+
337
+ it 'should report no failed tests' do
338
+ lambda { verbose(true) { test_task.invoke } }.should_not show_error(/fail/i)
339
+ end
340
+
341
+ it 'should return passed tests' do
342
+ test_task.invoke
343
+ test_task.passed_tests.should == ['PassingTest1', 'PassingTest2']
344
+ end
345
+
346
+ it 'should return no failed tests' do
347
+ test_task.invoke
348
+ test_task.failed_tests.should be_empty
349
+ end
350
+
351
+ it 'should execute teardown task' do
352
+ lambda { test_task.invoke }.should run_task('foo:test:teardown')
353
+ end
354
+
355
+ it 'should update the last successful run timestamp' do
356
+ before = Time.now ; test_task.invoke ; after = Time.now
357
+ (before-1..after+1).should cover(test_task.timestamp)
358
+ end
359
+ end
360
+
361
+
362
+ describe Buildr::TestTask, 'with failed test' do
363
+ include TestHelper
364
+
365
+ def test_task
366
+ @test_task ||= begin
367
+ define 'foo' do
368
+ test.using(:junit)
369
+ test.instance_eval do
370
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
371
+ @framework.stub!(:run).and_return(['PassingTest'])
372
+ end
373
+ end
374
+ project('foo').test
375
+ end
376
+ end
377
+
378
+ it 'should fail' do
379
+ lambda { test_task.invoke }.should raise_error(RuntimeError, /Tests failed/)
380
+ end
381
+
382
+ it 'should report failed tests' do
383
+ lambda { verbose(true) { test_task.invoke rescue nil } }.should show_error(/FailingTest/)
384
+ end
385
+
386
+ it 'should record failed tests' do
387
+ test_task.invoke rescue nil
388
+ File.read(project('foo').path_to('target', "#{test_task.framework}-failed")).should == 'FailingTest'
389
+ end
390
+
391
+ it 'should return failed tests' do
392
+ test_task.invoke rescue nil
393
+ test_task.failed_tests.should == ['FailingTest']
394
+ end
395
+
396
+ it 'should return passing tests as well' do
397
+ test_task.invoke rescue nil
398
+ test_task.passed_tests.should == ['PassingTest']
399
+ end
400
+
401
+ it 'should know what tests failed last time' do
402
+ test_task.invoke rescue nil
403
+ project('foo').test.last_failures.should == ['FailingTest']
404
+ end
405
+
406
+ it 'should not fail if fail_on_failure is false' do
407
+ test_task.using(:fail_on_failure=>false).invoke
408
+ lambda { test_task.invoke }.should_not raise_error
409
+ end
410
+
411
+ it 'should report failed tests even if fail_on_failure is false' do
412
+ test_task.using(:fail_on_failure=>false)
413
+ lambda { verbose(true) { test_task.invoke } }.should show_error(/FailingTest/)
414
+ end
415
+
416
+ it 'should return failed tests even if fail_on_failure is false' do
417
+ test_task.using(:fail_on_failure=>false).invoke
418
+ test_task.failed_tests.should == ['FailingTest']
419
+ end
420
+
421
+ it 'should execute teardown task' do
422
+ lambda { test_task.invoke rescue nil }.should run_task('foo:test:teardown')
423
+ end
424
+
425
+ it 'should not update the last successful run timestamp' do
426
+ a_second_ago = Time.now - 1
427
+ touch_last_successful_test_run test_task, a_second_ago
428
+ test_task.invoke rescue nil
429
+ test_task.timestamp.should <= a_second_ago
430
+ end
431
+ end
432
+
433
+
434
+ describe Buildr::Project, '#test' do
435
+ it 'should return the project\'s test task' do
436
+ define('foo') { test.should be(task('test')) }
437
+ end
438
+
439
+ it 'should accept prerequisites for task' do
440
+ define('foo') { test 'prereq' }
441
+ project('foo').test.prerequisites.should include('prereq')
442
+ end
443
+
444
+ it 'should accept actions for task' do
445
+ task 'action'
446
+ define('foo') { test { task('action').invoke } }
447
+ lambda { project('foo').test.invoke }.should run_tasks('action')
448
+ end
449
+
450
+ it 'should set fail_on_failure true by default' do
451
+ define('foo').test.options[:fail_on_failure].should be_true
452
+ end
453
+
454
+ it 'should set fork mode by default' do
455
+ define('foo').test.options[:fork].should == :once
456
+ end
457
+
458
+ it 'should set properties to empty hash by default' do
459
+ define('foo').test.options[:properties].should == {}
460
+ end
461
+
462
+ it 'should set environment variables to empty hash by default' do
463
+ define('foo').test.options[:environment].should == {}
464
+ end
465
+
466
+ it 'should inherit options from parent project' do
467
+ define 'foo' do
468
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
469
+ define 'bar' do
470
+ test.using :junit
471
+ test.options[:fail_on_failure].should be_false
472
+ test.options[:fork].should == :each
473
+ test.options[:properties][:foo].should == 'bar'
474
+ test.options[:environment]['config'].should == 'config.yaml'
475
+ end
476
+ end
477
+ end
478
+
479
+ it 'should clone options from parent project when using #using' do
480
+ define 'foo' do
481
+ define 'bar' do
482
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
483
+ test.using :junit
484
+ end.invoke
485
+ test.options[:fail_on_failure].should be_true
486
+ test.options[:fork].should == :once
487
+ test.options[:properties].should == {}
488
+ test.options[:environment].should == {}
489
+ end
490
+ end
491
+
492
+ it 'should clone options from parent project when using #options' do
493
+ define 'foo' do
494
+ define 'bar' do
495
+ test.options[:fail_on_failure] = false
496
+ test.options[:fork] = :each
497
+ test.options[:properties][:foo] = 'bar'
498
+ test.options[:environment]['config'] = 'config.yaml'
499
+ test.using :junit
500
+ end.invoke
501
+ test.options[:fail_on_failure].should be_true
502
+ test.options[:fork].should == :once
503
+ test.options[:properties].should == {}
504
+ test.options[:environment].should == {}
505
+ end
506
+ end
507
+
508
+ it 'should accept to set a test property in the top project' do
509
+ define 'foo' do
510
+ test.options[:properties][:foo] = 'bar'
511
+ end
512
+ project('foo').test.options[:properties][:foo].should == 'bar'
513
+ end
514
+
515
+ it 'should accept to set a test property in a subproject' do
516
+ define 'foo' do
517
+ define 'bar' do
518
+ test.options[:properties][:bar] = 'baz'
519
+ end
520
+ end
521
+ project('foo:bar').test.options[:properties][:bar].should == 'baz'
522
+ end
523
+
524
+ it 'should not change options of unrelated projects when using #options' do
525
+ define 'foo' do
526
+ test.options[:properties][:foo] = 'bar'
527
+ end
528
+ define 'bar' do
529
+ test.options[:properties].should == {}
530
+ end
531
+ end
532
+
533
+ it "should run from project's build task" do
534
+ write 'src/main/java/Foo.java'
535
+ write 'src/test/java/FooTest.java'
536
+ define('foo')
537
+ lambda { task('foo:build').invoke }.should run_task('foo:test')
538
+ end
539
+ end
540
+
541
+
542
+ describe Buildr::Project, '#test.compile' do
543
+ it 'should identify compiler from project' do
544
+ write 'src/test/java/com/example/Test.java'
545
+ define('foo') do
546
+ test.compile.compiler.should eql(:javac)
547
+ end
548
+ end
549
+
550
+ it 'should include identified sources' do
551
+ write 'src/test/java/Test.java'
552
+ define('foo') do
553
+ test.compile.sources.should include(_('src/test/java'))
554
+ end
555
+ end
556
+
557
+ it 'should compile to target/test/<code>' do
558
+ define 'foo', :target=>'targeted' do
559
+ test.compile.using(:javac)
560
+ test.compile.target.should eql(file('targeted/test/classes'))
561
+ end
562
+ end
563
+
564
+ it 'should use main compile dependencies' do
565
+ define 'foo' do
566
+ compile.using(:javac).with 'group:id:jar:1.0'
567
+ test.compile.using(:javac)
568
+ end
569
+ project('foo').test.compile.dependencies.should include(artifact('group:id:jar:1.0'))
570
+ end
571
+
572
+ it 'should include the main compiled target in its dependencies' do
573
+ define 'foo' do
574
+ compile.using(:javac).into 'bytecode'
575
+ test.compile.using(:javac)
576
+ end
577
+ project('foo').test.compile.dependencies.should include(file('bytecode'))
578
+ end
579
+
580
+ it 'should include the test framework dependencies' do
581
+ define 'foo' do
582
+ test.compile.using(:javac)
583
+ test.using(:junit)
584
+ end
585
+ project('foo').test.compile.dependencies.should include(*artifacts(JUnit.dependencies))
586
+ end
587
+
588
+ it 'should clean after itself' do
589
+ write 'src/test/java/Nothing.java', 'class Nothing {}'
590
+ define('foo') { test.compile.into 'bytecode' }
591
+ project('foo').test.compile.invoke
592
+ lambda { project('foo').clean.invoke }.should change { File.exist?('bytecode') }.to(false)
593
+ end
594
+ end
595
+
596
+
597
+ describe Buildr::Project, '#test.resources' do
598
+ it 'should ignore resources unless they exist' do
599
+ define('foo').test.resources.sources.should be_empty
600
+ project('foo').test.resources.target.should be_nil
601
+ end
602
+
603
+ it 'should pick resources from src/test/resources if found' do
604
+ mkpath 'src/test/resources'
605
+ define('foo') { test.resources.sources.should include(file('src/test/resources')) }
606
+ end
607
+
608
+ it 'should copy to the resources target directory' do
609
+ write 'src/test/resources/config.xml', '</xml>'
610
+ define('foo', :target=>'targeted').test.invoke
611
+ file('targeted/test/resources/config.xml').should contain('</xml>')
612
+ end
613
+
614
+ it 'should create target directory even if no files to copy' do
615
+ define('foo') do
616
+ test.resources.filter.into('resources')
617
+ end
618
+ lambda { file(File.expand_path('resources')).invoke }.should change { File.exist?('resources') }.to(true)
619
+ end
620
+
621
+ it 'should execute alongside compile task' do
622
+ task 'action'
623
+ define('foo') { test.resources { task('action').invoke } }
624
+ lambda { project('foo').test.compile.invoke }.should run_tasks('action')
625
+ end
626
+ end
627
+
628
+
629
+ describe Buildr::TestTask, '#invoke' do
630
+ include TestHelper
631
+
632
+ def test_task
633
+ @test_task ||= define('foo') {
634
+ test.using(:junit)
635
+ test.instance_eval do
636
+ @framework.stub!(:tests).and_return(['PassingTest'])
637
+ @framework.stub!(:run).and_return(['PassingTest'])
638
+ end
639
+ }.test
640
+ end
641
+
642
+ it 'should require dependencies to exist' do
643
+ lambda { test_task.with('no-such.jar').invoke }.should \
644
+ raise_error(RuntimeError, /Don't know how to build/)
645
+ end
646
+
647
+ it 'should run all dependencies as prerequisites' do
648
+ file(File.expand_path('no-such.jar')) { task('prereq').invoke }
649
+ lambda { test_task.with('no-such.jar').invoke }.should run_tasks(['prereq', 'foo:test'])
650
+ end
651
+
652
+ it 'should run tests if they have never run' do
653
+ lambda { test_task.invoke }.should run_task('foo:test')
654
+ end
655
+
656
+ it 'should not run tests if test option is off' do
657
+ Buildr.options.test = false
658
+ lambda { test_task.invoke }.should_not run_task('foo:test')
659
+ end
660
+
661
+ describe 'when there was a successful test run already' do
662
+ before do
663
+ @a_second_ago = Time.now - 1
664
+ src = ['main/java/Foo.java', 'main/resources/config.xml', 'test/java/FooTest.java', 'test/resources/config-test.xml'].map { |f| File.join('src', f) }
665
+ target = ['classes/Foo.class', 'resources/config.xml', 'test/classes/FooTest.class', 'test/resources/config-test.xml'].map { |f| File.join('target', f) }
666
+ files = ['buildfile'] + src + target
667
+ files.each { |file| write file }
668
+ dirs = (src + target).map { |file| file.pathmap('%d') }
669
+ (files + dirs ).each { |path| File.utime(@a_second_ago, @a_second_ago, path) }
670
+ touch_last_successful_test_run test_task, @a_second_ago
671
+ end
672
+
673
+ it 'should not run tests if nothing changed' do
674
+ lambda { test_task.invoke }.should_not run_task('foo:test')
675
+ end
676
+
677
+ it 'should run tests if options.test is :all' do
678
+ Buildr.options.test = :all
679
+ lambda { test_task.invoke }.should run_task('foo:test')
680
+ end
681
+
682
+ it 'should run tests if main compile target changed' do
683
+ touch project('foo').compile.target.to_s
684
+ lambda { test_task.invoke }.should run_task('foo:test')
685
+ end
686
+
687
+ it 'should run tests if test compile target changed' do
688
+ touch test_task.compile.target.to_s
689
+ lambda { test_task.invoke }.should run_task('foo:test')
690
+ end
691
+
692
+ it 'should run tests if main resources changed' do
693
+ touch project('foo').resources.target.to_s
694
+ lambda { test_task.invoke }.should run_task('foo:test')
695
+ end
696
+
697
+ it 'should run tests if test resources changed' do
698
+ touch test_task.resources.target.to_s
699
+ lambda { test_task.invoke }.should run_task('foo:test')
700
+ end
701
+
702
+ it 'should run tests if compile-dependent project changed' do
703
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
704
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
705
+ project('foo').compile.with project('bar')
706
+ lambda { test_task.invoke }.should run_task('foo:test')
707
+ end
708
+
709
+ it 'should run tests if test-dependent project changed' do
710
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
711
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
712
+ test_task.with project('bar')
713
+ lambda { test_task.invoke }.should run_task('foo:test')
714
+ end
715
+
716
+ it 'should run tests if buildfile changed' do
717
+ touch 'buildfile'
718
+ test_task.should_receive(:run_tests)
719
+ lambda { test_task.invoke }.should run_task('foo:test')
720
+ end
721
+
722
+ it 'should not run tests if buildfile changed but IGNORE_BUILDFILE is true' do
723
+ begin
724
+ ENV["IGNORE_BUILDFILE"] = "true"
725
+ test_task.should_not_receive(:run_tests)
726
+ test_task.invoke
727
+ ensure
728
+ ENV["IGNORE_BUILDFILE"] = nil
729
+ end
730
+ end
731
+ end
732
+ end
733
+
734
+ describe Rake::Task, 'test' do
735
+ it 'should be recursive' do
736
+ define('foo') { define 'bar' }
737
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:test')
738
+ end
739
+
740
+ it 'should be local task' do
741
+ define('foo') { define 'bar' }
742
+ lambda do
743
+ in_original_dir project('foo:bar').base_dir do
744
+ task('test').invoke
745
+ end
746
+ end.should run_task('foo:bar:test').but_not('foo:test')
747
+ end
748
+
749
+ it 'should stop at first failure' do
750
+ define('foo') { test { fail } }
751
+ define('bar') { test { fail } }
752
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test').but_not('bar:test')
753
+ end
754
+
755
+ it 'should ignore failure if options.test is :all' do
756
+ define('foo') { test { fail } }
757
+ define('bar') { test { fail } }
758
+ options.test = :all
759
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
760
+ end
761
+
762
+ it 'should ignore failure in subprojects if options.test is :all' do
763
+ define('foo') {
764
+ define('p1') { test { fail } }
765
+ define('p2') { test { } }
766
+ define('p3') { test { fail } }
767
+ }
768
+ define('bar') { test { fail } }
769
+ options.test = :all
770
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:p1:test', 'foo:p2:test', 'foo:p3:test', 'bar:test')
771
+ end
772
+
773
+ it 'should ignore failure in subprojects if environment variable test is \'all\'' do
774
+ define('foo') {
775
+ define('p1') { test { fail } }
776
+ define('p2') { test { } }
777
+ define('p3') { test { fail } }
778
+ }
779
+ define('bar') { test { fail } }
780
+ ENV['test'] = 'all'
781
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:p1:test', 'foo:p2:test', 'foo:p3:test', 'bar:test')
782
+ end
783
+
784
+ it 'should ignore failure if options.test is :all and target is build task ' do
785
+ define('foo') { test { fail } }
786
+ define('bar') { test { fail } }
787
+ options.test = :all
788
+ lambda { task('build').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
789
+ end
790
+
791
+ it 'should ignore failure if environment variable test is \'all\'' do
792
+ define('foo') { test { fail } }
793
+ define('bar') { test { fail } }
794
+ ENV['test'] = 'all'
795
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
796
+ end
797
+
798
+ it 'should ignore failure if environment variable TEST is \'all\'' do
799
+ define('foo') { test { fail } }
800
+ define('bar') { test { fail } }
801
+ ENV['TEST'] = 'all'
802
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
803
+ end
804
+
805
+ it 'should execute no tests if options.test is false' do
806
+ define('foo') { test { fail } }
807
+ define('bar') { test { fail } }
808
+ options.test = false
809
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
810
+ end
811
+
812
+ it 'should execute no tests if environment variable test is \'no\'' do
813
+ define('foo') { test { fail } }
814
+ define('bar') { test { fail } }
815
+ ENV['test'] = 'no'
816
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
817
+ end
818
+
819
+ it 'should execute no tests if environment variable TEST is \'no\'' do
820
+ define('foo') { test { fail } }
821
+ define('bar') { test { fail } }
822
+ ENV['TEST'] = 'no'
823
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
824
+ end
825
+
826
+ it "should not compile tests if environment variable test is 'no'" do
827
+ write "src/test/java/HelloTest.java", "public class HelloTest { public void testTest() {}}"
828
+ define('foo') { test { fail } }
829
+ ENV['test'] = 'no'
830
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test:compile')
831
+ end
832
+ end
833
+
834
+ describe 'test rule' do
835
+ include TestHelper
836
+
837
+ it 'should execute test task on local project' do
838
+ define('foo') { define 'bar' }
839
+ lambda { task('test:something').invoke }.should run_task('foo:test')
840
+ end
841
+
842
+ it 'should reset tasks to specific pattern' do
843
+ define 'foo' do
844
+ test.using(:junit)
845
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
846
+ define 'bar' do
847
+ test.using(:junit)
848
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
849
+ end
850
+ end
851
+ task('test:something').invoke
852
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
853
+ project.test.tests.should include('something')
854
+ project.test.tests.should_not include('nothing')
855
+ end
856
+ end
857
+
858
+ it 'should apply *name* pattern' do
859
+ define 'foo' do
860
+ test.using(:junit)
861
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
862
+ end
863
+ task('test:something').invoke
864
+ project('foo').test.tests.should include('prefix-something-suffix')
865
+ end
866
+
867
+ it 'should not apply *name* pattern if asterisks used' do
868
+ define 'foo' do
869
+ test.using(:junit)
870
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
871
+ end
872
+ task('test:*something').invoke
873
+ project('foo').test.tests.should include('prefix-something')
874
+ project('foo').test.tests.should_not include('prefix-something-suffix')
875
+ end
876
+
877
+ it 'should accept multiple tasks separated by commas' do
878
+ define 'foo' do
879
+ test.using(:junit)
880
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
881
+ end
882
+ task('test:foo,bar').invoke
883
+ project('foo').test.tests.should include('foo')
884
+ project('foo').test.tests.should include('bar')
885
+ project('foo').test.tests.should_not include('baz')
886
+ end
887
+
888
+ it 'should execute only the named tests' do
889
+ write 'src/test/java/TestSomething.java',
890
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
891
+ write 'src/test/java/TestFails.java',
892
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
893
+ define 'foo'
894
+ task('test:Something').invoke
895
+ end
896
+
897
+ it 'should execute the named tests even if the test task is not needed' do
898
+ define 'foo' do
899
+ test.using(:junit)
900
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
901
+ end
902
+ touch_last_successful_test_run project('foo').test
903
+ task('test:something').invoke
904
+ project('foo').test.tests.should include('something')
905
+ end
906
+
907
+ it 'should not execute excluded tests' do
908
+ define 'foo' do
909
+ test.using(:junit)
910
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
911
+ end
912
+ task('test:*,-nothing').invoke
913
+ project('foo').test.tests.should include('something')
914
+ project('foo').test.tests.should_not include('nothing')
915
+ end
916
+
917
+ it 'should not execute tests in excluded package' do
918
+ write 'src/test/java/com/example/foo/TestSomething.java',
919
+ 'package com.example.foo; public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
920
+ write 'src/test/java/com/example/bar/TestFails.java',
921
+ 'package com.example.bar; public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
922
+ define 'foo' do
923
+ test.using(:junit)
924
+ end
925
+ task('test:-com.example.bar').invoke
926
+ project('foo').test.tests.should include('com.example.foo.TestSomething')
927
+ project('foo').test.tests.should_not include('com.example.bar.TestFails')
928
+ end
929
+
930
+ it 'should not execute excluded tests with wildcards' do
931
+ define 'foo' do
932
+ test.using(:junit)
933
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
934
+ end
935
+ task('test:something,-s*,-n*').invoke
936
+ project('foo').test.tests.should_not include('something')
937
+ project('foo').test.tests.should_not include('nothing')
938
+ end
939
+
940
+ it 'should execute all tests except excluded tests' do
941
+ define 'foo' do
942
+ test.using(:junit)
943
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'anything', 'nothing']) }
944
+ end
945
+ task('test:-nothing').invoke
946
+ project('foo').test.tests.should include('something', 'anything')
947
+ project('foo').test.tests.should_not include('nothing')
948
+ end
949
+
950
+ it 'should ignore exclusions in buildfile' do
951
+ define 'foo' do
952
+ test.using(:junit)
953
+ test.exclude 'something'
954
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'anything', 'nothing']) }
955
+ end
956
+ task('test:-nothing').invoke
957
+ project('foo').test.tests.should include('something', 'anything')
958
+ project('foo').test.tests.should_not include('nothing')
959
+ end
960
+
961
+ it 'should ignore inclusions in buildfile' do
962
+ define 'foo' do
963
+ test.using(:junit)
964
+ test.include 'something'
965
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
966
+ end
967
+ task('test:nothing').invoke
968
+ project('foo').test.tests.should include('nothing')
969
+ project('foo').test.tests.should_not include('something')
970
+ end
971
+
972
+ it 'should not execute a test if it''s both included and excluded' do
973
+ define 'foo' do
974
+ test.using(:junit)
975
+ test.instance_eval { @framework.stub!(:tests).and_return(['nothing']) }
976
+ end
977
+ task('test:nothing,-nothing').invoke
978
+ project('foo').test.tests.should_not include('nothing')
979
+ end
980
+
981
+ it 'should not update the last successful test run timestamp' do
982
+ define 'foo' do
983
+ test.using(:junit)
984
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
985
+ end
986
+ a_second_ago = Time.now - 1
987
+ touch_last_successful_test_run project('foo').test, a_second_ago
988
+ task('test:something').invoke
989
+ project('foo').test.timestamp.should <= a_second_ago
990
+ end
991
+ end
992
+
993
+ describe 'test failed' do
994
+ include TestHelper
995
+
996
+ def test_task
997
+ @test_task ||= begin
998
+ define 'foo' do
999
+ test.using(:junit)
1000
+ test.instance_eval do
1001
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
1002
+ @framework.stub!(:run).and_return(['PassingTest'])
1003
+ end
1004
+ end
1005
+ project('foo').test
1006
+ end
1007
+ end
1008
+
1009
+ it 'should run the tests that failed the last time' do
1010
+ define 'foo' do
1011
+ test.using(:junit)
1012
+ test.instance_eval do
1013
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
1014
+ @framework.stub!(:run).and_return(['PassingTest'])
1015
+ end
1016
+ end
1017
+ write project('foo').path_to(:target, "junit-failed"), "FailingTest"
1018
+ task('test:failed').invoke rescue nil
1019
+ project('foo').test.tests.should include('FailingTest')
1020
+ project('foo').test.tests.should_not include('PassingTest')
1021
+ end
1022
+
1023
+ it 'should run failed tests, respecting excluded tests' do
1024
+ define 'foo' do
1025
+ test.using(:junit).exclude('ExcludedTest')
1026
+ test.instance_eval do
1027
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest', 'ExcludedTest'])
1028
+ @framework.stub!(:run).and_return(['PassingTest'])
1029
+ end
1030
+ end
1031
+ write project('foo').path_to(:target, "junit-failed"), "FailingTest\nExcludedTest"
1032
+ task('test:failed').invoke rescue nil
1033
+ project('foo').test.tests.should include('FailingTest')
1034
+ project('foo').test.tests.should_not include('ExcludedTest')
1035
+ end
1036
+
1037
+ it 'should run only the tests that failed the last time, even when failed tests have dependencies' do
1038
+ define 'parent' do
1039
+ define 'foo' do
1040
+ test.using(:junit)
1041
+ test.instance_eval do
1042
+ @framework.stub!(:tests).and_return(['PassingTest'])
1043
+ @framework.stub!(:run).and_return(['PassingTest'])
1044
+ end
1045
+ end
1046
+ define 'bar' do
1047
+ test.using(:junit)
1048
+ test.enhance ["parent:foo:test"]
1049
+ test.instance_eval do
1050
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
1051
+ @framework.stub!(:run).and_return(['PassingTest'])
1052
+ end
1053
+ end
1054
+ end
1055
+ write project('parent:bar').path_to(:target, "junit-failed"), "FailingTest"
1056
+ task('test:failed').invoke rescue nil
1057
+ project('parent:foo').test.tests.should_not include('PassingTest')
1058
+ project('parent:bar').test.tests.should include('FailingTest')
1059
+ project('parent:bar').test.tests.should_not include('PassingTest')
1060
+ end
1061
+
1062
+ end
1063
+
1064
+
1065
+ describe Buildr::Options, 'test' do
1066
+ it 'should be true by default' do
1067
+ Buildr.options.test.should be_true
1068
+ end
1069
+
1070
+ ['skip', 'no', 'off', 'false'].each do |value|
1071
+ it "should be false if test environment variable is '#{value}'" do
1072
+ lambda { ENV['test'] = value }.should change { Buildr.options.test }.to(false)
1073
+ end
1074
+ end
1075
+
1076
+ ['skip', 'no', 'off', 'false'].each do |value|
1077
+ it "should be false if TEST environment variable is '#{value}'" do
1078
+ lambda { ENV['TEST'] = value }.should change { Buildr.options.test }.to(false)
1079
+ end
1080
+ end
1081
+
1082
+ it 'should be :all if test environment variable is all' do
1083
+ lambda { ENV['test'] = 'all' }.should change { Buildr.options.test }.to(:all)
1084
+ end
1085
+
1086
+ it 'should be :all if TEST environment variable is all' do
1087
+ lambda { ENV['TEST'] = 'all' }.should change { Buildr.options.test }.to(:all)
1088
+ end
1089
+
1090
+ it 'should be true and warn for any other value' do
1091
+ ENV['TEST'] = 'funky'
1092
+ lambda { Buildr.options.test.should be(true) }.should show_warning(/expecting the environment variable/i)
1093
+ end
1094
+ end
1095
+
1096
+
1097
+ describe Buildr, 'integration' do
1098
+ it 'should return the same task from all contexts' do
1099
+ task = task('integration')
1100
+ define 'foo' do
1101
+ integration.should be(task)
1102
+ define 'bar' do
1103
+ integration.should be(task)
1104
+ end
1105
+ end
1106
+ integration.should be(task)
1107
+ end
1108
+
1109
+ it 'should respond to :setup and return setup task' do
1110
+ setup = integration.setup
1111
+ define('foo') { integration.setup.should be(setup) }
1112
+ end
1113
+
1114
+ it 'should respond to :setup and add prerequisites to integration:setup' do
1115
+ define('foo') { integration.setup 'prereq' }
1116
+ integration.setup.prerequisites.should include('prereq')
1117
+ end
1118
+
1119
+ it 'should respond to :setup and add action for integration:setup' do
1120
+ action = task('action')
1121
+ define('foo') { integration.setup { action.invoke } }
1122
+ lambda { integration.setup.invoke }.should run_tasks(action)
1123
+ end
1124
+
1125
+ it 'should respond to :teardown and return teardown task' do
1126
+ teardown = integration.teardown
1127
+ define('foo') { integration.teardown.should be(teardown) }
1128
+ end
1129
+
1130
+ it 'should respond to :teardown and add prerequisites to integration:teardown' do
1131
+ define('foo') { integration.teardown 'prereq' }
1132
+ integration.teardown.prerequisites.should include('prereq')
1133
+ end
1134
+
1135
+ it 'should respond to :teardown and add action for integration:teardown' do
1136
+ action = task('action')
1137
+ define('foo') { integration.teardown { action.invoke } }
1138
+ lambda { integration.teardown.invoke }.should run_tasks(action)
1139
+ end
1140
+ end
1141
+
1142
+
1143
+ describe Rake::Task, 'integration' do
1144
+ it 'should be a local task' do
1145
+ define('foo') { test.using :integration }
1146
+ define('bar', :base_dir=>'other') { test.using :integration }
1147
+ lambda { task('integration').invoke }.should run_task('foo:test').but_not('bar:test')
1148
+ end
1149
+
1150
+ it 'should be a recursive task' do
1151
+ define 'foo' do
1152
+ test.using :integration
1153
+ define('bar') { test.using :integration }
1154
+ end
1155
+ lambda { task('integration').invoke }.should run_tasks('foo:test', 'foo:bar:test')
1156
+ end
1157
+
1158
+ it 'should find nested integration tests' do
1159
+ define 'foo' do
1160
+ define('bar') { test.using :integration }
1161
+ end
1162
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test')
1163
+ end
1164
+
1165
+ it 'should ignore nested regular tasks' do
1166
+ define 'foo' do
1167
+ test.using :integration
1168
+ define('bar') { test.using :integration=>false }
1169
+ end
1170
+ lambda { task('integration').invoke }.should run_tasks('foo:test').but_not('foo:bar:test')
1171
+ end
1172
+
1173
+ it 'should agree not to run the same tasks as test' do
1174
+ define 'foo' do
1175
+ define 'bar' do
1176
+ test.using :integration
1177
+ define('baz') { test.using :integration=>false }
1178
+ end
1179
+ end
1180
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:baz:test').but_not('foo:bar:test')
1181
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test', 'foo:bar:baz:test')
1182
+ end
1183
+
1184
+ it 'should run setup task before any project integration tests' do
1185
+ define('foo') { test.using :integration }
1186
+ define('bar') { test.using :integration }
1187
+ lambda { task('integration').invoke }.should run_tasks([integration.setup, 'bar:test'], [integration.setup, 'foo:test'])
1188
+ end
1189
+
1190
+ it 'should run teardown task after all project integrations tests' do
1191
+ define('foo') { test.using :integration }
1192
+ define('bar') { test.using :integration }
1193
+ lambda { task('integration').invoke }.should run_tasks(['bar:test', integration.teardown], ['foo:test', integration.teardown])
1194
+ end
1195
+
1196
+ it 'should run test cases marked for integration' do
1197
+ write 'src/test/java/FailingTest.java',
1198
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
1199
+ define('foo') { test.using :integration }
1200
+ lambda { task('test').invoke }.should_not raise_error
1201
+ lambda { task('integration').invoke }.should raise_error(RuntimeError, /tests failed/i)
1202
+ end
1203
+
1204
+ it 'should run setup and teardown tasks marked for integration' do
1205
+ define('foo') { test.using :integration }
1206
+ lambda { task('test').invoke }.should run_tasks().but_not('foo:test:setup', 'foo:test:teardown')
1207
+ lambda { task('integration').invoke }.should run_tasks('foo:test:setup', 'foo:test:teardown')
1208
+ end
1209
+
1210
+ it 'should run test actions marked for integration' do
1211
+ task 'action'
1212
+ define 'foo' do
1213
+ test.using :integration, :junit
1214
+ end
1215
+ lambda { task('test').invoke }.should_not change { project('foo').test.passed_tests }
1216
+ lambda { task('integration').invoke }.should change { project('foo').test.passed_tests }
1217
+ project('foo').test.passed_tests.should be_empty
1218
+ end
1219
+
1220
+ it 'should not fail if test=all' do
1221
+ write 'src/test/java/FailingTest.java',
1222
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
1223
+ define('foo') { test.using :integration }
1224
+ options.test = :all
1225
+ lambda { task('integration').invoke }.should_not raise_error
1226
+ end
1227
+
1228
+ it 'should execute by local package task' do
1229
+ define 'foo', :version=>'1.0' do
1230
+ test.using :integration
1231
+ package :jar
1232
+ end
1233
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'])
1234
+ end
1235
+
1236
+ it 'should execute by local package task along with unit tests' do
1237
+ define 'foo', :version=>'1.0' do
1238
+ test.using :integration
1239
+ package :jar
1240
+ define('bar') { test.using :integration=>false }
1241
+ end
1242
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'],
1243
+ ['foo:bar:test', 'foo:bar:package'])
1244
+ end
1245
+
1246
+ it 'should not execute by local package task if test=no' do
1247
+ define 'foo', :version=>'1.0' do
1248
+ test.using :integration
1249
+ package :jar
1250
+ end
1251
+ options.test = false
1252
+ lambda { task('package').invoke }.should run_task('foo:package').but_not('foo:test')
1253
+ end
1254
+ end
1255
+
1256
+
1257
+ describe 'integration rule' do
1258
+ it 'should execute integration tests on local project' do
1259
+ define 'foo' do
1260
+ test.using :junit, :integration
1261
+ define 'bar'
1262
+ end
1263
+ lambda { task('integration:something').invoke }.should run_task('foo:test')
1264
+ end
1265
+
1266
+ it 'should reset tasks to specific pattern' do
1267
+ define 'foo' do
1268
+ test.using :junit, :integration
1269
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1270
+ define 'bar' do
1271
+ test.using :junit, :integration
1272
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1273
+ end
1274
+ end
1275
+ task('integration:something').invoke
1276
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
1277
+ project.test.tests.should include('something')
1278
+ project.test.tests.should_not include('nothing')
1279
+ end
1280
+ end
1281
+
1282
+ it 'should apply *name* pattern' do
1283
+ define 'foo' do
1284
+ test.using :junit, :integration
1285
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
1286
+ end
1287
+ task('integration:something').invoke
1288
+ project('foo').test.tests.should include('prefix-something-suffix')
1289
+ end
1290
+
1291
+ it 'should not apply *name* pattern if asterisks used' do
1292
+ define 'foo' do
1293
+ test.using :junit, :integration
1294
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
1295
+ end
1296
+ task('integration:*something').invoke
1297
+ project('foo').test.tests.should include('prefix-something')
1298
+ project('foo').test.tests.should_not include('prefix-something-suffix')
1299
+ end
1300
+
1301
+ it 'should accept multiple tasks separated by commas' do
1302
+ define 'foo' do
1303
+ test.using :junit, :integration
1304
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
1305
+ end
1306
+ task('integration:foo,bar').invoke
1307
+ project('foo').test.tests.should include('foo')
1308
+ project('foo').test.tests.should include('bar')
1309
+ project('foo').test.tests.should_not include('baz')
1310
+ end
1311
+
1312
+ it 'should execute only the named tests' do
1313
+ write 'src/test/java/TestSomething.java',
1314
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
1315
+ write 'src/test/java/TestFails.java',
1316
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
1317
+ define('foo') { test.using :junit, :integration }
1318
+ task('integration:Something').invoke
1319
+ end
1320
+ end