realityforge-buildr 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.md +3 -0
- data/Rakefile +50 -0
- data/addon/buildr/checkstyle-report.xsl +104 -0
- data/addon/buildr/checkstyle.rb +254 -0
- data/addon/buildr/git_auto_version.rb +36 -0
- data/addon/buildr/gpg.rb +90 -0
- data/addon/buildr/gwt.rb +413 -0
- data/addon/buildr/jacoco.rb +161 -0
- data/addon/buildr/pmd.rb +185 -0
- data/addon/buildr/single_intermediate_layout.rb +71 -0
- data/addon/buildr/spotbugs.rb +265 -0
- data/addon/buildr/top_level_generate_dir.rb +37 -0
- data/addon/buildr/wsgen.rb +192 -0
- data/bin/buildr +20 -0
- data/buildr.gemspec +61 -0
- data/lib/buildr.rb +86 -0
- data/lib/buildr/core/application.rb +705 -0
- data/lib/buildr/core/assets.rb +96 -0
- data/lib/buildr/core/build.rb +587 -0
- data/lib/buildr/core/common.rb +167 -0
- data/lib/buildr/core/compile.rb +599 -0
- data/lib/buildr/core/console.rb +124 -0
- data/lib/buildr/core/doc.rb +275 -0
- data/lib/buildr/core/environment.rb +128 -0
- data/lib/buildr/core/filter.rb +405 -0
- data/lib/buildr/core/help.rb +114 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +994 -0
- data/lib/buildr/core/test.rb +776 -0
- data/lib/buildr/core/transports.rb +456 -0
- data/lib/buildr/core/util.rb +77 -0
- data/lib/buildr/ide/idea.rb +1664 -0
- data/lib/buildr/java/commands.rb +230 -0
- data/lib/buildr/java/compiler.rb +85 -0
- data/lib/buildr/java/custom_pom.rb +300 -0
- data/lib/buildr/java/doc.rb +62 -0
- data/lib/buildr/java/packaging.rb +393 -0
- data/lib/buildr/java/pom.rb +191 -0
- data/lib/buildr/java/test_result.rb +54 -0
- data/lib/buildr/java/tests.rb +111 -0
- data/lib/buildr/packaging/archive.rb +586 -0
- data/lib/buildr/packaging/artifact.rb +1113 -0
- data/lib/buildr/packaging/artifact_namespace.rb +1010 -0
- data/lib/buildr/packaging/artifact_search.rb +138 -0
- data/lib/buildr/packaging/package.rb +237 -0
- data/lib/buildr/packaging/version_requirement.rb +189 -0
- data/lib/buildr/packaging/zip.rb +189 -0
- data/lib/buildr/packaging/ziptask.rb +387 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/release.rake +99 -0
- data/spec/addon/checkstyle_spec.rb +58 -0
- data/spec/core/application_spec.rb +576 -0
- data/spec/core/build_spec.rb +922 -0
- data/spec/core/common_spec.rb +670 -0
- data/spec/core/compile_spec.rb +656 -0
- data/spec/core/console_spec.rb +65 -0
- data/spec/core/doc_spec.rb +194 -0
- data/spec/core/extension_spec.rb +200 -0
- data/spec/core/project_spec.rb +736 -0
- data/spec/core/test_spec.rb +1131 -0
- data/spec/core/transport_spec.rb +452 -0
- data/spec/core/util_spec.rb +154 -0
- data/spec/ide/idea_spec.rb +1952 -0
- data/spec/java/commands_spec.rb +79 -0
- data/spec/java/compiler_spec.rb +274 -0
- data/spec/java/custom_pom_spec.rb +165 -0
- data/spec/java/doc_spec.rb +55 -0
- data/spec/java/packaging_spec.rb +786 -0
- data/spec/java/pom_spec.rb +162 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +224 -0
- data/spec/packaging/archive_spec.rb +686 -0
- data/spec/packaging/artifact_namespace_spec.rb +757 -0
- data/spec/packaging/artifact_spec.rb +1351 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +690 -0
- data/spec/sandbox.rb +166 -0
- data/spec/spec_helpers.rb +420 -0
- data/spec/version_requirement_spec.rb +145 -0
- data/spec/xpath_matchers.rb +123 -0
- metadata +295 -0
data/spec/sandbox.rb
ADDED
@@ -0,0 +1,166 @@
|
|
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
|
+
# The local repository we use for testing is void of any artifacts, which will break given
|
18
|
+
# that the code requires several artifacts. So we establish them first using the real local
|
19
|
+
# repository and cache these across test cases.
|
20
|
+
Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
|
21
|
+
repositories.remote << 'https://repo1.maven.org/maven2'
|
22
|
+
|
23
|
+
require 'rspec/retry'
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.verbose_retry = true # show retry status in spec process
|
26
|
+
end
|
27
|
+
|
28
|
+
artifacts(TestNG.dependencies).each do |path|
|
29
|
+
file(path).invoke
|
30
|
+
end
|
31
|
+
|
32
|
+
ENV['HOME'] = File.expand_path(File.join(File.dirname(__FILE__), '..', '_target', 'home'))
|
33
|
+
mkpath ENV['HOME']
|
34
|
+
|
35
|
+
# We need to run all tests inside a _sandbox, tacking a snapshot of Buildr before the test,
|
36
|
+
# and restoring everything to its previous state after the test. Damn state changes.
|
37
|
+
module Sandbox
|
38
|
+
|
39
|
+
class << self
|
40
|
+
attr_reader :tasks, :rules
|
41
|
+
|
42
|
+
def included(spec)
|
43
|
+
spec.before(:each) { sandbox }
|
44
|
+
spec.after(:each) { reset }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Require an optional extension without letting its callbacks pollute the Project class.
|
48
|
+
def require_optional_extension(extension_require_path)
|
49
|
+
project_callbacks_without_extension = Project.class_eval { @global_callbacks }.dup
|
50
|
+
begin
|
51
|
+
require extension_require_path
|
52
|
+
ensure
|
53
|
+
Project.class_eval { @global_callbacks = project_callbacks_without_extension }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@tasks = Buildr.application.tasks.collect do |original|
|
59
|
+
prerequisites = original.send(:prerequisites).map(&:to_s)
|
60
|
+
actions = original.instance_eval { @actions }.clone
|
61
|
+
lambda do
|
62
|
+
original.class.send(:define_task, original.name=>prerequisites).tap do |task|
|
63
|
+
task.comment = original.comment
|
64
|
+
actions.each { |action| task.enhance &action }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
@rules = Buildr.application.instance_variable_get(:@rules)
|
69
|
+
|
70
|
+
def sandbox
|
71
|
+
@_sandbox = {}
|
72
|
+
|
73
|
+
# Create a temporary directory where we can create files, e.g,
|
74
|
+
# for projects, compilation. We need a place that does not depend
|
75
|
+
# on the current directory.
|
76
|
+
@_sandbox[:original_dir] = Dir.pwd
|
77
|
+
@temp = File.join(File.dirname(__FILE__), '../_target/tmp')
|
78
|
+
FileUtils.mkpath @temp
|
79
|
+
Dir.chdir @temp
|
80
|
+
|
81
|
+
ARGV.clear
|
82
|
+
Buildr.application = Buildr::Application.new
|
83
|
+
Sandbox.tasks.each { |block| block.call }
|
84
|
+
Buildr.application.instance_variable_set :@rules, Sandbox.rules.clone
|
85
|
+
Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
|
86
|
+
|
87
|
+
@_sandbox[:load_path] = $LOAD_PATH.clone
|
88
|
+
|
89
|
+
# clear RUBYOPT since bundler hooks into it
|
90
|
+
# e.g. RUBYOPT=-I/usr/lib/ruby/gems/1.8/gems/bundler-1.0.15/lib -rbundler/setup
|
91
|
+
# and so Buildr's own Gemfile configuration taints e.g., JRuby's environment
|
92
|
+
@_sandbox[:ruby_opt] = ENV["RUBYOPT"]
|
93
|
+
ENV["RUBYOPT"] = nil
|
94
|
+
|
95
|
+
#@_sandbox[:loaded_features] = $LOADED_FEATURES.clone
|
96
|
+
|
97
|
+
# Later on we'll want to lose all the on_define created during the test.
|
98
|
+
@_sandbox[:on_define] = Project.class_eval { (@on_define || []).dup }
|
99
|
+
@_sandbox[:extension_modules] = Project.class_eval { (@extension_modules || []).dup }
|
100
|
+
@_sandbox[:global_callbacks] = Project.class_eval { (@global_callbacks || []).dup }
|
101
|
+
@_sandbox[:layout] = Layout.default.clone
|
102
|
+
|
103
|
+
# Create a local repository we can play with. However, our local repository will be void
|
104
|
+
# of some essential artifacts (e.g. JUnit artifacts required by build task), so we create
|
105
|
+
# these first (see above) and keep them across test cases.
|
106
|
+
@_sandbox[:artifacts] = Artifact.class_eval { @artifacts }.clone
|
107
|
+
@_sandbox[:local_repository] = Buildr.repositories.local
|
108
|
+
ENV['HOME'] = File.expand_path('home')
|
109
|
+
ENV['BUILDR_ENV'] = 'development'
|
110
|
+
|
111
|
+
@_sandbox[:env_keys] = ENV.keys
|
112
|
+
%w[DEBUG TEST HTTP_PROXY HTTPS_PROXY USER].each { |k| ENV.delete(k) ; ENV.delete(k.downcase) }
|
113
|
+
|
114
|
+
# By default, remote repository is user's own local M2 repository
|
115
|
+
# since we don't want to remotely download artifacts into the sandbox over and over
|
116
|
+
Buildr.repositories.instance_eval do
|
117
|
+
@remote = ["file://" + @local]
|
118
|
+
@local = @release_to = @snapshot_to = nil
|
119
|
+
end
|
120
|
+
Buildr.options.proxy.http = nil
|
121
|
+
|
122
|
+
# Don't output crap to the console.
|
123
|
+
trace false
|
124
|
+
verbose false
|
125
|
+
end
|
126
|
+
|
127
|
+
# Call this from teardown.
|
128
|
+
def reset
|
129
|
+
# Get rid of all the projects and the on_define blocks we used.
|
130
|
+
Project.clear
|
131
|
+
|
132
|
+
on_define = @_sandbox[:on_define]
|
133
|
+
extension_modules = @_sandbox[:extension_modules]
|
134
|
+
global_callbacks = @_sandbox[:global_callbacks]
|
135
|
+
|
136
|
+
Project.class_eval do
|
137
|
+
@on_define = on_define
|
138
|
+
@global_callbacks = global_callbacks
|
139
|
+
@extension_modules = extension_modules
|
140
|
+
end
|
141
|
+
|
142
|
+
POM.class_eval do
|
143
|
+
@cache = nil
|
144
|
+
end
|
145
|
+
|
146
|
+
Layout.default = @_sandbox[:layout].clone
|
147
|
+
|
148
|
+
$LOAD_PATH.replace @_sandbox[:load_path]
|
149
|
+
ENV['RUBYOPT'] = @_sandbox[:ruby_opt]
|
150
|
+
|
151
|
+
FileUtils.rm_rf @temp
|
152
|
+
mkpath ENV['HOME']
|
153
|
+
|
154
|
+
# Get rid of all artifacts.
|
155
|
+
@_sandbox[:artifacts].tap { |artifacts| Artifact.class_eval { @artifacts = artifacts } }
|
156
|
+
|
157
|
+
Buildr.repositories.local = @_sandbox[:local_repository]
|
158
|
+
|
159
|
+
# Restore options.
|
160
|
+
Buildr.options.test = nil
|
161
|
+
(ENV.keys - @_sandbox[:env_keys]).each { |key| ENV.delete key }
|
162
|
+
|
163
|
+
Dir.chdir @_sandbox[:original_dir]
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
@@ -0,0 +1,420 @@
|
|
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 pleasant 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.
|
27
|
+
select {|dep| dep.type == :runtime || (dep.type == :development && dep.name.to_s =~ /^rspec.*/) }.
|
28
|
+
each { |dep| gem dep.name, (dep.respond_to?(:requirement) ? dep.requirement.to_s : dep.version_requirements.to_s) }
|
29
|
+
|
30
|
+
# Make sure to load from these paths first, we don't want to load any
|
31
|
+
# code from Gem library.
|
32
|
+
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)),
|
33
|
+
File.expand_path('../addon', File.dirname(__FILE__))
|
34
|
+
|
35
|
+
# Buildr uses autoload extensively, but autoload when running specs creates
|
36
|
+
# a problem -- we sandbox $LOADED_FEATURES, so we end up autoloading the same
|
37
|
+
# module twice. This turns autoload into a require, which is not the right
|
38
|
+
# thing, but will do for now.
|
39
|
+
def autoload(symbol, path)
|
40
|
+
require path
|
41
|
+
end
|
42
|
+
require 'buildr'
|
43
|
+
|
44
|
+
# Give a chance for plugins to do a few things before requiring the sandbox.
|
45
|
+
include SandboxHook if defined?(SandboxHook)
|
46
|
+
|
47
|
+
require File.expand_path('sandbox', File.dirname(__FILE__))
|
48
|
+
|
49
|
+
module Matchers #:nodoc:
|
50
|
+
|
51
|
+
class << self
|
52
|
+
|
53
|
+
# Define matchers that operate by calling a method on the tested object.
|
54
|
+
# For example:
|
55
|
+
# foo.should contain(bar)
|
56
|
+
# calls:
|
57
|
+
# foo.contain(bar)
|
58
|
+
def match_using(*names)
|
59
|
+
names.each do |name|
|
60
|
+
matcher = Class.new do
|
61
|
+
# Initialize with expected arguments (i.e. contain(bar) initializes with bar).
|
62
|
+
define_method(:initialize) { |*args| @expects = args }
|
63
|
+
# Matches against actual value (i.e. foo.should exist called with foo).
|
64
|
+
define_method(:matches?) do |actual|
|
65
|
+
@actual = actual
|
66
|
+
return actual.send("#{name}?", *@expects) if actual.respond_to?(:"#{name}?", true)
|
67
|
+
return actual.send(name, *@expects) if actual.respond_to?(name.to_sym, true)
|
68
|
+
raise "You can't check #{actual.inspect}, it doesn't respond to #{name}."
|
69
|
+
end
|
70
|
+
# Some matchers have arguments, others don't, treat appropriately.
|
71
|
+
define_method :failure_message do
|
72
|
+
args = " " + @expects.map{ |arg| "'#{arg}'" }.join(", ") unless @expects.empty?
|
73
|
+
"Expected #{@actual} to #{name}#{args}"
|
74
|
+
end
|
75
|
+
define_method :negative_failure_message do
|
76
|
+
args = " " + @expects.map{ |arg| "'#{arg}'" }.join(", ") unless @expects.empty?
|
77
|
+
"Expected #{@actual} to not #{name}#{args}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# Define method to create matcher.
|
81
|
+
define_method(name) { |*args| matcher.new(*args) }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# Define delegate matchers for exist and contain methods.
|
88
|
+
match_using :exist, :contain
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
class ::Rake::FileTask
|
93
|
+
def exist?
|
94
|
+
File.exist?(self.to_s)
|
95
|
+
end
|
96
|
+
|
97
|
+
def contain(content)
|
98
|
+
IO.read(self.to_s).include?(content)
|
99
|
+
# File.exist?(self.to_s)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
module SpecHelpers
|
104
|
+
|
105
|
+
include Matchers
|
106
|
+
|
107
|
+
[:info, :warn, :error, :puts].each do |severity|
|
108
|
+
::Object.class_eval do
|
109
|
+
define_method severity do |*args|
|
110
|
+
$messages ||= {}
|
111
|
+
$messages[severity] ||= []
|
112
|
+
$messages[severity].push(*args)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class << Buildr.application
|
118
|
+
alias :deprecated_without_capture :deprecated
|
119
|
+
def deprecated(message)
|
120
|
+
verbose(true) { deprecated_without_capture message }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class MessageWithSeverityMatcher
|
125
|
+
def initialize(severity, message)
|
126
|
+
@severity = severity
|
127
|
+
@expect = message
|
128
|
+
end
|
129
|
+
|
130
|
+
def matches?(target)
|
131
|
+
$messages = {@severity => []}
|
132
|
+
target.call
|
133
|
+
return Regexp === @expect ? $messages[@severity].join('\n') =~ @expect : $messages[@severity].include?(@expect.to_s)
|
134
|
+
end
|
135
|
+
|
136
|
+
def failure_message
|
137
|
+
"Expected #{@severity} #{@expect.inspect}, " +
|
138
|
+
($messages[@severity].empty? ? "no #{@severity} issued" : "found #{$messages[@severity].inspect}")
|
139
|
+
end
|
140
|
+
|
141
|
+
def negative_failure_message
|
142
|
+
"Found unexpected #{$messages[@severity].inspect}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Test if an info message was shown. You can use a string or regular expression.
|
147
|
+
#
|
148
|
+
# For example:
|
149
|
+
# lambda { info 'ze test' }.should show_info(/ze test/)
|
150
|
+
def show_info(message)
|
151
|
+
MessageWithSeverityMatcher.new :info, message
|
152
|
+
end
|
153
|
+
|
154
|
+
# Test if a warning was shown. You can use a string or regular expression.
|
155
|
+
#
|
156
|
+
# For example:
|
157
|
+
# lambda { warn 'ze test' }.should show_warning(/ze test/)
|
158
|
+
def show_warning(message)
|
159
|
+
MessageWithSeverityMatcher.new :warn, message
|
160
|
+
end
|
161
|
+
|
162
|
+
# Test if an error message was shown. You can use a string or regular expression.
|
163
|
+
#
|
164
|
+
# For example:
|
165
|
+
# lambda { error 'ze test' }.should show_error(/ze test/)
|
166
|
+
def show_error(message)
|
167
|
+
MessageWithSeverityMatcher.new :error, message
|
168
|
+
end
|
169
|
+
|
170
|
+
# Test if any message was shown (puts). You can use a string or regular expression.
|
171
|
+
#
|
172
|
+
# For example:
|
173
|
+
# lambda { puts 'ze test' }.should show(/ze test/)
|
174
|
+
def show(message)
|
175
|
+
MessageWithSeverityMatcher.new :puts, message
|
176
|
+
end
|
177
|
+
|
178
|
+
# Yields a block that should try exiting the application.
|
179
|
+
# Accepts
|
180
|
+
#
|
181
|
+
# For example:
|
182
|
+
# test_exit(1) { puts "Hello" ; exit(1) }.should show("Hello")
|
183
|
+
#
|
184
|
+
def test_exit(status = nil)
|
185
|
+
return lambda {
|
186
|
+
begin
|
187
|
+
yield
|
188
|
+
raise "Exit was not called!"
|
189
|
+
rescue SystemExit => e
|
190
|
+
raise "Exit status incorrect! Expected: #{status}, got #{e.status}" if status && (e.status != status)
|
191
|
+
end
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
class ::Rake::Task
|
196
|
+
alias :execute_without_a_record :execute
|
197
|
+
def execute(args)
|
198
|
+
$executed ||= []
|
199
|
+
$executed << name
|
200
|
+
execute_without_a_record args
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class InvokeMatcher
|
205
|
+
def initialize(*tasks)
|
206
|
+
@expecting = tasks.map { |task| [task].flatten.map(&:to_s) }
|
207
|
+
end
|
208
|
+
|
209
|
+
def matches?(target)
|
210
|
+
$executed = []
|
211
|
+
target.call
|
212
|
+
return false unless all_ran?
|
213
|
+
return !@but_not.any_ran? if @but_not
|
214
|
+
return true
|
215
|
+
end
|
216
|
+
|
217
|
+
def failure_message
|
218
|
+
return @but_not.negative_failure_message if all_ran? && @but_not
|
219
|
+
"Expected the tasks #{expected} to run, but #{remaining} did not run, or not in the order we expected them to." +
|
220
|
+
" Tasks that ran: #{$executed.inspect}"
|
221
|
+
end
|
222
|
+
|
223
|
+
def negative_failure_message
|
224
|
+
if all_ran?
|
225
|
+
"Expected the tasks #{expected} to not run, but they all ran."
|
226
|
+
else
|
227
|
+
"Expected the tasks #{expected} to not run, and all but #{remaining} ran."
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def but_not(*tasks)
|
232
|
+
@but_not = InvokeMatcher.new(*tasks)
|
233
|
+
self
|
234
|
+
end
|
235
|
+
|
236
|
+
protected
|
237
|
+
|
238
|
+
def expected
|
239
|
+
@expecting.map { |tests| tests.join('=>') }.join(', ')
|
240
|
+
end
|
241
|
+
|
242
|
+
def remaining
|
243
|
+
@remaining.map { |tests| tests.join('=>') }.join(', ')
|
244
|
+
end
|
245
|
+
|
246
|
+
def all_ran?
|
247
|
+
@remaining ||= $executed.inject(@expecting) do |expecting, executed|
|
248
|
+
expecting.map { |tasks| tasks.first == executed ? tasks[1..-1] : tasks }.reject(&:empty?)
|
249
|
+
end
|
250
|
+
@remaining.empty?
|
251
|
+
end
|
252
|
+
|
253
|
+
def any_ran?
|
254
|
+
all_ran?
|
255
|
+
@remaining.size < @expecting.size
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
# Tests that all the tasks ran, in the order specified. Can also be used to test that some
|
261
|
+
# tasks and not others ran.
|
262
|
+
#
|
263
|
+
# Takes a list of arguments. Each argument can be a task name, matching only if that task ran.
|
264
|
+
# Each argument can be an array of task names, matching only if all these tasks ran in that order.
|
265
|
+
# So run_tasks('foo', 'bar') expects foo and bar to run in any order, but run_task(['foo', 'bar'])
|
266
|
+
# expects foo to run before bar.
|
267
|
+
#
|
268
|
+
# You can call but_not on the matchers to specify that certain tasks must not execute.
|
269
|
+
#
|
270
|
+
# For example:
|
271
|
+
# # Either task
|
272
|
+
# lambda { task('compile').invoke }.should run_tasks('compile', 'resources')
|
273
|
+
# # In that order
|
274
|
+
# lambda { task('build').invoke }.should run_tasks(['compile', 'test'])
|
275
|
+
# # With exclusion
|
276
|
+
# lambda { task('build').invoke }.should run_tasks('compile').but_not('install')
|
277
|
+
def run_tasks(*tasks)
|
278
|
+
InvokeMatcher.new *tasks
|
279
|
+
end
|
280
|
+
|
281
|
+
# Tests that a task ran. Similar to run_tasks, but accepts a single task name.
|
282
|
+
#
|
283
|
+
# For example:
|
284
|
+
# lambda { task('build').invoke }.should run_task('test')
|
285
|
+
def run_task(task)
|
286
|
+
InvokeMatcher.new [task]
|
287
|
+
end
|
288
|
+
|
289
|
+
class UriPathMatcher
|
290
|
+
def initialize(re)
|
291
|
+
@expression = re
|
292
|
+
end
|
293
|
+
|
294
|
+
def matches?(uri)
|
295
|
+
@uri = uri
|
296
|
+
uri.path =~ @expression
|
297
|
+
end
|
298
|
+
|
299
|
+
def description
|
300
|
+
"URI with path matching #{@expression} vs #{@uri}"
|
301
|
+
end
|
302
|
+
|
303
|
+
def failure_message_for_should
|
304
|
+
"expected #{description}"
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
# Matches a parsed URI's path against the given regular expression
|
309
|
+
def uri(re)
|
310
|
+
UriPathMatcher.new(re)
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
class AbsolutePathMatcher
|
315
|
+
def initialize(path)
|
316
|
+
@expected = File.expand_path(path.to_s)
|
317
|
+
end
|
318
|
+
|
319
|
+
def matches?(path)
|
320
|
+
@provided = File.expand_path(path.to_s)
|
321
|
+
@provided == @expected
|
322
|
+
end
|
323
|
+
|
324
|
+
def failure_message
|
325
|
+
"Expected path #{@expected}, but found path #{@provided}"
|
326
|
+
end
|
327
|
+
|
328
|
+
def negative_failure_message
|
329
|
+
"Expected a path other than #{@expected}"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def point_to_path(path)
|
334
|
+
AbsolutePathMatcher.new(path)
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
# Value covered by range. For example:
|
339
|
+
# (1..5).should cover(3)
|
340
|
+
RSpec::Matchers.define :cover do |actual|
|
341
|
+
match do |range|
|
342
|
+
actual >= range.min && actual <= range.max
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def suppress_stdout
|
348
|
+
stdout = $stdout
|
349
|
+
#$stdout = StringIO.new
|
350
|
+
begin
|
351
|
+
yield
|
352
|
+
ensure
|
353
|
+
$stdout = stdout
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def dryrun
|
358
|
+
Buildr.application.options.dryrun = true
|
359
|
+
begin
|
360
|
+
suppress_stdout { yield }
|
361
|
+
ensure
|
362
|
+
Buildr.application.options.dryrun = false
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
# We run tests with tracing off. Then things break. And we need to figure out what went wrong.
|
367
|
+
# So just use trace() as you would use verbose() to find and squash the bug.
|
368
|
+
def trace(value = nil)
|
369
|
+
old_value = Buildr.application.options.trace
|
370
|
+
Buildr.application.options.trace = value unless value.nil?
|
371
|
+
if block_given?
|
372
|
+
begin
|
373
|
+
yield
|
374
|
+
ensure
|
375
|
+
Buildr.application.options.trace = old_value
|
376
|
+
end
|
377
|
+
end
|
378
|
+
Buildr.application.options.trace
|
379
|
+
end
|
380
|
+
|
381
|
+
# Change the Buildr original directory, faking invocation from a different directory.
|
382
|
+
def in_original_dir(dir)
|
383
|
+
begin
|
384
|
+
original_dir = Buildr.application.original_dir
|
385
|
+
Buildr.application.instance_eval { @original_dir = File.expand_path(dir) }
|
386
|
+
yield
|
387
|
+
ensure
|
388
|
+
Buildr.application.instance_eval { @original_dir = original_dir }
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
# Buildr's define method creates a project definition but does not evaluate it
|
394
|
+
# (that happens once the buildfile is loaded), and we include Buildr's define in
|
395
|
+
# the test context so we can use it without prefixing with Buildr. This just patches
|
396
|
+
# define to evaluate the project definition before returning it.
|
397
|
+
def define(name, properties = nil, &block) #:yields:project
|
398
|
+
Project.define(name, properties, &block).tap { |project| project.invoke }
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
|
404
|
+
# Allow using matchers within the project definition.
|
405
|
+
class Buildr::Project
|
406
|
+
include ::RSpec::Matchers, SpecHelpers
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
::RSpec.configure do |config|
|
411
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
412
|
+
# Make all Buildr methods accessible from test cases, and add various helper methods.
|
413
|
+
config.include Buildr
|
414
|
+
config.include SpecHelpers
|
415
|
+
|
416
|
+
# Sandbox Buildr for each test.
|
417
|
+
config.include Sandbox
|
418
|
+
end
|
419
|
+
|
420
|
+
end
|