Remove use of root level namespace within the lib
This allows the easy creation of Zombie to mutate Mutant.
This commit is contained in:
parent
d6165b3525
commit
28bbf9af00
8 changed files with 43 additions and 34 deletions
|
@ -10,36 +10,10 @@ require 'pp'
|
||||||
|
|
||||||
# Library namespace
|
# Library namespace
|
||||||
module Mutant
|
module Mutant
|
||||||
|
|
||||||
# Return deep clone of object
|
|
||||||
#
|
|
||||||
# @param [Object] object
|
|
||||||
#
|
|
||||||
# @return [Object] object
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def self.deep_clone(object)
|
|
||||||
Marshal.load(Marshal.dump(object))
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check for ruby-1.8 mode
|
|
||||||
#
|
|
||||||
# @return [true]
|
|
||||||
# returns true if running under 1.8 mode
|
|
||||||
#
|
|
||||||
# @return [false]
|
|
||||||
# returns false otherwise
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def self.on_18?
|
|
||||||
RUBY_VERSION == '1.8.7'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'mutant/support/method_object'
|
require 'mutant/support/method_object'
|
||||||
|
require 'mutant/helper'
|
||||||
require 'mutant/random'
|
require 'mutant/random'
|
||||||
require 'mutant/mutator'
|
require 'mutant/mutator'
|
||||||
require 'mutant/mutation'
|
require 'mutant/mutation'
|
||||||
|
|
37
lib/mutant/helper.rb
Normal file
37
lib/mutant/helper.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
module Mutant
|
||||||
|
# Module for support methods
|
||||||
|
#
|
||||||
|
# They would normally be defined on the root namespace.
|
||||||
|
# But it is easier to create the Zombie when there are no
|
||||||
|
# References to the root namespace name within the library.
|
||||||
|
#
|
||||||
|
module Helper
|
||||||
|
|
||||||
|
# Return deep clone of object
|
||||||
|
#
|
||||||
|
# @param [Object] object
|
||||||
|
#
|
||||||
|
# @return [Object] object
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
def self.deep_clone(object)
|
||||||
|
Marshal.load(Marshal.dump(object))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check for ruby-1.8 mode
|
||||||
|
#
|
||||||
|
# @return [true]
|
||||||
|
# returns true if running under 1.8 mode
|
||||||
|
#
|
||||||
|
# @return [false]
|
||||||
|
# returns false otherwise
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
def self.on_18?
|
||||||
|
RUBY_VERSION == '1.8.7'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,7 +24,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def initialize(root)
|
def initialize(root)
|
||||||
@root = Mutant.deep_clone(root)
|
@root = Helper.deep_clone(root)
|
||||||
Rubinius.run_script(compiled_code)
|
Rubinius.run_script(compiled_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def initialize(node, block)
|
def initialize(node, block)
|
||||||
@node, @block = Mutant.deep_clone(node), block
|
@node, @block = Helper.deep_clone(node), block
|
||||||
IceNine.deep_freeze(@node)
|
IceNine.deep_freeze(@node)
|
||||||
dispatch
|
dispatch
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,11 +65,11 @@ module Mutant
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
# Using '!' instead of :! since syntax highlighting in vim does not
|
# Using :'!' instead of :! since syntax highlighting in vim does not
|
||||||
# capture literal symbol.
|
# capture literal symbol.
|
||||||
#
|
#
|
||||||
def invert(node)
|
def invert(node)
|
||||||
if Mutant.on_18?
|
if Helper.on_18?
|
||||||
return new(Rubinius::AST::Not,node)
|
return new(Rubinius::AST::Not,node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,7 @@ module Mutant
|
||||||
end
|
end
|
||||||
|
|
||||||
@reporter = options.fetch(:reporter, Reporter::Null)
|
@reporter = options.fetch(:reporter, Reporter::Null)
|
||||||
|
|
||||||
@errors = []
|
@errors = []
|
||||||
|
|
||||||
run
|
run
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe Mutant::Mutator, 'if statement' do
|
||||||
mutants << 'if condition; true; else false; end'
|
mutants << 'if condition; true; else false; end'
|
||||||
|
|
||||||
# Invert condition
|
# Invert condition
|
||||||
if Mutant.on_18?
|
if Mutant::Helper.on_18?
|
||||||
# Explicitly define ast as 18-mode does swap if and else on parsing when negation condition is
|
# Explicitly define ast as 18-mode does swap if and else on parsing when negation condition is
|
||||||
# present in condition.
|
# present in condition.
|
||||||
mutants << [:if, [:not, [:call, [:self], :condition, [:arglist]]], [:true], [:false]]
|
mutants << [:if, [:not, [:call, [:self], :condition, [:arglist]]], [:true], [:false]]
|
||||||
|
|
Loading…
Reference in a new issue