Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Exit with exit status on rake
  • Loading branch information
kddnewton committed Oct 28, 2022
commit 57f5a98d807e261fc945b4c8bbb3ce6fd7f603ad
2 changes: 1 addition & 1 deletion lib/syntax_tree/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run_task

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

SyntaxTree::CLI.run(arguments + Array(source_files))
abort if SyntaxTree::CLI.run(arguments + Array(source_files)) != 0
end
end
end
Expand Down
30 changes: 18 additions & 12 deletions test/rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,36 @@
module SyntaxTree
module Rake
class CheckTaskTest < Minitest::Test
Invoke = Struct.new(:args)
Invocation = Struct.new(:args)

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

invoke = nil
SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do
::Rake::Task["stree:check"].invoke
end

assert_equal(["check", source_files], invoke.args)
invocation = invoke("stree:check")
assert_equal(["check", source_files], invocation.args)
end

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

invoke = nil
SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do
::Rake::Task["stree:write"].invoke
end
invocation = invoke("stree:write")
assert_equal(["write", source_files], invocation.args)
end

assert_equal(["write", source_files], invoke.args)
private

def invoke(task_name)
invocation = nil
stub = ->(args) { invocation = Invocation.new(args) }

begin
SyntaxTree::CLI.stub(:run, stub) { ::Rake::Task[task_name].invoke }
flunk
rescue SystemExit
invocation
end
end
end
end
Expand Down