From fb8bb2ed2448daa052c5717bb417191c9c6724ec Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Thu, 22 Nov 2012 03:00:36 +0100 Subject: [PATCH] Add static fail and success strategies * Useful for benchmarking --- lib/mutant.rb | 1 + lib/mutant/cli.rb | 20 +++++++++++--------- lib/mutant/killer/static.rb | 19 +++++++++++++++++++ lib/mutant/strategy.rb | 10 ++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 lib/mutant/killer/static.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 82982a4b..da6d82ae 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -83,6 +83,7 @@ require 'mutant/matcher/method/instance' require 'mutant/matcher/method/classifier' require 'mutant/matcher/scope_methods' require 'mutant/killer' +require 'mutant/killer/static' require 'mutant/killer/rspec' require 'mutant/killer/forking' require 'mutant/strategy' diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index 9b8f8968..776a2af6 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -83,15 +83,17 @@ module Mutant private OPTIONS = { - '--code' => [:add_filter, Mutation::Filter::Code ], - '-I' => [:add_load_path ], - '--include' => [:add_load_path ], - '-r' => [:require_library ], - '--require' => [:require_library ], - #'--killer-fork' => [:enable_killer_fork ], - '--rspec-unit' => [:set_strategy, Strategy::Rspec::Unit ], - '--rspec-full' => [:set_strategy, Strategy::Rspec::Full ], - '--rspec-dm2' => [:set_strategy, Strategy::Rspec::DM2 ] + '--code' => [:add_filter, Mutation::Filter::Code ], + '-I' => [:add_load_path ], + '--include' => [:add_load_path ], + '-r' => [:require_library ], + '--require' => [:require_library ], + #'--killer-fork' => [:enable_killer_fork ], + '--rspec-unit' => [:set_strategy, Strategy::Rspec::Unit ], + '--rspec-full' => [:set_strategy, Strategy::Rspec::Full ], + '--rspec-dm2' => [:set_strategy, Strategy::Rspec::DM2 ], + '--static-fail' => [:set_strategy, Strategy::Static::Fail ], + '--static-success' => [:set_strategy, Strategy::Static::Success ] }.deep_freeze OPTION_PATTERN = %r(\A-(?:-)?[a-zA-Z0-9\-]+\z).freeze diff --git a/lib/mutant/killer/static.rb b/lib/mutant/killer/static.rb new file mode 100644 index 00000000..c6cf5c5d --- /dev/null +++ b/lib/mutant/killer/static.rb @@ -0,0 +1,19 @@ +module Mutant + class Killer + class Static < self + def run + self.class::RESULT + end + + class Success < self + TYPE = 'success'.freeze + RESULT = true + end + + class Fail < self + TYPE = 'fail'.freeze + RESULT = false + end + end + end +end diff --git a/lib/mutant/strategy.rb b/lib/mutant/strategy.rb index ba60bfba..df4c598b 100644 --- a/lib/mutant/strategy.rb +++ b/lib/mutant/strategy.rb @@ -18,6 +18,16 @@ module Mutant self::KILLER end + class Static < self + class Fail < self + KILLER = Killer::Static::Fail + end + + class Success < self + KILLER = Killer::Static::Success + end + end + class Rspec < self KILLER = Killer::Rspec