class Mutest::Env::Bootstrap

Bootstrap environment

Constants

CLASS_NAME_RAISED_EXCEPTION
CLASS_NAME_TYPE_MISMATCH_FORMAT
SEMANTICS_MESSAGE_FORMAT

Attributes

integration[R]

Configured mutest integration

@return [Mutest::Integration]

matchable_scopes[R]

Scopes that are eligible for matching

@return [Enumerable<Matcher::Scope>]

parser[R]

Parser for this environment

@return [Parser]

Public Class Methods

new(*) click to toggle source

Initialize object

@return [Object]

Calls superclass method
# File lib/mutest/env/bootstrap.rb, line 34
def initialize(*)
  super
  @parser = Parser.new
  infect
  initialize_matchable_scopes
end

Public Instance Methods

env() click to toggle source

Environment after bootstraping

@return [Env] rubocop:disable MethodLength

# File lib/mutest/env/bootstrap.rb, line 56
def env
  subjects = matched_subjects
  Env.new(
    actor_env:        Actor::Env.new(Thread),
    config:           config,
    integration:      integration,
    matchable_scopes: matchable_scopes,
    mutations:        subjects.flat_map(&:mutations),
    parser:           parser,
    selector:         Selector::Expression.new(integration),
    subjects:         subjects
  )
end
warn(message) click to toggle source

Print warning message

@param [String]

@return [self]

# File lib/mutest/env/bootstrap.rb, line 46
def warn(message)
  config.reporter.warn(message)
  self
end

Private Instance Methods

expression(scope) click to toggle source

Try to turn scope into expression

@param [Class, Module] scope

@return [Expression]

if scope can be represented in an expression

@return [nil]

otherwise
# File lib/mutest/env/bootstrap.rb, line 136
def expression(scope)
  name = scope_name(scope) or return

  unless name.instance_of?(String)
    semantics_warning(
      CLASS_NAME_TYPE_MISMATCH_FORMAT,
      name:        name,
      scope_class: scope.class,
      scope:       scope
    )
    return
  end

  config.expression_parser.try_parse(name)
end
infect() click to toggle source

Infect environment

@return [undefined]

# File lib/mutest/env/bootstrap.rb, line 101
def infect
  config.includes.each(&config.load_path.method(:<<))
  config.requires.each(&config.kernel.method(:require))
  @integration = config.integration.new(config).setup
end
initialize_matchable_scopes() click to toggle source

Initialize matchable scopes

@return [undefined]

# File lib/mutest/env/bootstrap.rb, line 117
def initialize_matchable_scopes
  scopes =
    ObjectSpace.each_object(Module).each_with_object([]) do |scope, aggregate|
      expression = expression(scope) || next
      aggregate << Scope.new(scope, expression)
    end

  @matchable_scopes = scopes.sort_by { |scope| scope.expression.syntax }
end
matched_subjects() click to toggle source

Matched subjects

@return [Enumerable<Subject>]

# File lib/mutest/env/bootstrap.rb, line 110
def matched_subjects
  Matcher::Compiler.call(config.matcher).call(self)
end
scope_name(scope) click to toggle source

Scope name from scoping object

@param [Class, Module] scope

@return [String]

if scope has a name and does not raise exceptions obtaining it

@return [nil]

otherwise
# File lib/mutest/env/bootstrap.rb, line 86
def scope_name(scope)
  scope.name
rescue StandardError => exception
  semantics_warning(
    CLASS_NAME_RAISED_EXCEPTION,
    exception:   exception.inspect,
    scope:       scope,
    scope_class: scope.class
  )
  nil
end
semantics_warning(format, **options) click to toggle source

Write a semantics warning

@return [undefined]

# File lib/mutest/env/bootstrap.rb, line 155
def semantics_warning(format, **options)
  message = format % options
  warn(format(SEMANTICS_MESSAGE_FORMAT, message: message))
end