Skip to content

Commit

Permalink
Unify rake task dependency checking
Browse files Browse the repository at this point in the history
This prepares for task generalisation.

This also solves the semantic difference between the need for the
minitest rake task backport and the absence of minitest, which would
otherwise fail if minitest were missing.
  • Loading branch information
lloeki committed Jul 11, 2024
1 parent bb3a7a0 commit 6137c52
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
11 changes: 10 additions & 1 deletion tasks/bundler.rake
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
require "bundler/gem_tasks"
# frozen_string_literal: true

# @type self: Rake::DSL

if Gem.loaded_specs["bundler"]
require "bundler/gem_tasks"
else
warn "'bundler' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end
7 changes: 7 additions & 0 deletions tasks/rbs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

# @type self: Rake::DSL

if Gem.loaded_specs["rbs"]
# noop
else
warn "'rbs' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end

namespace :rbs do
namespace :collection do
desc "Install RBS signatures"
Expand Down
4 changes: 2 additions & 2 deletions tasks/rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# @type self: Rake::DSL

begin
if Gem.loaded_specs["rspec"]
require "rspec/core/rake_task"
rescue LoadError
else
warn "'rspec' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end
Expand Down
6 changes: 3 additions & 3 deletions tasks/rubocop.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# @type self: Rake::DSL

begin
if Gem.loaded_specs["rubocop"]
require "rubocop/rake_task"
rescue LoadError
warn "'rubocop' gem not loaded: skipping tasks..."
else
warn "'rubocop' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end

Expand Down
6 changes: 3 additions & 3 deletions tasks/standard.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# @type self: Rake::DSL

begin
if Gem.loaded_specs["standard"]
require "standard/rake"
rescue LoadError
warn "'standard' gem not loaded: skipping tasks..."
else
warn "'standard' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end

Expand Down
6 changes: 3 additions & 3 deletions tasks/steep.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# @type self: Rake::TaskLib

begin
if Gem.loaded_specs["steep"]
require "steep"
rescue LoadError
warn "'steep' gem not loaded: skipping tasks..."
else
warn "'steep' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end

Expand Down
15 changes: 10 additions & 5 deletions tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

# @type self: Rake::DSL

begin
require "minitest/test_task"
rescue LoadError
# Backport "minitest/test_task" for minitest 5.15.0
require_relative "../vendor/minitest/test_task"
if Gem.loaded_specs["minitest"]
begin
require "minitest/test_task"
rescue LoadError
# Backport "minitest/test_task" for minitest 5.15.0
require_relative "../vendor/minitest/test_task"
end
else
warn "'minitest' gem not loaded: skipping tasks..." if Rake.verbose == true
return
end

Minitest::TestTask.create(:test) do |t|
Expand Down

0 comments on commit 6137c52

Please sign in to comment.