buildr 1.3.5-x86-mswin32

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 (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,257 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+
19
+
20
+ module TestCoverageHelper
21
+ def write_test options
22
+ write File.join(options[:in], "#{options[:for]}Test.java"),
23
+ "public class #{options[:for]}Test extends junit.framework.TestCase { public void test#{options[:for]}() { new #{options[:for]}(); } }"
24
+ end
25
+
26
+ # Rspec matcher using file glob patterns.
27
+ class FileNamePatternMatcher
28
+ def initialize(pattern)
29
+ @expected_pattern = pattern
30
+ @pattern_matcher = lambda { |filename| File.fnmatch? pattern, filename }
31
+ end
32
+
33
+ def matches?(directory)
34
+ @actual_filenames = Dir[File.join(directory,'*')]
35
+ @actual_filenames.any? &@pattern_matcher
36
+ end
37
+
38
+ def failure_message
39
+ "Expected to find at least one element matching '#{@expected_pattern}' among #{@actual_filenames.inspect}, but found none"
40
+ end
41
+
42
+ def negative_failure_message
43
+ "Expected to find no element matching '#{@expected_pattern}' among #{@actual_filenames.inspect}, but found matching element(s) #{@actual_filenames.select(&@pattern_matcher).inspect}"
44
+ end
45
+ end
46
+
47
+ # Test if a directory contains at least one file matching a given glob pattern.
48
+ #
49
+ # For example, to check that a directory contains at least one HTML file:
50
+ # '/path/to/some/directory'.should have_files_matching('*.html')
51
+ def have_files_matching pattern
52
+ FileNamePatternMatcher.new pattern
53
+ end
54
+ end
55
+
56
+ describe 'test coverage tool', :shared=>true do
57
+ include TestCoverageHelper
58
+
59
+ def toolname
60
+ @tool_module.name.split('::').last.downcase
61
+ end
62
+
63
+ def test_coverage_config
64
+ project('foo').send(toolname)
65
+ end
66
+
67
+ describe 'project-specific' do
68
+
69
+ before do
70
+ write 'src/main/java/Foo.java', 'public class Foo {}'
71
+ write_test :for=>'Foo', :in=>'src/test/java'
72
+ end
73
+
74
+ describe 'clean' do
75
+ before { define('foo') }
76
+
77
+ it 'should remove the instrumented directory' do
78
+ mkdir_p test_coverage_config.instrumented_dir.to_s
79
+ task('foo:clean').invoke
80
+ file(test_coverage_config.instrumented_dir).should_not exist
81
+ end
82
+
83
+ it 'should remove the reporting directory' do
84
+ mkdir_p test_coverage_config.report_dir
85
+ task('foo:clean').invoke
86
+ file(test_coverage_config.report_dir).should_not exist
87
+ end
88
+ end
89
+
90
+ describe 'instrumented directory' do
91
+ it 'should have a default value' do
92
+ define('foo')
93
+ test_coverage_config.instrumented_dir.should point_to_path('target/instrumented/classes')
94
+ end
95
+
96
+ it 'should be overridable' do
97
+ toolname = toolname()
98
+ define('foo') { send(toolname).instrumented_dir = path_to('target/coverage/classes') }
99
+ test_coverage_config.instrumented_dir.should point_to_path('target/coverage/classes')
100
+ end
101
+
102
+ it 'should be created during instrumentation' do
103
+ define('foo')
104
+ task("foo:#{toolname}:instrument").invoke
105
+ file(test_coverage_config.instrumented_dir).should exist
106
+ end
107
+ end
108
+
109
+ describe 'instrumentation' do
110
+ def instrumented_dir
111
+ file(test_coverage_config.instrumented_dir)
112
+ end
113
+
114
+ it 'should happen after compile' do
115
+ define('foo')
116
+ lambda { task("foo:#{toolname}:instrument").invoke }.should run_task('foo:compile')
117
+ end
118
+
119
+ it 'should put classes from compile.target in the instrumented directory' do
120
+ define('foo')
121
+ task("foo:#{toolname}:instrument").invoke
122
+ Dir.entries(instrumented_dir.to_s).should == Dir.entries(project('foo').compile.target.to_s)
123
+ end
124
+
125
+ it 'should touch instrumented directory if anything instrumented' do
126
+ a_long_time_ago = Time.now - 10
127
+ define('foo')
128
+ mkpath instrumented_dir.to_s
129
+ File.utime(a_long_time_ago, a_long_time_ago, instrumented_dir.to_s)
130
+ task("foo:#{toolname}:instrument").invoke
131
+ instrumented_dir.timestamp.should be_close(Time.now, 2)
132
+ end
133
+
134
+ it 'should not touch instrumented directory if nothing instrumented' do
135
+ a_long_time_ago = Time.now - 10
136
+ define('foo').compile.invoke
137
+ mkpath instrumented_dir.to_s
138
+ [project('foo').compile.target, instrumented_dir].map(&:to_s).each { |dir| File.utime(a_long_time_ago, a_long_time_ago, dir) }
139
+ task("foo:#{toolname}:instrument").invoke
140
+ instrumented_dir.timestamp.should be_close(a_long_time_ago, 2)
141
+ end
142
+ end
143
+
144
+ describe 'testing classpath' do
145
+ it 'should give priority to instrumented classes over non-instrumented ones' do
146
+ define('foo')
147
+ depends = project('foo').test.dependencies
148
+ depends.index(test_coverage_config.instrumented_dir).should < depends.index(project('foo').compile.target)
149
+ end
150
+
151
+ it 'should have the test coverage tools artifacts' do
152
+ define('foo')
153
+ artifacts(@tool_module.dependencies).each { |artifact| project('foo').test.dependencies.should include(artifact) }
154
+ end
155
+ end
156
+
157
+ describe 'html report' do
158
+ it 'should have html files' do
159
+ define('foo')
160
+ task("foo:#{toolname}:html").invoke
161
+ test_coverage_config.report_to(:html).should have_files_matching('*.html')
162
+ end
163
+
164
+ it 'should contain full source code, including comments' do
165
+ write 'src/main/java/Foo.java',
166
+ 'public class Foo { /* This comment is a TOKEN to check that test coverage reports include the source code */ }'
167
+ define('foo')
168
+ task("foo:#{toolname}:html").invoke
169
+ html_report_contents = Dir[File.join(test_coverage_config.report_dir, '**/*.html')].map{|path|File.open(path).read}.join
170
+ html_report_contents.force_encoding('ascii-8bit') if RUBY_VERSION >= '1.9'
171
+ html_report_contents.should =~ /TOKEN/
172
+ end
173
+ end
174
+ end
175
+
176
+ describe 'cross-project' do
177
+ describe 'reporting' do
178
+ before do
179
+ write 'src/main/java/Foo.java', 'public class Foo {}'
180
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
181
+ write_test :for=>'Bar', :in=>'bar/src/test/java'
182
+ define('foo') { define('bar') }
183
+ end
184
+
185
+ it 'should have a default target' do
186
+ @tool_module.report_to.should point_to_path(File.join('reports', toolname))
187
+ end
188
+
189
+ describe 'in html' do
190
+ it 'should be a defined task' do
191
+ Rake::Task.task_defined?("#{toolname}:html").should be(true)
192
+ end
193
+
194
+ it 'should happen after project instrumentation and testing' do
195
+ lambda { task("#{toolname}:html").invoke }.should run_tasks(["foo:#{toolname}:instrument", 'foo:bar:test'])
196
+ end
197
+
198
+ it 'should have html files' do
199
+ task("#{toolname}:html").invoke
200
+ @tool_module.report_to(:html).should have_files_matching('*.html')
201
+ end
202
+
203
+ it 'should contain full source code, including comments' do
204
+ write 'bar/src/main/java/Bar.java',
205
+ 'public class Bar { /* This comment is a TOKEN to check that test coverage reports include the source code */ }'
206
+ task("#{toolname}:html").invoke
207
+ html_report_contents = Dir[File.join(@tool_module.report_to(:html), '**/*.html')].map{|path|File.read(path)}.join
208
+ html_report_contents.force_encoding('ascii-8bit') if RUBY_VERSION >= '1.9'
209
+ html_report_contents.should =~ /TOKEN/
210
+ end
211
+
212
+ it 'should handle gracefully a project with no source' do
213
+ define 'baz', :base_dir=>'baz'
214
+ task("#{toolname}:html").invoke
215
+ lambda { task("#{toolname}:html").invoke }.should_not raise_error
216
+ end
217
+ end
218
+ end
219
+
220
+ describe 'clean' do
221
+ it 'should remove the report directory' do
222
+ define('foo')
223
+ mkdir_p @tool_module.report_to
224
+ task("#{toolname}:clean").invoke
225
+ file(@tool_module.report_to).should_not exist
226
+ end
227
+
228
+ it 'should be called when calling global clean' do
229
+ define('foo')
230
+ lambda { task('clean').invoke }.should run_task("#{toolname}:clean")
231
+ end
232
+ end
233
+ end
234
+
235
+ describe 'project with no source' do
236
+ it 'should not define an html report task' do
237
+ define 'foo'
238
+ Rake::Task.task_defined?("foo:#{toolname}:html").should be(false)
239
+ end
240
+
241
+ it 'should not raise an error when instrumenting' do
242
+ define('foo')
243
+ lambda { task("foo:#{toolname}:instrument").invoke }.should_not raise_error
244
+ end
245
+
246
+ it 'should not add the instrumented directory to the testing classpath' do
247
+ define 'foo'
248
+ depends = project('foo').test.dependencies
249
+ depends.should_not include(test_coverage_config.instrumented_dir)
250
+ end
251
+
252
+ it 'should not add the test coverage tools artifacts to the testing classpath' do
253
+ define('foo')
254
+ @tool_module.dependencies.each { |artifact| project('foo').test.dependencies.should_not include(artifact) }
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,493 @@
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::JUnit do
21
+ it 'should be the default test framework when test cases are in java' do
22
+ write 'src/test/java/com/exampe/FirstTest.java', <<-JAVA
23
+ package com.example;
24
+ public class FirstTest extends junit.framework.TestCase { }
25
+ JAVA
26
+ define 'foo'
27
+ project('foo').test.framework.should eql(:junit)
28
+ end
29
+
30
+ it 'should be picked if the test language is Java' do
31
+ define 'foo' do
32
+ test.compile.using(:javac)
33
+ test.framework.should eql(:junit)
34
+ end
35
+ end
36
+
37
+ it 'should include JUnit dependencies' do
38
+ define('foo') { test.using(:junit) }
39
+ project('foo').test.compile.dependencies.should include(artifact("junit:junit:jar:#{JUnit.version}"))
40
+ project('foo').test.dependencies.should include(artifact("junit:junit:jar:#{JUnit.version}"))
41
+ end
42
+
43
+ it 'should have REQUIRES up to version 1.5 since it was deprecated in 1.3.3' do
44
+ Buildr::VERSION.should < '1.5'
45
+ lambda { JUnit::REQUIRES }.should_not raise_error
46
+ end
47
+
48
+ it 'should pick JUnit version from junit build settings' do
49
+ Buildr::JUnit.instance_eval { @dependencies = nil }
50
+ write 'build.yaml', 'junit: 1.2.3'
51
+ define('foo') { test.using(:junit) }
52
+ project('foo').test.compile.dependencies.should include(artifact("junit:junit:jar:1.2.3"))
53
+ end
54
+
55
+ it 'should include JMock dependencies' do
56
+ define('foo') { test.using(:junit) }
57
+ project('foo').test.compile.dependencies.should include(artifact("jmock:jmock:jar:#{JMock.version}"))
58
+ project('foo').test.dependencies.should include(artifact("jmock:jmock:jar:#{JMock.version}"))
59
+ end
60
+
61
+ it 'should pick JUnit version from junit build settings' do
62
+ Buildr::JUnit.instance_eval { @dependencies = nil } # JUnit caches JMock dependencies
63
+ Buildr::JMock.instance_eval { @dependencies = nil }
64
+ write 'build.yaml', 'jmock: 1.2.3'
65
+ define('foo') { test.using(:junit) }
66
+ project('foo').test.compile.dependencies.should include(artifact("jmock:jmock:jar:1.2.3"))
67
+ end
68
+
69
+ it 'should include public classes extending junit.framework.TestCase' do
70
+ write 'src/test/java/com/example/FirstTest.java', <<-JAVA
71
+ package com.example;
72
+ public class FirstTest extends junit.framework.TestCase {
73
+ public void testNothing() { }
74
+ }
75
+ JAVA
76
+ write 'src/test/java/com/example/AnotherOne.java', <<-JAVA
77
+ package com.example;
78
+ public class AnotherOne extends junit.framework.TestCase {
79
+ public void testNothing() { }
80
+ }
81
+ JAVA
82
+ define('foo').test.invoke
83
+ project('foo').test.tests.should include('com.example.FirstTest', 'com.example.AnotherOne')
84
+ end
85
+
86
+ it 'should include public classes with annotated test cases' do
87
+ write 'src/test/java/com/example/FirstTest.java', <<-JAVA
88
+ package com.example;
89
+ import org.junit.Test;
90
+ public class FirstTest {
91
+ public void utilityMethod() { }
92
+ @Test
93
+ public void annotated() { }
94
+ }
95
+ JAVA
96
+ define('foo').test.invoke
97
+ project('foo').test.tests.should include('com.example.FirstTest')
98
+ end
99
+
100
+ it 'should include public classes with RunWith annotation' do
101
+ write 'src/test/java/com/example/TestSuite.java', <<-JAVA
102
+ package com.example;
103
+ import org.junit.Test;
104
+ public class TestSuite {
105
+ @Test
106
+ public void annotated() { }
107
+ }
108
+ JAVA
109
+ write 'src/test/java/com/example/RunSuite.java', <<-JAVA
110
+ package com.example;
111
+ import org.junit.runner.RunWith;
112
+ import org.junit.runners.Suite;
113
+ @RunWith(Suite.class)
114
+ @Suite.SuiteClasses({TestSuite.class})
115
+ public class RunSuite {
116
+ }
117
+ JAVA
118
+ define('foo').test.invoke
119
+ project('foo').test.tests.should include('com.example.RunSuite')
120
+ end
121
+
122
+ it 'should ignore classes not extending junit.framework.TestCase' do
123
+ write 'src/test/java/NotATest.java', <<-JAVA
124
+ public class NotATest { }
125
+ JAVA
126
+ define('foo').test.invoke
127
+ project('foo').test.tests.should be_empty
128
+ end
129
+
130
+ it 'should ignore inner classes' do
131
+ write 'src/test/java/InnerClassTest.java', <<-JAVA
132
+ public class InnerClassTest extends junit.framework.TestCase {
133
+ public void testNothing() { }
134
+
135
+ public class InnerTest extends junit.framework.TestCase {
136
+ public void testNothing() { }
137
+ }
138
+ }
139
+ JAVA
140
+ define('foo').test.invoke
141
+ project('foo').test.tests.should eql(['InnerClassTest'])
142
+ end
143
+
144
+ it 'should ignore abstract classes' do
145
+ write 'src/test/java/AbstractClassTest.java', <<-JAVA
146
+ public abstract class AbstractClassTest extends junit.framework.TestCase {
147
+ public void testNothing() { }
148
+ }
149
+ JAVA
150
+ define('foo').test.invoke
151
+ project('foo').test.tests.should be_empty
152
+ end
153
+
154
+ it 'should ignore classes with no tests in them' do
155
+ write 'src/test/java/NoTests.java', <<-JAVA
156
+ public class NoTests {
157
+ }
158
+ JAVA
159
+ define('foo').test.invoke
160
+ project('foo').test.tests.should be_empty
161
+ end
162
+
163
+ it 'should pass when JUnit test case passes' do
164
+ write 'src/test/java/PassingTest.java', <<-JAVA
165
+ public class PassingTest extends junit.framework.TestCase {
166
+ public void testNothing() {}
167
+ }
168
+ JAVA
169
+ lambda { define('foo').test.invoke }.should_not raise_error
170
+ end
171
+
172
+ it 'should fail when JUnit test case fails' do
173
+ write 'src/test/java/FailingTest.java', <<-JAVA
174
+ public class FailingTest extends junit.framework.TestCase {
175
+ public void testFailure() {
176
+ assertTrue(false);
177
+ }
178
+ }
179
+ JAVA
180
+ lambda { define('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/) rescue nil
181
+ end
182
+
183
+ it 'should report failed test names' do
184
+ write 'src/test/java/FailingTest.java', <<-JAVA
185
+ public class FailingTest extends junit.framework.TestCase {
186
+ public void testFailure() {
187
+ assertTrue(false);
188
+ }
189
+ }
190
+ JAVA
191
+ define('foo').test.invoke rescue
192
+ project('foo').test.failed_tests.should include('FailingTest')
193
+ end
194
+
195
+ it 'should report to reports/junit' do
196
+ write 'src/test/java/PassingTest.java', <<-JAVA
197
+ public class PassingTest extends junit.framework.TestCase {
198
+ public void testNothing() {}
199
+ }
200
+ JAVA
201
+ define 'foo' do
202
+ test.report_to.should be(file('reports/junit'))
203
+ end
204
+ project('foo').test.invoke
205
+ project('foo').file('reports/junit/TEST-PassingTest.txt').should exist
206
+ project('foo').file('reports/junit/TEST-PassingTest.xml').should exist
207
+ end
208
+
209
+ it 'should pass properties to JVM' do
210
+ write 'src/test/java/PropertyTest.java', <<-JAVA
211
+ public class PropertyTest extends junit.framework.TestCase {
212
+ public void testProperty() {
213
+ assertEquals("value", System.getProperty("name"));
214
+ }
215
+ }
216
+ JAVA
217
+ define('foo').test.using :properties=>{ 'name'=>'value' }
218
+ project('foo').test.invoke
219
+ project('foo').test.options[:properties]["baseDir"].should eql(project("foo").test.compile.target.to_s)
220
+ end
221
+
222
+ it 'should pass environment to JVM' do
223
+ write 'src/test/java/EnvironmentTest.java', <<-JAVA
224
+ public class EnvironmentTest extends junit.framework.TestCase {
225
+ public void testEnvironment() {
226
+ assertEquals("value", System.getenv("NAME"));
227
+ }
228
+ }
229
+ JAVA
230
+ define('foo').test.using :environment=>{ 'NAME'=>'value' }
231
+ project('foo').test.invoke
232
+ end
233
+
234
+ it 'should set current directory' do
235
+ mkpath 'baz'
236
+ expected = File.expand_path('baz')
237
+ expected.gsub!('/', '\\') if expected =~ /^[A-Z]:/ # Java returns back slashed paths for windows
238
+ write 'baz/src/test/java/CurrentDirectoryTest.java', <<-JAVA
239
+ public class CurrentDirectoryTest extends junit.framework.TestCase {
240
+ public void testCurrentDirectory() throws Exception {
241
+ assertEquals(#{expected.inspect}, new java.io.File(".").getCanonicalPath());
242
+ }
243
+ }
244
+ JAVA
245
+ define 'bar' do
246
+ define 'baz' do
247
+ test.include 'CurrentDirectoryTest'
248
+ end
249
+ end
250
+ project('bar:baz').test.invoke
251
+ end
252
+
253
+ def fork_tests(mode)
254
+ write 'src/test/java/Shared.java', <<-JAVA
255
+ public class Shared {
256
+ public static boolean flag = false;
257
+ }
258
+ JAVA
259
+ write 'src/test/java/TestCase1.java', <<-JAVA
260
+ public class TestCase1 extends junit.framework.TestCase {
261
+ public void testSameVM() {
262
+ assertFalse(Shared.flag);
263
+ Shared.flag = true;
264
+ }
265
+ }
266
+ JAVA
267
+ write 'src/test/java/TestCase2.java', <<-JAVA
268
+ public class TestCase2 extends junit.framework.TestCase {
269
+ public void testSameVM() {
270
+ assertFalse(Shared.flag);
271
+ Shared.flag = true;
272
+ }
273
+ }
274
+ JAVA
275
+ define 'foo' do
276
+ test.using :fork=>mode, :fail_on_failure=>false
277
+ end
278
+ project('foo').test.invoke
279
+ end
280
+
281
+ it 'should run all test cases in same VM if fork is once' do
282
+ fork_tests :once
283
+ project('foo').test.failed_tests.size.should eql(1)
284
+ end
285
+
286
+ it 'should run each test case in separate same VM if fork is each' do
287
+ fork_tests :each
288
+ project('foo').test.failed_tests.should be_empty
289
+ end
290
+
291
+ after do
292
+ # Yes, this is ugly. Better solution?
293
+ Buildr::JUnit.instance_eval { @dependencies = nil }
294
+ Buildr::JMock.instance_eval { @dependencies = nil }
295
+ end
296
+ end
297
+
298
+
299
+ describe Buildr::JUnit, 'report' do
300
+ it 'should default to the target directory reports/junit' do
301
+ JUnit.report.target.should eql('reports/junit')
302
+ end
303
+
304
+ it 'should generate report into the target directory' do
305
+ JUnit.report.target = 'test-report'
306
+ lambda { task('junit:report').invoke }.should change { File.exist?(JUnit.report.target) }.to(true)
307
+ end
308
+
309
+ it 'should clean after itself' do
310
+ mkpath JUnit.report.target
311
+ lambda { task('clean').invoke }.should change { File.exist?(JUnit.report.target) }.to(false)
312
+ end
313
+
314
+ it 'should generate a consolidated XML report' do
315
+ lambda { task('junit:report').invoke }.should change { File.exist?('reports/junit/TESTS-TestSuites.xml') }.to(true)
316
+ end
317
+
318
+ it 'should default to generating a report with frames' do
319
+ JUnit.report.frames.should be_true
320
+ end
321
+
322
+ it 'should generate single page when frames is false' do
323
+ JUnit.report.frames = false
324
+ task('junit:report').invoke
325
+ file('reports/junit/html/junit-noframes.html').should exist
326
+ end
327
+
328
+ it 'should generate frame page when frames is false' do
329
+ JUnit.report.frames = true
330
+ task('junit:report').invoke
331
+ file('reports/junit/html/index.html').should exist
332
+ end
333
+
334
+ it 'should generate reports from all projects that ran test cases' do
335
+ write 'src/test/java/TestSomething.java', <<-JAVA
336
+ public class TestSomething extends junit.framework.TestCase {
337
+ public void testNothing() {}
338
+ }
339
+ JAVA
340
+ define 'foo'
341
+ project('foo').test.invoke
342
+ task('junit:report').invoke
343
+ FileList['reports/junit/html/*TestSomething.html'].size.should be(1)
344
+ end
345
+
346
+ after do
347
+ JUnit.instance_eval { @report = nil }
348
+ end
349
+ end
350
+
351
+
352
+ describe Buildr::TestNG do
353
+ it 'should be selectable in project' do
354
+ define 'foo' do
355
+ test.using(:testng)
356
+ test.framework.should eql(:testng)
357
+ end
358
+ end
359
+
360
+ it 'should be selectable in parent project' do
361
+ write 'bar/src/test/java/TestCase.java'
362
+ define 'foo' do
363
+ test.using(:testng)
364
+ define 'bar'
365
+ end
366
+ project('foo:bar').test.framework.should eql(:testng)
367
+ end
368
+
369
+ it 'should include TestNG dependencies' do
370
+ define('foo') { test.using :testng }
371
+ project('foo').test.compile.dependencies.should include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
372
+ project('foo').test.dependencies.should include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
373
+ end
374
+
375
+ it 'should include TestNG dependencies' do
376
+ define('foo') { test.using :testng }
377
+ project('foo').test.compile.dependencies.should include(artifact("jmock:jmock:jar:#{JMock.version}"))
378
+ project('foo').test.dependencies.should include(artifact("jmock:jmock:jar:#{JMock.version}"))
379
+ end
380
+
381
+ it 'should include classes using TestNG annotations' do
382
+ write 'src/test/java/com/example/AnnotatedClass.java', <<-JAVA
383
+ package com.example;
384
+ @org.testng.annotations.Test
385
+ public class AnnotatedClass { }
386
+ JAVA
387
+ write 'src/test/java/com/example/AnnotatedMethod.java', <<-JAVA
388
+ package com.example;
389
+ public class AnnotatedMethod {
390
+ @org.testng.annotations.Test
391
+ public void annotated() { }
392
+ }
393
+ JAVA
394
+ define('foo') { test.using(:testng) }
395
+ project('foo').test.invoke
396
+ project('foo').test.tests.should include('com.example.AnnotatedClass', 'com.example.AnnotatedMethod')
397
+ end
398
+
399
+ it 'should ignore classes not using TestNG annotations' do
400
+ write 'src/test/java/NotATestClass.java', 'public class NotATestClass {}'
401
+ define('foo') { test.using(:testng) }
402
+ project('foo').test.invoke
403
+ project('foo').test.tests.should be_empty
404
+ end
405
+
406
+ it 'should ignore inner classes' do
407
+ write 'src/test/java/InnerClassTest.java', <<-JAVA
408
+ @org.testng.annotations.Test
409
+ public class InnerClassTest {
410
+ public class InnerTest {
411
+ }
412
+ }
413
+ JAVA
414
+ define('foo') { test.using(:testng) }
415
+ project('foo').test.invoke
416
+ project('foo').test.tests.should eql(['InnerClassTest'])
417
+ end
418
+
419
+ it 'should pass when TestNG test case passes' do
420
+ write 'src/test/java/PassingTest.java', <<-JAVA
421
+ public class PassingTest {
422
+ @org.testng.annotations.Test
423
+ public void testNothing() {}
424
+ }
425
+ JAVA
426
+ define('foo') { test.using(:testng) }
427
+ lambda { project('foo').test.invoke }.should_not raise_error
428
+ end
429
+
430
+ it 'should fail when TestNG test case fails' do
431
+ write 'src/test/java/FailingTest.java', <<-JAVA
432
+ public class FailingTest {
433
+ @org.testng.annotations.Test
434
+ public void testNothing() {
435
+ org.testng.AssertJUnit.assertTrue(false);
436
+ }
437
+ }
438
+ JAVA
439
+ define('foo') { test.using(:testng) }
440
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/)
441
+ end
442
+
443
+ it 'should fail when multiple TestNG test case fail' do
444
+ write 'src/test/java/FailingTest1.java', <<-JAVA
445
+ public class FailingTest1 {
446
+ @org.testng.annotations.Test
447
+ public void testNothing() {
448
+ org.testng.AssertJUnit.assertTrue(false);
449
+ }
450
+ }
451
+ JAVA
452
+ write 'src/test/java/FailingTest2.java', <<-JAVA
453
+ public class FailingTest2 {
454
+ @org.testng.annotations.Test
455
+ public void testNothing() {
456
+ org.testng.AssertJUnit.assertTrue(false);
457
+ }
458
+ }
459
+ JAVA
460
+ define('foo') { test.using(:testng) }
461
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/)
462
+ end
463
+
464
+ it 'should report failed test names' do
465
+ write 'src/test/java/FailingTest.java', <<-JAVA
466
+ public class FailingTest {
467
+ @org.testng.annotations.Test
468
+ public void testNothing() {
469
+ org.testng.AssertJUnit.assertTrue(false);
470
+ }
471
+ }
472
+ JAVA
473
+ define('foo') { test.using(:testng) }
474
+ project('foo').test.invoke rescue nil
475
+ project('foo').test.failed_tests.should include('FailingTest')
476
+ end
477
+
478
+ it 'should report to reports/testng' do
479
+ define('foo') { test.using(:testng) }
480
+ project('foo').test.report_to.should be(project('foo').file('reports/testng'))
481
+ end
482
+
483
+ it 'should generate reports' do
484
+ write 'src/test/java/PassingTest.java', <<-JAVA
485
+ public class PassingTest {
486
+ @org.testng.annotations.Test
487
+ public void testNothing() {}
488
+ }
489
+ JAVA
490
+ define('foo') { test.using(:testng) }
491
+ lambda { project('foo').test.invoke }.should change { File.exist?('reports/testng/foo/index.html') }.to(true)
492
+ end
493
+ end