Skip to content

Commit

Permalink
Ensure exit with status 1 [#1 status:resolved].
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 30, 2009
1 parent d054e24 commit 0229237
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def start(given_args=ARGV, config={})
else
config[:shell].error e.message
end
exit(1) if exit_on_failure?
end

protected
Expand Down Expand Up @@ -491,6 +492,12 @@ def from_superclass(method, default=nil)
end
end

# A flag that makes the process exit with status 1 if any error happens.
#
def exit_on_failure?
false
end

# SIGNATURE: Sets the baseclass. This is where the superclass lookup
# finishes.
def baseclass #:nodoc:
Expand Down
4 changes: 4 additions & 0 deletions lib/thor/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ def save_yaml(yaml)
File.open(yaml_file, "w") { |f| f.puts yaml.to_yaml }
end

def self.exit_on_failure?
true
end

# Load the thorfiles. If relevant_to is supplied, looks for specific files
# in the thor_root instead of loading them all.
#
Expand Down
4 changes: 2 additions & 2 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
end

it "raises error if a class/task cannot be found" do
mock(Thor::Runner).exit(1)
content = capture(:stderr){ Thor::Runner.start(["help", "unknown"]) }
content.must =~ /could not find Thor class or task 'unknown'/
end
Expand Down Expand Up @@ -67,6 +68,7 @@
end

it "raises an error if class/task can't be found" do
mock(Thor::Runner).exit(1)
ARGV.replace ["unknown"]
capture(:stderr){ Thor::Runner.start }.must =~ /could not find Thor class or task 'unknown'/
end
Expand Down Expand Up @@ -180,10 +182,8 @@

it "displays the modules installed in a pretty way" do
stdout = capture(:stdout) { Thor::Runner.start(["installed"]) }

stdout.must =~ /random\s*amazing/
stdout.must =~ /amazing:describe NAME \[\-\-forcefully\]\s+# say that someone is amazing/m
stdout.must =~ /amazing:hello\s+# say hello/m
end
end

Expand Down

0 comments on commit 0229237

Please sign in to comment.