Remove use of root level namespace within the lib

This allows the easy creation of Zombie to mutate Mutant.
This commit is contained in:
Markus Schirp 2012-08-16 22:59:25 +02:00
parent d6165b3525
commit 28bbf9af00
8 changed files with 43 additions and 34 deletions

View file

@ -10,36 +10,10 @@ require 'pp'
# Library namespace
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
require 'mutant/support/method_object'
require 'mutant/helper'
require 'mutant/random'
require 'mutant/mutator'
require 'mutant/mutation'

37
lib/mutant/helper.rb Normal file
View 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

View file

@ -24,7 +24,7 @@ module Mutant
# @api private
#
def initialize(root)
@root = Mutant.deep_clone(root)
@root = Helper.deep_clone(root)
Rubinius.run_script(compiled_code)
end

View file

@ -44,7 +44,7 @@ module Mutant
# @api private
#
def initialize(node, block)
@node, @block = Mutant.deep_clone(node), block
@node, @block = Helper.deep_clone(node), block
IceNine.deep_freeze(@node)
dispatch
end

View file

@ -65,11 +65,11 @@ module Mutant
#
# @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.
#
def invert(node)
if Mutant.on_18?
if Helper.on_18?
return new(Rubinius::AST::Not,node)
end

View file

@ -55,9 +55,7 @@ module Mutant
end
@reporter = options.fetch(:reporter, Reporter::Null)
@errors = []
run
end

View file

View file

@ -10,7 +10,7 @@ describe Mutant::Mutator, 'if statement' do
mutants << 'if condition; true; else false; end'
# 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
# present in condition.
mutants << [:if, [:not, [:call, [:self], :condition, [:arglist]]], [:true], [:false]]