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,78 @@
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
+ describe Run::JavaRunner do
21
+
22
+ it 'should fail on error' do
23
+ define 'foo' do
24
+ run.using :java, :main => 'org.example.NonExistentMain' # class doesn't exist
25
+ end
26
+ lambda { project('foo').run.invoke }.should raise_error(RuntimeError, /Failed to execute java/)
27
+ end
28
+
29
+ it 'should execute main class' do
30
+ write 'src/main/java/org/example/Main.java', <<-JAVA
31
+ package org.example;
32
+ public class Main {
33
+ public static void main(String[] args) {
34
+ System.out.println("Hello, world!");
35
+ }
36
+ }
37
+ JAVA
38
+ define 'foo' do
39
+ run.using :main => 'org.example.Main'
40
+ end
41
+ project('foo').run.prerequisites.should include(task("foo:compile"))
42
+ end
43
+
44
+ it 'should accept :main option as an array including parameters for the main class' do
45
+ define 'foo' do
46
+ run.using :java, :main => ['org.example.Main', '-t', 'input.txt']
47
+ end
48
+ Java::Commands.should_receive(:java).once.with do |*args|
49
+ args[0].should == ['org.example.Main', '-t', 'input.txt']
50
+ end
51
+ project('foo').run.invoke
52
+ end
53
+
54
+ it 'should accept :java_args and pass them to java' do
55
+ define 'foo' do
56
+ run.using :java, :main => 'foo', :java_args => ['-server']
57
+ end
58
+ Java::Commands.should_receive(:java).once.with do |*args|
59
+ args[0].should == 'foo'
60
+ args[1][:java_args].should include('-server')
61
+ end
62
+ project('foo').run.invoke
63
+ end
64
+
65
+ it 'should accept :properties and pass them as -Dproperty=value to java' do
66
+ define 'foo' do
67
+ run.using :java, :main => 'foo', :properties => { :foo => 'one', :bar => 'two' }
68
+ end
69
+ Java::Commands.should_receive(:java).once.with do |*args|
70
+ args[0].should == 'foo'
71
+ args[1][:properties][:foo].should == 'one'
72
+ args[1][:properties][:bar].should == 'two'
73
+ end
74
+ project('foo').run.invoke
75
+ end
76
+
77
+ end
78
+
@@ -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.expand_path(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
+ shared_examples_for 'test coverage tool' 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,497 @@
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
+ 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
+ two_or_later = JMock.version[0,1].to_i >= 2
58
+ group = two_or_later ? "org.jmock" : "jmock"
59
+ project('foo').test.compile.dependencies.should include(artifact("#{group}:jmock:jar:#{JMock.version}"))
60
+ project('foo').test.dependencies.should include(artifact("#{group}:jmock:jar:#{JMock.version}"))
61
+ end
62
+
63
+ it 'should pick JUnit version from junit build settings' do
64
+ Buildr::JUnit.instance_eval { @dependencies = nil } # JUnit caches JMock dependencies
65
+ Buildr::JMock.instance_eval { @dependencies = nil }
66
+ write 'build.yaml', 'jmock: 1.2.3'
67
+ define('foo') { test.using(:junit) }
68
+ project('foo').test.compile.dependencies.should include(artifact("jmock:jmock:jar:1.2.3"))
69
+ end
70
+
71
+ it 'should include public classes extending junit.framework.TestCase' do
72
+ write 'src/test/java/com/example/FirstTest.java', <<-JAVA
73
+ package com.example;
74
+ public class FirstTest extends junit.framework.TestCase {
75
+ public void testNothing() { }
76
+ }
77
+ JAVA
78
+ write 'src/test/java/com/example/AnotherOne.java', <<-JAVA
79
+ package com.example;
80
+ public class AnotherOne extends junit.framework.TestCase {
81
+ public void testNothing() { }
82
+ }
83
+ JAVA
84
+ define('foo').test.invoke
85
+ project('foo').test.tests.should include('com.example.FirstTest', 'com.example.AnotherOne')
86
+ end
87
+
88
+ it 'should include public classes with annotated test cases' do
89
+ write 'src/test/java/com/example/FirstTest.java', <<-JAVA
90
+ package com.example;
91
+ import org.junit.Test;
92
+ public class FirstTest {
93
+ public void utilityMethod() { }
94
+ @Test
95
+ public void annotated() { }
96
+ }
97
+ JAVA
98
+ define('foo').test.invoke
99
+ project('foo').test.tests.should include('com.example.FirstTest')
100
+ end
101
+
102
+ it 'should include public classes with RunWith annotation' do
103
+ write 'src/test/java/com/example/TestSuite.java', <<-JAVA
104
+ package com.example;
105
+ import org.junit.Test;
106
+ public class TestSuite {
107
+ @Test
108
+ public void annotated() { }
109
+ }
110
+ JAVA
111
+ write 'src/test/java/com/example/RunSuite.java', <<-JAVA
112
+ package com.example;
113
+ import org.junit.runner.RunWith;
114
+ import org.junit.runners.Suite;
115
+ @RunWith(Suite.class)
116
+ @Suite.SuiteClasses({TestSuite.class})
117
+ public class RunSuite {
118
+ }
119
+ JAVA
120
+ define('foo').test.invoke
121
+ project('foo').test.tests.should include('com.example.RunSuite')
122
+ end
123
+
124
+ it 'should ignore classes not extending junit.framework.TestCase' do
125
+ write 'src/test/java/NotATest.java', <<-JAVA
126
+ public class NotATest { }
127
+ JAVA
128
+ define('foo').test.invoke
129
+ project('foo').test.tests.should be_empty
130
+ end
131
+
132
+ it 'should ignore inner classes' do
133
+ write 'src/test/java/InnerClassTest.java', <<-JAVA
134
+ public class InnerClassTest extends junit.framework.TestCase {
135
+ public void testNothing() { }
136
+
137
+ public class InnerTest extends junit.framework.TestCase {
138
+ public void testNothing() { }
139
+ }
140
+ }
141
+ JAVA
142
+ define('foo').test.invoke
143
+ project('foo').test.tests.should eql(['InnerClassTest'])
144
+ end
145
+
146
+ it 'should ignore abstract classes' do
147
+ write 'src/test/java/AbstractClassTest.java', <<-JAVA
148
+ public abstract class AbstractClassTest extends junit.framework.TestCase {
149
+ public void testNothing() { }
150
+ }
151
+ JAVA
152
+ define('foo').test.invoke
153
+ project('foo').test.tests.should be_empty
154
+ end
155
+
156
+ it 'should ignore classes with no tests in them' do
157
+ write 'src/test/java/NoTests.java', <<-JAVA
158
+ public class NoTests {
159
+ }
160
+ JAVA
161
+ define('foo').test.invoke
162
+ project('foo').test.tests.should be_empty
163
+ end
164
+
165
+ it 'should pass when JUnit test case passes' do
166
+ write 'src/test/java/PassingTest.java', <<-JAVA
167
+ public class PassingTest extends junit.framework.TestCase {
168
+ public void testNothing() {}
169
+ }
170
+ JAVA
171
+ lambda { define('foo').test.invoke }.should_not raise_error
172
+ end
173
+
174
+ it 'should fail when JUnit test case fails' do
175
+ write 'src/test/java/FailingTest.java', <<-JAVA
176
+ public class FailingTest extends junit.framework.TestCase {
177
+ public void testFailure() {
178
+ assertTrue(false);
179
+ }
180
+ }
181
+ JAVA
182
+ lambda { define('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/) rescue nil
183
+ end
184
+
185
+ it 'should report failed test names' do
186
+ write 'src/test/java/FailingTest.java', <<-JAVA
187
+ public class FailingTest extends junit.framework.TestCase {
188
+ public void testFailure() {
189
+ assertTrue(false);
190
+ }
191
+ }
192
+ JAVA
193
+ define('foo').test.invoke rescue
194
+ project('foo').test.failed_tests.should include('FailingTest')
195
+ end
196
+
197
+ it 'should report to reports/junit' do
198
+ write 'src/test/java/PassingTest.java', <<-JAVA
199
+ public class PassingTest extends junit.framework.TestCase {
200
+ public void testNothing() {}
201
+ }
202
+ JAVA
203
+ define 'foo' do
204
+ test.report_to.should be(file('reports/junit'))
205
+ end
206
+ project('foo').test.invoke
207
+ project('foo').file('reports/junit/TEST-PassingTest.txt').should exist
208
+ project('foo').file('reports/junit/TEST-PassingTest.xml').should exist
209
+ end
210
+
211
+ it 'should pass properties to JVM' do
212
+ write 'src/test/java/PropertyTest.java', <<-JAVA
213
+ public class PropertyTest extends junit.framework.TestCase {
214
+ public void testProperty() {
215
+ assertEquals("value", System.getProperty("name"));
216
+ }
217
+ }
218
+ JAVA
219
+ define('foo').test.using :properties=>{ 'name'=>'value' }
220
+ project('foo').test.invoke
221
+ project('foo').test.options[:properties]["baseDir"].should eql(project("foo").test.compile.target.to_s)
222
+ end
223
+
224
+ it 'should pass environment to JVM' do
225
+ write 'src/test/java/EnvironmentTest.java', <<-JAVA
226
+ public class EnvironmentTest extends junit.framework.TestCase {
227
+ public void testEnvironment() {
228
+ assertEquals("value", System.getenv("NAME"));
229
+ }
230
+ }
231
+ JAVA
232
+ define('foo').test.using :environment=>{ 'NAME'=>'value' }
233
+ project('foo').test.invoke
234
+ end
235
+
236
+ it 'should set current directory' do
237
+ mkpath 'baz'
238
+ expected = File.expand_path('baz')
239
+ expected.gsub!('/', '\\') if expected =~ /^[A-Z]:/ # Java returns back slashed paths for windows
240
+ write 'baz/src/test/java/CurrentDirectoryTest.java', <<-JAVA
241
+ public class CurrentDirectoryTest extends junit.framework.TestCase {
242
+ public void testCurrentDirectory() throws Exception {
243
+ assertEquals(#{expected.inspect}, new java.io.File(".").getCanonicalPath());
244
+ }
245
+ }
246
+ JAVA
247
+ define 'bar' do
248
+ define 'baz' do
249
+ test.include 'CurrentDirectoryTest'
250
+ end
251
+ end
252
+ project('bar:baz').test.invoke
253
+ end
254
+
255
+ def fork_tests(mode)
256
+ write 'src/test/java/Shared.java', <<-JAVA
257
+ public class Shared {
258
+ public static boolean flag = false;
259
+ }
260
+ JAVA
261
+ write 'src/test/java/TestCase1.java', <<-JAVA
262
+ public class TestCase1 extends junit.framework.TestCase {
263
+ public void testSameVM() {
264
+ assertFalse(Shared.flag);
265
+ Shared.flag = true;
266
+ }
267
+ }
268
+ JAVA
269
+ write 'src/test/java/TestCase2.java', <<-JAVA
270
+ public class TestCase2 extends junit.framework.TestCase {
271
+ public void testSameVM() {
272
+ assertFalse(Shared.flag);
273
+ Shared.flag = true;
274
+ }
275
+ }
276
+ JAVA
277
+ define 'foo' do
278
+ test.using :fork=>mode, :fail_on_failure=>false
279
+ end
280
+ project('foo').test.invoke
281
+ end
282
+
283
+ it 'should run all test cases in same VM if fork is once' do
284
+ fork_tests :once
285
+ project('foo').test.failed_tests.size.should eql(1)
286
+ end
287
+
288
+ it 'should run each test case in separate same VM if fork is each' do
289
+ fork_tests :each
290
+ project('foo').test.failed_tests.should be_empty
291
+ end
292
+
293
+ after do
294
+ # Yes, this is ugly. Better solution?
295
+ Buildr::JUnit.instance_eval { @dependencies = nil }
296
+ Buildr::JMock.instance_eval { @dependencies = nil }
297
+ end
298
+ end
299
+
300
+
301
+ describe Buildr::JUnit, 'report' do
302
+ it 'should default to the target directory reports/junit' do
303
+ JUnit.report.target.should eql('reports/junit')
304
+ end
305
+
306
+ it 'should generate report into the target directory' do
307
+ JUnit.report.target = 'test-report'
308
+ lambda { task('junit:report').invoke }.should change { File.exist?(JUnit.report.target) }.to(true)
309
+ end
310
+
311
+ it 'should clean after itself' do
312
+ mkpath JUnit.report.target
313
+ lambda { task('clean').invoke }.should change { File.exist?(JUnit.report.target) }.to(false)
314
+ end
315
+
316
+ it 'should generate a consolidated XML report' do
317
+ lambda { task('junit:report').invoke }.should change { File.exist?('reports/junit/TESTS-TestSuites.xml') }.to(true)
318
+ end
319
+
320
+ it 'should default to generating a report with frames' do
321
+ JUnit.report.frames.should be_true
322
+ end
323
+
324
+ it 'should generate single page when frames is false' do
325
+ JUnit.report.frames = false
326
+ task('junit:report').invoke
327
+ file('reports/junit/html/junit-noframes.html').should exist
328
+ end
329
+
330
+ it 'should generate frame page when frames is false' do
331
+ JUnit.report.frames = true
332
+ task('junit:report').invoke
333
+ file('reports/junit/html/index.html').should exist
334
+ end
335
+
336
+ it 'should generate reports from all projects that ran test cases' do
337
+ write 'src/test/java/TestSomething.java', <<-JAVA
338
+ public class TestSomething extends junit.framework.TestCase {
339
+ public void testNothing() {}
340
+ }
341
+ JAVA
342
+ define 'foo'
343
+ project('foo').test.invoke
344
+ task('junit:report').invoke
345
+ FileList['reports/junit/html/*TestSomething.html'].size.should be(1)
346
+ end
347
+
348
+ after do
349
+ JUnit.instance_eval { @report = nil }
350
+ end
351
+ end
352
+
353
+
354
+ describe Buildr::TestNG do
355
+ it 'should be selectable in project' do
356
+ define 'foo' do
357
+ test.using(:testng)
358
+ test.framework.should eql(:testng)
359
+ end
360
+ end
361
+
362
+ it 'should be selectable in parent project' do
363
+ write 'bar/src/test/java/TestCase.java'
364
+ define 'foo' do
365
+ test.using(:testng)
366
+ define 'bar'
367
+ end
368
+ project('foo:bar').test.framework.should eql(:testng)
369
+ end
370
+
371
+ it 'should include TestNG dependencies' do
372
+ define('foo') { test.using :testng }
373
+ project('foo').test.compile.dependencies.should include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
374
+ project('foo').test.dependencies.should include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
375
+ end
376
+
377
+ it 'should include TestNG dependencies' do
378
+ define('foo') { test.using :testng }
379
+ two_or_later = JMock.version[0,1].to_i >= 2
380
+ group = two_or_later ? "org.jmock" : "jmock"
381
+ project('foo').test.compile.dependencies.should include(artifact("#{group}:jmock:jar:#{JMock.version}"))
382
+ project('foo').test.dependencies.should include(artifact("#{group}:jmock:jar:#{JMock.version}"))
383
+ end
384
+
385
+ it 'should include classes using TestNG annotations' do
386
+ write 'src/test/java/com/example/AnnotatedClass.java', <<-JAVA
387
+ package com.example;
388
+ @org.testng.annotations.Test
389
+ public class AnnotatedClass { }
390
+ JAVA
391
+ write 'src/test/java/com/example/AnnotatedMethod.java', <<-JAVA
392
+ package com.example;
393
+ public class AnnotatedMethod {
394
+ @org.testng.annotations.Test
395
+ public void annotated() { }
396
+ }
397
+ JAVA
398
+ define('foo') { test.using(:testng) }
399
+ project('foo').test.invoke
400
+ project('foo').test.tests.should include('com.example.AnnotatedClass', 'com.example.AnnotatedMethod')
401
+ end
402
+
403
+ it 'should ignore classes not using TestNG annotations' do
404
+ write 'src/test/java/NotATestClass.java', 'public class NotATestClass {}'
405
+ define('foo') { test.using(:testng) }
406
+ project('foo').test.invoke
407
+ project('foo').test.tests.should be_empty
408
+ end
409
+
410
+ it 'should ignore inner classes' do
411
+ write 'src/test/java/InnerClassTest.java', <<-JAVA
412
+ @org.testng.annotations.Test
413
+ public class InnerClassTest {
414
+ public class InnerTest {
415
+ }
416
+ }
417
+ JAVA
418
+ define('foo') { test.using(:testng) }
419
+ project('foo').test.invoke
420
+ project('foo').test.tests.should eql(['InnerClassTest'])
421
+ end
422
+
423
+ it 'should pass when TestNG test case passes' do
424
+ write 'src/test/java/PassingTest.java', <<-JAVA
425
+ public class PassingTest {
426
+ @org.testng.annotations.Test
427
+ public void testNothing() {}
428
+ }
429
+ JAVA
430
+ define('foo') { test.using(:testng) }
431
+ lambda { project('foo').test.invoke }.should_not raise_error
432
+ end
433
+
434
+ it 'should fail when TestNG test case fails' do
435
+ write 'src/test/java/FailingTest.java', <<-JAVA
436
+ public class FailingTest {
437
+ @org.testng.annotations.Test
438
+ public void testNothing() {
439
+ org.testng.AssertJUnit.assertTrue(false);
440
+ }
441
+ }
442
+ JAVA
443
+ define('foo') { test.using(:testng) }
444
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/)
445
+ end
446
+
447
+ it 'should fail when multiple TestNG test case fail' do
448
+ write 'src/test/java/FailingTest1.java', <<-JAVA
449
+ public class FailingTest1 {
450
+ @org.testng.annotations.Test
451
+ public void testNothing() {
452
+ org.testng.AssertJUnit.assertTrue(false);
453
+ }
454
+ }
455
+ JAVA
456
+ write 'src/test/java/FailingTest2.java', <<-JAVA
457
+ public class FailingTest2 {
458
+ @org.testng.annotations.Test
459
+ public void testNothing() {
460
+ org.testng.AssertJUnit.assertTrue(false);
461
+ }
462
+ }
463
+ JAVA
464
+ define('foo') { test.using(:testng) }
465
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/)
466
+ end
467
+
468
+ it 'should report failed test names' do
469
+ write 'src/test/java/FailingTest.java', <<-JAVA
470
+ public class FailingTest {
471
+ @org.testng.annotations.Test
472
+ public void testNothing() {
473
+ org.testng.AssertJUnit.assertTrue(false);
474
+ }
475
+ }
476
+ JAVA
477
+ define('foo') { test.using(:testng) }
478
+ project('foo').test.invoke rescue nil
479
+ project('foo').test.failed_tests.should include('FailingTest')
480
+ end
481
+
482
+ it 'should report to reports/testng' do
483
+ define('foo') { test.using(:testng) }
484
+ project('foo').test.report_to.should be(project('foo').file('reports/testng'))
485
+ end
486
+
487
+ it 'should generate reports' do
488
+ write 'src/test/java/PassingTest.java', <<-JAVA
489
+ public class PassingTest {
490
+ @org.testng.annotations.Test
491
+ public void testNothing() {}
492
+ }
493
+ JAVA
494
+ define('foo') { test.using(:testng) }
495
+ lambda { project('foo').test.invoke }.should change { File.exist?('reports/testng/foo/index.html') }.to(true)
496
+ end
497
+ end