buildr 1.3.5-x86-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,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.join(File.dirname(__FILE__), '../spec_helpers')
18
+
19
+ describe 'scala' do
20
+ # Specific version of Scala required for specs
21
+ required_version = '2.7.3'
22
+ scala_version_str = "version 2.7.3.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,261 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+ require 'buildr/scala'
19
+
20
+ # TODO's
21
+ # -test passing System props
22
+ # -test passing ENV variables
23
+ # -test exclude group
24
+ # -test include Suite's
25
+ # -test exclude Suite's
26
+
27
+
28
+ describe Buildr::Scala::ScalaTest do
29
+ it 'should be the default test framework when test cases are in Scala' do
30
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
31
+ package com.example
32
+ import org.scalatest.FunSuite
33
+ class MySuite extends FunSuite {
34
+ test("addition") {
35
+ val sum = 1 + 1
36
+ assert(sum === 2)
37
+ }
38
+ }
39
+ SCALA
40
+ define 'foo'
41
+ project('foo').test.framework.should eql(:scalatest)
42
+ end
43
+
44
+ it 'should include Scalatest dependencies' do
45
+ define('foo') { test.using(:scalatest) }
46
+ project('foo').test.compile.dependencies.should include(*artifacts(Scala::ScalaTest.dependencies))
47
+ project('foo').test.dependencies.should include(*artifacts(Scala::ScalaTest.dependencies))
48
+ end
49
+
50
+ it 'should include JMock dependencies' do
51
+ define('foo') { test.using(:scalatest) }
52
+ project('foo').test.compile.dependencies.should include(*artifacts(JMock.dependencies))
53
+ project('foo').test.dependencies.should include(*artifacts(JMock.dependencies))
54
+ end
55
+
56
+ it 'should include ScalaCheck dependencies' do
57
+ define('foo') { test.using(:scalatest) }
58
+ project('foo').test.compile.dependencies.should include(*artifacts(Scala::Check.dependencies))
59
+ project('foo').test.dependencies.should include(*artifacts(Scala::Check.dependencies))
60
+ end
61
+
62
+ it 'should set current directory' do
63
+ mkpath 'baz'
64
+ expected = File.expand_path('baz')
65
+ expected.gsub!('/', '\\') if expected =~ /^[A-Z]:/ # Java returns back slashed paths for windows
66
+ write 'baz/src/test/scala/CurrentDirectoryTestSuite.scala', <<-SCALA
67
+ class CurrentDirectoryTestSuite extends org.scalatest.FunSuite {
68
+ test("testCurrentDirectory") {
69
+ assert("value" === System.getenv("NAME"))
70
+ assert(#{expected.inspect} === new java.io.File(".").getCanonicalPath())
71
+ }
72
+ }
73
+ SCALA
74
+ define 'bar' do
75
+ define 'baz' do
76
+ test.include 'CurrentDirectoryTest'
77
+ end
78
+ end
79
+ project('bar:baz').test.invoke
80
+ end
81
+
82
+ it 'should include public classes extending org.scalatest.FunSuite' do
83
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
84
+ package com.example
85
+ import org.scalatest.FunSuite
86
+ class MySuite extends FunSuite {
87
+ test("addition") {
88
+ val sum = 1 + 1
89
+ assert(sum === 2)
90
+ }
91
+ }
92
+ SCALA
93
+ define('foo').test.invoke
94
+ project('foo').test.tests.should include('com.example.MySuite')
95
+ end
96
+
97
+ it 'should ignore classes not extending org.scalatest.FunSuite' do
98
+ write 'src/test/scala/com/example/NotASuite.scala', <<-SCALA
99
+ package com.example
100
+ class Another {
101
+ }
102
+ SCALA
103
+ define('foo').test.invoke
104
+ project('foo').test.tests.should be_empty
105
+ end
106
+
107
+ it 'should ignore inner classes' do
108
+ write 'src/test/scala/com/example/InnerClassTest.scala', <<-SCALA
109
+ package com.example
110
+ import org.scalatest.FunSuite
111
+ class InnerClassTest extends FunSuite {
112
+ test("addition") {
113
+ val sum = 1 + 1
114
+ assert(sum === 2)
115
+ }
116
+
117
+ class InnerSuite extends FunSuite {
118
+ test("addition") {
119
+ val sum = 1 + 1
120
+ assert(sum === 2)
121
+ }
122
+ }
123
+ }
124
+ SCALA
125
+ define('foo').test.invoke
126
+ project('foo').test.tests.should eql(['com.example.InnerClassTest'])
127
+ end
128
+
129
+ it 'should pass when ScalaTest test case passes' do
130
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
131
+ class PassingSuite extends org.scalatest.FunSuite {
132
+ test("addition") {
133
+ val sum = 1 + 1
134
+ assert(sum === 2)
135
+ }
136
+ }
137
+ SCALA
138
+ lambda { define('foo').test.invoke }.should_not raise_error
139
+ end
140
+
141
+ it 'should fail when ScalaTest test case fails' do
142
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
143
+ class FailingSuite extends org.scalatest.FunSuite {
144
+ test("failing") {
145
+ assert(false)
146
+ }
147
+ }
148
+ SCALA
149
+ lambda { define('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/) rescue nil
150
+ end
151
+
152
+ it 'should report failed test names' do
153
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
154
+ class FailingSuite extends org.scalatest.FunSuite {
155
+ test("failing") {
156
+ assert(false)
157
+ }
158
+ }
159
+ SCALA
160
+ define('foo').test.invoke rescue
161
+ project('foo').test.failed_tests.should include('FailingSuite')
162
+ end
163
+
164
+ it 'should report to reports/scalatest/TEST-TestSuiteName.txt' do
165
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
166
+ class PassingSuite extends org.scalatest.FunSuite {
167
+ test("passing") {
168
+ assert(true)
169
+ }
170
+ }
171
+ SCALA
172
+ define 'foo' do
173
+ test.report_to.should be(file('reports/scalatest'))
174
+ end
175
+ project('foo').test.invoke
176
+ project('foo').file('reports/scalatest/TEST-PassingSuite.txt').should exist
177
+ end
178
+
179
+ it 'should pass properties to Suite' do
180
+ write 'src/test/scala/PropertyTestSuite.scala', <<-SCALA
181
+ import org.scalatest._
182
+ class PropertyTestSuite extends FunSuite {
183
+ var properties = Map[String, Any]()
184
+ test("testProperty") {
185
+ assert(properties("name") === "value")
186
+ }
187
+
188
+ protected override def runTests(testName: Option[String], reporter: Reporter, stopper: Stopper,
189
+ includes: Set[String], excludes: Set[String], properties: Map[String, Any]) {
190
+ this.properties = properties;
191
+ super.runTests(testName, reporter, stopper, includes, excludes, properties)
192
+ }
193
+ }
194
+ SCALA
195
+ define('foo').test.using :properties=>{ 'name'=>'value' }
196
+ project('foo').test.invoke
197
+ end
198
+
199
+ it 'should run with ScalaCheck automatic test case generation' do
200
+ write 'src/test/scala/MySuite.scala', <<-SCALA
201
+ import org.scalatest.prop.PropSuite
202
+ import org.scalacheck.Arbitrary._
203
+ import org.scalacheck.Prop._
204
+
205
+ class MySuite extends PropSuite {
206
+
207
+ test("list concatenation") {
208
+ val x = List(1, 2, 3)
209
+ val y = List(4, 5, 6)
210
+ assert(x ::: y === List(1, 2, 3, 4, 5, 6))
211
+ check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size)
212
+ }
213
+
214
+ test(
215
+ "list concatenation using a test method",
216
+ (a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size
217
+ )
218
+ }
219
+ SCALA
220
+ define('foo')
221
+ project('foo').test.invoke
222
+ project('foo').test.passed_tests.should include('MySuite')
223
+ end
224
+
225
+ it 'should fail if ScalaCheck test case fails' do
226
+ write 'src/test/scala/StringSuite.scala', <<-SCALA
227
+ import org.scalatest.prop.PropSuite
228
+ import org.scalacheck.Arbitrary._
229
+ import org.scalacheck.Prop._
230
+
231
+ class StringSuite extends PropSuite {
232
+ test("startsWith") {
233
+ check( (a: String, b: String) => (a+b).startsWith(a) )
234
+ }
235
+
236
+ test("endsWith") {
237
+ check( (a: String, b: String) => (a+b).endsWith(b) )
238
+ }
239
+
240
+ // Is this really always true?
241
+ test("concat") {
242
+ check( (a: String, b: String) => (a+b).length > a.length && (a+b).length > b.length )
243
+ }
244
+
245
+ test("substring2") {
246
+ check( (a: String, b: String) => (a+b).substring(a.length) == b )
247
+ }
248
+
249
+ test("substring3") {
250
+ check( (a: String, b: String, c: String) =>
251
+ (a+b+c).substring(a.length, a.length+b.length) == b )
252
+ }
253
+ }
254
+ SCALA
255
+ define('foo')
256
+ project('foo').test.invoke rescue
257
+ project('foo').test.failed_tests.should include('StringSuite')
258
+ end
259
+
260
+ end
261
+
@@ -0,0 +1,340 @@
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
+ spec.dependencies.each { |dep| gem dep.name, dep.version_requirements.to_s }
26
+
27
+ # Make sure to load from these paths first, we don't want to load any
28
+ # code from Gem library.
29
+ $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)),
30
+ File.expand_path('../addon', File.dirname(__FILE__))
31
+
32
+ # Buildr uses autoload extensively, but autoload when running specs creates
33
+ # a problem -- we sandbox $LOADED_FEATURES, so we endup autoloading the same
34
+ # module twice. This turns autoload into a require, which is not the right
35
+ # thing, but will do for now.
36
+ def autoload(symbol, path)
37
+ require path
38
+ end
39
+ require 'buildr'
40
+
41
+ # Give a chance for plugins to do a few things before requiring the sandbox.
42
+ include SandboxHook if defined?(SandboxHook)
43
+
44
+ require File.expand_path('sandbox', File.dirname(__FILE__))
45
+
46
+ module SpecHelpers
47
+
48
+ include Checks::Matchers
49
+
50
+ [:info, :warn, :error, :puts].each do |severity|
51
+ ::Object.class_eval do
52
+ define_method severity do |*args|
53
+ $messages ||= {}
54
+ $messages[severity] ||= []
55
+ $messages[severity].push(*args)
56
+ end
57
+ end
58
+ end
59
+
60
+ class << Buildr.application
61
+ alias :deprecated_without_capture :deprecated
62
+ def deprecated(message)
63
+ verbose(true) { deprecated_without_capture message }
64
+ end
65
+ end
66
+
67
+ class MessageWithSeverityMatcher
68
+ def initialize(severity, message)
69
+ @severity = severity
70
+ @expect = message
71
+ end
72
+
73
+ def matches?(target)
74
+ $messages = {@severity => []}
75
+ target.call
76
+ return Regexp === @expect ? $messages[@severity].join('\n') =~ @expect : $messages[@severity].include?(@expect.to_s)
77
+ end
78
+
79
+ def failure_message
80
+ "Expected #{@severity} #{@expect.inspect}, " +
81
+ ($messages[@severity].empty? ? "no #{@severity} issued" : "found #{$messages[@severity].inspect}")
82
+ end
83
+
84
+ def negative_failure_message
85
+ "Found unexpected #{$messages[@severity].inspect}"
86
+ end
87
+ end
88
+
89
+ # Test if an info message was shown. You can use a string or regular expression.
90
+ #
91
+ # For example:
92
+ # lambda { info 'ze test' }.should show_info(/ze test/)
93
+ def show_info(message)
94
+ MessageWithSeverityMatcher.new :info, message
95
+ end
96
+
97
+ # Test if a warning was shown. You can use a string or regular expression.
98
+ #
99
+ # For example:
100
+ # lambda { warn 'ze test' }.should show_warning(/ze test/)
101
+ def show_warning(message)
102
+ MessageWithSeverityMatcher.new :warn, message
103
+ end
104
+
105
+ # Test if an error message was shown. You can use a string or regular expression.
106
+ #
107
+ # For example:
108
+ # lambda { error 'ze test' }.should show_error(/ze test/)
109
+ def show_error(message)
110
+ MessageWithSeverityMatcher.new :error, message
111
+ end
112
+
113
+ # Test if any message was shown (puts). You can use a string or regular expression.
114
+ #
115
+ # For example:
116
+ # lambda { puts 'ze test' }.should show(/ze test/)
117
+ def show(message)
118
+ MessageWithSeverityMatcher.new :puts, message
119
+ end
120
+
121
+ class ::Rake::Task
122
+ alias :execute_without_a_record :execute
123
+ def execute(args)
124
+ $executed ||= []
125
+ $executed << name
126
+ execute_without_a_record args
127
+ end
128
+ end
129
+
130
+ class InvokeMatcher
131
+ def initialize(*tasks)
132
+ @expecting = tasks.map { |task| [task].flatten.map(&:to_s) }
133
+ end
134
+
135
+ def matches?(target)
136
+ $executed = []
137
+ target.call
138
+ return false unless all_ran?
139
+ return !@but_not.any_ran? if @but_not
140
+ return true
141
+ end
142
+
143
+ def failure_message
144
+ return @but_not.negative_failure_message if all_ran? && @but_not
145
+ "Expected the tasks #{expected} to run, but #{remaining} did not run, or not in the order we expected them to." +
146
+ " Tasks that ran: #{$executed.inspect}"
147
+ end
148
+
149
+ def negative_failure_message
150
+ if all_ran?
151
+ "Expected the tasks #{expected} to not run, but they all ran."
152
+ else
153
+ "Expected the tasks #{expected} to not run, and all but #{remaining} ran."
154
+ end
155
+ end
156
+
157
+ def but_not(*tasks)
158
+ @but_not = InvokeMatcher.new(*tasks)
159
+ self
160
+ end
161
+
162
+ protected
163
+
164
+ def expected
165
+ @expecting.map { |tests| tests.join('=>') }.join(', ')
166
+ end
167
+
168
+ def remaining
169
+ @remaining.map { |tests| tests.join('=>') }.join(', ')
170
+ end
171
+
172
+ def all_ran?
173
+ @remaining ||= $executed.inject(@expecting) do |expecting, executed|
174
+ expecting.map { |tasks| tasks.first == executed ? tasks[1..-1] : tasks }.reject(&:empty?)
175
+ end
176
+ @remaining.empty?
177
+ end
178
+
179
+ def any_ran?
180
+ all_ran?
181
+ @remaining.size < @expecting.size
182
+ end
183
+
184
+ end
185
+
186
+ # Tests that all the tasks ran, in the order specified. Can also be used to test that some
187
+ # tasks and not others ran.
188
+ #
189
+ # Takes a list of arguments. Each argument can be a task name, matching only if that task ran.
190
+ # Each argument can be an array of task names, matching only if all these tasks ran in that order.
191
+ # So run_tasks('foo', 'bar') expects foo and bar to run in any order, but run_task(['foo', 'bar'])
192
+ # expects foo to run before bar.
193
+ #
194
+ # You can call but_not on the matchers to specify that certain tasks must not execute.
195
+ #
196
+ # For example:
197
+ # # Either task
198
+ # lambda { task('compile').invoke }.should run_tasks('compile', 'resources')
199
+ # # In that order
200
+ # lambda { task('build').invoke }.should run_tasks(['compile', 'test'])
201
+ # # With exclusion
202
+ # lambda { task('build').invoke }.should run_tasks('compile').but_not('install')
203
+ def run_tasks(*tasks)
204
+ InvokeMatcher.new *tasks
205
+ end
206
+
207
+ # Tests that a task ran. Similar to run_tasks, but accepts a single task name.
208
+ #
209
+ # For example:
210
+ # lambda { task('build').invoke }.should run_task('test')
211
+ def run_task(task)
212
+ InvokeMatcher.new [task]
213
+ end
214
+
215
+ class UriPathMatcher
216
+ def initialize(re)
217
+ @expression = re
218
+ end
219
+
220
+ def matches?(uri)
221
+ @uri = uri
222
+ uri.path =~ @expression
223
+ end
224
+
225
+ def description
226
+ "URI with path matching #{@expression}"
227
+ end
228
+ end
229
+
230
+ # Matches a parsed URI's path against the given regular expression
231
+ def uri(re)
232
+ UriPathMatcher.new(re)
233
+ end
234
+
235
+
236
+ class AbsolutePathMatcher
237
+ def initialize(path)
238
+ @expected = File.expand_path(path.to_s)
239
+ end
240
+
241
+ def matches?(path)
242
+ @provided = File.expand_path(path.to_s)
243
+ @provided == @expected
244
+ end
245
+
246
+ def failure_message
247
+ "Expected path #{@expected}, but found path #{@provided}"
248
+ end
249
+
250
+ def negative_failure_message
251
+ "Expected a path other than #{@expected}"
252
+ end
253
+ end
254
+
255
+ def point_to_path(path)
256
+ AbsolutePathMatcher.new(path)
257
+ end
258
+
259
+
260
+ # Value covered by range. For example:
261
+ # (1..5).should cover(3)
262
+ def cover(value)
263
+ simple_matcher :cover do |given|
264
+ value >= given.min && value <= given.max
265
+ end
266
+ end
267
+
268
+
269
+ def suppress_stdout
270
+ stdout = $stdout
271
+ $stdout = StringIO.new
272
+ begin
273
+ yield
274
+ ensure
275
+ $stdout = stdout
276
+ end
277
+ end
278
+
279
+ def dryrun
280
+ Buildr.application.options.dryrun = true
281
+ begin
282
+ suppress_stdout { yield }
283
+ ensure
284
+ Buildr.application.options.dryrun = false
285
+ end
286
+ end
287
+
288
+ # We run tests with tracing off. Then things break. And we need to figure out what went wrong.
289
+ # So just use trace() as you would use verbose() to find and squash the bug.
290
+ def trace(value = nil)
291
+ old_value = Buildr.application.options.trace
292
+ Buildr.application.options.trace = value unless value.nil?
293
+ if block_given?
294
+ begin
295
+ yield
296
+ ensure
297
+ Buildr.application.options.trace = old_value
298
+ end
299
+ end
300
+ Buildr.application.options.trace
301
+ end
302
+
303
+ # Change the Buildr original directory, faking invocation from a different directory.
304
+ def in_original_dir(dir)
305
+ begin
306
+ original_dir = Buildr.application.original_dir
307
+ Buildr.application.instance_eval { @original_dir = File.expand_path(dir) }
308
+ yield
309
+ ensure
310
+ Buildr.application.instance_eval { @original_dir = original_dir }
311
+ end
312
+ end
313
+
314
+
315
+ # Buildr's define method creates a project definition but does not evaluate it
316
+ # (that happens once the buildfile is loaded), and we include Buildr's define in
317
+ # the test context so we can use it without prefixing with Buildr. This just patches
318
+ # define to evaluate the project definition before returning it.
319
+ def define(name, properties = nil, &block) #:yields:project
320
+ Project.define(name, properties, &block).tap { |project| project.invoke }
321
+ end
322
+
323
+ end
324
+
325
+
326
+ # Allow using matchers within the project definition.
327
+ class Buildr::Project
328
+ include ::Spec::Matchers, SpecHelpers
329
+ end
330
+
331
+
332
+ Spec::Runner.configure do |config|
333
+ # Make all Buildr methods accessible from test cases, and add various helper methods.
334
+ config.include Buildr, SpecHelpers
335
+
336
+ # Sanbdox Buildr for each test.
337
+ config.include Sandbox
338
+ end
339
+
340
+ end