Skip to content

Commit

Permalink
+ Added Minitest.register_plugin.
Browse files Browse the repository at this point in the history
+ Extended plugin system to work with modules/classes for opt-out plugins.
[git-p4: depot-paths = "//src/minitest/dev/": change = 14160]
  • Loading branch information
zenspider committed Jun 16, 2024
1 parent 0a1289f commit 2c5f1b7
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions lib/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def self.after_run &block
@@after_run << block
end

##
# Register a plugin to be used. Does NOT require / load it.

def self.register_plugin name_or_mod
self.extensions << name_or_mod
nil
end

def self.load_plugins # :nodoc:
return unless defined? Gem

Expand All @@ -115,9 +123,20 @@ def self.load_plugins # :nodoc:
end

def self.init_plugins options # :nodoc:
self.extensions.each do |name|
msg = "plugin_#{name}_init"
send msg, options if self.respond_to? msg
self.extensions.each do |mod_or_meth|
case mod_or_meth
when Symbol, String then
name = mod_or_meth
msg = "plugin_#{name}_init"
next unless self.respond_to? msg
send msg, options
when Module then
recv = mod_or_meth
next unless recv.respond_to? :minitest_plugin_init
recv.minitest_plugin_init options
else
raise ArgumentError, "blahblah %p" % [mod_or_meth]
end
end
end

Expand Down Expand Up @@ -185,9 +204,19 @@ def self.process_args args = [] # :nodoc:
opts.separator ""
opts.separator "Known extensions: #{extensions.join(", ")}"

extensions.each do |meth|
msg = "plugin_#{meth}_options"
send msg, opts, options if self.respond_to?(msg)
extensions.each do |mod_or_meth|
case mod_or_meth
when Symbol, String then
meth = mod_or_meth
msg = "plugin_#{meth}_options"
send msg, opts, options if respond_to?(msg)
when Module
recv = mod_or_meth
next unless recv.respond_to? :minitest_plugin_options
recv.minitest_plugin_options opts, options
else
raise ArgumentError, "blahblah %p" % [mod_or_meth]
end
end
end

Expand Down

0 comments on commit 2c5f1b7

Please sign in to comment.