buildr-gemjar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. data/.braids +8 -0
  2. data/.gitignore +5 -0
  3. data/.rvmrc +1 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +20 -0
  7. data/README.md +98 -0
  8. data/Rakefile +8 -0
  9. data/buildr-gemjar.gemspec +42 -0
  10. data/lib/buildr-gemjar.rb +162 -0
  11. data/lib/buildr-gemjar/version.rb +3 -0
  12. data/meta.rakefile +30 -0
  13. data/spec/buildr-gemjar/version_spec.rb +11 -0
  14. data/spec/buildr-gemjar_spec.rb +179 -0
  15. data/spec/repo_builder.rb +59 -0
  16. data/spec/spec_helper.rb +44 -0
  17. data/vendor/buildr/.gitignore +17 -0
  18. data/vendor/buildr/CHANGELOG +1283 -0
  19. data/vendor/buildr/Gemfile +4 -0
  20. data/vendor/buildr/LICENSE +176 -0
  21. data/vendor/buildr/NOTICE +26 -0
  22. data/vendor/buildr/README.rdoc +134 -0
  23. data/vendor/buildr/Rakefile +44 -0
  24. data/vendor/buildr/_buildr +35 -0
  25. data/vendor/buildr/_jbuildr +35 -0
  26. data/vendor/buildr/addon/buildr/antlr.rb +65 -0
  27. data/vendor/buildr/addon/buildr/bnd.rb +147 -0
  28. data/vendor/buildr/addon/buildr/cobertura.rb +22 -0
  29. data/vendor/buildr/addon/buildr/drb.rb +281 -0
  30. data/vendor/buildr/addon/buildr/emma.rb +22 -0
  31. data/vendor/buildr/addon/buildr/hibernate.rb +149 -0
  32. data/vendor/buildr/addon/buildr/javacc.rb +85 -0
  33. data/vendor/buildr/addon/buildr/jaxb_xjc.rb +72 -0
  34. data/vendor/buildr/addon/buildr/jdepend.rb +60 -0
  35. data/vendor/buildr/addon/buildr/jetty.rb +248 -0
  36. data/vendor/buildr/addon/buildr/jibx.rb +86 -0
  37. data/vendor/buildr/addon/buildr/nailgun.rb +221 -0
  38. data/vendor/buildr/addon/buildr/openjpa.rb +88 -0
  39. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  40. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  41. data/vendor/buildr/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  42. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  43. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  44. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  45. data/vendor/buildr/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  46. data/vendor/buildr/addon/buildr/protobuf.rb +88 -0
  47. data/vendor/buildr/addon/buildr/xmlbeans.rb +93 -0
  48. data/vendor/buildr/all-in-one/_buildr +19 -0
  49. data/vendor/buildr/all-in-one/buildr +368 -0
  50. data/vendor/buildr/all-in-one/buildr.cmd +1 -0
  51. data/vendor/buildr/bin/buildr +19 -0
  52. data/vendor/buildr/buildr.buildfile +58 -0
  53. data/vendor/buildr/buildr.gemspec +74 -0
  54. data/vendor/buildr/doc/_config.yml +1 -0
  55. data/vendor/buildr/doc/_layouts/default.html +90 -0
  56. data/vendor/buildr/doc/_layouts/preface.html +22 -0
  57. data/vendor/buildr/doc/artifacts.textile +217 -0
  58. data/vendor/buildr/doc/building.textile +276 -0
  59. data/vendor/buildr/doc/contributing.textile +268 -0
  60. data/vendor/buildr/doc/css/default.css +236 -0
  61. data/vendor/buildr/doc/css/print.css +101 -0
  62. data/vendor/buildr/doc/css/syntax.css +23 -0
  63. data/vendor/buildr/doc/download.textile +138 -0
  64. data/vendor/buildr/doc/extending.textile +212 -0
  65. data/vendor/buildr/doc/images/1442160941-frontcover.jpg +0 -0
  66. data/vendor/buildr/doc/images/asf-logo.gif +0 -0
  67. data/vendor/buildr/doc/images/asf-logo.png +0 -0
  68. data/vendor/buildr/doc/images/buildr-hires.png +0 -0
  69. data/vendor/buildr/doc/images/buildr.png +0 -0
  70. data/vendor/buildr/doc/images/favicon.png +0 -0
  71. data/vendor/buildr/doc/images/growl-icon.tiff +0 -0
  72. data/vendor/buildr/doc/images/note.png +0 -0
  73. data/vendor/buildr/doc/images/project-structure.png +0 -0
  74. data/vendor/buildr/doc/images/tip.png +0 -0
  75. data/vendor/buildr/doc/images/zbuildr.png +0 -0
  76. data/vendor/buildr/doc/images/zbuildr.tif +0 -0
  77. data/vendor/buildr/doc/index.textile +69 -0
  78. data/vendor/buildr/doc/installing.textile +284 -0
  79. data/vendor/buildr/doc/languages.textile +599 -0
  80. data/vendor/buildr/doc/mailing_lists.textile +29 -0
  81. data/vendor/buildr/doc/more_stuff.textile +845 -0
  82. data/vendor/buildr/doc/packaging.textile +618 -0
  83. data/vendor/buildr/doc/preface.textile +54 -0
  84. data/vendor/buildr/doc/projects.textile +276 -0
  85. data/vendor/buildr/doc/quick_start.textile +210 -0
  86. data/vendor/buildr/doc/releasing.textile +117 -0
  87. data/vendor/buildr/doc/scripts/buildr-git.rb +512 -0
  88. data/vendor/buildr/doc/scripts/gitflow.rb +296 -0
  89. data/vendor/buildr/doc/scripts/install-jruby.sh +44 -0
  90. data/vendor/buildr/doc/scripts/install-linux.sh +73 -0
  91. data/vendor/buildr/doc/scripts/install-osx.sh +52 -0
  92. data/vendor/buildr/doc/settings_profiles.textile +287 -0
  93. data/vendor/buildr/doc/testing.textile +247 -0
  94. data/vendor/buildr/etc/KEYS +189 -0
  95. data/vendor/buildr/lib/buildr.rb +44 -0
  96. data/vendor/buildr/lib/buildr/clojure.rb +34 -0
  97. data/vendor/buildr/lib/buildr/clojure/shell.rb +52 -0
  98. data/vendor/buildr/lib/buildr/core.rb +34 -0
  99. data/vendor/buildr/lib/buildr/core/application.rb +700 -0
  100. data/vendor/buildr/lib/buildr/core/build.rb +516 -0
  101. data/vendor/buildr/lib/buildr/core/cc.rb +166 -0
  102. data/vendor/buildr/lib/buildr/core/checks.rb +253 -0
  103. data/vendor/buildr/lib/buildr/core/common.rb +151 -0
  104. data/vendor/buildr/lib/buildr/core/compile.rb +622 -0
  105. data/vendor/buildr/lib/buildr/core/doc.rb +276 -0
  106. data/vendor/buildr/lib/buildr/core/environment.rb +129 -0
  107. data/vendor/buildr/lib/buildr/core/filter.rb +404 -0
  108. data/vendor/buildr/lib/buildr/core/generate.rb +197 -0
  109. data/vendor/buildr/lib/buildr/core/help.rb +119 -0
  110. data/vendor/buildr/lib/buildr/core/jrebel.rb +42 -0
  111. data/vendor/buildr/lib/buildr/core/linux.rb +30 -0
  112. data/vendor/buildr/lib/buildr/core/osx.rb +46 -0
  113. data/vendor/buildr/lib/buildr/core/progressbar.rb +161 -0
  114. data/vendor/buildr/lib/buildr/core/project.rb +975 -0
  115. data/vendor/buildr/lib/buildr/core/run.rb +43 -0
  116. data/vendor/buildr/lib/buildr/core/shell.rb +137 -0
  117. data/vendor/buildr/lib/buildr/core/test.rb +843 -0
  118. data/vendor/buildr/lib/buildr/core/transports.rb +565 -0
  119. data/vendor/buildr/lib/buildr/core/util.rb +537 -0
  120. data/vendor/buildr/lib/buildr/groovy.rb +20 -0
  121. data/vendor/buildr/lib/buildr/groovy/bdd.rb +106 -0
  122. data/vendor/buildr/lib/buildr/groovy/compiler.rb +153 -0
  123. data/vendor/buildr/lib/buildr/groovy/doc.rb +76 -0
  124. data/vendor/buildr/lib/buildr/groovy/shell.rb +57 -0
  125. data/vendor/buildr/lib/buildr/ide.rb +19 -0
  126. data/vendor/buildr/lib/buildr/ide/eclipse.rb +427 -0
  127. data/vendor/buildr/lib/buildr/ide/eclipse/java.rb +53 -0
  128. data/vendor/buildr/lib/buildr/ide/eclipse/plugin.rb +71 -0
  129. data/vendor/buildr/lib/buildr/ide/eclipse/scala.rb +68 -0
  130. data/vendor/buildr/lib/buildr/ide/idea.rb +576 -0
  131. data/vendor/buildr/lib/buildr/java.rb +25 -0
  132. data/vendor/buildr/lib/buildr/java/ant.rb +94 -0
  133. data/vendor/buildr/lib/buildr/java/bdd.rb +460 -0
  134. data/vendor/buildr/lib/buildr/java/cobertura.rb +297 -0
  135. data/vendor/buildr/lib/buildr/java/commands.rb +223 -0
  136. data/vendor/buildr/lib/buildr/java/compiler.rb +135 -0
  137. data/vendor/buildr/lib/buildr/java/deprecated.rb +141 -0
  138. data/vendor/buildr/lib/buildr/java/doc.rb +86 -0
  139. data/vendor/buildr/lib/buildr/java/ecj.rb +69 -0
  140. data/vendor/buildr/lib/buildr/java/emma.rb +244 -0
  141. data/vendor/buildr/lib/buildr/java/external.rb +73 -0
  142. data/vendor/buildr/lib/buildr/java/jruby.rb +122 -0
  143. data/vendor/buildr/lib/buildr/java/jtestr_result.rb +295 -0
  144. data/vendor/buildr/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  145. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  146. data/vendor/buildr/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  147. data/vendor/buildr/lib/buildr/java/packaging.rb +734 -0
  148. data/vendor/buildr/lib/buildr/java/pom.rb +178 -0
  149. data/vendor/buildr/lib/buildr/java/rjb.rb +154 -0
  150. data/vendor/buildr/lib/buildr/java/test_result.rb +101 -0
  151. data/vendor/buildr/lib/buildr/java/tests.rb +362 -0
  152. data/vendor/buildr/lib/buildr/java/version_requirement.rb +172 -0
  153. data/vendor/buildr/lib/buildr/packaging.rb +25 -0
  154. data/vendor/buildr/lib/buildr/packaging/archive.rb +535 -0
  155. data/vendor/buildr/lib/buildr/packaging/artifact.rb +903 -0
  156. data/vendor/buildr/lib/buildr/packaging/artifact_namespace.rb +984 -0
  157. data/vendor/buildr/lib/buildr/packaging/artifact_search.rb +140 -0
  158. data/vendor/buildr/lib/buildr/packaging/gems.rb +105 -0
  159. data/vendor/buildr/lib/buildr/packaging/package.rb +249 -0
  160. data/vendor/buildr/lib/buildr/packaging/tar.rb +189 -0
  161. data/vendor/buildr/lib/buildr/packaging/version_requirement.rb +192 -0
  162. data/vendor/buildr/lib/buildr/packaging/zip.rb +178 -0
  163. data/vendor/buildr/lib/buildr/packaging/ziptask.rb +356 -0
  164. data/vendor/buildr/lib/buildr/resources/buildr.icns +0 -0
  165. data/vendor/buildr/lib/buildr/resources/completed.png +0 -0
  166. data/vendor/buildr/lib/buildr/resources/failed.png +0 -0
  167. data/vendor/buildr/lib/buildr/resources/icons-license.txt +17 -0
  168. data/vendor/buildr/lib/buildr/run.rb +195 -0
  169. data/vendor/buildr/lib/buildr/scala.rb +26 -0
  170. data/vendor/buildr/lib/buildr/scala/bdd.rb +118 -0
  171. data/vendor/buildr/lib/buildr/scala/compiler.rb +242 -0
  172. data/vendor/buildr/lib/buildr/scala/doc.rb +142 -0
  173. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  174. data/vendor/buildr/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  175. data/vendor/buildr/lib/buildr/scala/shell.rb +52 -0
  176. data/vendor/buildr/lib/buildr/scala/tests.rb +171 -0
  177. data/vendor/buildr/lib/buildr/shell.rb +185 -0
  178. data/vendor/buildr/lib/buildr/version.rb +18 -0
  179. data/vendor/buildr/rakelib/all-in-one.rake +113 -0
  180. data/vendor/buildr/rakelib/checks.rake +57 -0
  181. data/vendor/buildr/rakelib/doc.rake +137 -0
  182. data/vendor/buildr/rakelib/metrics.rake +39 -0
  183. data/vendor/buildr/rakelib/package.rake +73 -0
  184. data/vendor/buildr/rakelib/release.rake +161 -0
  185. data/vendor/buildr/rakelib/rspec.rake +101 -0
  186. data/vendor/buildr/rakelib/setup.rake +66 -0
  187. data/vendor/buildr/rakelib/stage.rake +220 -0
  188. data/vendor/buildr/spec/addon/bnd_spec.rb +330 -0
  189. data/vendor/buildr/spec/addon/drb_spec.rb +328 -0
  190. data/vendor/buildr/spec/addon/jaxb_xjc_spec.rb +125 -0
  191. data/vendor/buildr/spec/core/application_spec.rb +631 -0
  192. data/vendor/buildr/spec/core/build_spec.rb +837 -0
  193. data/vendor/buildr/spec/core/cc_spec.rb +224 -0
  194. data/vendor/buildr/spec/core/checks_spec.rb +519 -0
  195. data/vendor/buildr/spec/core/common_spec.rb +725 -0
  196. data/vendor/buildr/spec/core/compile_spec.rb +658 -0
  197. data/vendor/buildr/spec/core/doc_spec.rb +195 -0
  198. data/vendor/buildr/spec/core/extension_spec.rb +201 -0
  199. data/vendor/buildr/spec/core/generate_spec.rb +33 -0
  200. data/vendor/buildr/spec/core/project_spec.rb +772 -0
  201. data/vendor/buildr/spec/core/run_spec.rb +93 -0
  202. data/vendor/buildr/spec/core/shell_spec.rb +146 -0
  203. data/vendor/buildr/spec/core/test_spec.rb +1320 -0
  204. data/vendor/buildr/spec/core/transport_spec.rb +544 -0
  205. data/vendor/buildr/spec/core/util_spec.rb +141 -0
  206. data/vendor/buildr/spec/groovy/bdd_spec.rb +80 -0
  207. data/vendor/buildr/spec/groovy/compiler_spec.rb +251 -0
  208. data/vendor/buildr/spec/groovy/doc_spec.rb +65 -0
  209. data/vendor/buildr/spec/ide/eclipse_spec.rb +739 -0
  210. data/vendor/buildr/spec/ide/idea_spec.rb +1144 -0
  211. data/vendor/buildr/spec/java/ant_spec.rb +37 -0
  212. data/vendor/buildr/spec/java/bdd_spec.rb +374 -0
  213. data/vendor/buildr/spec/java/cobertura_spec.rb +112 -0
  214. data/vendor/buildr/spec/java/commands_spec.rb +93 -0
  215. data/vendor/buildr/spec/java/compiler_spec.rb +252 -0
  216. data/vendor/buildr/spec/java/doc_spec.rb +56 -0
  217. data/vendor/buildr/spec/java/ecj_spec.rb +115 -0
  218. data/vendor/buildr/spec/java/emma_spec.rb +121 -0
  219. data/vendor/buildr/spec/java/external_spec.rb +56 -0
  220. data/vendor/buildr/spec/java/java_spec.rb +132 -0
  221. data/vendor/buildr/spec/java/packaging_spec.rb +1270 -0
  222. data/vendor/buildr/spec/java/run_spec.rb +78 -0
  223. data/vendor/buildr/spec/java/test_coverage_helper.rb +257 -0
  224. data/vendor/buildr/spec/java/tests_spec.rb +497 -0
  225. data/vendor/buildr/spec/packaging/archive_spec.rb +775 -0
  226. data/vendor/buildr/spec/packaging/artifact_namespace_spec.rb +743 -0
  227. data/vendor/buildr/spec/packaging/artifact_spec.rb +1066 -0
  228. data/vendor/buildr/spec/packaging/packaging_helper.rb +63 -0
  229. data/vendor/buildr/spec/packaging/packaging_spec.rb +719 -0
  230. data/vendor/buildr/spec/sandbox.rb +165 -0
  231. data/vendor/buildr/spec/scala/bdd_spec.rb +124 -0
  232. data/vendor/buildr/spec/scala/compiler_spec.rb +289 -0
  233. data/vendor/buildr/spec/scala/doc_spec.rb +88 -0
  234. data/vendor/buildr/spec/scala/scala.rb +38 -0
  235. data/vendor/buildr/spec/scala/tests_spec.rb +283 -0
  236. data/vendor/buildr/spec/spec_helpers.rb +369 -0
  237. data/vendor/buildr/spec/version_requirement_spec.rb +143 -0
  238. data/vendor/buildr/spec/xpath_matchers.rb +121 -0
  239. data/vendor/buildr/tests/BUILDR-320/Buildfile +29 -0
  240. data/vendor/buildr/tests/JavaSystemProperty/Buildfile +18 -0
  241. data/vendor/buildr/tests/JavaSystemProperty/src/test/java/FooTest.java +24 -0
  242. data/vendor/buildr/tests/compile_with_parent/Buildfile +18 -0
  243. data/vendor/buildr/tests/compile_with_parent/child/src/main/java/Foo.java +23 -0
  244. data/vendor/buildr/tests/helloWorld/Buildfile +20 -0
  245. data/vendor/buildr/tests/helloWorld/src/main/java/HelloWorld.java +23 -0
  246. data/vendor/buildr/tests/integration_testing.rb +56 -0
  247. data/vendor/buildr/tests/junit3/Buildfile +9 -0
  248. data/vendor/buildr/tests/junit3/src/main/java/Foo.java +23 -0
  249. data/vendor/buildr/tests/junit3/src/test/java/FooTest.java +28 -0
  250. data/vendor/buildr/tests/package_war_as_jar/Buildfile +15 -0
  251. data/vendor/buildr/tests/package_war_as_jar/src/main/java/Foo.java +19 -0
  252. metadata +524 -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