From 7bf70d96343e5f54e808ac55eedaab33943df0f4 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sat, 19 Mar 2016 15:13:05 +0000 Subject: [PATCH] Add support for explicit type in meta examples * This is needed to relate examples to node types for nodes that cannot stand alone. Example are :where nodes that do not have syntax outside a :case --- config/flay.yml | 2 +- config/reek.yml | 2 + lib/mutant/meta.rb | 4 +- lib/mutant/meta/example.rb | 3 +- lib/mutant/meta/example/dsl.rb | 22 +++-- lib/mutant/meta/example/verification.rb | 4 +- meta/and.rb | 2 +- meta/and_asgn.rb | 2 +- meta/array.rb | 4 +- meta/begin.rb | 4 +- meta/block.rb | 14 +-- meta/block_pass.rb | 2 +- meta/blockarg.rb | 2 +- meta/boolean.rb | 13 --- meta/break.rb | 2 +- meta/case.rb | 4 +- meta/casgn.rb | 4 +- meta/cbase.rb | 2 +- meta/const.rb | 2 +- meta/csend.rb | 2 +- meta/cvar.rb | 2 +- meta/cvasgn.rb | 2 +- meta/date.rb | 8 +- meta/def.rb | 28 +++--- meta/defined.rb | 2 +- meta/dstr.rb | 2 +- meta/dsym.rb | 2 +- meta/ensure.rb | 2 +- meta/false.rb | 2 +- meta/float.rb | 6 +- meta/gvar.rb | 2 +- meta/gvasgn.rb | 2 +- meta/hash.rb | 2 +- meta/if.rb | 6 +- meta/int.rb | 2 +- meta/ivar.rb | 2 +- meta/ivasgn.rb | 2 +- meta/kwbegin.rb | 2 +- meta/lvar.rb | 2 +- meta/lvasgn.rb | 2 +- meta/masgn.rb | 2 +- meta/match_current_line.rb | 2 +- meta/next.rb | 2 +- meta/nil.rb | 2 +- meta/nthref.rb | 4 +- meta/op_assgn.rb | 2 +- meta/or.rb | 2 +- meta/or_asgn.rb | 10 +- meta/range.rb | 4 +- meta/redo.rb | 2 +- meta/regex.rb | 4 +- meta/rescue.rb | 8 +- meta/restarg.rb | 2 +- meta/return.rb | 4 +- meta/self.rb | 2 +- meta/send.rb | 96 +++++++++---------- meta/str.rb | 2 +- meta/super.rb | 6 +- meta/{symbol.rb => sym.rb} | 2 +- meta/true.rb | 2 +- meta/until.rb | 2 +- meta/while.rb | 4 +- meta/yield.rb | 2 +- spec/unit/mutant/meta/example/dsl_spec.rb | 10 +- .../mutant/meta/example/verification_spec.rb | 7 +- spec/unit/mutant/meta/example_spec.rb | 7 +- 66 files changed, 186 insertions(+), 182 deletions(-) delete mode 100644 meta/boolean.rb rename meta/{symbol.rb => sym.rb} (67%) diff --git a/config/flay.yml b/config/flay.yml index aaff9513..57f9d0d1 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1168 +total_score: 1160 diff --git a/config/reek.yml b/config/reek.yml index e9f9d852..429ea105 100644 --- a/config/reek.yml +++ b/config/reek.yml @@ -32,6 +32,7 @@ LongParameterList: enabled: true exclude: - Mutant::Matcher::Method::Instance#self.build + - Mutant::Meta::Example::DSL # 3 vars max_params: 2 LongYieldList: enabled: true @@ -64,6 +65,7 @@ TooManyInstanceVariables: exclude: - Mutant::Mutator # 4 vars - Mutant::Parallel::Master # 4 vars + - Mutant::Meta::Example::DSL # 4 vars max_instance_variables: 3 TooManyMethods: enabled: true diff --git a/lib/mutant/meta.rb b/lib/mutant/meta.rb index ebd4c54d..951976bf 100644 --- a/lib/mutant/meta.rb +++ b/lib/mutant/meta.rb @@ -14,9 +14,9 @@ module Mutant # Add example # # @return [undefined] - def self.add(&block) + def self.add(type, &block) file = caller.first.split(':in', 2).first - ALL << DSL.call(file, block) + ALL << DSL.call(file, type, block) end Pathname.glob(Pathname.new(__dir__).parent.parent.join('meta', '*.rb')) diff --git a/lib/mutant/meta/example.rb b/lib/mutant/meta/example.rb index 963236f0..13026e35 100644 --- a/lib/mutant/meta/example.rb +++ b/lib/mutant/meta/example.rb @@ -1,7 +1,7 @@ module Mutant module Meta class Example - include Adamantium, Concord::Public.new(:file, :node, :mutations) + include Adamantium, Anima.new(:file, :node, :node_type, :expected) # Verification instance for example # @@ -27,6 +27,7 @@ module Mutant end end memoize :generated + end # Example end # Meta end # Mutant diff --git a/lib/mutant/meta/example/dsl.rb b/lib/mutant/meta/example/dsl.rb index 47a3859e..a8255aaf 100644 --- a/lib/mutant/meta/example/dsl.rb +++ b/lib/mutant/meta/example/dsl.rb @@ -8,8 +8,8 @@ module Mutant # Run DSL on block # # @return [Example] - def self.call(file, block) - instance = new(file) + def self.call(file, type, block) + instance = new(file, type) instance.instance_eval(&block) instance.example end @@ -19,9 +19,10 @@ module Mutant # Initialize object # # @return [undefined] - def initialize(file) + def initialize(file, type) @file = file - @source = nil + @type = type + @node = nil @expected = [] end @@ -32,8 +33,13 @@ module Mutant # @raise [RuntimeError] # in case example cannot be build def example - fail 'source not defined' unless @source - Example.new(@file, @source, @expected) + fail 'source not defined' unless @node + Example.new( + file: @file, + node: @node, + node_type: @type, + expected: @expected + ) end private @@ -44,8 +50,8 @@ module Mutant # # @return [undefined] def source(input) - fail 'source already defined' if @source - @source = node(input) + fail 'source already defined' if @node + @node = node(input) end # Add expected mutation diff --git a/lib/mutant/meta/example/verification.rb b/lib/mutant/meta/example/verification.rb index 55549512..2f1992c9 100644 --- a/lib/mutant/meta/example/verification.rb +++ b/lib/mutant/meta/example/verification.rb @@ -34,7 +34,7 @@ module Mutant # # @return [Array] def unexpected - mutations.map(&:node) - example.mutations + mutations.map(&:node) - example.expected end memoize :unexpected @@ -76,7 +76,7 @@ module Mutant # # @return [Array] def missing - example.mutations - mutations.map(&:node) + example.expected - mutations.map(&:node) end memoize :missing diff --git a/meta/and.rb b/meta/and.rb index db7c71d2..6628febf 100644 --- a/meta/and.rb +++ b/meta/and.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :and do source 'true and false' singleton_mutations diff --git a/meta/and_asgn.rb b/meta/and_asgn.rb index f30d07ee..fd731e5a 100644 --- a/meta/and_asgn.rb +++ b/meta/and_asgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :and_asgn do source 'a &&= 1' singleton_mutations diff --git a/meta/array.rb b/meta/array.rb index f8ff6349..c7ecca05 100644 --- a/meta/array.rb +++ b/meta/array.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :array do source '[true]' singleton_mutations @@ -8,7 +8,7 @@ Mutant::Meta::Example.add do mutation '[]' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :array do source '[true, false]' singleton_mutations diff --git a/meta/begin.rb b/meta/begin.rb index 6667016a..896d827d 100644 --- a/meta/begin.rb +++ b/meta/begin.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :begin do source 'true; false' # Mutation of each statement in block @@ -12,7 +12,7 @@ Mutant::Meta::Example.add do mutation 'false' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :begin do source s(:begin, s(:true)) # Mutation of each statement in block diff --git a/meta/block.rb b/meta/block.rb index 7d83a844..faa15e6f 100644 --- a/meta/block.rb +++ b/meta/block.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { a; b }' singleton_mutations @@ -14,7 +14,7 @@ Mutant::Meta::Example.add do mutation 'a; b' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { |a, b| }' singleton_mutations @@ -27,7 +27,7 @@ Mutant::Meta::Example.add do mutation 'foo { || }' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { |(a, b), c| }' singleton_mutations @@ -44,7 +44,7 @@ Mutant::Meta::Example.add do mutation 'foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo(a, b) {}' singleton_mutations @@ -59,7 +59,7 @@ Mutant::Meta::Example.add do mutation 'foo {}' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { |(a)| }' singleton_mutations @@ -70,7 +70,7 @@ Mutant::Meta::Example.add do mutation 'foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { bar(nil) }' singleton_mutations @@ -84,7 +84,7 @@ Mutant::Meta::Example.add do mutation 'bar(nil)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block do source 'foo { self << true }' singleton_mutations diff --git a/meta/block_pass.rb b/meta/block_pass.rb index 7aa048af..2c835db6 100644 --- a/meta/block_pass.rb +++ b/meta/block_pass.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :block_pass do source 'foo(&bar)' singleton_mutations diff --git a/meta/blockarg.rb b/meta/blockarg.rb index 7aa007de..3e582a07 100644 --- a/meta/blockarg.rb +++ b/meta/blockarg.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :blockarg do source 'foo { |&bar| }' singleton_mutations diff --git a/meta/boolean.rb b/meta/boolean.rb deleted file mode 100644 index 54af3a31..00000000 --- a/meta/boolean.rb +++ /dev/null @@ -1,13 +0,0 @@ -Mutant::Meta::Example.add do - source 'true' - - mutation 'nil' - mutation 'false' -end - -Mutant::Meta::Example.add do - source 'false' - - mutation 'nil' - mutation 'true' -end diff --git a/meta/break.rb b/meta/break.rb index 3790bb11..fb71048a 100644 --- a/meta/break.rb +++ b/meta/break.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :break do source 'break true' singleton_mutations diff --git a/meta/case.rb b/meta/case.rb index a6bb65f5..5ff2ab86 100644 --- a/meta/case.rb +++ b/meta/case.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :case do source <<-RUBY case when true @@ -29,7 +29,7 @@ Mutant::Meta::Example.add do RUBY end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :case do source <<-RUBY case condition when A diff --git a/meta/casgn.rb b/meta/casgn.rb index a433b867..be366261 100644 --- a/meta/casgn.rb +++ b/meta/casgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :casgn do source 'A = true' mutation 'A__MUTANT__ = true' @@ -7,7 +7,7 @@ Mutant::Meta::Example.add do mutation 'remove_const :A' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :casgn do source 'self::A = true' mutation 'self::A__MUTANT__ = true' diff --git a/meta/cbase.rb b/meta/cbase.rb index 2986f037..a2b996cc 100644 --- a/meta/cbase.rb +++ b/meta/cbase.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :cbase do source '::A' singleton_mutations diff --git a/meta/const.rb b/meta/const.rb index 8e1db0a0..936a15d2 100644 --- a/meta/const.rb +++ b/meta/const.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :const do source 'A::B::C' singleton_mutations diff --git a/meta/csend.rb b/meta/csend.rb index f74085be..8d21098e 100644 --- a/meta/csend.rb +++ b/meta/csend.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :csend do source 'a&.b' singleton_mutations diff --git a/meta/cvar.rb b/meta/cvar.rb index 193dfacc..05c4574a 100644 --- a/meta/cvar.rb +++ b/meta/cvar.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :cvar do source '@@a' singleton_mutations diff --git a/meta/cvasgn.rb b/meta/cvasgn.rb index 54b796f1..c52d9bee 100644 --- a/meta/cvasgn.rb +++ b/meta/cvasgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :cvasgn do source '@@a = true' singleton_mutations diff --git a/meta/date.rb b/meta/date.rb index 1f0a0ae4..78c15c07 100644 --- a/meta/date.rb +++ b/meta/date.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'Date.parse(nil)' singleton_mutations @@ -17,7 +17,7 @@ Mutant::Meta::Example.add do mutation 'Date.jisx0301(nil)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source '::Date.parse(nil)' singleton_mutations @@ -37,7 +37,7 @@ Mutant::Meta::Example.add do mutation '::Date.jisx0301(nil)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'Date.iso8601(nil)' singleton_mutations @@ -46,7 +46,7 @@ Mutant::Meta::Example.add do mutation 'Date' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'Foo::Date.parse(nil)' singleton_mutations diff --git a/meta/def.rb b/meta/def.rb index ec243299..7ef49c83 100644 --- a/meta/def.rb +++ b/meta/def.rb @@ -1,11 +1,11 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo; end' mutation 'def foo; raise; end' mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a, *b); nil; end' mutation 'def foo(_a, *b); nil; end' @@ -18,7 +18,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a, *); nil; end' mutation 'def foo(_a, *); nil; end' @@ -30,7 +30,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo; foo; rescue; end' mutation 'def foo; raise; end' @@ -43,7 +43,7 @@ Mutant::Meta::Example.add do mutation 'def foo; foo; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def a; foo; rescue; bar; else; baz; end' # Mutate all bodies @@ -72,7 +72,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :a' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo; true; false; end' # Mutation of each statement in block @@ -93,7 +93,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a, b); end' # Deletion of each argument @@ -113,7 +113,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a, b = nil); true; end' mutation 'def foo(_a, b = nil); true; end' @@ -130,7 +130,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(_unused); end' mutation 'def foo(_unused); raise; end' @@ -138,7 +138,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(_unused = true); end' mutation 'def foo(_unused = nil); end' @@ -149,7 +149,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a = 0, b = 0); end' mutation 'def foo(a = 0, _b = 0); end' mutation 'def foo(_a = 0, b = 0); end' @@ -171,7 +171,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def foo(a = true); end' mutation 'def foo(a); end' @@ -184,7 +184,7 @@ Mutant::Meta::Example.add do mutation 'remove_method :foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def self.foo; true; false; end' # Body presence mutation @@ -203,7 +203,7 @@ Mutant::Meta::Example.add do mutation 'def self.foo; raise; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :def do source 'def self.foo(a, b); end' diff --git a/meta/defined.rb b/meta/defined.rb index 48214224..6bce9192 100644 --- a/meta/defined.rb +++ b/meta/defined.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :defined? do source 'defined?(foo)' singleton_mutations diff --git a/meta/dstr.rb b/meta/dstr.rb index 5a6db57b..d23c31dc 100644 --- a/meta/dstr.rb +++ b/meta/dstr.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :dstr do source '"foo#{bar}baz"' singleton_mutations diff --git a/meta/dsym.rb b/meta/dsym.rb index c94a1835..49a73107 100644 --- a/meta/dsym.rb +++ b/meta/dsym.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :dsym do source ':"foo#{bar}baz"' singleton_mutations diff --git a/meta/ensure.rb b/meta/ensure.rb index 45543073..a69ccb5d 100644 --- a/meta/ensure.rb +++ b/meta/ensure.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :ensure do source 'begin; rescue; ensure; true; end' singleton_mutations diff --git a/meta/false.rb b/meta/false.rb index a864f0db..83f07276 100644 --- a/meta/false.rb +++ b/meta/false.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :false do source 'false' mutation 'nil' diff --git a/meta/float.rb b/meta/float.rb index 1c445e59..4c4533c4 100644 --- a/meta/float.rb +++ b/meta/float.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :float do source '10.0' singleton_mutations @@ -14,7 +14,7 @@ Mutant::Meta::Example.add do mutation '-10.0' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :float do source '0.0' singleton_mutations @@ -24,7 +24,7 @@ Mutant::Meta::Example.add do mutation '(-1.0 / 0.0)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :float do source '-0.0' singleton_mutations diff --git a/meta/gvar.rb b/meta/gvar.rb index 037d6fd2..2293a3ea 100644 --- a/meta/gvar.rb +++ b/meta/gvar.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :gvar do source '$a' singleton_mutations diff --git a/meta/gvasgn.rb b/meta/gvasgn.rb index d2276d0e..0a95bef0 100644 --- a/meta/gvasgn.rb +++ b/meta/gvasgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :gvasgn do source '$a = true' singleton_mutations diff --git a/meta/hash.rb b/meta/hash.rb index edf3c5d9..32b3267f 100644 --- a/meta/hash.rb +++ b/meta/hash.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :hash do source '{true => true, false => false}' singleton_mutations diff --git a/meta/if.rb b/meta/if.rb index 610c8ccb..064e7119 100644 --- a/meta/if.rb +++ b/meta/if.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :if do source 'if condition; true; else false; end' singleton_mutations @@ -33,7 +33,7 @@ Mutant::Meta::Example.add do mutation 'if condition; true; else nil; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :if do source 'if condition; true; end' singleton_mutations @@ -46,7 +46,7 @@ Mutant::Meta::Example.add do mutation 'true' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :if do source 'unless condition; true; end' singleton_mutations diff --git a/meta/int.rb b/meta/int.rb index 455f7f8d..a68e847e 100644 --- a/meta/int.rb +++ b/meta/int.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :int do source '10' singleton_mutations diff --git a/meta/ivar.rb b/meta/ivar.rb index ba5f8b3f..e3959a96 100644 --- a/meta/ivar.rb +++ b/meta/ivar.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :ivar do source '@foo' singleton_mutations diff --git a/meta/ivasgn.rb b/meta/ivasgn.rb index 2c865c31..26e010df 100644 --- a/meta/ivasgn.rb +++ b/meta/ivasgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :ivasgn do source '@a = true' singleton_mutations diff --git a/meta/kwbegin.rb b/meta/kwbegin.rb index 4ff1456c..0dc8ea50 100644 --- a/meta/kwbegin.rb +++ b/meta/kwbegin.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :kwbegin do source 'begin; true; end' singleton_mutations diff --git a/meta/lvar.rb b/meta/lvar.rb index e6e6ebfb..2e658e2e 100644 --- a/meta/lvar.rb +++ b/meta/lvar.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :lvar do source 'a = nil; a' mutation 'a = nil; nil' diff --git a/meta/lvasgn.rb b/meta/lvasgn.rb index 324460b1..da7de9f2 100644 --- a/meta/lvasgn.rb +++ b/meta/lvasgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :lvasgn do source 'a = true' singleton_mutations diff --git a/meta/masgn.rb b/meta/masgn.rb index b3545d50..bf408311 100644 --- a/meta/masgn.rb +++ b/meta/masgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :masgn do source 'a, b = c, d' singleton_mutations diff --git a/meta/match_current_line.rb b/meta/match_current_line.rb index f05ed272..7a8acbb9 100644 --- a/meta/match_current_line.rb +++ b/meta/match_current_line.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :match_current_line do source 'true if /foo/' singleton_mutations diff --git a/meta/next.rb b/meta/next.rb index 01a753c6..4407938c 100644 --- a/meta/next.rb +++ b/meta/next.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :next do source 'next true' singleton_mutations diff --git a/meta/nil.rb b/meta/nil.rb index 42e62c9f..235ae1d4 100644 --- a/meta/nil.rb +++ b/meta/nil.rb @@ -1,3 +1,3 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :nil do source 'nil' end diff --git a/meta/nthref.rb b/meta/nthref.rb index a510f6bc..5fe0b36f 100644 --- a/meta/nthref.rb +++ b/meta/nthref.rb @@ -1,10 +1,10 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :nthref do source '$1' mutation '$2' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :nthref do source '$2' mutation '$3' diff --git a/meta/op_assgn.rb b/meta/op_assgn.rb index 6299039c..dabe5763 100644 --- a/meta/op_assgn.rb +++ b/meta/op_assgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :op_asgn do source '@a.b += 1' singleton_mutations diff --git a/meta/or.rb b/meta/or.rb index c452ad7b..85999a0c 100644 --- a/meta/or.rb +++ b/meta/or.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or do source 'true or false' singleton_mutations diff --git a/meta/or_asgn.rb b/meta/or_asgn.rb index 4fd3d6f7..f1a9156a 100644 --- a/meta/or_asgn.rb +++ b/meta/or_asgn.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or_asgn do source 'a ||= 1' singleton_mutations @@ -10,7 +10,7 @@ Mutant::Meta::Example.add do mutation 'a ||= 2' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or_asgn do source '@a ||= 1' singleton_mutations @@ -21,13 +21,13 @@ Mutant::Meta::Example.add do mutation '@a ||= 2' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or_asgn do source 'Foo ||= nil' singleton_mutations end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or_asgn do source '@a ||= self.bar' singleton_mutations @@ -36,7 +36,7 @@ Mutant::Meta::Example.add do mutation '@a ||= bar' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :or_asgn do source 'foo[:bar] ||= 1' singleton_mutations diff --git a/meta/range.rb b/meta/range.rb index f3fa8ebd..38218827 100644 --- a/meta/range.rb +++ b/meta/range.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :irange do source '1..100' singleton_mutations @@ -20,7 +20,7 @@ Mutant::Meta::Example.add do mutation '1..-100' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :erange do source '1...100' singleton_mutations diff --git a/meta/redo.rb b/meta/redo.rb index e52022de..0554edbf 100644 --- a/meta/redo.rb +++ b/meta/redo.rb @@ -1,3 +1,3 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :redo do source 'redo' end diff --git a/meta/regex.rb b/meta/regex.rb index 3d44c98b..930824f0 100644 --- a/meta/regex.rb +++ b/meta/regex.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :regexp do source '/foo/' singleton_mutations @@ -6,7 +6,7 @@ Mutant::Meta::Example.add do mutation '/a\A/' # match nothing end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :regexp do source '/#{foo.bar}n/' singleton_mutations diff --git a/meta/rescue.rb b/meta/rescue.rb index e1a591d5..25d00ee1 100644 --- a/meta/rescue.rb +++ b/meta/rescue.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :rescue do source 'begin; rescue ExceptionA, ExceptionB => error; true; end' singleton_mutations @@ -11,7 +11,7 @@ Mutant::Meta::Example.add do end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :rescue do source 'begin; rescue SomeException => error; true; end' singleton_mutations @@ -22,7 +22,7 @@ Mutant::Meta::Example.add do mutation 'begin; true; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :rescue do source 'begin; rescue => error; true end' singleton_mutations @@ -32,7 +32,7 @@ Mutant::Meta::Example.add do mutation 'begin; true; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :rescue do source 'begin; rescue; true end' singleton_mutations diff --git a/meta/restarg.rb b/meta/restarg.rb index b5386694..9e6c00c7 100644 --- a/meta/restarg.rb +++ b/meta/restarg.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :restarg do source 'foo(*bar)' singleton_mutations diff --git a/meta/return.rb b/meta/return.rb index 8431d4e5..6df54f79 100644 --- a/meta/return.rb +++ b/meta/return.rb @@ -1,10 +1,10 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :return do source 'return' singleton_mutations end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :return do source 'return foo' singleton_mutations diff --git a/meta/self.rb b/meta/self.rb index d6984312..cae8f232 100644 --- a/meta/self.rb +++ b/meta/self.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :self do source 'self' mutation 'nil' diff --git a/meta/send.rb b/meta/send.rb index 50a7faf2..c74ab13e 100644 --- a/meta/send.rb +++ b/meta/send.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'a > b' singleton_mutations @@ -14,7 +14,7 @@ Mutant::Meta::Example.add do mutation 'b' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'A.const_get(:B)' singleton_mutations @@ -28,7 +28,7 @@ Mutant::Meta::Example.add do mutation 'self.const_get(:B)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'A.const_get(bar)' singleton_mutations @@ -40,7 +40,7 @@ Mutant::Meta::Example.add do mutation 'self.const_get(bar)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'method(bar)' singleton_mutations @@ -51,7 +51,7 @@ Mutant::Meta::Example.add do mutation 'method(self)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'a >= b' singleton_mutations @@ -67,7 +67,7 @@ Mutant::Meta::Example.add do mutation 'b' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'a <= b' singleton_mutations @@ -83,7 +83,7 @@ Mutant::Meta::Example.add do mutation 'b' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'a < b' singleton_mutations @@ -99,21 +99,21 @@ Mutant::Meta::Example.add do mutation 'b' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'reverse_each' singleton_mutations mutation 'each' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'reverse_merge' singleton_mutations mutation 'merge' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'reverse_map' singleton_mutations @@ -121,14 +121,14 @@ Mutant::Meta::Example.add do mutation 'each' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'map' singleton_mutations mutation 'each' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.to_s' singleton_mutations @@ -137,7 +137,7 @@ Mutant::Meta::Example.add do mutation 'foo.to_str' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.to_a' singleton_mutations @@ -147,7 +147,7 @@ Mutant::Meta::Example.add do mutation 'foo.to_set' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.to_i' singleton_mutations @@ -157,7 +157,7 @@ Mutant::Meta::Example.add do mutation 'Integer(foo)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.to_h' singleton_mutations @@ -166,7 +166,7 @@ Mutant::Meta::Example.add do mutation 'foo.to_hash' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo == bar' singleton_mutations @@ -180,7 +180,7 @@ Mutant::Meta::Example.add do mutation 'foo.equal?(bar)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.is_a?(bar)' singleton_mutations @@ -193,7 +193,7 @@ Mutant::Meta::Example.add do mutation 'foo.instance_of?(bar)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.is_a?(bar)' singleton_mutations @@ -206,7 +206,7 @@ Mutant::Meta::Example.add do mutation 'foo.instance_of?(bar)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.kind_of?(bar)' singleton_mutations @@ -219,7 +219,7 @@ Mutant::Meta::Example.add do mutation 'foo.instance_of?(bar)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.gsub(a, b)' singleton_mutations @@ -235,7 +235,7 @@ Mutant::Meta::Example.add do mutation 'self.gsub(a, b)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.values_at(a, b)' singleton_mutations @@ -251,7 +251,7 @@ Mutant::Meta::Example.add do mutation 'foo.values_at' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.dig(a, b)' singleton_mutations @@ -267,7 +267,7 @@ Mutant::Meta::Example.add do mutation 'foo.dig' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.dig(a)' singleton_mutations @@ -280,7 +280,7 @@ Mutant::Meta::Example.add do mutation 'a' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.dig' singleton_mutations @@ -288,7 +288,7 @@ Mutant::Meta::Example.add do mutation 'self.dig' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.__send__(bar)' singleton_mutations @@ -301,7 +301,7 @@ Mutant::Meta::Example.add do mutation 'foo.__send__(self)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.send(bar)' singleton_mutations @@ -315,7 +315,7 @@ Mutant::Meta::Example.add do mutation 'foo.send(self)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.bar = baz' singleton_mutations @@ -326,7 +326,7 @@ Mutant::Meta::Example.add do # This one could probably be removed end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.bar = baz' singleton_mutations @@ -339,7 +339,7 @@ Mutant::Meta::Example.add do # This one could probably be removed end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo[bar] = baz' singleton_mutations @@ -353,7 +353,7 @@ Mutant::Meta::Example.add do mutation 'baz' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo(*bar)' singleton_mutations @@ -365,20 +365,20 @@ Mutant::Meta::Example.add do mutation 'foo(*self)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo(&bar)' singleton_mutations mutation 'foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo' singleton_mutations end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.foo' singleton_mutations @@ -386,14 +386,14 @@ Mutant::Meta::Example.add do end Unparser::Constants::KEYWORDS.each do |keyword| - Mutant::Meta::Example.add do + Mutant::Meta::Example.add :send do source "self.#{keyword}" singleton_mutations end end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo.bar' singleton_mutations @@ -401,7 +401,7 @@ Mutant::Meta::Example.add do mutation 'self.bar' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.class.foo' singleton_mutations @@ -409,14 +409,14 @@ Mutant::Meta::Example.add do mutation 'self.foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo(nil)' singleton_mutations mutation 'foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.foo(nil)' singleton_mutations @@ -424,7 +424,7 @@ Mutant::Meta::Example.add do mutation 'foo(nil)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.fetch(nil)' singleton_mutations @@ -434,7 +434,7 @@ Mutant::Meta::Example.add do end Unparser::Constants::KEYWORDS.each do |keyword| - Mutant::Meta::Example.add do + Mutant::Meta::Example.add :send do source "foo.#{keyword}(nil)" singleton_mutations @@ -444,7 +444,7 @@ Unparser::Constants::KEYWORDS.each do |keyword| end end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo(nil, nil)' singleton_mutations @@ -452,7 +452,7 @@ Mutant::Meta::Example.add do mutation 'foo(nil)' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source '(left - right) / foo' singleton_mutations @@ -470,7 +470,7 @@ Mutant::Meta::Example.add do mutation 'self / foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo[1]' singleton_mutations @@ -488,7 +488,7 @@ Mutant::Meta::Example.add do mutation 'foo[self]' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self.foo[]' singleton_mutations @@ -500,7 +500,7 @@ Mutant::Meta::Example.add do mutation 'foo[]' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'self[foo]' singleton_mutations @@ -513,7 +513,7 @@ Mutant::Meta::Example.add do mutation 'foo' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'foo[*bar]' singleton_mutations @@ -531,7 +531,7 @@ Mutant::Meta::Example.add do end (Mutant::AST::Types::BINARY_METHOD_OPERATORS - %i[<= >= < > == != eql?]).each do |operator| - Mutant::Meta::Example.add do + Mutant::Meta::Example.add :send do source "true #{operator} false" singleton_mutations @@ -544,7 +544,7 @@ end end end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :send do source 'a != b' singleton_mutations diff --git a/meta/str.rb b/meta/str.rb index 5fd50fe8..45fda7a0 100644 --- a/meta/str.rb +++ b/meta/str.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :str do source '"foo"' singleton_mutations diff --git a/meta/super.rb b/meta/super.rb index 3ae37f2f..1989357e 100644 --- a/meta/super.rb +++ b/meta/super.rb @@ -1,17 +1,17 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :super do source 'super' singleton_mutations mutation 'super()' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :super do source 'super()' singleton_mutations end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :super do source 'super(foo, bar)' singleton_mutations diff --git a/meta/symbol.rb b/meta/sym.rb similarity index 67% rename from meta/symbol.rb rename to meta/sym.rb index 5f6cc0ff..94ab31bf 100644 --- a/meta/symbol.rb +++ b/meta/sym.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :sym do source ':foo' singleton_mutations diff --git a/meta/true.rb b/meta/true.rb index 3d1f9dce..64681e4c 100644 --- a/meta/true.rb +++ b/meta/true.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :true do source 'true' mutation 'nil' diff --git a/meta/until.rb b/meta/until.rb index dc1976e6..3edd1f1f 100644 --- a/meta/until.rb +++ b/meta/until.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :until do source 'until true; foo; bar; end' singleton_mutations diff --git a/meta/while.rb b/meta/while.rb index 06032bda..cc41bfd2 100644 --- a/meta/while.rb +++ b/meta/while.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :while do source 'while true; foo; bar; end' singleton_mutations @@ -14,7 +14,7 @@ Mutant::Meta::Example.add do mutation 'while true; raise; end' end -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :while do source 'while true; end' singleton_mutations diff --git a/meta/yield.rb b/meta/yield.rb index 7ff469aa..b8485dc0 100644 --- a/meta/yield.rb +++ b/meta/yield.rb @@ -1,4 +1,4 @@ -Mutant::Meta::Example.add do +Mutant::Meta::Example.add :yield do source 'yield true' singleton_mutations diff --git a/spec/unit/mutant/meta/example/dsl_spec.rb b/spec/unit/mutant/meta/example/dsl_spec.rb index 785fd6bb..d64d826f 100644 --- a/spec/unit/mutant/meta/example/dsl_spec.rb +++ b/spec/unit/mutant/meta/example/dsl_spec.rb @@ -1,13 +1,19 @@ RSpec.describe Mutant::Meta::Example::DSL do describe '.call' do - subject { described_class.call(file, block) } + subject { described_class.call(file, type, block) } let(:file) { 'foo.rb' } let(:node) { s(:false) } + let(:type) { node.type } let(:expected) { [] } let(:expected_example) do - Mutant::Meta::Example.new(file, node, expected) + Mutant::Meta::Example.new( + file: file, + node: node, + node_type: type, + expected: expected + ) end def self.expect_example(&block) diff --git a/spec/unit/mutant/meta/example/verification_spec.rb b/spec/unit/mutant/meta/example/verification_spec.rb index 36d345e2..98ecb055 100644 --- a/spec/unit/mutant/meta/example/verification_spec.rb +++ b/spec/unit/mutant/meta/example/verification_spec.rb @@ -3,9 +3,10 @@ RSpec.describe Mutant::Meta::Example::Verification do let(:example) do Mutant::Meta::Example.new( - 'foo.rb', - s(:true), - expected_nodes + file: 'foo.rb', + node: s(:true), + node_type: :true, + expected: expected_nodes ) end diff --git a/spec/unit/mutant/meta/example_spec.rb b/spec/unit/mutant/meta/example_spec.rb index b3063446..0f18e5a7 100644 --- a/spec/unit/mutant/meta/example_spec.rb +++ b/spec/unit/mutant/meta/example_spec.rb @@ -1,9 +1,10 @@ RSpec.describe Mutant::Meta::Example do let(:object) do described_class.new( - file, - node, - mutation_nodes + file: file, + node: node, + node_type: node.type, + expected: mutation_nodes ) end