mutant 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -11
- data/.rspec +0 -1
- data/.travis.yml +14 -3
- data/Changelog.md +3 -0
- data/Gemfile +5 -1
- data/Gemfile.devtools +49 -0
- data/Guardfile +18 -0
- data/README.md +67 -0
- data/Rakefile +4 -1
- data/TODO +13 -0
- data/bin/mutant +14 -0
- data/bin/zombie +14 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +26 -0
- data/config/site.reek +93 -0
- data/config/yardstick.yml +2 -0
- data/lib/inflector.rb +7 -0
- data/lib/inflector/defaults.rb +62 -0
- data/lib/inflector/inflections.rb +209 -0
- data/lib/inflector/methods.rb +149 -0
- data/lib/inflector/version.rb +3 -0
- data/lib/mutant.rb +96 -21
- data/lib/mutant/cli.rb +309 -0
- data/lib/mutant/color.rb +61 -0
- data/lib/mutant/context.rb +36 -0
- data/lib/mutant/context/scope.rb +138 -0
- data/lib/mutant/differ.rb +100 -0
- data/lib/mutant/helper.rb +38 -0
- data/lib/mutant/killer.rb +136 -0
- data/lib/mutant/killer/forking.rb +41 -0
- data/lib/mutant/killer/rspec.rb +49 -0
- data/lib/mutant/killer/static.rb +19 -0
- data/lib/mutant/loader.rb +129 -0
- data/lib/mutant/matcher.rb +55 -0
- data/lib/mutant/matcher/chain.rb +66 -0
- data/lib/mutant/matcher/method.rb +173 -0
- data/lib/mutant/matcher/method/classifier.rb +126 -0
- data/lib/mutant/matcher/method/instance.rb +67 -0
- data/lib/mutant/matcher/method/singleton.rb +141 -0
- data/lib/mutant/matcher/object_space.rb +114 -0
- data/lib/mutant/matcher/scope_methods.rb +127 -0
- data/lib/mutant/mutation.rb +101 -12
- data/lib/mutant/mutation/filter.rb +75 -0
- data/lib/mutant/mutation/filter/code.rb +68 -0
- data/lib/mutant/mutation/filter/regexp.rb +39 -0
- data/lib/mutant/mutation/filter/whitelist.rb +47 -0
- data/lib/mutant/mutator.rb +134 -30
- data/lib/mutant/mutator/node.rb +163 -0
- data/lib/mutant/mutator/node/arguments.rb +24 -0
- data/lib/mutant/mutator/node/block.rb +24 -0
- data/lib/mutant/mutator/node/define.rb +24 -0
- data/lib/mutant/mutator/node/if_statement.rb +93 -0
- data/lib/mutant/mutator/node/literal.rb +54 -0
- data/lib/mutant/mutator/node/literal/array.rb +28 -0
- data/lib/mutant/mutator/node/literal/boolean.rb +49 -0
- data/lib/mutant/mutator/node/literal/dynamic.rb +24 -0
- data/lib/mutant/mutator/node/literal/empty_array.rb +26 -0
- data/lib/mutant/mutator/node/literal/fixnum.rb +37 -0
- data/lib/mutant/mutator/node/literal/float.rb +48 -0
- data/lib/mutant/mutator/node/literal/hash.rb +89 -0
- data/lib/mutant/mutator/node/literal/nil.rb +25 -0
- data/lib/mutant/mutator/node/literal/range.rb +94 -0
- data/lib/mutant/mutator/node/literal/regex.rb +43 -0
- data/lib/mutant/mutator/node/literal/string.rb +26 -0
- data/lib/mutant/mutator/node/literal/symbol.rb +26 -0
- data/lib/mutant/mutator/node/noop.rb +55 -0
- data/lib/mutant/mutator/node/receiver_case.rb +140 -0
- data/lib/mutant/mutator/node/return.rb +31 -0
- data/lib/mutant/mutator/node/send.rb +112 -0
- data/lib/mutant/mutator/registry.rb +48 -0
- data/lib/mutant/mutator/util.rb +87 -0
- data/lib/mutant/random.rb +24 -27
- data/lib/mutant/reporter.rb +48 -30
- data/lib/mutant/reporter/cli.rb +221 -0
- data/lib/mutant/reporter/null.rb +42 -0
- data/lib/mutant/reporter/stats.rb +64 -0
- data/lib/mutant/runner.rb +112 -0
- data/lib/mutant/strategy.rb +42 -0
- data/lib/mutant/strategy/rspec.rb +59 -0
- data/lib/mutant/strategy/rspec/example_lookup.rb +122 -0
- data/lib/mutant/subject.rb +115 -0
- data/lib/mutant/support/method_object.rb +31 -0
- data/locator.rb +87 -0
- data/mutant.gemspec +21 -21
- data/spec/integration/mutant/differ_spec.rb +15 -0
- data/spec/integration/mutant/loader_spec.rb +21 -0
- data/spec/integration/mutant/method_matching_spec.rb +269 -0
- data/spec/integration/mutant/rspec_killer_spec.rb +24 -0
- data/spec/integration/mutant/runner_spec.rb +26 -0
- data/spec/integration/mutant/zombie_spec.rb +8 -0
- data/spec/rcov.opts +7 -0
- data/spec/shared/command_method_behavior.rb +7 -0
- data/spec/shared/each_method_behaviour.rb +15 -0
- data/spec/shared/hash_method_behavior.rb +17 -0
- data/spec/shared/idempotent_method_behavior.rb +7 -0
- data/spec/shared/invertible_method_behaviour.rb +9 -0
- data/spec/shared/method_filter_parse_behavior.rb +16 -0
- data/spec/shared/method_match_behavior.rb +39 -0
- data/spec/shared/mutator_behavior.rb +46 -0
- data/spec/spec_helper.rb +11 -14
- data/spec/support/compress_helper.rb +10 -0
- data/spec/support/rspec.rb +22 -0
- data/spec/support/test_app.rb +5 -0
- data/spec/support/zombie.rb +141 -0
- data/spec/unit/mutant/cli/class_methods/new_spec.rb +87 -0
- data/spec/unit/mutant/cli/class_methods/run_spec.rb +38 -0
- data/spec/unit/mutant/context/root_spec.rb +11 -0
- data/spec/unit/mutant/context/scope/class_methods/build_spec.rb +29 -0
- data/spec/unit/mutant/context/scope/root_spec.rb +22 -0
- data/spec/unit/mutant/context/scope/unqualified_name_spec.rb +27 -0
- data/spec/unit/mutant/killer/fail_ques_spec.rb +39 -0
- data/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb +32 -0
- data/spec/unit/mutant/loader/eval/class_methods/run_spec.rb +33 -0
- data/spec/unit/mutant/loader/rubinius/class_methods/run_spec.rb +42 -0
- data/spec/unit/mutant/matcher/chain/each_spec.rb +37 -0
- data/spec/unit/mutant/matcher/chain/matchers_spec.rb +12 -0
- data/spec/unit/mutant/matcher/class_methods/from_string_spec.rb +49 -0
- data/spec/unit/mutant/matcher/class_methods/parse_spec.rb +12 -0
- data/spec/unit/mutant/matcher/each_spec.rb +14 -0
- data/spec/unit/mutant/matcher/method/class_methods/parse_spec.rb +21 -0
- data/spec/unit/mutant/matcher/method/classifier/class_methods/run_spec.rb +34 -0
- data/spec/unit/mutant/matcher/method/method_spec.rb +11 -0
- data/spec/unit/mutant/matcher/object_space/class_methods/parse_spec.rb +24 -0
- data/spec/unit/mutant/matcher/object_space/each_spec.rb +31 -0
- data/spec/unit/mutant/mutator/each_spec.rb +25 -0
- data/spec/unit/mutant/mutator/emit_new_spec.rb +51 -0
- data/spec/unit/mutant/mutator/emit_spec.rb +52 -0
- data/spec/unit/mutant/mutator/node/block/mutation_spec.rb +36 -0
- data/spec/unit/mutant/mutator/node/define/mutation_spec.rb +47 -0
- data/spec/unit/mutant/mutator/node/if_statement/mutation_spec.rb +30 -0
- data/spec/unit/mutant/mutator/node/literal/array_spec.rb +30 -0
- data/spec/unit/mutant/mutator/node/literal/boolean/mutation_spec.rb +23 -0
- data/spec/unit/mutant/mutator/node/literal/empty_array_spec.rb +17 -0
- data/spec/unit/mutant/mutator/node/literal/fixnum_spec.rb +17 -0
- data/spec/unit/mutant/mutator/node/literal/float_spec.rb +25 -0
- data/spec/unit/mutant/mutator/node/literal/hash_spec.rb +34 -0
- data/spec/unit/mutant/mutator/node/literal/nil_spec.rb +13 -0
- data/spec/unit/mutant/mutator/node/literal/range_spec.rb +35 -0
- data/spec/unit/mutant/mutator/node/literal/regex_spec.rb +23 -0
- data/spec/unit/mutant/mutator/node/literal/string_spec.rb +17 -0
- data/spec/unit/mutant/mutator/node/literal/symbol_spec.rb +17 -0
- data/spec/unit/mutant/mutator/node/receiver_case/mutation_spec.rb +27 -0
- data/spec/unit/mutant/mutator/node/return/mutation_spec.rb +21 -0
- data/spec/unit/mutant/mutator/node/send/mutation_spec.rb +78 -0
- data/spec/unit/mutant/mutator/self_spec.rb +7 -0
- data/spec/unit/mutant/subject/class_methods/new_spec.rb +13 -0
- data/spec/unit/mutant/subject/context_spec.rb +14 -0
- data/spec/unit/mutant/subject/each_spec.rb +35 -0
- data/spec/unit/mutant/subject/node_spec.rb +13 -0
- data/tasks/metrics/ci.rake +7 -0
- data/tasks/metrics/flay.rake +41 -0
- data/tasks/metrics/flog.rake +43 -0
- data/tasks/metrics/heckle.rake +216 -0
- data/tasks/metrics/metric_fu.rake +31 -0
- data/tasks/metrics/reek.rake +15 -0
- data/tasks/metrics/roodi.rake +15 -0
- data/tasks/metrics/yardstick.rake +23 -0
- data/tasks/spec.rake +45 -0
- data/tasks/yard.rake +9 -0
- data/test_app/.rspec +1 -0
- data/test_app/lib/test_app.rb +5 -0
- data/test_app/lib/test_app/literal.rb +32 -0
- data/test_app/spec/shared/command_method_behavior.rb +7 -0
- data/test_app/spec/shared/each_method_behaviour.rb +15 -0
- data/test_app/spec/shared/hash_method_behavior.rb +17 -0
- data/test_app/spec/shared/idempotent_method_behavior.rb +7 -0
- data/test_app/spec/shared/invertible_method_behaviour.rb +9 -0
- data/test_app/spec/shared/method_filter_parse_behavior.rb +16 -0
- data/test_app/spec/shared/method_match_behavior.rb +39 -0
- data/test_app/spec/shared/mutator_behavior.rb +44 -0
- data/test_app/spec/spec_helper.rb +7 -0
- data/test_app/spec/unit/test_app/literal/command_spec.rb +9 -0
- data/test_app/spec/unit/test_app/literal/string_spec.rb +9 -0
- metadata +346 -124
- data/.rvmrc +0 -1
- data/Readme.md +0 -13
- data/exe/mutate +0 -6
- data/lib/mutant/extensions.rb +0 -8
- data/lib/mutant/formatter.rb +0 -19
- data/lib/mutant/implementation.rb +0 -70
- data/lib/mutant/literal.rb +0 -147
- data/lib/mutant/method.rb +0 -31
- data/lib/mutant/mutatee.rb +0 -61
- data/lib/mutant/node.rb +0 -26
- data/lib/mutant/runners/rspec.rb +0 -34
- data/lib/mutant/version.rb +0 -3
- data/spec/functional/class_spec.rb +0 -46
- data/spec/functional/instance_method/array_spec.rb +0 -53
- data/spec/functional/instance_method/boolean_spec.rb +0 -101
- data/spec/functional/instance_method/call_spec.rb +0 -161
- data/spec/functional/instance_method/fixnum_spec.rb +0 -53
- data/spec/functional/instance_method/float_spec.rb +0 -53
- data/spec/functional/instance_method/hash_spec.rb +0 -53
- data/spec/functional/instance_method/if_spec.rb +0 -57
- data/spec/functional/instance_method/ivar_assign_spec.rb +0 -62
- data/spec/functional/instance_method/range_spec.rb +0 -53
- data/spec/functional/instance_method/regex_spec.rb +0 -55
- data/spec/functional/instance_method/string_spec.rb +0 -53
- data/spec/functional/instance_method/symbol_spec.rb +0 -53
- data/spec/functional/reporter/method_loaded_spec.rb +0 -62
- data/spec/functional/reporter/running_mutations_spec.rb +0 -60
- data/spec/functional/runners/rspec_spec.rb +0 -26
- data/spec/functional/singleton_method/array_spec.rb +0 -53
- data/spec/functional/singleton_method/boolean_spec.rb +0 -101
- data/spec/functional/singleton_method/call_spec.rb +0 -161
- data/spec/functional/singleton_method/fixnum_spec.rb +0 -53
- data/spec/functional/singleton_method/float_spec.rb +0 -53
- data/spec/functional/singleton_method/hash_spec.rb +0 -53
- data/spec/functional/singleton_method/if_spec.rb +0 -57
- data/spec/functional/singleton_method/ivar_assign_spec.rb +0 -60
- data/spec/functional/singleton_method/range_spec.rb +0 -53
- data/spec/functional/singleton_method/regex_spec.rb +0 -55
- data/spec/functional/singleton_method/string_spec.rb +0 -53
- data/spec/functional/singleton_method/symbol_spec.rb +0 -53
- data/spec/mutant/extensions_spec.rb +0 -13
- data/spec/mutant/implementation_spec.rb +0 -223
- data/spec/mutant/literal_spec.rb +0 -129
- data/spec/mutant/mutatee_spec.rb +0 -28
- data/spec/mutant/node_spec.rb +0 -41
- data/spec/mutant/random_spec.rb +0 -33
- data/spec/mutant/reporter_spec.rb +0 -17
- data/spec/mutant_spec.rb +0 -28
- data/spec/support/example_group_helpers.rb +0 -11
- data/spec/support/example_helpers.rb +0 -5
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This spec is only present to ensure 100% test coverage.
|
4
|
+
# The code should not be triggered on runtime.
|
5
|
+
|
6
|
+
describe Mutant::Matcher, '#each' do
|
7
|
+
subject { object.send(:each) }
|
8
|
+
|
9
|
+
let(:object) { described_class.allocate }
|
10
|
+
|
11
|
+
it 'should raise error' do
|
12
|
+
expect { subject }.to raise_error(NotImplementedError, 'Mutant::Matcher#each is not implemented')
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::Method, '.parse' do
|
4
|
+
subject { described_class.parse(input) }
|
5
|
+
|
6
|
+
let(:response) { mock('Response') }
|
7
|
+
let(:input) { mock('Input') }
|
8
|
+
|
9
|
+
let(:classifier) { described_class::Classifier }
|
10
|
+
|
11
|
+
before do
|
12
|
+
classifier.stub(:run => response)
|
13
|
+
end
|
14
|
+
|
15
|
+
it { should be(response) }
|
16
|
+
|
17
|
+
it 'should call classifier' do
|
18
|
+
classifier.should_receive(:run).with(input).and_return(response)
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::Method::Classifier, '.run' do
|
4
|
+
subject { described_class.run(input) }
|
5
|
+
|
6
|
+
context 'with explicit toplevel scope' do
|
7
|
+
let(:input) { '::TestApp::Literal#string' }
|
8
|
+
let(:expected_class) { Mutant::Matcher::Method::Instance }
|
9
|
+
|
10
|
+
it_should_behave_like 'a method filter parse result'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with instance method notation' do
|
14
|
+
let(:input) { 'TestApp::Literal#string' }
|
15
|
+
let(:expected_class) { Mutant::Matcher::Method::Instance }
|
16
|
+
|
17
|
+
it_should_behave_like 'a method filter parse result'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with singleton method notation' do
|
21
|
+
let(:input) { 'TestApp::Literal.string' }
|
22
|
+
let(:expected_class) { Mutant::Matcher::Method::Singleton }
|
23
|
+
|
24
|
+
it_should_behave_like 'a method filter parse result'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with invalid notation' do
|
28
|
+
let(:input) { 'Foo' }
|
29
|
+
|
30
|
+
it 'should return nil' do
|
31
|
+
should be(nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::Method, '#method' do
|
4
|
+
subject { object.send(:method) }
|
5
|
+
|
6
|
+
let(:object) { described_class.allocate }
|
7
|
+
|
8
|
+
it 'should raise error' do
|
9
|
+
expect { subject }.to raise_error(NotImplementedError, 'Mutant::Matcher::Method#method is not implemented')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::ObjectSpace, '.parse' do
|
4
|
+
subject { object.parse(input) }
|
5
|
+
|
6
|
+
let(:object) { described_class }
|
7
|
+
|
8
|
+
let(:matcher) { mock('Matcher') }
|
9
|
+
|
10
|
+
context 'with valid notation' do
|
11
|
+
let(:input) { '::TestApp::Literal' }
|
12
|
+
|
13
|
+
it 'should return matcher' do
|
14
|
+
described_class.should_receive(:new).with(%r(\ATestApp::Literal(\z|::))).and_return(matcher)
|
15
|
+
should be(matcher)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with invalid notation' do
|
20
|
+
let(:input) { 'TestApp' }
|
21
|
+
|
22
|
+
it { should be(nil) }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Matcher::ObjectSpace, '#each' do
|
4
|
+
before do
|
5
|
+
pending "defunct"
|
6
|
+
end
|
7
|
+
subject { object.each { |item| yields << item } }
|
8
|
+
|
9
|
+
let(:yields) { [] }
|
10
|
+
let(:object) { described_class.new(/\ATestApp::Literal(\z|::)/) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
Mutant::Matcher::Method::Singleton.stub(:each).and_yield(matcher_a)
|
14
|
+
Mutant::Matcher::Method::Instance.stub(:each).and_yield(matcher_b)
|
15
|
+
matcher_a.stub(:each).and_yield(subject_a)
|
16
|
+
matcher_b.stub(:each).and_yield(subject_b)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
let(:matcher_a) { mock('Matcher A') }
|
21
|
+
let(:matcher_b) { mock('Matcher B') }
|
22
|
+
|
23
|
+
let(:subject_a) { mock('Subject A') }
|
24
|
+
let(:subject_b) { mock('Subject B') }
|
25
|
+
|
26
|
+
it_should_behave_like 'an #each method'
|
27
|
+
|
28
|
+
it 'should yield subjects' do
|
29
|
+
expect { subject }.to change { yields }.from([]).to([subject_a, subject_b])
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file is the sandbox for new mutations.
|
2
|
+
# Once finished mutation test will be moved to class specfic
|
3
|
+
# file.
|
4
|
+
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe Mutant::Mutator, '.each' do
|
8
|
+
|
9
|
+
pending 'interpolated string literal (DynamicString)' do
|
10
|
+
let(:source) { '"foo#{1}bar"' }
|
11
|
+
|
12
|
+
let(:random_string) { 'this-is-random' }
|
13
|
+
|
14
|
+
let(:mutations) do
|
15
|
+
mutations = []
|
16
|
+
mutations << 'nil'
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
Mutant::Random.stub(:hex_string => random_string)
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_behave_like 'a mutator'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, '#emit_new' do
|
4
|
+
subject { object.send(:emit_new) { generated } }
|
5
|
+
|
6
|
+
class Block
|
7
|
+
def arguments; @arguments; end
|
8
|
+
|
9
|
+
def called?
|
10
|
+
defined?(@arguments)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(*arguments)
|
14
|
+
@arguments = arguments
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:object) { class_under_test.new(input, block) }
|
19
|
+
let(:block) { Block.new }
|
20
|
+
let(:input) { :input }
|
21
|
+
|
22
|
+
let(:class_under_test) do
|
23
|
+
Class.new(described_class) do
|
24
|
+
def dispatch
|
25
|
+
#noop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when new object generated' do
|
31
|
+
let(:generated) { :generated }
|
32
|
+
|
33
|
+
it 'should call block' do
|
34
|
+
subject
|
35
|
+
block.should be_called
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should call block with generated object' do
|
39
|
+
subject
|
40
|
+
block.arguments.should eql([generated])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when new AST could not be generated' do
|
45
|
+
let(:generated) { input }
|
46
|
+
|
47
|
+
it 'should raise error' do
|
48
|
+
expect { subject }.to raise_error(RuntimeError, 'New AST could not be generated after 3 attempts')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, '#emit' do
|
4
|
+
subject { object.send(:emit, generated) }
|
5
|
+
|
6
|
+
class Block
|
7
|
+
def arguments; @arguments; end
|
8
|
+
|
9
|
+
def called?
|
10
|
+
defined?(@arguments)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(*arguments)
|
14
|
+
@arguments = arguments
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:object) { class_under_test.new(input, block) }
|
19
|
+
let(:block) { Block.new }
|
20
|
+
let(:input) { :nput }
|
21
|
+
|
22
|
+
let(:class_under_test) do
|
23
|
+
Class.new(described_class) do
|
24
|
+
def dispatch
|
25
|
+
#noop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with generated that is not equal to input' do
|
31
|
+
let(:generated) { :generated }
|
32
|
+
|
33
|
+
it 'should call block' do
|
34
|
+
subject
|
35
|
+
block.should be_called
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should call block with generated' do
|
39
|
+
subject
|
40
|
+
block.arguments.should eql([generated])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with generated object that is equal to input' do
|
45
|
+
let(:generated) { input }
|
46
|
+
|
47
|
+
it 'should not call block' do
|
48
|
+
subject
|
49
|
+
block.should_not be_called
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, 'block' do
|
4
|
+
|
5
|
+
context 'with more than one statement' do
|
6
|
+
let(:source) { "self.foo\nself.bar" }
|
7
|
+
|
8
|
+
let(:mutations) do
|
9
|
+
mutations = []
|
10
|
+
|
11
|
+
# Mutation of each statement in block
|
12
|
+
mutations << "foo\nself.bar"
|
13
|
+
mutations << "self.foo\nbar"
|
14
|
+
|
15
|
+
## Remove statement in block
|
16
|
+
mutations << [:block, 'self.foo'.to_sexp]
|
17
|
+
mutations << [:block, 'self.bar'.to_sexp]
|
18
|
+
mutations << [:block]
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like 'a mutator'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
context 'with one statement' do
|
26
|
+
let(:node) { Rubinius::AST::Block.new(1, ['self.foo'.to_ast]) }
|
27
|
+
|
28
|
+
let(:mutations) do
|
29
|
+
mutations = []
|
30
|
+
mutations << [:block, 'foo'.to_sexp]
|
31
|
+
mutations << [:block]
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like 'a mutator'
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, 'define' do
|
4
|
+
|
5
|
+
context 'with no arguments' do
|
6
|
+
let(:source) { 'def foo; self.bar; self.baz; end' }
|
7
|
+
|
8
|
+
let(:mutations) do
|
9
|
+
mutations = []
|
10
|
+
|
11
|
+
# Mutation of each statement in block
|
12
|
+
mutations << 'def foo; bar; self.baz; end'
|
13
|
+
mutations << 'def foo; self.bar; baz; end'
|
14
|
+
|
15
|
+
# Remove statement in block
|
16
|
+
mutations << 'def foo; self.baz; end'
|
17
|
+
mutations << 'def foo; self.bar; end'
|
18
|
+
|
19
|
+
# Remove all statements
|
20
|
+
mutations << [:defn, :foo, [:args], [:scope, [:block]]]
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_behave_like 'a mutator'
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'define on singleton' do
|
27
|
+
let(:source) { 'def self.foo; self.bar; self.baz; end' }
|
28
|
+
|
29
|
+
let(:mutations) do
|
30
|
+
mutations = []
|
31
|
+
|
32
|
+
# Body presence mutations
|
33
|
+
mutations << 'def self.foo; bar; self.baz; end'
|
34
|
+
mutations << 'def self.foo; self.bar; baz; end'
|
35
|
+
|
36
|
+
# Body presence mutations
|
37
|
+
mutations << 'def self.foo; self.bar; end'
|
38
|
+
mutations << 'def self.foo; self.baz; end'
|
39
|
+
|
40
|
+
# Remove all statements
|
41
|
+
mutations << [:defs, [:self], :foo, [:args], [:scope, [:block]]]
|
42
|
+
end
|
43
|
+
|
44
|
+
it_should_behave_like 'a mutator'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator, 'if statement' do
|
4
|
+
let(:source) { 'if self.condition; true; else false; end' }
|
5
|
+
|
6
|
+
let(:mutations) do
|
7
|
+
mutants = []
|
8
|
+
|
9
|
+
# mutations of condition
|
10
|
+
mutants << 'if condition; true; else false; end'
|
11
|
+
|
12
|
+
mutants << 'if !self.condition; true; else false; end'
|
13
|
+
|
14
|
+
# Deleted else branch
|
15
|
+
mutants << 'if self.condition; true end'
|
16
|
+
|
17
|
+
# Deleted if branch with promoting else branch to if branch
|
18
|
+
mutants << 'if self.condition; false end'
|
19
|
+
|
20
|
+
# mutations of body
|
21
|
+
mutants << 'if self.condition; false; else false; end'
|
22
|
+
mutants << 'if self.condition; nil; else false; end'
|
23
|
+
|
24
|
+
# mutations of else body
|
25
|
+
mutants << 'if self.condition; true; else true; end'
|
26
|
+
mutants << 'if self.condition; true; else nil; end'
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like 'a mutator'
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator::Node::Literal, 'array' do
|
4
|
+
let(:source) { '[true, false]' }
|
5
|
+
|
6
|
+
let(:mutations) do
|
7
|
+
mutations = []
|
8
|
+
|
9
|
+
# Literal replaced with nil
|
10
|
+
mutations << [:nil]
|
11
|
+
|
12
|
+
# Mutation of each element in array
|
13
|
+
mutations << '[nil, false]'
|
14
|
+
mutations << '[false, false]'
|
15
|
+
mutations << '[true, nil]'
|
16
|
+
mutations << '[true, true]'
|
17
|
+
|
18
|
+
# Remove each element of array once
|
19
|
+
mutations << '[true]'
|
20
|
+
mutations << '[false]'
|
21
|
+
|
22
|
+
# Empty array
|
23
|
+
mutations << '[]'
|
24
|
+
|
25
|
+
# Extra element
|
26
|
+
mutations << '[true, false, nil]'
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like 'a mutator'
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mutant::Mutator::Node::Literal, 'boolean' do
|
4
|
+
context 'true literal' do
|
5
|
+
let(:source) { 'true' }
|
6
|
+
|
7
|
+
let(:mutations) do
|
8
|
+
%w(nil false)
|
9
|
+
end
|
10
|
+
|
11
|
+
it_should_behave_like 'a mutator'
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'false literal' do
|
15
|
+
let(:source) { 'false' }
|
16
|
+
|
17
|
+
let(:mutations) do
|
18
|
+
%w(nil true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like 'a mutator'
|
22
|
+
end
|
23
|
+
end
|