Skip to content

Commit 57f5a98

Browse files
committed
Exit with exit status on rake
1 parent 7405a3a commit 57f5a98

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/syntax_tree/rake/task.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run_task
7878

7979
arguments << "--ignore-files=#{ignore_files}" if ignore_files != ""
8080

81-
SyntaxTree::CLI.run(arguments + Array(source_files))
81+
abort if SyntaxTree::CLI.run(arguments + Array(source_files)) != 0
8282
end
8383
end
8484
end

test/rake_test.rb

+18-12
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,36 @@
66
module SyntaxTree
77
module Rake
88
class CheckTaskTest < Minitest::Test
9-
Invoke = Struct.new(:args)
9+
Invocation = Struct.new(:args)
1010

1111
def test_check_task
1212
source_files = "{app,config,lib}/**/*.rb"
1313
CheckTask.new { |t| t.source_files = source_files }
1414

15-
invoke = nil
16-
SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do
17-
::Rake::Task["stree:check"].invoke
18-
end
19-
20-
assert_equal(["check", source_files], invoke.args)
15+
invocation = invoke("stree:check")
16+
assert_equal(["check", source_files], invocation.args)
2117
end
2218

2319
def test_write_task
2420
source_files = "{app,config,lib}/**/*.rb"
2521
WriteTask.new { |t| t.source_files = source_files }
2622

27-
invoke = nil
28-
SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do
29-
::Rake::Task["stree:write"].invoke
30-
end
23+
invocation = invoke("stree:write")
24+
assert_equal(["write", source_files], invocation.args)
25+
end
3126

32-
assert_equal(["write", source_files], invoke.args)
27+
private
28+
29+
def invoke(task_name)
30+
invocation = nil
31+
stub = ->(args) { invocation = Invocation.new(args) }
32+
33+
begin
34+
SyntaxTree::CLI.stub(:run, stub) { ::Rake::Task[task_name].invoke }
35+
flunk
36+
rescue SystemExit
37+
invocation
38+
end
3339
end
3440
end
3541
end

0 commit comments

Comments
 (0)