Skip to content

Style, pattern matching, rake exit status #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 28, 2022
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