mguymon-buildr 1.4.5-java

Sign up to get free protection for your applications and to get access to all the features.
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,88 @@
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
+ describe "Scaladoc" do
20
+
21
+ before(:each) do
22
+ # Force Scala 2.8.1 for specs; don't want to rely on SCALA_HOME
23
+ Buildr.settings.build['scala.version'] = "2.8.1"
24
+ end
25
+
26
+ it 'should pick -doc-title from project name by default' do
27
+ define 'foo' do
28
+ compile.using(:scalac)
29
+
30
+ define 'bar' do
31
+ compile.using(:scalac)
32
+ end
33
+ end
34
+
35
+ project('foo').doc.options[:"doc-title"].should eql('foo')
36
+ project('foo:bar').doc.options[:"doc-title"].should eql('foo:bar')
37
+ end
38
+
39
+ it 'should pick -doc-title from project description by default, if available' do
40
+ desc 'My App'
41
+ define 'foo' do
42
+ compile.using(:scalac)
43
+ end
44
+ project('foo').doc.options[:"doc-title"].should eql('My App')
45
+ end
46
+
47
+ it 'should not override explicit "doc-title" option' do
48
+ define 'foo' do
49
+ compile.using(:scalac)
50
+ doc.using "doc-title" => 'explicit'
51
+ end
52
+ project('foo').doc.options[:"doc-title"].should eql('explicit')
53
+ end
54
+
55
+ it 'should convert :windowtitle to -doc-title for Scala 2.8.1' do
56
+ write 'src/main/scala/com/example/Test.scala', 'package com.example; class Test { val i = 1 }'
57
+ define('foo') do
58
+ doc.using :windowtitle => "foo"
59
+ end
60
+ Java.scala.tools.nsc.ScalaDoc.should_receive(:process) do |args|
61
+ # Convert Java Strings to Ruby Strings, if needed.
62
+ args.map { |a| a.is_a?(String) ? a : a.toString }.should include("-doc-title")
63
+ 0 # normal return
64
+ end
65
+ project('foo').doc.invoke
66
+ end
67
+ end
68
+
69
+ describe "package(:scaladoc)" do
70
+ it "should generate target/project-version-scaladoc.jar" do
71
+ write 'src/main/scala/Foo.scala', 'class Foo'
72
+ define 'foo', :version=>'1.0' do
73
+ package(:scaladoc)
74
+ end
75
+
76
+ scaladoc = project('foo').package(:scaladoc)
77
+ scaladoc.should point_to_path('target/foo-1.0-scaladoc.jar')
78
+
79
+ lambda {
80
+ project('foo').task('package').invoke
81
+ }.should change { File.exist?('target/foo-1.0-scaladoc.jar') }.to(true)
82
+
83
+ scaladoc.should exist
84
+ scaladoc.should contain('index.html')
85
+ scaladoc.should contain('Foo.html')
86
+ end
87
+ end
88
+
@@ -0,0 +1,38 @@
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
+ describe 'scala' do
20
+ # Specific version of Scala required for specs
21
+ required_version = '2.8.1'
22
+ scala_version_str = "2.8.1.final"
23
+
24
+ it 'should automatically add the remote scala-tools.org repository' do
25
+ # NOTE: the sandbox environment clears "repositories.remote" so we can't
26
+ # test for this spec right now.
27
+ #
28
+ # repositories.remote.should include('http://scala-tools.org/repo-releases')
29
+ end
30
+
31
+ it "specifications require Scala #{required_version}" do
32
+ Scala.version.should eql(required_version)
33
+ end
34
+
35
+ it "should provide the Scala version string" do
36
+ Scala.version_str.should eql(scala_version_str)
37
+ end
38
+ end
@@ -0,0 +1,283 @@
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
+ # TODO's
20
+ # -test passing System props
21
+ # -test passing ENV variables
22
+ # -test exclude group
23
+ # -test include Suite's
24
+ # -test exclude Suite's
25
+
26
+
27
+ describe Buildr::Scala::ScalaTest do
28
+
29
+ before(:each) do
30
+ # Force Scala 2.8.1 for specs; don't want to rely on SCALA_HOME
31
+ Buildr.settings.build['scala.version'] = "2.8.1"
32
+ end
33
+
34
+ it 'should be the default test framework when test cases are in Scala' do
35
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
36
+ package com.example
37
+ import org.scalatest.FunSuite
38
+ class MySuite extends FunSuite {
39
+ test("addition") {
40
+ val sum = 1 + 1
41
+ assert(sum === 2)
42
+ }
43
+ }
44
+ SCALA
45
+ define 'foo'
46
+ project('foo').test.framework.should eql(:scalatest)
47
+ end
48
+
49
+ it 'should include Scalatest dependencies' do
50
+ define('foo') { test.using(:scalatest) }
51
+ project('foo').test.compile.dependencies.should include(*artifacts(Scala::ScalaTest.dependencies))
52
+ project('foo').test.dependencies.should include(*artifacts(Scala::ScalaTest.dependencies))
53
+ end
54
+
55
+ it 'should include JMock dependencies' do
56
+ define('foo') { test.using(:scalatest) }
57
+ project('foo').test.compile.dependencies.should include(*artifacts(JMock.dependencies))
58
+ project('foo').test.dependencies.should include(*artifacts(JMock.dependencies))
59
+ end
60
+
61
+ it 'should include ScalaCheck dependencies' do
62
+ define('foo') { test.using(:scalatest) }
63
+ project('foo').test.compile.dependencies.should include(*artifacts(Scala::Check.dependencies))
64
+ project('foo').test.dependencies.should include(*artifacts(Scala::Check.dependencies))
65
+ end
66
+
67
+ it 'should set current directory' do
68
+ mkpath 'baz'
69
+ expected = File.expand_path('baz')
70
+ expected.gsub!('/', '\\') if expected =~ /^[A-Z]:/ # Java returns back slashed paths for windows
71
+ write 'baz/src/test/scala/CurrentDirectoryTestSuite.scala', <<-SCALA
72
+ class CurrentDirectoryTestSuite extends org.scalatest.FunSuite {
73
+ test("testCurrentDirectory") {
74
+ assert("value" === System.getenv("NAME"))
75
+ assert(#{expected.inspect} === new java.io.File(".").getCanonicalPath())
76
+ }
77
+ }
78
+ SCALA
79
+ define 'bar' do
80
+ define 'baz' do
81
+ test.include 'CurrentDirectoryTest'
82
+ end
83
+ end
84
+ project('bar:baz').test.invoke
85
+ end
86
+
87
+ it 'should include public classes extending org.scalatest.FunSuite' do
88
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
89
+ package com.example
90
+ import org.scalatest.FunSuite
91
+ class MySuite extends FunSuite {
92
+ test("addition") {
93
+ val sum = 1 + 1
94
+ assert(sum === 2)
95
+ }
96
+ }
97
+ SCALA
98
+ define('foo').test.invoke
99
+ project('foo').test.tests.should include('com.example.MySuite')
100
+ end
101
+
102
+ it 'should ignore classes not extending org.scalatest.FunSuite' do
103
+ write 'src/test/scala/com/example/NotASuite.scala', <<-SCALA
104
+ package com.example
105
+ class Another {
106
+ }
107
+ SCALA
108
+ define('foo').test.invoke
109
+ project('foo').test.tests.should be_empty
110
+ end
111
+
112
+ it 'should ignore inner classes' do
113
+ write 'src/test/scala/com/example/InnerClassTest.scala', <<-SCALA
114
+ package com.example
115
+ import org.scalatest.FunSuite
116
+ class InnerClassTest extends FunSuite {
117
+ test("addition") {
118
+ val sum = 1 + 1
119
+ assert(sum === 2)
120
+ }
121
+
122
+ class InnerSuite extends FunSuite {
123
+ test("addition") {
124
+ val sum = 1 + 1
125
+ assert(sum === 2)
126
+ }
127
+ }
128
+ }
129
+ SCALA
130
+ define('foo').test.invoke
131
+ project('foo').test.tests.should eql(['com.example.InnerClassTest'])
132
+ end
133
+
134
+ it 'should pass when ScalaTest test case passes' do
135
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
136
+ class PassingSuite extends org.scalatest.FunSuite {
137
+ test("addition") {
138
+ val sum = 1 + 1
139
+ assert(sum === 2)
140
+ }
141
+ }
142
+ SCALA
143
+ lambda { define('foo').test.invoke }.should_not raise_error
144
+ end
145
+
146
+ it 'should fail when ScalaTest test case fails' do
147
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
148
+ class FailingSuite extends org.scalatest.FunSuite {
149
+ test("failing") {
150
+ assert(false)
151
+ }
152
+ }
153
+ SCALA
154
+ lambda { define('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/) rescue nil
155
+ end
156
+
157
+ it 'should report failed test names' do
158
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
159
+ class FailingSuite extends org.scalatest.FunSuite {
160
+ test("failing") {
161
+ assert(false)
162
+ }
163
+ }
164
+ SCALA
165
+ define('foo').test.invoke rescue
166
+ project('foo').test.failed_tests.should include('FailingSuite')
167
+ end
168
+
169
+ it 'should report to reports/scalatest/TEST-TestSuiteName.xml' do
170
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
171
+ class PassingSuite extends org.scalatest.FunSuite {
172
+ test("passing") {
173
+ assert(true)
174
+ }
175
+ }
176
+ SCALA
177
+ define 'foo' do
178
+ test.report_to.should be(file('reports/scalatest'))
179
+ end
180
+ project('foo').test.invoke
181
+ project('foo').file('reports/scalatest/TEST-PassingSuite.xml').should exist
182
+ end
183
+
184
+ it 'should report to reports/scalatest/TEST-TestSuiteName.txt' do
185
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
186
+ class PassingSuite extends org.scalatest.FunSuite {
187
+ test("passing") {
188
+ assert(true)
189
+ }
190
+ }
191
+ SCALA
192
+ define 'foo' do
193
+ test.report_to.should be(file('reports/scalatest'))
194
+ end
195
+ project('foo').test.invoke
196
+ project('foo').file('reports/scalatest/TEST-PassingSuite.txt').should exist
197
+ end
198
+
199
+ it 'should pass properties to Suite' do
200
+ write 'src/test/scala/PropertyTestSuite.scala', <<-SCALA
201
+ import org.scalatest._
202
+ class PropertyTestSuite extends FunSuite {
203
+ var configMap = Map[String, Any]()
204
+ test("testProperty") {
205
+ assert(configMap("name") === "value")
206
+ }
207
+
208
+ protected override def runTests(testName: Option[String], reporter: Reporter, stopper: Stopper,
209
+ filter: Filter, configMap: Map[String, Any],
210
+ distributor: Option[Distributor], tracker: Tracker) {
211
+ this.configMap = configMap
212
+ super.runTests(testName, reporter, stopper, filter, configMap, distributor, tracker)
213
+ }
214
+ }
215
+ SCALA
216
+ define('foo').test.using :properties=>{ 'name'=>'value' }
217
+ project('foo').test.invoke
218
+ end
219
+
220
+ it 'should run with ScalaCheck automatic test case generation' do
221
+ write 'src/test/scala/MySuite.scala', <<-SCALA
222
+ import org.scalatest.FunSuite
223
+ import org.scalatest.prop.Checkers
224
+ import org.scalacheck.Arbitrary._
225
+ import org.scalacheck.Prop._
226
+
227
+ class MySuite extends FunSuite with Checkers {
228
+
229
+ test("list concatenation") {
230
+ val x = List(1, 2, 3)
231
+ val y = List(4, 5, 6)
232
+ assert(x ::: y === List(1, 2, 3, 4, 5, 6))
233
+ check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size)
234
+ }
235
+
236
+ test("list concatenation using a test method") {
237
+ check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size)
238
+ }
239
+ }
240
+ SCALA
241
+ define('foo')
242
+ project('foo').test.invoke
243
+ project('foo').test.passed_tests.should include('MySuite')
244
+ end
245
+
246
+ it 'should fail if ScalaCheck test case fails' do
247
+ write 'src/test/scala/StringSuite.scala', <<-SCALA
248
+ import org.scalatest.FunSuite
249
+ import org.scalatest.prop.Checkers
250
+ import org.scalacheck.Arbitrary._
251
+ import org.scalacheck.Prop._
252
+
253
+ class StringSuite extends FunSuite with Checkers {
254
+ test("startsWith") {
255
+ check( (a: String, b: String) => (a+b).startsWith(a) )
256
+ }
257
+
258
+ test("endsWith") {
259
+ check( (a: String, b: String) => (a+b).endsWith(b) )
260
+ }
261
+
262
+ // Is this really always true?
263
+ test("concat") {
264
+ check( (a: String, b: String) => (a+b).length > a.length && (a+b).length > b.length )
265
+ }
266
+
267
+ test("substring2") {
268
+ check( (a: String, b: String) => (a+b).substring(a.length) == b )
269
+ }
270
+
271
+ test("substring3") {
272
+ check( (a: String, b: String, c: String) =>
273
+ (a+b+c).substring(a.length, a.length+b.length) == b )
274
+ }
275
+ }
276
+ SCALA
277
+ define('foo')
278
+ project('foo').test.invoke rescue
279
+ project('foo').test.failed_tests.should include('StringSuite')
280
+ end
281
+
282
+ end
283
+
@@ -0,0 +1,369 @@
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
+ # This file gets loaded twice when running 'spec spec/*' and not with pleasent results,
18
+ # so ignore the second attempt to load it.
19
+ unless defined?(SpecHelpers)
20
+
21
+ require 'rubygems'
22
+
23
+ # For testing we use the gem requirements specified on the buildr.gemspec
24
+ spec = Gem::Specification.load(File.expand_path('../buildr.gemspec', File.dirname(__FILE__)))
25
+ # Dependency.version_requirements deprecated in rubygems 1.3.6
26
+ spec.dependencies.select {|dep| dep.type == :runtime }.each { |dep| gem dep.name, (dep.respond_to?(:requirement) ? dep.requirement.to_s : dep.version_requirements.to_s) }
27
+
28
+ # Make sure to load from these paths first, we don't want to load any
29
+ # code from Gem library.
30
+ $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)),
31
+ File.expand_path('../addon', File.dirname(__FILE__))
32
+
33
+ # Buildr uses autoload extensively, but autoload when running specs creates
34
+ # a problem -- we sandbox $LOADED_FEATURES, so we endup autoloading the same
35
+ # module twice. This turns autoload into a require, which is not the right
36
+ # thing, but will do for now.
37
+ def autoload(symbol, path)
38
+ require path
39
+ end
40
+ require 'buildr'
41
+ # load ecj
42
+ require 'buildr/java/ecj'
43
+ #Make ecj appear as a compiler that doesn't apply:
44
+ class Buildr::Compiler::Ecj
45
+ class << self
46
+ def applies_to?(project, task)
47
+ false
48
+ end
49
+ end
50
+ end
51
+
52
+ # Give a chance for plugins to do a few things before requiring the sandbox.
53
+ include SandboxHook if defined?(SandboxHook)
54
+
55
+ require File.expand_path('sandbox', File.dirname(__FILE__))
56
+
57
+ module SpecHelpers
58
+
59
+ include Checks::Matchers
60
+
61
+ [:info, :warn, :error, :puts].each do |severity|
62
+ ::Object.class_eval do
63
+ define_method severity do |*args|
64
+ $messages ||= {}
65
+ $messages[severity] ||= []
66
+ $messages[severity].push(*args)
67
+ end
68
+ end
69
+ end
70
+
71
+ class << Buildr.application
72
+ alias :deprecated_without_capture :deprecated
73
+ def deprecated(message)
74
+ verbose(true) { deprecated_without_capture message }
75
+ end
76
+ end
77
+
78
+ class MessageWithSeverityMatcher
79
+ def initialize(severity, message)
80
+ @severity = severity
81
+ @expect = message
82
+ end
83
+
84
+ def matches?(target)
85
+ $messages = {@severity => []}
86
+ target.call
87
+ return Regexp === @expect ? $messages[@severity].join('\n') =~ @expect : $messages[@severity].include?(@expect.to_s)
88
+ end
89
+
90
+ def failure_message
91
+ "Expected #{@severity} #{@expect.inspect}, " +
92
+ ($messages[@severity].empty? ? "no #{@severity} issued" : "found #{$messages[@severity].inspect}")
93
+ end
94
+
95
+ def negative_failure_message
96
+ "Found unexpected #{$messages[@severity].inspect}"
97
+ end
98
+ end
99
+
100
+ # Test if an info message was shown. You can use a string or regular expression.
101
+ #
102
+ # For example:
103
+ # lambda { info 'ze test' }.should show_info(/ze test/)
104
+ def show_info(message)
105
+ MessageWithSeverityMatcher.new :info, message
106
+ end
107
+
108
+ # Test if a warning was shown. You can use a string or regular expression.
109
+ #
110
+ # For example:
111
+ # lambda { warn 'ze test' }.should show_warning(/ze test/)
112
+ def show_warning(message)
113
+ MessageWithSeverityMatcher.new :warn, message
114
+ end
115
+
116
+ # Test if an error message was shown. You can use a string or regular expression.
117
+ #
118
+ # For example:
119
+ # lambda { error 'ze test' }.should show_error(/ze test/)
120
+ def show_error(message)
121
+ MessageWithSeverityMatcher.new :error, message
122
+ end
123
+
124
+ # Test if any message was shown (puts). You can use a string or regular expression.
125
+ #
126
+ # For example:
127
+ # lambda { puts 'ze test' }.should show(/ze test/)
128
+ def show(message)
129
+ MessageWithSeverityMatcher.new :puts, message
130
+ end
131
+
132
+ # Yields a block that should try exiting the application.
133
+ # Accepts
134
+ #
135
+ # For example:
136
+ # test_exit(1) { puts "Hello" ; exit(1) }.should show("Hello")
137
+ #
138
+ def test_exit(status = nil)
139
+ return lambda {
140
+ begin
141
+ yield
142
+ raise "Exit was not called!"
143
+ rescue SystemExit => e
144
+ raise "Exit status incorrect! Expected: #{status}, got #{e.status}" if status && (e.status != status)
145
+ end
146
+ }
147
+ end
148
+
149
+ class ::Rake::Task
150
+ alias :execute_without_a_record :execute
151
+ def execute(args)
152
+ $executed ||= []
153
+ $executed << name
154
+ execute_without_a_record args
155
+ end
156
+ end
157
+
158
+ class InvokeMatcher
159
+ def initialize(*tasks)
160
+ @expecting = tasks.map { |task| [task].flatten.map(&:to_s) }
161
+ end
162
+
163
+ def matches?(target)
164
+ $executed = []
165
+ target.call
166
+ return false unless all_ran?
167
+ return !@but_not.any_ran? if @but_not
168
+ return true
169
+ end
170
+
171
+ def failure_message
172
+ return @but_not.negative_failure_message if all_ran? && @but_not
173
+ "Expected the tasks #{expected} to run, but #{remaining} did not run, or not in the order we expected them to." +
174
+ " Tasks that ran: #{$executed.inspect}"
175
+ end
176
+
177
+ def negative_failure_message
178
+ if all_ran?
179
+ "Expected the tasks #{expected} to not run, but they all ran."
180
+ else
181
+ "Expected the tasks #{expected} to not run, and all but #{remaining} ran."
182
+ end
183
+ end
184
+
185
+ def but_not(*tasks)
186
+ @but_not = InvokeMatcher.new(*tasks)
187
+ self
188
+ end
189
+
190
+ protected
191
+
192
+ def expected
193
+ @expecting.map { |tests| tests.join('=>') }.join(', ')
194
+ end
195
+
196
+ def remaining
197
+ @remaining.map { |tests| tests.join('=>') }.join(', ')
198
+ end
199
+
200
+ def all_ran?
201
+ @remaining ||= $executed.inject(@expecting) do |expecting, executed|
202
+ expecting.map { |tasks| tasks.first == executed ? tasks[1..-1] : tasks }.reject(&:empty?)
203
+ end
204
+ @remaining.empty?
205
+ end
206
+
207
+ def any_ran?
208
+ all_ran?
209
+ @remaining.size < @expecting.size
210
+ end
211
+
212
+ end
213
+
214
+ # Tests that all the tasks ran, in the order specified. Can also be used to test that some
215
+ # tasks and not others ran.
216
+ #
217
+ # Takes a list of arguments. Each argument can be a task name, matching only if that task ran.
218
+ # Each argument can be an array of task names, matching only if all these tasks ran in that order.
219
+ # So run_tasks('foo', 'bar') expects foo and bar to run in any order, but run_task(['foo', 'bar'])
220
+ # expects foo to run before bar.
221
+ #
222
+ # You can call but_not on the matchers to specify that certain tasks must not execute.
223
+ #
224
+ # For example:
225
+ # # Either task
226
+ # lambda { task('compile').invoke }.should run_tasks('compile', 'resources')
227
+ # # In that order
228
+ # lambda { task('build').invoke }.should run_tasks(['compile', 'test'])
229
+ # # With exclusion
230
+ # lambda { task('build').invoke }.should run_tasks('compile').but_not('install')
231
+ def run_tasks(*tasks)
232
+ InvokeMatcher.new *tasks
233
+ end
234
+
235
+ # Tests that a task ran. Similar to run_tasks, but accepts a single task name.
236
+ #
237
+ # For example:
238
+ # lambda { task('build').invoke }.should run_task('test')
239
+ def run_task(task)
240
+ InvokeMatcher.new [task]
241
+ end
242
+
243
+ class UriPathMatcher
244
+ def initialize(re)
245
+ @expression = re
246
+ end
247
+
248
+ def matches?(uri)
249
+ @uri = uri
250
+ uri.path =~ @expression
251
+ end
252
+
253
+ def description
254
+ "URI with path matching #{@expression}"
255
+ end
256
+ end
257
+
258
+ # Matches a parsed URI's path against the given regular expression
259
+ def uri(re)
260
+ UriPathMatcher.new(re)
261
+ end
262
+
263
+
264
+ class AbsolutePathMatcher
265
+ def initialize(path)
266
+ @expected = File.expand_path(path.to_s)
267
+ end
268
+
269
+ def matches?(path)
270
+ @provided = File.expand_path(path.to_s)
271
+ @provided == @expected
272
+ end
273
+
274
+ def failure_message
275
+ "Expected path #{@expected}, but found path #{@provided}"
276
+ end
277
+
278
+ def negative_failure_message
279
+ "Expected a path other than #{@expected}"
280
+ end
281
+ end
282
+
283
+ def point_to_path(path)
284
+ AbsolutePathMatcher.new(path)
285
+ end
286
+
287
+
288
+ # Value covered by range. For example:
289
+ # (1..5).should cover(3)
290
+ RSpec::Matchers.define :cover do |actual|
291
+ match do |range|
292
+ actual >= range.min && actual <= range.max
293
+ end
294
+ end
295
+
296
+
297
+ def suppress_stdout
298
+ stdout = $stdout
299
+ $stdout = StringIO.new
300
+ begin
301
+ yield
302
+ ensure
303
+ $stdout = stdout
304
+ end
305
+ end
306
+
307
+ def dryrun
308
+ Buildr.application.options.dryrun = true
309
+ begin
310
+ suppress_stdout { yield }
311
+ ensure
312
+ Buildr.application.options.dryrun = false
313
+ end
314
+ end
315
+
316
+ # We run tests with tracing off. Then things break. And we need to figure out what went wrong.
317
+ # So just use trace() as you would use verbose() to find and squash the bug.
318
+ def trace(value = nil)
319
+ old_value = Buildr.application.options.trace
320
+ Buildr.application.options.trace = value unless value.nil?
321
+ if block_given?
322
+ begin
323
+ yield
324
+ ensure
325
+ Buildr.application.options.trace = old_value
326
+ end
327
+ end
328
+ Buildr.application.options.trace
329
+ end
330
+
331
+ # Change the Buildr original directory, faking invocation from a different directory.
332
+ def in_original_dir(dir)
333
+ begin
334
+ original_dir = Buildr.application.original_dir
335
+ Buildr.application.instance_eval { @original_dir = File.expand_path(dir) }
336
+ yield
337
+ ensure
338
+ Buildr.application.instance_eval { @original_dir = original_dir }
339
+ end
340
+ end
341
+
342
+
343
+ # Buildr's define method creates a project definition but does not evaluate it
344
+ # (that happens once the buildfile is loaded), and we include Buildr's define in
345
+ # the test context so we can use it without prefixing with Buildr. This just patches
346
+ # define to evaluate the project definition before returning it.
347
+ def define(name, properties = nil, &block) #:yields:project
348
+ Project.define(name, properties, &block).tap { |project| project.invoke }
349
+ end
350
+
351
+ end
352
+
353
+
354
+ # Allow using matchers within the project definition.
355
+ class Buildr::Project
356
+ include ::RSpec::Matchers, SpecHelpers
357
+ end
358
+
359
+
360
+ ::RSpec.configure do |config|
361
+ # Make all Buildr methods accessible from test cases, and add various helper methods.
362
+ config.include Buildr
363
+ config.include SpecHelpers
364
+
365
+ # Sanbdox Buildr for each test.
366
+ config.include Sandbox
367
+ end
368
+
369
+ end