mutant 0.2.20 → 0.3.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +10 -11
- data/Changelog.md +93 -38
- data/Gemfile +3 -1
- data/Gemfile.devtools +16 -20
- data/Guardfile +1 -1
- data/README.md +36 -16
- data/Rakefile +21 -2
- data/TODO +11 -7
- data/bin/mutant +4 -0
- data/bin/zombie +4 -0
- data/config/devtools.yml +2 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/{site.reek → reek.yml} +94 -70
- data/lib/mutant/cli/classifier/method.rb +100 -0
- data/lib/mutant/cli/classifier/namespace.rb +47 -0
- data/lib/mutant/cli/classifier/scope.rb +35 -0
- data/lib/mutant/cli/classifier.rb +141 -0
- data/lib/mutant/cli.rb +115 -162
- data/lib/mutant/color.rb +2 -2
- data/lib/mutant/config.rb +27 -0
- data/lib/mutant/constants.rb +32 -17
- data/lib/mutant/context/scope.rb +33 -51
- data/lib/mutant/context.rb +8 -19
- data/lib/mutant/differ.rb +5 -5
- data/lib/mutant/helper.rb +2 -17
- data/lib/mutant/killer/forked.rb +44 -0
- data/lib/mutant/killer/forking.rb +3 -57
- data/lib/mutant/killer/rspec.rb +16 -20
- data/lib/mutant/killer/static.rb +6 -7
- data/lib/mutant/killer.rb +48 -74
- data/lib/mutant/loader.rb +6 -6
- data/lib/mutant/matcher/chain.rb +4 -25
- data/lib/mutant/matcher/method/instance.rb +14 -24
- data/lib/mutant/matcher/method/singleton.rb +35 -46
- data/lib/mutant/matcher/method.rb +95 -83
- data/lib/mutant/matcher/{scope_methods.rb → methods.rb} +53 -76
- data/lib/mutant/matcher/namespace.rb +71 -0
- data/lib/mutant/matcher/scope.rb +34 -0
- data/lib/mutant/matcher.rb +24 -34
- data/lib/mutant/mutation/evil.rb +35 -0
- data/lib/mutant/mutation/filter/code.rb +7 -28
- data/lib/mutant/mutation/filter/regexp.rb +6 -18
- data/lib/mutant/mutation/filter/whitelist.rb +5 -4
- data/lib/mutant/mutation/filter.rb +10 -9
- data/lib/mutant/mutation/neutral.rb +35 -0
- data/lib/mutant/mutation.rb +21 -61
- data/lib/mutant/mutator/node/argument.rb +88 -0
- data/lib/mutant/mutator/node/arguments.rb +52 -0
- data/lib/mutant/mutator/node/assignment.rb +34 -38
- data/lib/mutant/mutator/node/begin.rb +33 -0
- data/lib/mutant/mutator/node/block.rb +14 -14
- data/lib/mutant/mutator/node/case.rb +59 -0
- data/lib/mutant/mutator/node/define.rb +26 -22
- data/lib/mutant/mutator/node/if.rb +31 -71
- data/lib/mutant/mutator/node/literal/array.rb +25 -9
- data/lib/mutant/mutator/node/literal/boolean.rb +13 -30
- data/lib/mutant/mutator/node/literal/dynamic.rb +6 -5
- data/lib/mutant/mutator/node/literal/fixnum.rb +18 -7
- data/lib/mutant/mutator/node/literal/float.rb +15 -8
- data/lib/mutant/mutator/node/literal/hash.rb +33 -52
- data/lib/mutant/mutator/node/literal/nil.rb +8 -7
- data/lib/mutant/mutator/node/literal/range.rb +25 -50
- data/lib/mutant/mutator/node/literal/regex.rb +15 -23
- data/lib/mutant/mutator/node/literal/string.rb +7 -6
- data/lib/mutant/mutator/node/literal/symbol.rb +7 -6
- data/lib/mutant/mutator/node/literal.rb +4 -46
- data/lib/mutant/mutator/node/mlhs.rb +27 -0
- data/lib/mutant/mutator/node/noop.rb +18 -43
- data/lib/mutant/mutator/node/return.rb +8 -8
- data/lib/mutant/mutator/node/send/binary.rb +31 -0
- data/lib/mutant/mutator/node/send.rb +106 -72
- data/lib/mutant/mutator/node/super.rb +15 -20
- data/lib/mutant/mutator/node/when.rb +32 -7
- data/lib/mutant/mutator/node/while.rb +9 -7
- data/lib/mutant/mutator/node.rb +116 -66
- data/lib/mutant/mutator/registry.rb +14 -11
- data/lib/mutant/mutator/util/array.rb +9 -9
- data/lib/mutant/mutator/util/symbol.rb +6 -20
- data/lib/mutant/mutator/util.rb +6 -3
- data/lib/mutant/mutator.rb +12 -28
- data/lib/mutant/node_helpers.rb +28 -0
- data/lib/mutant/random.rb +3 -2
- data/lib/mutant/reporter/cli/printer/config.rb +174 -0
- data/lib/mutant/reporter/cli/printer/killer.rb +42 -0
- data/lib/mutant/reporter/cli/printer/mutation.rb +55 -0
- data/lib/mutant/reporter/cli/printer/subject.rb +147 -0
- data/lib/mutant/reporter/cli/printer.rb +165 -0
- data/lib/mutant/reporter/cli.rb +9 -277
- data/lib/mutant/reporter/null.rb +6 -30
- data/lib/mutant/reporter.rb +6 -73
- data/lib/mutant/runner/config.rb +82 -0
- data/lib/mutant/runner/mutation.rb +58 -0
- data/lib/mutant/runner/subject.rb +81 -0
- data/lib/mutant/runner.rb +42 -92
- data/lib/mutant/singleton_methods.rb +2 -2
- data/lib/mutant/strategy/method_expansion.rb +51 -0
- data/lib/mutant/strategy/rspec/dm2/lookup/method.rb +142 -0
- data/lib/mutant/strategy/rspec/dm2/lookup.rb +61 -0
- data/lib/mutant/strategy/rspec/dm2.rb +22 -0
- data/lib/mutant/strategy/rspec.rb +20 -22
- data/lib/mutant/strategy/static.rb +18 -0
- data/lib/mutant/strategy.rb +15 -50
- data/lib/mutant/subject/method.rb +100 -0
- data/lib/mutant/subject.rb +18 -49
- data/lib/mutant/support/method_object.rb +4 -2
- data/lib/mutant.rb +40 -35
- data/mutant.gemspec +9 -8
- data/spec/integration/mutant/rspec_killer_spec.rb +3 -3
- data/spec/integration/mutant/test_mutator_handles_types_spec.rb +9 -0
- data/spec/integration/mutant/zombie_spec.rb +1 -1
- data/spec/shared/method_matcher_behavior.rb +35 -0
- data/spec/shared/mutator_behavior.rb +63 -32
- data/spec/spec_helper.rb +13 -3
- data/spec/support/ice_nine_config.rb +8 -0
- data/spec/support/rspec.rb +1 -1
- data/spec/support/zombie.rb +1 -1
- data/spec/unit/mutant/cli/class_methods/new_spec.rb +42 -28
- data/spec/unit/mutant/cli/class_methods/run_spec.rb +15 -13
- data/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb +44 -0
- data/spec/unit/mutant/context/scope/root_spec.rb +4 -4
- data/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb +6 -5
- data/spec/unit/mutant/killer/success_predicate_spec.rb +28 -0
- data/spec/unit/mutant/loader/eval/class_methods/run_spec.rb +1 -1
- data/spec/unit/mutant/matcher/chain/each_spec.rb +1 -1
- data/spec/unit/mutant/matcher/chain/matchers_spec.rb +1 -1
- data/spec/unit/mutant/matcher/method/instance/each_spec.rb +112 -0
- data/spec/unit/mutant/matcher/method/singleton/each_spec.rb +93 -0
- data/spec/unit/mutant/matcher/methods/instance/each_spec.rb +59 -0
- data/spec/unit/mutant/matcher/methods/singleton/each_spec.rb +53 -0
- data/spec/unit/mutant/matcher/namespace/each_spec.rb +37 -0
- data/spec/unit/mutant/mutator/node/begin/mutation_spec.rb +33 -0
- data/spec/unit/mutant/mutator/node/block/mutation_spec.rb +42 -14
- data/spec/unit/mutant/mutator/node/case/mutation_spec.rb +319 -0
- data/spec/unit/mutant/mutator/node/define/mutation_spec.rb +31 -27
- data/spec/unit/mutant/mutator/node/if/mutation_spec.rb +75 -0
- data/spec/unit/mutant/mutator/node/literal/fixnum_spec.rb +1 -1
- data/spec/unit/mutant/mutator/node/literal/hash_spec.rb +2 -2
- data/spec/unit/mutant/mutator/node/literal/nil_spec.rb +1 -3
- data/spec/unit/mutant/mutator/node/literal/regex_spec.rb +1 -9
- data/spec/unit/mutant/mutator/node/return/mutation_spec.rb +6 -2
- data/spec/unit/mutant/mutator/node/send/mutation_spec.rb +111 -108
- data/spec/unit/mutant/mutator/node/super/mutation_spec.rb +0 -33
- data/spec/unit/mutant/mutator/node/while/mutation_spec.rb +2 -2
- data/spec/unit/mutant/runner/config/subjects_spec.rb +38 -0
- data/spec/unit/mutant/runner/config/success_predicate_spec.rb +53 -0
- data/spec/unit/mutant/runner/failed_predicte_spec.rb +33 -0
- data/spec/unit/mutant/runner/mutation/killer_spec.rb +39 -0
- data/spec/unit/mutant/runner/subject/success_predicate_spec.rb +49 -0
- data/spec/unit/mutant/strategy/method_expansion/class_methods/run_spec.rb +49 -0
- data/spec/unit/mutant/strategy/rspec/dm2/lookup/method/instance/spec_files_spec.rb +52 -0
- data/spec/unit/mutant/strategy/rspec/dm2/lookup/method/singleton/spec_files_spec.rb +42 -0
- data/spec/unit/mutant/subject/context_spec.rb +6 -3
- data/spec/unit/mutant/subject/each_spec.rb +11 -8
- data/spec/unit/mutant/subject/node_spec.rb +6 -2
- data/test_app/spec/shared/method_filter_parse_behavior.rb +0 -2
- data/test_app/spec/shared/method_match_behavior.rb +1 -1
- data/test_app/spec/spec_helper.rb +4 -2
- metadata +101 -109
- data/config/roodi.yml +0 -26
- data/lib/mutant/matcher/method/classifier.rb +0 -141
- data/lib/mutant/matcher/object_space.rb +0 -114
- data/lib/mutant/mutator/node/actual_arguments.rb +0 -25
- data/lib/mutant/mutator/node/default_arguments.rb +0 -25
- data/lib/mutant/mutator/node/formal_arguments_19/default_mutations.rb +0 -33
- data/lib/mutant/mutator/node/formal_arguments_19/pattern_argument_expansion.rb +0 -35
- data/lib/mutant/mutator/node/formal_arguments_19/require_defaults.rb +0 -37
- data/lib/mutant/mutator/node/formal_arguments_19.rb +0 -41
- data/lib/mutant/mutator/node/iter_19.rb +0 -27
- data/lib/mutant/mutator/node/literal/empty_array.rb +0 -26
- data/lib/mutant/mutator/node/pattern_arguments.rb +0 -41
- data/lib/mutant/mutator/node/pattern_variable.rb +0 -23
- data/lib/mutant/mutator/node/receiver_case.rb +0 -122
- data/lib/mutant/mutator/node/send/binary_operator_method.rb +0 -61
- data/lib/mutant/mutator/node/send/with_arguments.rb +0 -81
- data/lib/mutant/reporter/stats.rb +0 -120
- data/lib/mutant/strategy/rspec/example_lookup.rb +0 -163
- data/spec/integration/mutant/method_matching_spec.rb +0 -269
- data/spec/shared/method_match_behavior.rb +0 -39
- data/spec/unit/mutant/killer/fail_ques_spec.rb +0 -39
- data/spec/unit/mutant/matcher/class_methods/from_string_spec.rb +0 -49
- data/spec/unit/mutant/matcher/class_methods/parse_spec.rb +0 -12
- data/spec/unit/mutant/matcher/method/class_methods/parse_spec.rb +0 -21
- data/spec/unit/mutant/matcher/method/classifier/class_methods/run_spec.rb +0 -52
- data/spec/unit/mutant/matcher/object_space/class_methods/parse_spec.rb +0 -24
- data/spec/unit/mutant/matcher/object_space/each_spec.rb +0 -31
- data/spec/unit/mutant/mutator/node/if_statement/mutation_spec.rb +0 -60
- data/spec/unit/mutant/mutator/node/receiver_case/mutation_spec.rb +0 -27
- data/spec/unit/mutant/strategy/rspec/example_lookup/spec_file_spec.rb +0 -236
- data/spec/unit/mutant/subject/class_methods/new_spec.rb +0 -13
- data/tasks/metrics/ci.rake +0 -7
- data/tasks/metrics/flay.rake +0 -41
- data/tasks/metrics/flog.rake +0 -43
- data/tasks/metrics/heckle.rake +0 -216
- data/tasks/metrics/metric_fu.rake +0 -31
- data/tasks/metrics/reek.rake +0 -15
- data/tasks/metrics/roodi.rake +0 -15
- data/tasks/metrics/yardstick.rake +0 -23
- data/tasks/spec.rake +0 -45
- data/tasks/yard.rake +0 -9
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::Namespace, '#each' do
|
4
|
+
subject { object.each { |item| yields << item } }
|
5
|
+
|
6
|
+
let(:yields) { [] }
|
7
|
+
let(:object) { described_class.new(TestApp::Literal) }
|
8
|
+
|
9
|
+
let(:singleton_a) { mock('SingletonA', :name => 'TestApp::Literal') }
|
10
|
+
let(:singleton_b) { mock('SingletonB', :name => 'TestApp::Foo') }
|
11
|
+
let(:subject_a) { mock('SubjectA') }
|
12
|
+
let(:subject_b) { mock('SubjectB') }
|
13
|
+
|
14
|
+
before do
|
15
|
+
Mutant::Matcher::Methods::Singleton.stub(:each).with(singleton_a).and_yield(subject_a)
|
16
|
+
Mutant::Matcher::Methods::Instance.stub(:each).with(singleton_a).and_yield(subject_b)
|
17
|
+
ObjectSpace.stub(:each_object => [singleton_a, singleton_b])
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with no block' do
|
21
|
+
subject { object.each }
|
22
|
+
|
23
|
+
it { should be_instance_of(to_enum.class) }
|
24
|
+
|
25
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
26
|
+
pending 'FIX RBX rspec? BUG HERE'
|
27
|
+
else
|
28
|
+
it 'yields the expected values' do
|
29
|
+
subject.to_a.should eql(object.to_a)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should yield subjects' do
|
35
|
+
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, 'begin' do
|
4
|
+
|
5
|
+
# This mutation and only this mutation can result in
|
6
|
+
# and empty emit that is parsed into nil, unparser cannot
|
7
|
+
# handle this so we guard this here!
|
8
|
+
def generate(node)
|
9
|
+
return '' if node.nil?
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:source) { "true\nfalse" }
|
14
|
+
|
15
|
+
let(:mutations) do
|
16
|
+
mutations = []
|
17
|
+
|
18
|
+
# Mutation of each statement in block
|
19
|
+
mutations << "true\ntrue"
|
20
|
+
mutations << "false\nfalse"
|
21
|
+
mutations << "nil\nfalse"
|
22
|
+
mutations << "true\nnil"
|
23
|
+
|
24
|
+
# Remove statement in block
|
25
|
+
mutations << 'true'
|
26
|
+
mutations << 'false'
|
27
|
+
|
28
|
+
# Replace block with empty
|
29
|
+
mutations << ''
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like 'a mutator'
|
33
|
+
end
|
@@ -1,35 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mutant::Mutator, 'block' do
|
4
|
-
|
5
|
-
|
6
|
-
let(:source) { "self.foo\nself.bar" }
|
4
|
+
context 'with block' do
|
5
|
+
let(:source) { 'foo() { a; b }' }
|
7
6
|
|
8
7
|
let(:mutations) do
|
9
8
|
mutations = []
|
9
|
+
mutations << 'foo { a }'
|
10
|
+
mutations << 'foo { b }'
|
11
|
+
mutations << 'foo {}'
|
12
|
+
mutations << 'foo'
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like 'a mutator'
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with block args' do
|
10
19
|
|
11
|
-
|
12
|
-
mutations << "foo\nself.bar".to_ast
|
13
|
-
mutations << "self.foo\nbar".to_ast
|
20
|
+
let(:source) { 'foo { |a, b| }' }
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
before do
|
23
|
+
Mutant::Random.stub(:hex_string => :random)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:mutations) do
|
27
|
+
mutations = []
|
28
|
+
mutations << 'foo'
|
29
|
+
mutations << 'foo { |a, b| ::Object.new }'
|
30
|
+
mutations << 'foo { |a, srandom| }'
|
31
|
+
mutations << 'foo { |srandom, b| }'
|
32
|
+
mutations << 'foo { |a| }'
|
33
|
+
mutations << 'foo { |b| }'
|
34
|
+
mutations << 'foo { || }'
|
19
35
|
end
|
20
36
|
|
21
37
|
it_should_behave_like 'a mutator'
|
22
38
|
end
|
23
39
|
|
40
|
+
context 'with block pattern args' do
|
24
41
|
|
42
|
+
before do
|
43
|
+
Mutant::Random.stub(:hex_string => :random)
|
44
|
+
end
|
25
45
|
|
26
|
-
|
27
|
-
let(:node) { Rubinius::AST::Block.new(1, ['self.foo'.to_ast]) }
|
46
|
+
let(:source) { 'foo { |(a, b), c| }' }
|
28
47
|
|
29
48
|
let(:mutations) do
|
30
49
|
mutations = []
|
31
|
-
mutations <<
|
32
|
-
mutations <<
|
50
|
+
mutations << 'foo { || }'
|
51
|
+
mutations << 'foo { |a, b, c| }'
|
52
|
+
mutations << 'foo { |(a, b), c| ::Object.new }'
|
53
|
+
mutations << 'foo { |(a), c| }'
|
54
|
+
mutations << 'foo { |(b), c| }'
|
55
|
+
mutations << 'foo { |(a, b)| }'
|
56
|
+
mutations << 'foo { |c| }'
|
57
|
+
mutations << 'foo { |(srandom, b), c| }'
|
58
|
+
mutations << 'foo { |(a, srandom), c| }'
|
59
|
+
mutations << 'foo { |(a, b), srandom| }'
|
60
|
+
mutations << 'foo'
|
33
61
|
end
|
34
62
|
|
35
63
|
it_should_behave_like 'a mutator'
|
@@ -0,0 +1,319 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator::Node::Case do
|
4
|
+
let(:random_string) { 'random' }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Mutant::Random.stub(:hex_string => random_string)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'with multiple when branches' do
|
11
|
+
let(:source) do
|
12
|
+
<<-RUBY
|
13
|
+
case :condition
|
14
|
+
when :foo
|
15
|
+
:foo
|
16
|
+
when :bar, :baz
|
17
|
+
:barbaz
|
18
|
+
else
|
19
|
+
:else
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:mutations) do
|
25
|
+
mutations = []
|
26
|
+
|
27
|
+
# Presence of branches
|
28
|
+
mutations << <<-RUBY
|
29
|
+
case :condition
|
30
|
+
when :bar, :baz
|
31
|
+
:barbaz
|
32
|
+
else
|
33
|
+
:else
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
mutations << <<-RUBY
|
37
|
+
case :condition
|
38
|
+
when :foo
|
39
|
+
:foo
|
40
|
+
else
|
41
|
+
:else
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
mutations << <<-RUBY
|
45
|
+
case :condition
|
46
|
+
when :foo
|
47
|
+
:foo
|
48
|
+
when :bar, :baz
|
49
|
+
:barbaz
|
50
|
+
end
|
51
|
+
RUBY
|
52
|
+
|
53
|
+
# Mutations of condition
|
54
|
+
mutations << <<-RUBY
|
55
|
+
case nil
|
56
|
+
when :foo
|
57
|
+
:foo
|
58
|
+
when :bar, :baz
|
59
|
+
:barbaz
|
60
|
+
else
|
61
|
+
:else
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
mutations << <<-RUBY
|
65
|
+
case :srandom
|
66
|
+
when :foo
|
67
|
+
:foo
|
68
|
+
when :bar, :baz
|
69
|
+
:barbaz
|
70
|
+
else
|
71
|
+
:else
|
72
|
+
end
|
73
|
+
RUBY
|
74
|
+
|
75
|
+
# Mutations of branch bodies
|
76
|
+
mutations << <<-RUBY
|
77
|
+
case :condition
|
78
|
+
when :foo
|
79
|
+
nil
|
80
|
+
when :bar, :baz
|
81
|
+
:barbaz
|
82
|
+
else
|
83
|
+
:else
|
84
|
+
end
|
85
|
+
RUBY
|
86
|
+
mutations << <<-RUBY
|
87
|
+
case :condition
|
88
|
+
when :foo
|
89
|
+
:srandom
|
90
|
+
when :bar, :baz
|
91
|
+
:barbaz
|
92
|
+
else
|
93
|
+
:else
|
94
|
+
end
|
95
|
+
RUBY
|
96
|
+
mutations << <<-RUBY
|
97
|
+
case :condition
|
98
|
+
when :foo
|
99
|
+
:foo
|
100
|
+
when :bar, :baz
|
101
|
+
:srandom
|
102
|
+
else
|
103
|
+
:else
|
104
|
+
end
|
105
|
+
RUBY
|
106
|
+
mutations << <<-RUBY
|
107
|
+
case :condition
|
108
|
+
when :foo
|
109
|
+
:foo
|
110
|
+
when :bar, :baz
|
111
|
+
nil
|
112
|
+
else
|
113
|
+
:else
|
114
|
+
end
|
115
|
+
RUBY
|
116
|
+
mutations << <<-RUBY
|
117
|
+
case :condition
|
118
|
+
when :foo
|
119
|
+
:foo
|
120
|
+
when :bar, :baz
|
121
|
+
:barbaz
|
122
|
+
else
|
123
|
+
:srandom
|
124
|
+
end
|
125
|
+
RUBY
|
126
|
+
mutations << <<-RUBY
|
127
|
+
case :condition
|
128
|
+
when :foo
|
129
|
+
:foo
|
130
|
+
when :bar, :baz
|
131
|
+
:barbaz
|
132
|
+
else
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
RUBY
|
136
|
+
|
137
|
+
# Mutations of when conditions
|
138
|
+
mutations << <<-RUBY
|
139
|
+
case :condition
|
140
|
+
when :srandom
|
141
|
+
:foo
|
142
|
+
when :bar, :baz
|
143
|
+
:barbaz
|
144
|
+
else
|
145
|
+
:else
|
146
|
+
end
|
147
|
+
RUBY
|
148
|
+
mutations << <<-RUBY
|
149
|
+
case :condition
|
150
|
+
when nil
|
151
|
+
:foo
|
152
|
+
when :bar, :baz
|
153
|
+
:barbaz
|
154
|
+
else
|
155
|
+
:else
|
156
|
+
end
|
157
|
+
RUBY
|
158
|
+
mutations << <<-RUBY
|
159
|
+
case :condition
|
160
|
+
when :foo
|
161
|
+
:foo
|
162
|
+
when :srandom, :baz
|
163
|
+
:barbaz
|
164
|
+
else
|
165
|
+
:else
|
166
|
+
end
|
167
|
+
RUBY
|
168
|
+
mutations << <<-RUBY
|
169
|
+
case :condition
|
170
|
+
when :foo
|
171
|
+
:foo
|
172
|
+
when nil, :baz
|
173
|
+
:barbaz
|
174
|
+
else
|
175
|
+
:else
|
176
|
+
end
|
177
|
+
RUBY
|
178
|
+
mutations << <<-RUBY
|
179
|
+
case :condition
|
180
|
+
when :foo
|
181
|
+
:foo
|
182
|
+
when :bar, nil
|
183
|
+
:barbaz
|
184
|
+
else
|
185
|
+
:else
|
186
|
+
end
|
187
|
+
RUBY
|
188
|
+
mutations << <<-RUBY
|
189
|
+
case :condition
|
190
|
+
when :foo
|
191
|
+
:foo
|
192
|
+
when :bar, :srandom
|
193
|
+
:barbaz
|
194
|
+
else
|
195
|
+
:else
|
196
|
+
end
|
197
|
+
RUBY
|
198
|
+
mutations << <<-RUBY
|
199
|
+
case :condition
|
200
|
+
when :foo
|
201
|
+
:foo
|
202
|
+
when :baz
|
203
|
+
:barbaz
|
204
|
+
else
|
205
|
+
:else
|
206
|
+
end
|
207
|
+
RUBY
|
208
|
+
mutations << <<-RUBY
|
209
|
+
case :condition
|
210
|
+
when :foo
|
211
|
+
:foo
|
212
|
+
when :bar
|
213
|
+
:barbaz
|
214
|
+
else
|
215
|
+
:else
|
216
|
+
end
|
217
|
+
RUBY
|
218
|
+
end
|
219
|
+
|
220
|
+
it_should_behave_like 'a mutator'
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'with one when branch' do
|
224
|
+
let(:source) do
|
225
|
+
<<-RUBY
|
226
|
+
case :condition
|
227
|
+
when :foo
|
228
|
+
:foo
|
229
|
+
else
|
230
|
+
:else
|
231
|
+
end
|
232
|
+
RUBY
|
233
|
+
end
|
234
|
+
|
235
|
+
let(:mutations) do
|
236
|
+
mutations = []
|
237
|
+
|
238
|
+
# Presence of branches
|
239
|
+
mutations << <<-RUBY
|
240
|
+
case :condition
|
241
|
+
when :foo
|
242
|
+
:foo
|
243
|
+
end
|
244
|
+
RUBY
|
245
|
+
|
246
|
+
# Mutations of condition
|
247
|
+
mutations << <<-RUBY
|
248
|
+
case nil
|
249
|
+
when :foo
|
250
|
+
:foo
|
251
|
+
else
|
252
|
+
:else
|
253
|
+
end
|
254
|
+
RUBY
|
255
|
+
mutations << <<-RUBY
|
256
|
+
case :srandom
|
257
|
+
when :foo
|
258
|
+
:foo
|
259
|
+
else
|
260
|
+
:else
|
261
|
+
end
|
262
|
+
RUBY
|
263
|
+
|
264
|
+
# Mutations of branch bodies
|
265
|
+
mutations << <<-RUBY
|
266
|
+
case :condition
|
267
|
+
when :foo
|
268
|
+
nil
|
269
|
+
else
|
270
|
+
:else
|
271
|
+
end
|
272
|
+
RUBY
|
273
|
+
mutations << <<-RUBY
|
274
|
+
case :condition
|
275
|
+
when :foo
|
276
|
+
:srandom
|
277
|
+
else
|
278
|
+
:else
|
279
|
+
end
|
280
|
+
RUBY
|
281
|
+
mutations << <<-RUBY
|
282
|
+
case :condition
|
283
|
+
when :foo
|
284
|
+
:foo
|
285
|
+
else
|
286
|
+
:srandom
|
287
|
+
end
|
288
|
+
RUBY
|
289
|
+
mutations << <<-RUBY
|
290
|
+
case :condition
|
291
|
+
when :foo
|
292
|
+
:foo
|
293
|
+
else
|
294
|
+
nil
|
295
|
+
end
|
296
|
+
RUBY
|
297
|
+
|
298
|
+
# Mutations of when conditions
|
299
|
+
mutations << <<-RUBY
|
300
|
+
case :condition
|
301
|
+
when :srandom
|
302
|
+
:foo
|
303
|
+
else
|
304
|
+
:else
|
305
|
+
end
|
306
|
+
RUBY
|
307
|
+
mutations << <<-RUBY
|
308
|
+
case :condition
|
309
|
+
when nil
|
310
|
+
:foo
|
311
|
+
else
|
312
|
+
:else
|
313
|
+
end
|
314
|
+
RUBY
|
315
|
+
end
|
316
|
+
|
317
|
+
it_should_behave_like 'a mutator'
|
318
|
+
end
|
319
|
+
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mutant::Mutator, '
|
3
|
+
describe Mutant::Mutator, 'def' do
|
4
4
|
|
5
5
|
context 'with no arguments' do
|
6
|
-
let(:source) { 'def foo;
|
6
|
+
let(:source) { 'def foo; true; false; end' }
|
7
7
|
|
8
8
|
let(:mutations) do
|
9
9
|
mutations = []
|
10
10
|
|
11
11
|
# Mutation of each statement in block
|
12
|
-
mutations << 'def foo;
|
13
|
-
mutations << 'def foo;
|
12
|
+
mutations << 'def foo; true; true; end'
|
13
|
+
mutations << 'def foo; false; false; end'
|
14
|
+
mutations << 'def foo; true; nil; end'
|
15
|
+
mutations << 'def foo; nil; false; end'
|
14
16
|
|
15
17
|
# Remove statement in block
|
16
|
-
mutations << 'def foo;
|
17
|
-
mutations << 'def foo;
|
18
|
+
mutations << 'def foo; true; end'
|
19
|
+
mutations << 'def foo; false; end'
|
18
20
|
|
19
21
|
# Remove all statements
|
20
22
|
mutations << 'def foo; end'
|
@@ -24,7 +26,7 @@ describe Mutant::Mutator, 'define' do
|
|
24
26
|
end
|
25
27
|
|
26
28
|
context 'with arguments' do
|
27
|
-
let(:source) { 'def foo(a, b);
|
29
|
+
let(:source) { 'def foo(a, b); end' }
|
28
30
|
|
29
31
|
before do
|
30
32
|
Mutant::Random.stub(:hex_string => 'random')
|
@@ -34,29 +36,29 @@ describe Mutant::Mutator, 'define' do
|
|
34
36
|
mutations = []
|
35
37
|
|
36
38
|
# Deletion of each argument
|
37
|
-
mutations << 'def foo(a);
|
38
|
-
mutations << 'def foo(b);
|
39
|
+
mutations << 'def foo(a); end'
|
40
|
+
mutations << 'def foo(b); end'
|
39
41
|
|
40
42
|
# Deletion of all arguments
|
41
|
-
mutations << 'def foo;
|
43
|
+
mutations << 'def foo; end'
|
42
44
|
|
43
45
|
# Rename each argument
|
44
|
-
mutations << 'def foo(srandom, b);
|
45
|
-
mutations << 'def foo(a, srandom);
|
46
|
+
mutations << 'def foo(srandom, b); end'
|
47
|
+
mutations << 'def foo(a, srandom); end'
|
46
48
|
|
47
49
|
# Mutation of body
|
48
|
-
mutations << 'def foo(a, b); Object.new; end'
|
50
|
+
mutations << 'def foo(a, b); ::Object.new; end'
|
49
51
|
end
|
50
52
|
|
51
53
|
it_should_behave_like 'a mutator'
|
52
54
|
end
|
53
55
|
|
54
|
-
context 'with
|
56
|
+
context 'with argument beginning in an underscore' do
|
55
57
|
let(:source) { 'def foo(_unused); end' }
|
56
58
|
|
57
59
|
let(:mutations) do
|
58
60
|
mutations = []
|
59
|
-
mutations << 'def foo(_unused); Object.new; end'
|
61
|
+
mutations << 'def foo(_unused); ::Object.new; end'
|
60
62
|
mutations << 'def foo; end'
|
61
63
|
end
|
62
64
|
|
@@ -64,38 +66,40 @@ describe Mutant::Mutator, 'define' do
|
|
64
66
|
end
|
65
67
|
|
66
68
|
context 'default argument' do
|
67
|
-
let(:source) { 'def foo(a =
|
69
|
+
let(:source) { 'def foo(a = true); end' }
|
68
70
|
|
69
71
|
before do
|
70
72
|
Mutant::Random.stub(:hex_string => 'random')
|
71
73
|
end
|
72
74
|
|
73
|
-
let(:mutations) do
|
75
|
+
let(:mutations) do
|
74
76
|
mutations = []
|
75
77
|
mutations << 'def foo(a); end'
|
76
78
|
mutations << 'def foo(); end'
|
77
|
-
mutations << 'def foo(a =
|
79
|
+
mutations << 'def foo(a = false); end'
|
78
80
|
mutations << 'def foo(a = nil); end'
|
79
|
-
mutations << 'def foo(
|
80
|
-
mutations << 'def foo(
|
81
|
+
mutations << 'def foo(srandom = true); end'
|
82
|
+
mutations << 'def foo(a = true); ::Object.new; end'
|
81
83
|
end
|
82
84
|
|
83
85
|
it_should_behave_like 'a mutator'
|
84
86
|
end
|
85
87
|
|
86
88
|
context 'define on singleton' do
|
87
|
-
let(:source) { 'def self.foo;
|
89
|
+
let(:source) { 'def self.foo; true; false; end' }
|
88
90
|
|
89
91
|
let(:mutations) do
|
90
92
|
mutations = []
|
91
93
|
|
92
94
|
# Body presence mutations
|
93
|
-
mutations << 'def self.foo;
|
94
|
-
mutations << 'def self.foo;
|
95
|
-
|
95
|
+
mutations << 'def self.foo; false; false; end'
|
96
|
+
mutations << 'def self.foo; true; true; end'
|
97
|
+
mutations << 'def self.foo; true; nil; end'
|
98
|
+
mutations << 'def self.foo; nil; false; end'
|
99
|
+
|
96
100
|
# Body presence mutations
|
97
|
-
mutations << 'def self.foo;
|
98
|
-
mutations << 'def self.foo;
|
101
|
+
mutations << 'def self.foo; true; end'
|
102
|
+
mutations << 'def self.foo; false; end'
|
99
103
|
|
100
104
|
# Remove all statements
|
101
105
|
mutations << 'def self.foo; end'
|
@@ -127,7 +131,7 @@ describe Mutant::Mutator, 'define' do
|
|
127
131
|
mutations << 'def self.foo(a, srandom); nil; end'
|
128
132
|
|
129
133
|
# Mutation of body
|
130
|
-
mutations << 'def self.foo(a, b); Object.new; end'
|
134
|
+
mutations << 'def self.foo(a, b); ::Object.new; end'
|
131
135
|
end
|
132
136
|
|
133
137
|
it_should_behave_like 'a mutator'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, 'if' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Mutant::Random.stub(:hex_string => 'random')
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'with if and else branches' do
|
10
|
+
let(:source) { 'if :condition; true; else false; end' }
|
11
|
+
|
12
|
+
let(:mutations) do
|
13
|
+
mutants = []
|
14
|
+
|
15
|
+
# mutations of condition
|
16
|
+
mutants << 'if :srandom; true; else false; end'
|
17
|
+
mutants << 'if !:condition; true; else false; end'
|
18
|
+
mutants << 'if nil; true; else false; end'
|
19
|
+
mutants << 'if true; true; else false; end'
|
20
|
+
mutants << 'if false; true; else false; end'
|
21
|
+
|
22
|
+
# Deleted else branch
|
23
|
+
mutants << 'if :condition; true end'
|
24
|
+
|
25
|
+
# Deleted if branch resuting in unless rendering
|
26
|
+
mutants << 'unless :condition; false; end'
|
27
|
+
|
28
|
+
# Deleted if branch with promoting else branch to if branch
|
29
|
+
mutants << 'if :condition; false end'
|
30
|
+
|
31
|
+
# mutations of if body
|
32
|
+
mutants << 'if :condition; false; else false; end'
|
33
|
+
mutants << 'if :condition; nil; else false; end'
|
34
|
+
|
35
|
+
# mutations of else body
|
36
|
+
mutants << 'if :condition; true; else true; end'
|
37
|
+
mutants << 'if :condition; true; else nil; end'
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_behave_like 'a mutator'
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'if with one branch' do
|
44
|
+
let(:source) { 'if condition; true; end' }
|
45
|
+
|
46
|
+
let(:mutations) do
|
47
|
+
mutants = []
|
48
|
+
mutants << 'if !condition; true; end'
|
49
|
+
mutants << 'if condition; false; end'
|
50
|
+
mutants << 'if condition; nil; end'
|
51
|
+
mutants << 'if true; true; end'
|
52
|
+
mutants << 'if false; true; end'
|
53
|
+
end
|
54
|
+
|
55
|
+
it_should_behave_like 'a mutator'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'unless with one branch' do
|
59
|
+
let(:source) { 'unless :condition; true; end' }
|
60
|
+
|
61
|
+
let(:mutations) do
|
62
|
+
mutants = []
|
63
|
+
mutants << 'unless !:condition; true; end'
|
64
|
+
mutants << 'unless :srandom; true; end'
|
65
|
+
mutants << 'unless nil; true; end'
|
66
|
+
mutants << 'unless :condition; false; end'
|
67
|
+
mutants << 'unless :condition; nil; end'
|
68
|
+
mutants << 'unless true; true; end'
|
69
|
+
mutants << 'unless false; true; end'
|
70
|
+
mutants << 'if :condition; true; end'
|
71
|
+
end
|
72
|
+
|
73
|
+
it_should_behave_like 'a mutator'
|
74
|
+
end
|
75
|
+
end
|
@@ -20,8 +20,8 @@ describe Mutant::Mutator::Node::Literal, 'hash' do
|
|
20
20
|
mutations << '{ true => true , false => nil }'
|
21
21
|
|
22
22
|
# Remove each key once
|
23
|
-
mutations << '{ true => true }'
|
24
|
-
mutations << '{ false => false }'
|
23
|
+
mutations << '{ true => true }'
|
24
|
+
mutations << '{ false => false }'
|
25
25
|
|
26
26
|
# Empty hash
|
27
27
|
mutations << '{}'
|