mutant 0.8.24 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/Changelog.md +14 -654
- data/Gemfile +13 -0
- data/Gemfile.lock +59 -64
- data/LICENSE +271 -20
- data/README.md +73 -140
- data/Rakefile +0 -21
- data/bin/mutant +7 -2
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +5 -9
- data/docs/incremental.md +76 -0
- data/docs/known-problems.md +0 -14
- data/docs/mutant-minitest.md +1 -1
- data/docs/mutant-rspec.md +2 -24
- data/lib/mutant.rb +45 -53
- data/lib/mutant/ast/nodes.rb +0 -2
- data/lib/mutant/ast/types.rb +1 -117
- data/lib/mutant/base.rb +192 -0
- data/lib/mutant/bootstrap.rb +145 -0
- data/lib/mutant/cli.rb +68 -54
- data/lib/mutant/config.rb +119 -6
- data/lib/mutant/env.rb +94 -8
- data/lib/mutant/expression.rb +6 -1
- data/lib/mutant/expression/parser.rb +9 -31
- data/lib/mutant/integration.rb +64 -36
- data/lib/mutant/isolation.rb +16 -1
- data/lib/mutant/isolation/fork.rb +105 -40
- data/lib/mutant/license.rb +34 -0
- data/lib/mutant/license/subscription.rb +47 -0
- data/lib/mutant/license/subscription/commercial.rb +57 -0
- data/lib/mutant/license/subscription/opensource.rb +77 -0
- data/lib/mutant/loader.rb +27 -4
- data/lib/mutant/matcher.rb +48 -1
- data/lib/mutant/matcher/chain.rb +1 -1
- data/lib/mutant/matcher/config.rb +0 -2
- data/lib/mutant/matcher/filter.rb +1 -1
- data/lib/mutant/matcher/method.rb +11 -7
- data/lib/mutant/matcher/methods.rb +1 -1
- data/lib/mutant/matcher/namespace.rb +1 -1
- data/lib/mutant/matcher/null.rb +1 -1
- data/lib/mutant/matcher/scope.rb +1 -1
- data/lib/mutant/meta/example/dsl.rb +0 -8
- data/lib/mutant/mutation.rb +1 -2
- data/lib/mutant/mutator/node.rb +2 -9
- data/lib/mutant/mutator/node/arguments.rb +1 -1
- data/lib/mutant/mutator/node/class.rb +0 -8
- data/lib/mutant/mutator/node/define.rb +0 -12
- data/lib/mutant/mutator/node/generic.rb +30 -44
- data/lib/mutant/mutator/node/index.rb +4 -4
- data/lib/mutant/mutator/node/literal/regex.rb +0 -39
- data/lib/mutant/mutator/node/send.rb +13 -12
- data/lib/mutant/parallel.rb +61 -40
- data/lib/mutant/parallel/driver.rb +59 -0
- data/lib/mutant/parallel/source.rb +6 -2
- data/lib/mutant/parallel/worker.rb +63 -45
- data/lib/mutant/range.rb +15 -0
- data/lib/mutant/reporter/cli.rb +5 -11
- data/lib/mutant/reporter/cli/format.rb +3 -46
- data/lib/mutant/reporter/cli/printer/config.rb +5 -6
- data/lib/mutant/reporter/cli/printer/env.rb +40 -0
- data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
- data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
- data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
- data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
- data/lib/mutant/repository.rb +0 -65
- data/lib/mutant/repository/diff.rb +104 -0
- data/lib/mutant/repository/diff/ranges.rb +52 -0
- data/lib/mutant/result.rb +16 -7
- data/lib/mutant/runner.rb +38 -47
- data/lib/mutant/runner/sink.rb +1 -1
- data/lib/mutant/selector/null.rb +19 -0
- data/lib/mutant/subject.rb +3 -1
- data/lib/mutant/subject/method/instance.rb +3 -1
- data/lib/mutant/transform.rb +511 -0
- data/lib/mutant/variable.rb +282 -0
- data/lib/mutant/version.rb +1 -1
- data/lib/mutant/warnings.rb +113 -0
- data/meta/case.rb +1 -0
- data/meta/class.rb +0 -9
- data/meta/def.rb +1 -26
- data/meta/regexp.rb +10 -20
- data/meta/send.rb +14 -46
- data/mutant-minitest.gemspec +1 -1
- data/mutant-rspec.gemspec +2 -2
- data/mutant.gemspec +15 -16
- data/mutant.yml +6 -0
- data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
- data/spec/integration/mutant/minitest_spec.rb +3 -2
- data/spec/integration/mutant/rspec_spec.rb +4 -3
- data/spec/integrations.yml +16 -13
- data/spec/shared/base_behavior.rb +45 -0
- data/spec/shared/framework_integration_behavior.rb +43 -14
- data/spec/spec_helper.rb +21 -17
- data/spec/support/corpus.rb +56 -95
- data/spec/support/shared_context.rb +37 -14
- data/spec/support/xspec.rb +7 -3
- data/spec/unit/mutant/bootstrap_spec.rb +216 -0
- data/spec/unit/mutant/cli_spec.rb +173 -117
- data/spec/unit/mutant/config_spec.rb +126 -0
- data/spec/unit/mutant/either_spec.rb +247 -0
- data/spec/unit/mutant/env_spec.rb +162 -40
- data/spec/unit/mutant/expression/method_spec.rb +16 -0
- data/spec/unit/mutant/expression/parser_spec.rb +29 -33
- data/spec/unit/mutant/expression_spec.rb +5 -7
- data/spec/unit/mutant/integration_spec.rb +100 -9
- data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
- data/spec/unit/mutant/isolation/result_spec.rb +33 -1
- data/spec/unit/mutant/license_spec.rb +257 -0
- data/spec/unit/mutant/loader_spec.rb +50 -11
- data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
- data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
- data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
- data/spec/unit/mutant/matcher_spec.rb +102 -0
- data/spec/unit/mutant/maybe_spec.rb +60 -0
- data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
- data/spec/unit/mutant/mutation_spec.rb +13 -6
- data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
- data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
- data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
- data/spec/unit/mutant/parallel_spec.rb +105 -8
- data/spec/unit/mutant/range_spec.rb +141 -0
- data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
- data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
- data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
- data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
- data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
- data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
- data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
- data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
- data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
- data/spec/unit/mutant/repository/diff_spec.rb +84 -71
- data/spec/unit/mutant/require_highjack_spec.rb +1 -1
- data/spec/unit/mutant/result/env_spec.rb +39 -9
- data/spec/unit/mutant/result/test_spec.rb +14 -0
- data/spec/unit/mutant/runner_spec.rb +88 -41
- data/spec/unit/mutant/selector/expression_spec.rb +11 -10
- data/spec/unit/mutant/selector/null_spec.rb +17 -0
- data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
- data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
- data/spec/unit/mutant/subject_spec.rb +9 -1
- data/spec/unit/mutant/transform/array_spec.rb +92 -0
- data/spec/unit/mutant/transform/bool_spec.rb +63 -0
- data/spec/unit/mutant/transform/error_spec.rb +132 -0
- data/spec/unit/mutant/transform/exception_spec.rb +44 -0
- data/spec/unit/mutant/transform/hash_spec.rb +236 -0
- data/spec/unit/mutant/transform/index_spec.rb +92 -0
- data/spec/unit/mutant/transform/named_spec.rb +49 -0
- data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
- data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
- data/spec/unit/mutant/variable_spec.rb +618 -0
- data/spec/unit/mutant/warnings_spec.rb +89 -0
- data/spec/unit/mutant/world_spec.rb +63 -0
- data/test_app/Gemfile.minitest +0 -2
- metadata +79 -113
- data/.gitattributes +0 -1
- data/.ruby-gemset +0 -1
- data/config/triage.yml +0 -2
- data/lib/mutant/actor.rb +0 -57
- data/lib/mutant/actor/env.rb +0 -31
- data/lib/mutant/actor/mailbox.rb +0 -34
- data/lib/mutant/actor/receiver.rb +0 -42
- data/lib/mutant/actor/sender.rb +0 -26
- data/lib/mutant/ast/meta/restarg.rb +0 -19
- data/lib/mutant/ast/regexp.rb +0 -42
- data/lib/mutant/ast/regexp/transformer.rb +0 -187
- data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
- data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
- data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
- data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
- data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
- data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
- data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
- data/lib/mutant/env/bootstrap.rb +0 -160
- data/lib/mutant/matcher/compiler.rb +0 -60
- data/lib/mutant/mutator/node/regexp.rb +0 -35
- data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
- data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
- data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
- data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
- data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
- data/lib/mutant/parallel/master.rb +0 -181
- data/lib/mutant/reporter/cli/printer/status.rb +0 -53
- data/lib/mutant/reporter/cli/tput.rb +0 -46
- data/lib/mutant/warning_filter.rb +0 -61
- data/meta/regexp/character_types.rb +0 -23
- data/meta/regexp/regexp_alternation_meta.rb +0 -13
- data/meta/regexp/regexp_bol_anchor.rb +0 -10
- data/meta/regexp/regexp_bos_anchor.rb +0 -18
- data/meta/regexp/regexp_capture_group.rb +0 -19
- data/meta/regexp/regexp_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_eos_anchor.rb +0 -8
- data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
- data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
- data/meta/regexp/regexp_root_expression.rb +0 -10
- data/meta/restarg.rb +0 -10
- data/spec/support/fake_actor.rb +0 -111
- data/spec/support/warning.rb +0 -66
- data/spec/unit/mutant/actor/binding_spec.rb +0 -34
- data/spec/unit/mutant/actor/env_spec.rb +0 -31
- data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
- data/spec/unit/mutant/actor/message_spec.rb +0 -25
- data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
- data/spec/unit/mutant/actor/sender_spec.rb +0 -24
- data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
- data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
- data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
- data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
- data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
- data/spec/unit/mutant/parallel/master_spec.rb +0 -338
- data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
- data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
- data/spec/unit/mutant/warning_filter_spec.rb +0 -106
- data/spec/unit/mutant_spec.rb +0 -17
- data/test_app/Gemfile.rspec3.7 +0 -7
@@ -43,4 +43,20 @@ RSpec.describe Mutant::Expression::Method do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe '#syntax' do
|
48
|
+
subject { object.syntax }
|
49
|
+
|
50
|
+
context 'on instance method' do
|
51
|
+
let(:input) { instance_method }
|
52
|
+
|
53
|
+
it { should eql(instance_method) }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'on singleton method' do
|
57
|
+
let(:input) { singleton_method }
|
58
|
+
|
59
|
+
it { should eql(singleton_method) }
|
60
|
+
end
|
61
|
+
end
|
46
62
|
end
|
@@ -1,46 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Mutant::Expression::Parser do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
subject { object.call(input) }
|
8
|
-
|
9
|
-
context 'on nonsense' do
|
10
|
-
let(:input) { 'foo bar' }
|
4
|
+
subject do
|
5
|
+
Mutant::Config::DEFAULT.expression_parser
|
6
|
+
end
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
'Expression: "foo bar" is not valid'
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
8
|
+
def apply
|
9
|
+
subject.apply(input)
|
10
|
+
end
|
19
11
|
|
12
|
+
describe '#apply' do
|
20
13
|
context 'on a valid expression' do
|
21
14
|
let(:input) { 'Foo' }
|
22
15
|
|
23
|
-
it
|
16
|
+
it 'returns sucess' do
|
17
|
+
expect(apply).to eql(
|
18
|
+
Mutant::Either::Right.new(
|
19
|
+
Mutant::Expression::Namespace::Exact.new(scope_name: 'Foo')
|
20
|
+
)
|
21
|
+
)
|
22
|
+
end
|
24
23
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '.try_parse' do
|
28
|
-
subject { object.try_parse(input) }
|
29
24
|
|
30
|
-
context 'on
|
25
|
+
context 'on invalid input' do
|
31
26
|
let(:input) { 'foo bar' }
|
32
27
|
|
33
|
-
it
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
it { should eql(Mutant::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
|
28
|
+
it 'returns returns error' do
|
29
|
+
expect(apply).to eql(
|
30
|
+
Mutant::Either::Left.new('Expression: "foo bar" is invalid')
|
31
|
+
)
|
32
|
+
end
|
40
33
|
end
|
41
34
|
|
42
|
-
context 'on ambiguous
|
43
|
-
|
35
|
+
context 'on ambiguous input' do
|
36
|
+
subject do
|
37
|
+
described_class.new([test_a, test_b])
|
38
|
+
end
|
44
39
|
|
45
40
|
let(:test_a) do
|
46
41
|
Class.new(Mutant::Expression) do
|
@@ -58,10 +53,11 @@ RSpec.describe Mutant::Expression::Parser do
|
|
58
53
|
|
59
54
|
let(:input) { 'test-syntax' }
|
60
55
|
|
61
|
-
it '
|
62
|
-
expect
|
63
|
-
Mutant::
|
64
|
-
|
56
|
+
it 'returns error' do
|
57
|
+
expect(apply).to eql(
|
58
|
+
Mutant::Either::Left.new(
|
59
|
+
'Expression: "test-syntax" is ambiguous'
|
60
|
+
)
|
65
61
|
)
|
66
62
|
end
|
67
63
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Mutant::Expression do
|
4
|
-
let(:parser) { Mutant::Config::DEFAULT.expression_parser }
|
5
|
-
|
6
4
|
describe '#prefix?' do
|
7
|
-
let(:object) {
|
5
|
+
let(:object) { parse_expression('Foo*') }
|
8
6
|
|
9
7
|
subject { object.prefix?(other) }
|
10
8
|
|
11
9
|
context 'when object is a prefix of other' do
|
12
|
-
let(:other) {
|
10
|
+
let(:other) { parse_expression('Foo::Bar') }
|
13
11
|
|
14
12
|
it { should be(true) }
|
15
13
|
end
|
16
14
|
|
17
15
|
context 'when other is not a prefix of other' do
|
18
|
-
let(:other) {
|
16
|
+
let(:other) { parse_expression('Bar') }
|
19
17
|
|
20
18
|
it { should be(false) }
|
21
19
|
end
|
@@ -32,13 +30,13 @@ RSpec.describe Mutant::Expression do
|
|
32
30
|
|
33
31
|
subject { object.try_parse(input) }
|
34
32
|
|
35
|
-
context '
|
33
|
+
context 'good input' do
|
36
34
|
let(:input) { 'foo' }
|
37
35
|
|
38
36
|
it { should eql(object.new(foo: 'foo')) }
|
39
37
|
end
|
40
38
|
|
41
|
-
context '
|
39
|
+
context 'bad input' do
|
42
40
|
let(:input) { 'bar' }
|
43
41
|
|
44
42
|
it { should be(nil) }
|
@@ -1,30 +1,121 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe Mutant::Integration do
|
4
|
+
subject { class_under_test.new(Mutant::Config::DEFAULT) }
|
4
5
|
|
5
6
|
let(:class_under_test) do
|
6
7
|
Class.new(described_class)
|
7
8
|
end
|
8
9
|
|
9
|
-
let(:object) { class_under_test.new(Mutant::Config::DEFAULT) }
|
10
|
-
|
11
10
|
describe '#setup' do
|
12
|
-
|
13
|
-
|
11
|
+
def apply
|
12
|
+
subject.setup
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns self' do
|
16
|
+
expect(apply).to be(subject)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
describe '.setup' do
|
17
|
-
|
21
|
+
def apply
|
22
|
+
described_class.setup(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:kernel) { class_double(Kernel) }
|
26
|
+
let(:integration) { instance_double(Mutant::Integration::Null) }
|
27
|
+
let(:integration_name) { 'null' }
|
28
|
+
|
29
|
+
let(:config) do
|
30
|
+
instance_double(
|
31
|
+
Mutant::Config,
|
32
|
+
integration: integration_name
|
33
|
+
)
|
34
|
+
end
|
18
35
|
|
19
|
-
let(:
|
20
|
-
|
36
|
+
let(:env) do
|
37
|
+
instance_double(
|
38
|
+
Mutant::Env,
|
39
|
+
config: config,
|
40
|
+
world: world
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:world) do
|
45
|
+
instance_double(
|
46
|
+
Mutant::World,
|
47
|
+
kernel: kernel
|
48
|
+
)
|
49
|
+
end
|
21
50
|
|
22
51
|
before do
|
23
|
-
|
52
|
+
allow(kernel).to receive_messages(require: undefined)
|
53
|
+
allow(described_class).to receive_messages(const_get: described_class::Null)
|
54
|
+
allow(described_class::Null).to receive_messages(new: integration)
|
55
|
+
allow(integration).to receive_messages(setup: integration)
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when require fails' do
|
59
|
+
let(:exception) { LoadError.new('some-load-error') }
|
60
|
+
|
61
|
+
before do
|
62
|
+
allow(kernel).to receive(:require).and_raise(exception)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns error' do
|
66
|
+
expect(apply).to eql(Mutant::Either::Left.new(<<~MESSAGE))
|
67
|
+
Unable to load integration mutant-null:
|
68
|
+
#{exception.inspect}
|
69
|
+
You may have to install the gem mutant-null!
|
70
|
+
MESSAGE
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when constant lookup fails' do
|
75
|
+
let(:exception) { NameError.new('some-name-error') }
|
76
|
+
|
77
|
+
before do
|
78
|
+
allow(described_class).to receive(:const_get).and_raise(exception)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns error' do
|
82
|
+
expect(apply).to eql(Mutant::Either::Left.new(<<~MESSAGE))
|
83
|
+
Unable to load integration mutant-null:
|
84
|
+
#{exception.inspect}
|
85
|
+
This is a bug in the integration you have to report.
|
86
|
+
The integration is supposed to define Mutant::Integration::Null!
|
87
|
+
MESSAGE
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'performs actions in expected sequence' do
|
92
|
+
apply
|
93
|
+
|
94
|
+
expect(kernel)
|
95
|
+
.to have_received(:require)
|
24
96
|
.with('mutant/integration/null')
|
97
|
+
.ordered
|
98
|
+
|
99
|
+
expect(described_class)
|
100
|
+
.to have_received(:const_get)
|
101
|
+
.with('Null')
|
102
|
+
.ordered
|
103
|
+
|
104
|
+
expect(described_class::Null)
|
105
|
+
.to have_received(:new)
|
106
|
+
.with(config)
|
107
|
+
.ordered
|
108
|
+
|
109
|
+
expect(integration)
|
110
|
+
.to have_received(:setup)
|
111
|
+
.ordered
|
25
112
|
end
|
26
113
|
|
27
|
-
it
|
114
|
+
it 'returns integration instance' do
|
115
|
+
expect(apply).to eql(
|
116
|
+
Mutant::Either::Right.new(integration)
|
117
|
+
)
|
118
|
+
end
|
28
119
|
end
|
29
120
|
end
|
30
121
|
|
@@ -11,22 +11,35 @@
|
|
11
11
|
RSpec.describe Mutant::Isolation::Fork do
|
12
12
|
let(:block_return) { instance_double(Object, :block_return) }
|
13
13
|
let(:block_return_blob) { instance_double(String, :block_return_blob) }
|
14
|
-
let(:devnull) { instance_double(Proc, :devnull) }
|
15
14
|
let(:io) { class_double(IO) }
|
16
15
|
let(:isolated_block) { -> { block_return } }
|
16
|
+
let(:log_fragment) { 'log message' }
|
17
|
+
let(:log_reader) { instance_double(IO, :log_reader) }
|
18
|
+
let(:log_writer) { instance_double(IO, :log_writer) }
|
17
19
|
let(:marshal) { class_double(Marshal) }
|
20
|
+
let(:pid) { class_double(Integer) }
|
18
21
|
let(:process) { class_double(Process) }
|
19
|
-
let(:
|
20
|
-
let(:
|
22
|
+
let(:result_fragment) { 'result body' }
|
23
|
+
let(:result_reader) { instance_double(IO, :result_reader) }
|
24
|
+
let(:result_writer) { instance_double(IO, :result_writer) }
|
21
25
|
let(:stderr) { instance_double(IO, :stderr) }
|
22
26
|
let(:stdout) { instance_double(IO, :stdout) }
|
23
|
-
let(:writer) { instance_double(IO, :writer) }
|
24
|
-
let(:nullio) { instance_double(IO, :nullio) }
|
25
27
|
|
26
28
|
let(:status_success) do
|
27
29
|
instance_double(Process::Status, success?: true)
|
28
30
|
end
|
29
31
|
|
32
|
+
let(:world) do
|
33
|
+
instance_double(
|
34
|
+
Mutant::World,
|
35
|
+
io: io,
|
36
|
+
marshal: marshal,
|
37
|
+
process: process,
|
38
|
+
stderr: stderr,
|
39
|
+
stdout: stdout
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
30
43
|
let(:fork_success) do
|
31
44
|
{
|
32
45
|
receiver: process,
|
@@ -49,9 +62,9 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
49
62
|
}
|
50
63
|
end
|
51
64
|
|
52
|
-
|
65
|
+
def close(descriptor)
|
53
66
|
{
|
54
|
-
receiver:
|
67
|
+
receiver: descriptor,
|
55
68
|
selector: :close
|
56
69
|
}
|
57
70
|
end
|
@@ -60,40 +73,82 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
60
73
|
{
|
61
74
|
receiver: marshal,
|
62
75
|
selector: :load,
|
63
|
-
arguments: [
|
76
|
+
arguments: [result_fragment],
|
64
77
|
reaction: {
|
65
78
|
return: block_return
|
66
79
|
}
|
67
80
|
}
|
68
81
|
end
|
69
82
|
|
83
|
+
let(:read_fragments) do
|
84
|
+
[
|
85
|
+
{
|
86
|
+
receiver: io,
|
87
|
+
selector: :select,
|
88
|
+
arguments: [[log_reader, result_reader]],
|
89
|
+
reaction: { return: [[log_reader, result_reader], []] }
|
90
|
+
},
|
91
|
+
{
|
92
|
+
receiver: log_reader,
|
93
|
+
selector: :eof?,
|
94
|
+
reaction: { return: false }
|
95
|
+
},
|
96
|
+
{
|
97
|
+
receiver: log_reader,
|
98
|
+
selector: :read_nonblock,
|
99
|
+
arguments: [4096],
|
100
|
+
reaction: { return: log_fragment }
|
101
|
+
},
|
102
|
+
{
|
103
|
+
receiver: result_reader,
|
104
|
+
selector: :eof?,
|
105
|
+
reaction: { return: false }
|
106
|
+
},
|
107
|
+
{
|
108
|
+
receiver: result_reader,
|
109
|
+
selector: :read_nonblock,
|
110
|
+
arguments: [4096],
|
111
|
+
reaction: { return: result_fragment }
|
112
|
+
},
|
113
|
+
{
|
114
|
+
receiver: io,
|
115
|
+
selector: :select,
|
116
|
+
arguments: [[log_reader, result_reader]],
|
117
|
+
reaction: { return: [[log_reader, result_reader], []] }
|
118
|
+
},
|
119
|
+
{
|
120
|
+
receiver: log_reader,
|
121
|
+
selector: :eof?,
|
122
|
+
reaction: { return: true }
|
123
|
+
},
|
124
|
+
{
|
125
|
+
receiver: result_reader,
|
126
|
+
selector: :eof?,
|
127
|
+
reaction: { return: true }
|
128
|
+
}
|
129
|
+
]
|
130
|
+
end
|
131
|
+
|
70
132
|
let(:killfork) do
|
71
133
|
[
|
72
134
|
# Inside the killfork
|
73
135
|
{
|
74
|
-
receiver:
|
136
|
+
receiver: log_reader,
|
75
137
|
selector: :close
|
76
138
|
},
|
77
139
|
{
|
78
|
-
receiver:
|
79
|
-
selector: :
|
80
|
-
},
|
81
|
-
{
|
82
|
-
receiver: devnull,
|
83
|
-
selector: :call,
|
84
|
-
reaction: {
|
85
|
-
yields: [nullio]
|
86
|
-
}
|
140
|
+
receiver: result_reader,
|
141
|
+
selector: :close
|
87
142
|
},
|
88
143
|
{
|
89
144
|
receiver: stderr,
|
90
145
|
selector: :reopen,
|
91
|
-
arguments: [
|
146
|
+
arguments: [log_writer]
|
92
147
|
},
|
93
148
|
{
|
94
149
|
receiver: stdout,
|
95
150
|
selector: :reopen,
|
96
|
-
arguments: [
|
151
|
+
arguments: [log_writer]
|
97
152
|
},
|
98
153
|
{
|
99
154
|
receiver: marshal,
|
@@ -104,27 +159,21 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
104
159
|
}
|
105
160
|
},
|
106
161
|
{
|
107
|
-
receiver:
|
162
|
+
receiver: result_writer,
|
108
163
|
selector: :syswrite,
|
109
164
|
arguments: [block_return_blob]
|
110
165
|
},
|
111
|
-
|
166
|
+
close(result_writer),
|
167
|
+
close(log_writer)
|
112
168
|
]
|
113
169
|
end
|
114
170
|
|
115
171
|
describe '#call' do
|
116
|
-
|
117
|
-
described_class.new(
|
118
|
-
devnull: devnull,
|
119
|
-
io: io,
|
120
|
-
marshal: marshal,
|
121
|
-
process: process,
|
122
|
-
stderr: stderr,
|
123
|
-
stdout: stdout
|
124
|
-
)
|
125
|
-
end
|
172
|
+
subject { described_class.new(world) }
|
126
173
|
|
127
|
-
|
174
|
+
def apply
|
175
|
+
subject.call(&isolated_block)
|
176
|
+
end
|
128
177
|
|
129
178
|
let(:prefork_expectations) do
|
130
179
|
[
|
@@ -133,7 +182,15 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
133
182
|
selector: :pipe,
|
134
183
|
arguments: [binmode: true],
|
135
184
|
reaction: {
|
136
|
-
yields: [[
|
185
|
+
yields: [[result_reader, result_writer]]
|
186
|
+
}
|
187
|
+
},
|
188
|
+
{
|
189
|
+
receiver: io,
|
190
|
+
selector: :pipe,
|
191
|
+
arguments: [binmode: true],
|
192
|
+
reaction: {
|
193
|
+
yields: [[log_reader, log_writer]]
|
137
194
|
}
|
138
195
|
}
|
139
196
|
]
|
@@ -145,7 +202,8 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
145
202
|
*prefork_expectations,
|
146
203
|
fork_success,
|
147
204
|
*killfork,
|
148
|
-
|
205
|
+
close(result_writer),
|
206
|
+
*read_fragments,
|
149
207
|
load_success,
|
150
208
|
child_wait
|
151
209
|
].map(&XSpec::MessageExpectation.method(:parse))
|
@@ -153,37 +211,36 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
153
211
|
|
154
212
|
specify do
|
155
213
|
XSpec::ExpectationVerifier.verify(self, expectations) do
|
156
|
-
expect(
|
214
|
+
expect(apply).to eql(Mutant::Isolation::Result::Success.new(block_return, log_fragment))
|
157
215
|
end
|
158
216
|
end
|
159
217
|
end
|
160
218
|
|
161
|
-
context 'when expected exception was raised when
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
219
|
+
context 'when expected exception was raised when loading result' do
|
220
|
+
let(:exception) { ArgumentError.new }
|
221
|
+
|
222
|
+
let(:expectations) do
|
223
|
+
[
|
224
|
+
*prefork_expectations,
|
225
|
+
fork_success,
|
226
|
+
*killfork,
|
227
|
+
close(result_writer),
|
228
|
+
*read_fragments,
|
229
|
+
{
|
230
|
+
receiver: marshal,
|
231
|
+
selector: :load,
|
232
|
+
arguments: [result_fragment],
|
233
|
+
reaction: {
|
234
|
+
exception: exception
|
235
|
+
}
|
236
|
+
},
|
237
|
+
child_wait
|
238
|
+
].map(&XSpec::MessageExpectation.method(:parse))
|
239
|
+
end
|
240
|
+
|
241
|
+
specify do
|
242
|
+
XSpec::ExpectationVerifier.verify(self, expectations) do
|
243
|
+
expect(apply).to eql(Mutant::Isolation::Result::Exception.new(exception))
|
187
244
|
end
|
188
245
|
end
|
189
246
|
end
|
@@ -206,7 +263,7 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
206
263
|
|
207
264
|
specify do
|
208
265
|
XSpec::ExpectationVerifier.verify(self, expectations) do
|
209
|
-
expect(
|
266
|
+
expect(apply).to eql(result_class.new)
|
210
267
|
end
|
211
268
|
end
|
212
269
|
end
|
@@ -218,8 +275,8 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
218
275
|
|
219
276
|
let(:expected_result) do
|
220
277
|
Mutant::Isolation::Result::ErrorChain.new(
|
221
|
-
described_class::ChildError.new(status_error),
|
222
|
-
Mutant::Isolation::Result::Success.new(block_return)
|
278
|
+
described_class::ChildError.new(status_error, log_fragment),
|
279
|
+
Mutant::Isolation::Result::Success.new(block_return, log_fragment)
|
223
280
|
)
|
224
281
|
end
|
225
282
|
|
@@ -228,7 +285,8 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
228
285
|
*prefork_expectations,
|
229
286
|
fork_success,
|
230
287
|
*killfork,
|
231
|
-
|
288
|
+
close(result_writer),
|
289
|
+
*read_fragments,
|
232
290
|
load_success,
|
233
291
|
{
|
234
292
|
receiver: process,
|
@@ -243,7 +301,7 @@ RSpec.describe Mutant::Isolation::Fork do
|
|
243
301
|
|
244
302
|
specify do
|
245
303
|
XSpec::ExpectationVerifier.verify(self, expectations) do
|
246
|
-
expect(
|
304
|
+
expect(apply).to eql(expected_result)
|
247
305
|
end
|
248
306
|
end
|
249
307
|
end
|