Skip to content

Commit

Permalink
Exit with negative exit code on problems.
Browse files Browse the repository at this point in the history
  - Switch to test/spec
  - Add .autotest recipe
  - exit with -1 if a command fails
  • Loading branch information
Manfred committed Aug 20, 2008
1 parent a4398f4 commit bbe3edb
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 21 deletions.
26 changes: 26 additions & 0 deletions .autotest
@@ -0,0 +1,26 @@
Autotest.add_hook :initialize do |at|
at.unit_diff = 'cat'
at.failed_results_re = /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)\n\[([^:]*):.*\]/

at.add_exception %r%^\./(?:db|doc|log|public|script|tmp|vendor|data|content|config)%
at.add_exception %r%\.svn%

at.clear_mappings

at.add_mapping %r%^lib/(.*)\.rb% do |_, match|
sqwat = match[1].gsub('/', '_')
"test/#{sqwat}_spec.rb"
end

at.add_mapping %r%^test/.*_spec\.rb$% do |filename, _|
filename
end

class << at
def consolidate_failures(failed)
failed.inject(new_hash_of_arrays) do |filters, (method, klass, filename)|
filters[File.expand_path(filename)] << method; filters
end
end
end
end
13 changes: 13 additions & 0 deletions lib/hail.rb
@@ -1,8 +1,16 @@
require 'optparse'

require 'hail/workbench'

module Hail
VERSION = '0.6.0'

def self.run_command(options={})
if options[:command] == 'init'
Workbench.init(options)
end
end

def self.run(args)
options = {}
opts = OptionParser.new do |opts|
Expand All @@ -23,6 +31,11 @@ def self.run(args)
end
end
opts.parse!(args)

unless run_command(options)
exit -1
end

options
end
end
7 changes: 7 additions & 0 deletions lib/hail/workbench.rb
@@ -0,0 +1,7 @@
module Hail
class Workbench
def self.init(options={})
true
end
end
end
Empty file removed test/.bacon
Empty file.
25 changes: 22 additions & 3 deletions test/hail_spec.rb
@@ -1,16 +1,21 @@
require File.expand_path('../helper.rb', __FILE__)

require 'hail'

describe "Hail" do
extend StdOutReceptor
require 'receptor'
require 'stdout_receptor'

describe "Hail, invoked from the commandline" do
include StdOutReceptor

before do
Receptor.instance.messages.clear
Hail.stubs(:run_command).returns(true)
end

it "should switch to verbose mode" do
options = Hail.run(['--verbose'])
options[:verbose].should.be.true
options[:verbose].should.be true
end

it "should show a help message" do
Expand All @@ -28,4 +33,18 @@
end
stdout_lines.first.should =~ /Hail [\d\.]+/
end

it "should exit with a negative code when running into a problem" do
Hail.stubs(:run_command).returns(false)
Hail.expects(:exit).with(-1)
Hail.run([]).should == {}
end
end

describe "Hail, when running a command" do
it "should initialize a new Workbench on init" do
options = {:command => 'init'}
Hail::Workbench.expects(:init).with(options)
Hail.run_command(options)
end
end
19 changes: 1 addition & 18 deletions test/helper.rb
@@ -1,24 +1,7 @@
require 'rubygems' rescue LoadError

require 'bacon'
require 'test/spec'
require 'mocha'

$:.unshift(File.expand_path('../lib', __FILE__))

require 'receptor'

module StdOutReceptor
def capturing_stdout
original_stdout = $stdout
$stdout = Receptor.instance
yield
ensure
$stdout = original_stdout
end

def stdout_lines
Receptor.instance.message.map { |call| call[1] }
end
end

$:.unshift(File.expand_path('../../lib', __FILE__))
13 changes: 13 additions & 0 deletions test/lib/stdout_receptor.rb
@@ -0,0 +1,13 @@
module StdOutReceptor
def capturing_stdout
original_stdout = $stdout
$stdout = Receptor.instance
yield
ensure
$stdout = original_stdout
end

def stdout_lines
Receptor.instance.message.map { |call| call[1] }
end
end

0 comments on commit bbe3edb

Please sign in to comment.