Implement brew test --debug

This commit is contained in:
Jack Nagel 2014-09-18 14:16:07 -05:00
parent 1abcb0b348
commit 79a6e59e6e
5 changed files with 29 additions and 17 deletions

View File

@ -179,8 +179,7 @@ Note that these flags should only appear after a command.
several different ways. See [SPECIFYING FORMULAE][].
If `--debug` is passed and brewing fails, open an interactive debugging
session with access to IRB, ruby-debug, or a shell inside the temporary
build directory.
session with access to IRB or a shell inside the temporary build directory.
If `--env=std` is passed, use the standard build environment instead of superenv.
@ -332,14 +331,17 @@ Note that these flags should only appear after a command.
Ensures all tapped formula are symlinked into Library/Formula and prunes dead
formula from Library/Formula.
* `test` [--devel|--HEAD] <formula>:
* `test` [--devel|--HEAD] [--debug] <formula>:
A few formulae provide a test method. `brew test <formula>` runs this
test method. There is no standard output or return code, but it should
generally indicate to the user if something is wrong with the installed
formula.
To test the development or head version of a formula, `--devel` or
`--HEAD` must be passed.,
To test the development or head version of a formula, use `--devel` or
`--HEAD`.
If `--debug` is passed and the test fails, an interactive debugger will be
launched with access to IRB or a shell inside the temporary test directory.
Example: `brew install jruby && brew test jruby`

View File

@ -1,5 +1,6 @@
require "extend/ENV"
require "timeout"
require "debrew"
module Homebrew
TEST_TIMEOUT_SECONDS = 5*60
@ -50,11 +51,12 @@ module Homebrew
f.extend(Test::Unit::Assertions)
f.extend(Homebrew::Assertions)
f.extend(Debrew::Formula) if ARGV.debug?
begin
# tests can also return false to indicate failure
Timeout::timeout TEST_TIMEOUT_SECONDS do
raise if f.test == false
raise if f.run_test == false
end
rescue FailedAssertion => e
ofail "#{f.name}: failed"

View File

@ -21,6 +21,10 @@ module Debrew
def install
Debrew.debrew { super }
end
def test
Debrew.debrew { super }
end
end
module Resource

View File

@ -473,21 +473,23 @@ class Formula
active_spec.verify_download_integrity(fn)
end
def test
def run_test
self.build = Tab.for_formula(self)
ret = nil
mktemp do
@testpath = Pathname.pwd
ret = instance_eval(&self.class.test)
@testpath = nil
test
end
ret
ensure
@testpath = nil
end
def test_defined?
false
end
def test
end
protected
# Pretty titles the command and buffers stdout/stderr
@ -769,9 +771,8 @@ class Formula
end
def test &block
return @test unless block_given?
define_method(:test_defined?) { true }
@test = block
define_method(:test, &block)
end
end
end

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "BREW" "1" "July 2014" "Homebrew" "brew"
.TH "BREW" "1" "September 2014" "Homebrew" "brew"
.
.SH "NAME"
\fBbrew\fR \- The missing package manager for OS X
@ -197,7 +197,7 @@ Install \fIformula\fR\.
\fIformula\fR is usually the name of the formula to install, but it can be specified several different ways\. See \fISPECIFYING FORMULAE\fR\.
.
.IP
If \fB\-\-debug\fR is passed and brewing fails, open an interactive debugging session with access to IRB, ruby\-debug, or a shell inside the temporary build directory\.
If \fB\-\-debug\fR is passed and brewing fails, open an interactive debugging session with access to IRB or a shell inside the temporary build directory\.
.
.IP
If \fB\-\-env=std\fR is passed, use the standard build environment instead of superenv\.
@ -353,11 +353,14 @@ Tap a new formula repository from GitHub, or list existing taps\.
Ensures all tapped formula are symlinked into Library/Formula and prunes dead formula from Library/Formula\.
.
.TP
\fBtest\fR [\-\-devel|\-\-HEAD] \fIformula\fR
\fBtest\fR [\-\-devel|\-\-HEAD] [\-\-debug] \fIformula\fR
A few formulae provide a test method\. \fBbrew test <formula>\fR runs this test method\. There is no standard output or return code, but it should generally indicate to the user if something is wrong with the installed formula\.
.
.IP
To test the development or head version of a formula, \fB\-\-devel\fR or \fB\-\-HEAD\fR must be passed\.,
To test the development or head version of a formula, use \fB\-\-devel\fR or \fB\-\-HEAD\fR\.
.
.IP
If \fB\-\-debug\fR is passed and the test fails, an interactive debugger will be launched with access to IRB or a shell inside the temporary test directory\.
.
.IP
Example: \fBbrew install jruby && brew test jruby\fR