Module: Minitest
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Exceptions:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
ErrorOnWarning
|
|
Defined in: | lib/minitest.rb, lib/minitest/assertions.rb, lib/minitest/benchmark.rb, lib/minitest/benchmark.rb, lib/minitest/compress.rb, lib/minitest/error_on_warning.rb, lib/minitest/manual_plugins.rb, lib/minitest/mock.rb, lib/minitest/parallel.rb, lib/minitest/pride_plugin.rb, lib/minitest/test.rb, lib/minitest/test_task.rb, lib/minitest/unit.rb |
Overview
The top-level namespace for Minitest
. Also the location of the main runtime. See .run for more information.
Constant Summary
-
VERSION =
Internal use only
# File 'lib/minitest.rb', line 13"5.25.2"
Class Method Summary
-
.__run(reporter, options)
Internal run method.
-
.after_run(&block)
A simple hook allowing you to run a block of code after everything is done running.
-
.autorun
Registers Minitest to run at process exit.
-
.load(*names)
Manually load plugins by name.
-
.register_plugin(name_or_mod)
Register a plugin to be used.
-
.run(args = [])
This is the top-level run method.
- .cattr_accessor(name) Internal use only
-
.clock_time
Internal use only
See additional method definition at line 1216.
- .empty_run!(options) Internal use only
- .filter_backtrace(bt) Internal use only
- .init_plugins(options) Internal use only
- .load_plugins Internal use only
- .plugin_pride_init(options) Internal use only
- .plugin_pride_options(opts, _options) Internal use only
- .process_args(args = []) Internal use only
- .run_one_method(klass, method_name) Internal use only
Instance Method Summary
-
#backtrace_filter
Filter object for backtraces.
-
#extensions
Names of known extension plugins.
-
#info_signal
The signal to use for dumping information to STDERR.
-
#parallel_executor
Parallel
test executor. -
#reporter
Reporter
object to be used for all runs. -
#seed
The random seed used for this run.
ErrorOnWarning
- Included
Class Method Details
.__run(reporter, options)
Internal run method. Responsible for telling all ::Minitest::Runnable
sub-classes to run.
# File 'lib/minitest.rb', line 323
def self.__run reporter, suites = Runnable.runnables.shuffle parallel, serial = suites.partition { |s| s.test_order == :parallel } # If we run the parallel tests before the serial tests, the parallel tests # could run in parallel with the serial tests. This would be bad because # the serial tests won't lock around Reporter#record. Run the serial tests # first, so that after they complete, the parallel tests will lock when # recording results. serial.map { |suite| suite.run reporter, } + parallel.map { |suite| suite.run reporter, } end
.after_run(&block)
A simple hook allowing you to run a block of code after everything is done running. Eg:
Minitest.after_run { p $debugging_info }
# File 'lib/minitest.rb', line 97
def self.after_run &block @@after_run << block end
.autorun
Registers Minitest to run at process exit
# File 'lib/minitest.rb', line 70
def self.autorun Warning[:deprecated] = true if Object.const_defined?(:Warning) && Warning.respond_to?(:[]=) at_exit { next if $! and not ($!.kind_of? SystemExit and $!.success?) exit_code = nil pid = Process.pid at_exit { next if !Minitest.allow_fork && Process.pid != pid @@after_run.reverse_each(&:call) exit exit_code || false } exit_code = Minitest.run ARGV } unless @@installed_at_exit @@installed_at_exit = true end
.cattr_accessor(name)
# File 'lib/minitest.rb', line 19
def self.cattr_accessor name # :nodoc: (class << self; self; end).attr_accessor name end
.clock_time
See additional method definition at line 1216.
# File 'lib/minitest.rb', line 1220
def self.clock_time Process.clock_gettime Process::CLOCK_MONOTONIC end
.empty_run!(options)
# File 'lib/minitest.rb', line 303
def self.empty_run! # :nodoc: filter = [:filter] return true unless filter # no filter, but nothing ran == success warn "Nothing ran for filter: %s" % [filter] require "did_you_mean" # soft dependency, punt if it doesn't load ms = Runnable.runnables.flat_map(&:runnable_methods) cs = DidYouMean::SpellChecker.new(dictionary: ms).correct filter warn DidYouMean::Formatter. cs unless cs.empty? rescue LoadError # do nothing end
.filter_backtrace(bt)
# File 'lib/minitest.rb', line 336
def self.filter_backtrace bt # :nodoc: result = backtrace_filter.filter bt result = bt.dup if result.empty? result end
.init_plugins(options)
# File 'lib/minitest.rb', line 125
def self.init_plugins # :nodoc: 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, when Module then recv = mod_or_meth next unless recv.respond_to? :minitest_plugin_init recv.minitest_plugin_init else raise ArgumentError, "plugin is %p, but it must be a symbol, string or module" % [mod_or_meth] end end end
.load(*names)
Manually load plugins by name.
# File 'lib/minitest/manual_plugins.rb', line 9
def self.load *names names.each do |name| require "minitest/#{name}_plugin" self.extensions << name.to_s end end
.load_plugins
# File 'lib/minitest.rb', line 109
def self.load_plugins # :nodoc: return unless defined? Gem seen = {} Gem.find_files("minitest/*_plugin.rb").each do |plugin_path| name = File.basename plugin_path, "_plugin.rb" next if seen[name] seen[name] = true require plugin_path self.extensions << name end end
.plugin_pride_init(options)
.plugin_pride_options(opts, _options)
.process_args(args = [])
# File 'lib/minitest.rb', line 143
def self.process_args args = [] # :nodoc: = { :io => $stdout, } orig_args = args.dup OptionParser.new do |opts| opts. = "minitest options:" opts.version = Minitest::VERSION opts.on "-h", "--help", "Display this help." do puts opts exit end opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or set $MT_NO_PLUGINS)." desc = "Sets random seed. Also via env. Eg: SEED=n rake" opts.on "-s", "--seed SEED", Integer, desc do |m| [:seed] = m.to_i end opts.on "-v", "--verbose", "Verbose. Show progress processing files." do [:verbose] = true end opts.on "-q", "--quiet", "Quiet. Show no progress processing files." do [:quiet] = true end opts.on "--show-skips", "Show skipped at the end of run." do [:show_skips] = true end opts.on "-n", "--name PATTERN", "Filter run on /regexp/ or string." do |a| [:filter] = a end opts.on "-e", "--exclude PATTERN", "Exclude /regexp/ or string from run." do |a| [:exclude] = a end opts.on "-S", "--skip CODES", String, "Skip reporting of certain types of results (eg E)." do |s| [:skip] = s.chars.to_a end ruby27plus = ::Warning.respond_to? :[]= opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s| [:Werror] = true case s when "error", "all", nil then require "minitest/error_on_warning" $VERBOSE = true ::Warning[:deprecated] = true if ruby27plus else ::Warning[s.to_sym] = true if ruby27plus # check validity of category end end unless extensions.empty? opts.separator "" opts.separator "Known extensions: #{extensions.join ", "}" 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, if respond_to? msg when Module recv = mod_or_meth next unless recv.respond_to? : recv. opts, else raise ArgumentError, "plugin is %p, but it must be a symbol, string or module" % [mod_or_meth] end end end begin opts.parse! args rescue OptionParser::InvalidOption => e puts puts e puts puts opts exit 1 end orig_args -= args end unless [:seed] then srand [:seed] = (ENV["SEED"] || srand).to_i % 0xFFFF orig_args << "--seed" << [:seed].to_s end [:args] = orig_args.map { |s| s.match?(/[\s|&<>$()]/) ? s.inspect : s }.join " " end
.register_plugin(name_or_mod)
Register a plugin to be used. Does NOT require / load it.
# File 'lib/minitest.rb', line 104
def self.register_plugin name_or_mod self.extensions << name_or_mod nil end
.run(args = [])
This is the top-level run method. Everything starts from here. It tells each ::Minitest::Runnable
sub-class to run, and each of those are responsible for doing whatever they do.
The overall structure of a run looks like this:
Minitest.autorun
Minitest.run(args)
Minitest.load_plugins
Minitest.process_args
Minitest.init_plugins
Minitest.__run(reporter, )
Runnable.runnables.each
runnable_klass.run(reporter, )
self.runnable_methods.each
self.run_one_method(self, runnable_method, reporter)
Minitest.run_one_method(klass, runnable_method)
klass.new(runnable_method).run
# File 'lib/minitest.rb', line 269
def self.run args = [] self.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"] = process_args args Minitest.seed = [:seed] srand Minitest.seed reporter = CompositeReporter.new reporter << SummaryReporter.new( [:io], ) reporter << ProgressReporter.new( [:io], ) unless [:quiet] self.reporter = reporter # this makes it available to plugins self.init_plugins self.reporter = nil # runnables shouldn't depend on the reporter, ever self.parallel_executor.start if parallel_executor.respond_to? :start reporter.start begin __run reporter, rescue Interrupt warn "Interrupted. Exiting..." end self.parallel_executor.shutdown # might have been removed/replaced during init_plugins: summary = reporter.reporters.grep(SummaryReporter).first reporter.report return empty_run! if summary && summary.count == 0 reporter.passed? end
.run_one_method(klass, method_name)
Instance Method Details
#backtrace_filter
Filter object for backtraces.
# File 'lib/minitest.rb', line 44
cattr_accessor :backtrace_filter
#extensions
Names of known extension plugins.
# File 'lib/minitest.rb', line 56
cattr_accessor :extensions
#info_signal
The signal to use for dumping information to STDERR. Defaults to “INFO”.
# File 'lib/minitest.rb', line 61
cattr_accessor :info_signal
#parallel_executor
::Minitest::Parallel
test executor
# File 'lib/minitest.rb', line 34
cattr_accessor :parallel_executor
#reporter
::Minitest::Reporter
object to be used for all runs.
NOTE: This accessor is only available during setup, not during runs.
# File 'lib/minitest.rb', line 51
cattr_accessor :reporter
#seed
The random seed used for this run. This is used to srand at the start of the run and between each Runnable.run.
Set via .run after processing args.
# File 'lib/minitest.rb', line 29
cattr_accessor :seed