Class: Test::Unit::AutoRunner (Ruby 2.7.5)
Description: Class : Test::Unit::AutoRunner - Ruby 2.7.5

### Home Classes Methods

### In Files

- test-unit-3.3.4/lib/test/unit/autorunner.rb

### Parent

Object

### Namespace

- CLASS Test::Unit::AutoRunner::StopOnFailureListener

### Methods

- ::collector
- ::default_runner
- ::default_runner=
- ::need_auto_run=
- ::need_auto_run?
- ::new
- ::prepare
- ::register_collector
- ::register_color_scheme
- ::register_runner
- ::run
- ::runner
- ::setup_option
- ::standalone?
- #keyword_display
- #load_config
- #options
- #prepare
- #process_args
- #run
- #stop_on_failure?

### Class/Module Index

Quicksearch

- Object
- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- Test::Unit::Assertions
- Test::Unit::Assertions::AssertExceptionHelper
- Test::Unit::Assertions::AssertExceptionHelper::WrappedException
- Test::Unit::Assertions::AssertionMessage
- Test::Unit::Assertions::AssertionMessage::ArrayInspector
- Test::Unit::Assertions::AssertionMessage::DelayedLiteral
- Test::Unit::Assertions::AssertionMessage::HashInspector
- Test::Unit::Assertions::AssertionMessage::Inspector
- Test::Unit::Assertions::AssertionMessage::Literal
- Test::Unit::Assertions::AssertionMessage::MaybeContainer
- Test::Unit::Assertions::AssertionMessage::NumericInspector
- Test::Unit::Assertions::AssertionMessage::Template
- Test::Unit::Assertions::ThrowTagExtractor
- Test::Unit::Attribute
- Test::Unit::Attribute::BaseClassMethods
- Test::Unit::Attribute::ClassMethods
- Test::Unit::Attribute::StringifyKeyHash
- Test::Unit::AttributeMatcher
- Test::Unit::AutoRunner
- Test::Unit::AutoRunner::StopOnFailureListener
- Test::Unit::AutoRunnerLoader
- Test::Unit::CodeSnippetFetcher
- Test::Unit::Collector
- Test::Unit::Collector::Descendant
- Test::Unit::Collector::Dir
- Test::Unit::Collector::Load
- Test::Unit::Collector::ObjectSpace
- Test::Unit::Collector::XML
- Test::Unit::Collector::XML::Listener
- Test::Unit::Color
- Test::Unit::Color::Error
- Test::Unit::Color::ParseError
- Test::Unit::ColorScheme
- Test::Unit::Data
- Test::Unit::Data::ClassMethods
- Test::Unit::Data::ClassMethods::Loader
- Test::Unit::DataSets
- Test::Unit::Diff
- Test::Unit::Diff::Differ
- Test::Unit::Diff::ReadableDiffer
- Test::Unit::Diff::SequenceMatcher
- Test::Unit::Diff::UTF8Line
- Test::Unit::Diff::UnifiedDiffer
- Test::Unit::Error
- Test::Unit::ErrorHandler
- Test::Unit::ExceptionHandler
- Test::Unit::ExceptionHandler::ClassMethods
- Test::Unit::Failure
- Test::Unit::FailureHandler
- Test::Unit::FaultLocationDetector
- Test::Unit::Fixture
- Test::Unit::Fixture::ClassMethods
- Test::Unit::Fixture::Fixture
- Test::Unit::Fixture::HookPoint
- Test::Unit::MixColor
- Test::Unit::Notification
- Test::Unit::NotificationHandler
- Test::Unit::NotifiedError
- Test::Unit::NullResultContainerInitializer
- Test::Unit::Omission
- Test::Unit::OmissionHandler
- Test::Unit::OmittedError
- Test::Unit::PendedError
- Test::Unit::Pending
- Test::Unit::PendingHandler
- Test::Unit::Priority
- Test::Unit::Priority::Checker
- Test::Unit::Priority::ClassMethods
- Test::Unit::TestCase
- Test::Unit::TestCase::InternalData
- Test::Unit::TestCaseNotificationSupport
- Test::Unit::TestCaseOmissionSupport
- Test::Unit::TestCasePendingSupport
- Test::Unit::TestResult
- Test::Unit::TestResultErrorSupport
- Test::Unit::TestResultFailureSupport
- Test::Unit::TestResultNotificationSupport
- Test::Unit::TestResultOmissionSupport
- Test::Unit::TestResultPendingSupport
- Test::Unit::TestSuite
- Test::Unit::UI
- Test::Unit::UI::Console
- Test::Unit::UI::Console::ColorizedReadableDiffer
- Test::Unit::UI::Console::OutputLevel
- Test::Unit::UI::Console::TestRunner
- Test::Unit::UI::Emacs
- Test::Unit::UI::Emacs::TestRunner
- Test::Unit::UI::TestRunner
- Test::Unit::UI::TestRunnerMediator
- Test::Unit::UI::TestRunnerUtilities
- Test::Unit::UI::XML
- Test::Unit::UI::XML::TestRunner
- Test::Unit::Util
- Test::Unit::Util::BacktraceFilter
- Test::Unit::Util::MethodOwnerFinder
- Test::Unit::Util::Observable
- Test::Unit::Util::Output
- Test::Unit::Util::ProcWrapper

No matching classes.

# Test::Unit::AutoRunner

### Constants

ADDITIONAL_OPTIONS
COLLECTORS
PREPARE_HOOKS
RUNNERS

### Attributes

base[RW]
collector[W]
color_scheme[RW]
default_test_paths[RW]
exclude[RW]
filters[RW]
listeners[RW]
pattern[RW]
runner[W]
runner_options[R]
stop_on_failure[W]
suite[R]
to_run[RW]
workdir[RW]

### Public Class Methods

collector(id) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 43
    def collector(id)
      COLLECTORS[id.to_s]
    end

default_runner() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 29
    def default_runner
      runner(@@default_runner)
    end

default_runner=(id) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 33
    def default_runner=(id)
      @@default_runner = id
    end

need_auto_run=(need) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 82
    def need_auto_run=(need)
      @@need_auto_run = need
    end

need_auto_run?() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 78
    def need_auto_run?
      @@need_auto_run
    end

new(standalone) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 149
    def initialize(standalone)
      @standalone = standalone
      @runner = default_runner
      @collector = default_collector
      @filters = []
      @to_run = []
      @default_test_paths = []
      @color_scheme = ColorScheme.default
      @runner_options = {}
      @default_arguments = []
      @workdir = nil
      @listeners = []
      @stop_on_failure = false
      config_file = "test-unit.yml"
      if File.exist?(config_file)
        load_config(config_file)
      else
        load_global_config
      end
      yield(self) if block_given?
    end

prepare(hook=nil, &block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 56
    def prepare(hook=nil, &block)
      hook ||= Proc.new(&block)
      PREPARE_HOOKS << hook
    end

register_collector(id, collector_builder=nil, &block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 37
    def register_collector(id, collector_builder=nil, &block)
      collector_builder ||= Proc.new(&block)
      COLLECTORS[id] = collector_builder
      COLLECTORS[id.to_s] = collector_builder
    end

register_color_scheme(id, scheme) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 47
    def register_color_scheme(id, scheme)
      ColorScheme[id] = scheme
    end

register_runner(id, runner_builder=nil, &block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 18
    def register_runner(id, runner_builder=nil, &block)
      runner_builder ||= Proc.new(&block)
      RUNNERS[id] = runner_builder
      RUNNERS[id.to_s] = runner_builder
    end

run(force_standalone=false, default_dir=nil, argv=ARGV, &block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 61
    def run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
      r = new(force_standalone || standalone?, &block)
      r.base = default_dir
      r.prepare
      r.process_args(argv)
      r.run
    end

runner(id) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 24
    def runner(id)
      RUNNERS[id.to_s]
    end

setup_option(option_builder=nil, &block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 51
    def setup_option(option_builder=nil, &block)
      option_builder ||= Proc.new(&block)
      ADDITIONAL_OPTIONS << option_builder
    end

standalone?() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 69
    def standalone?
      return false unless("-e" == $0)
      ObjectSpace.each_object(Class) do |klass|
        return false if(klass < TestCase)
      end
      true
    end

### Public Instance Methods

keyword_display(keywords) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 407
    def keyword_display(keywords)
      keywords = keywords.collect do |keyword, _|
        keyword.to_s
      end.uniq.sort

      i = 0
      keywords.collect do |keyword|
        if (i > 0 and keyword[0] == keywords[i - 1][0]) or
            ((i < keywords.size - 1) and (keyword[0] == keywords[i + 1][0]))
          n = 2
        else
          n = 1
        end
        i += 1
        keyword.sub(/^(.{#{n}})([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')
      end.join(", ")
    end

load_config(file) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 443
    def load_config(file)
      require "yaml"
      config = YAML.load(File.read(file))
      runner_name = config["runner"]
      @runner = self.class.runner(runner_name) || @runner
      @collector = self.class.collector(config["collector"]) || @collector
      (config["color_schemes"] || {}).each do |name, options|
        ColorScheme[name] = options
      end
      runner_options = {}
      (config["#{runner_name}_options"] || {}).each do |key, value|
        key = key.to_sym
        value = ColorScheme[value] if key == :color_scheme
        if key == :arguments
          @default_arguments.concat(value.split)
        else
          runner_options[key.to_sym] = value
        end
      end
      @runner_options = @runner_options.merge(runner_options)
    end

options() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 193
    def options
      @options ||= OptionParser.new do |o|
        o.banner = "Test::Unit automatic runner."
        o.banner += "\nUsage: #{$0} [options] [-- untouched arguments]"

        o.on("-r", "--runner=RUNNER", RUNNERS,
             "Use the given RUNNER.",
             "(" + keyword_display(RUNNERS) + ")") do |r|
          @runner = r
        end

        o.on("--collector=COLLECTOR", COLLECTORS,
             "Use the given COLLECTOR.",
             "(" + keyword_display(COLLECTORS) + ")") do |collector|
          @collector = collector
        end

        if (@standalone)
          o.on("-b", "--basedir=DIR", "Base directory of test suites.") do |b|
            @base = b
          end

          o.on("-w", "--workdir=DIR", "Working directory to run tests.") do |w|
            @workdir = w
          end

          o.on("--default-test-path=PATH",
               "Add PATH to the default test paths.",
               "The PATH is used when user doesn't specify any test path.",
               "You can specify this option multiple times.") do |path|
            @default_test_paths << path
          end

          o.on("-a", "--add=TORUN", Array,
               "Add TORUN to the list of things to run;",
               "can be a file or a directory.") do |paths|
            paths.each do |path|
              add_test_path(path)
            end
          end

          @pattern = []
          o.on("-p", "--pattern=PATTERN", Regexp,
               "Match files to collect against PATTERN.") do |e|
            @pattern << e
          end

          @exclude = []
          o.on("-x", "--exclude=PATTERN", Regexp,
               "Ignore files to collect against PATTERN.") do |e|
            @exclude << e
          end
        end

        o.on("-n", "--name=NAME", String,
             "Runs tests matching NAME.",
             "Use '/PATTERN/' for NAME to use regular expression.") do |name|
          name = (%r{\A/(.*)/\Z} =~ name ? Regexp.new($1) : name)
          @filters << lambda do |test|
            return true if name === test.method_name
            return true if name === test.local_name
            false
          end
        end

        o.on("--ignore-name=NAME", String,
             "Ignores tests matching NAME.",
             "Use '/PATTERN/' for NAME to use regular expression.") do |n|
          n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
          case n
          when Regexp
            @filters << proc {|t| n =~ t.method_name ? false : true}
          else
            @filters << proc {|t| n != t.method_name}
          end
        end

        o.on("-t", "--testcase=TESTCASE", String,
             "Runs tests in TestCases matching TESTCASE.",
             "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n|
          n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
          @filters << lambda do |test|
            match_test_case_name(test, n)
          end
        end

        o.on("--ignore-testcase=TESTCASE", String,
             "Ignores tests in TestCases matching TESTCASE.",
             "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n|
          n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n)
          @filters << lambda do |test|
            not match_test_case_name(test, n)
          end
        end

        o.on("--location=LOCATION", String,
             "Runs tests that defined in LOCATION.",
             "LOCATION is one of PATH:LINE, PATH or LINE") do |location|
          if /\A\d+\z/ =~ location
            path = nil
            line = location.to_i
          else
            path, line, = location.split(/:(\d+)/, 2)
            line = line.to_i unless line.nil?
          end
          add_location_filter(path, line)
        end

        o.on("--attribute=EXPRESSION", String,
             "Runs tests that matches EXPRESSION.",
             "EXPRESSION is evaluated as Ruby's expression.",
             "Test attribute name can be used with no receiver in EXPRESSION.",
             "EXPRESSION examples:",
             "  !slow",
             "  tag == 'important' and !slow") do |expression|
          @filters << lambda do |test|
            matcher = AttributeMatcher.new(test)
            matcher.match?(expression)
          end
        end

        priority_filter = Proc.new do |test|
          if @filters == [priority_filter]
            Priority::Checker.new(test).need_to_run?
          else
            nil
          end
        end
        o.on("--[no-]priority-mode",
             "Runs some tests based on their priority.") do |priority_mode|
          if priority_mode
            Priority.enable
            @filters |= [priority_filter]
          else
            Priority.disable
            @filters -= [priority_filter]
          end
        end

        o.on("--default-priority=PRIORITY",
             Priority.available_values,
             "Uses PRIORITY as default priority",
             "(#{keyword_display(Priority.available_values)})") do |priority|
          Priority.default = priority
        end

        o.on("-I", "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
             "Appends directory list to $LOAD_PATH.") do |dirs|
          $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
        end

        color_schemes = ColorScheme.all
        o.on("--color-scheme=SCHEME", color_schemes,
             "Use SCHEME as color scheme.",
             "(#{keyword_display(color_schemes)})") do |scheme|
          @color_scheme = scheme
        end

        o.on("--config=FILE",
             "Use YAML fomat FILE content as configuration file.") do |file|
          load_config(file)
        end

        o.on("--order=ORDER", TestCase::AVAILABLE_ORDERS,
             "Run tests in a test case in ORDER order.",
             "(#{keyword_display(TestCase::AVAILABLE_ORDERS)})") do |order|
          TestCase.test_order = order
        end

        assertion_message_class = Test::Unit::Assertions::AssertionMessage
        o.on("--max-diff-target-string-size=SIZE", Integer,
             "Shows diff if both expected result string size and " +
             "actual result string size are " +
             "less than or equal SIZE in bytes.",
             "(#{assertion_message_class.max_diff_target_string_size})") do |size|
          assertion_message_class.max_diff_target_string_size = size
        end

        o.on("--[no-]stop-on-failure",
             "Stops immediately on the first non success test",
             "(#{@stop_on_failure})") do |boolean|
          @stop_on_failure = boolean
        end

        ADDITIONAL_OPTIONS.each do |option_builder|
          option_builder.call(self, o)
        end

        o.on("--",
             "Stop processing options so that the",
             "remaining options will be passed to the",
             "test."){o.terminate}

        o.on("-h", "--help", "Display this help."){puts o; exit}

        o.on_tail
        o.on_tail("Deprecated options:")

        o.on_tail("--console", "Console runner (use --runner).") do
          warn("Deprecated option (--console).")
          @runner = self.class.runner(:console)
        end

        if RUNNERS[:fox]
          o.on_tail("--fox", "Fox runner (use --runner).") do
            warn("Deprecated option (--fox).")
            @runner = self.class.runner(:fox)
          end
        end

        o.on_tail
      end
    end

prepare() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 175
    def prepare
      PREPARE_HOOKS.each do |handler|
        handler.call(self)
      end
    end

process_args(args=ARGV) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 181
    def process_args(args=ARGV)
      begin
        args.unshift(*@default_arguments)
        options.order!(args) {|arg| add_test_path(arg)}
      rescue OptionParser::ParseError => e
        puts e
        puts options
        exit(false)
      end
      not @to_run.empty?
    end

run() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 425
    def run
      self.class.need_auto_run = false
      suite = @collector[self]
      return false if suite.nil?
      return true if suite.empty?
      runner = @runner[self]
      return false if runner.nil?
      @runner_options[:color_scheme] ||= @color_scheme
      @runner_options[:listeners] ||= []
      @runner_options[:listeners].concat(@listeners)
      if @stop_on_failure
        @runner_options[:listeners] << StopOnFailureListener.new
      end
      change_work_directory do
        runner.run(suite, @runner_options).passed?
      end
    end

stop_on_failure?() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/autorunner.rb, line 171
    def stop_on_failure?
      @stop_on_failure
    end