From 1c99c685944a4f607697213f7ace25f386e420f6 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 1 Nov 2012 14:40:59 -0500 Subject: [PATCH] Allow tests to be specified in the DSL Tests can now be specified as a block in the DSL. A temporary test directory is set up automatically when calling Formula#test. The semantics of the test remain the same: the block can either raise an exception or return false to signal failure. Signed-off-by: Jack Nagel --- Library/Homebrew/formula.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3d3c23ec37..a150800ba5 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -15,9 +15,9 @@ class Formula attr_reader :name, :path, :homepage, :downloader attr_reader :stable, :bottle, :devel, :head, :active_spec - # The build folder, usually in /tmp. - # Will only be non-nil during the stage method. - attr_reader :buildpath + # The current working directory during builds and tests. + # Will only be non-nil inside #stage and #test. + attr_reader :buildpath, :testpath # Homebrew determines the name def initialize name='__UNKNOWN__', path=nil @@ -586,6 +586,16 @@ public @active_spec.verify_download_integrity(fn) end + def test + ret = nil + mktemp do + @testpath = Pathname.pwd + ret = instance_eval(&self.class.test) + @testpath = nil + end + ret + end + private def stage @@ -777,6 +787,11 @@ private CompilerFailure.new(compiler) end end + + def test &block + return @test unless block_given? + @test = block + end end end