mutant 0.8.24 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/Changelog.md +14 -654
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +59 -64
  6. data/LICENSE +271 -20
  7. data/README.md +73 -140
  8. data/Rakefile +0 -21
  9. data/bin/mutant +7 -2
  10. data/config/reek.yml +2 -1
  11. data/config/rubocop.yml +5 -9
  12. data/docs/incremental.md +76 -0
  13. data/docs/known-problems.md +0 -14
  14. data/docs/mutant-minitest.md +1 -1
  15. data/docs/mutant-rspec.md +2 -24
  16. data/lib/mutant.rb +45 -53
  17. data/lib/mutant/ast/nodes.rb +0 -2
  18. data/lib/mutant/ast/types.rb +1 -117
  19. data/lib/mutant/base.rb +192 -0
  20. data/lib/mutant/bootstrap.rb +145 -0
  21. data/lib/mutant/cli.rb +68 -54
  22. data/lib/mutant/config.rb +119 -6
  23. data/lib/mutant/env.rb +94 -8
  24. data/lib/mutant/expression.rb +6 -1
  25. data/lib/mutant/expression/parser.rb +9 -31
  26. data/lib/mutant/integration.rb +64 -36
  27. data/lib/mutant/isolation.rb +16 -1
  28. data/lib/mutant/isolation/fork.rb +105 -40
  29. data/lib/mutant/license.rb +34 -0
  30. data/lib/mutant/license/subscription.rb +47 -0
  31. data/lib/mutant/license/subscription/commercial.rb +57 -0
  32. data/lib/mutant/license/subscription/opensource.rb +77 -0
  33. data/lib/mutant/loader.rb +27 -4
  34. data/lib/mutant/matcher.rb +48 -1
  35. data/lib/mutant/matcher/chain.rb +1 -1
  36. data/lib/mutant/matcher/config.rb +0 -2
  37. data/lib/mutant/matcher/filter.rb +1 -1
  38. data/lib/mutant/matcher/method.rb +11 -7
  39. data/lib/mutant/matcher/methods.rb +1 -1
  40. data/lib/mutant/matcher/namespace.rb +1 -1
  41. data/lib/mutant/matcher/null.rb +1 -1
  42. data/lib/mutant/matcher/scope.rb +1 -1
  43. data/lib/mutant/meta/example/dsl.rb +0 -8
  44. data/lib/mutant/mutation.rb +1 -2
  45. data/lib/mutant/mutator/node.rb +2 -9
  46. data/lib/mutant/mutator/node/arguments.rb +1 -1
  47. data/lib/mutant/mutator/node/class.rb +0 -8
  48. data/lib/mutant/mutator/node/define.rb +0 -12
  49. data/lib/mutant/mutator/node/generic.rb +30 -44
  50. data/lib/mutant/mutator/node/index.rb +4 -4
  51. data/lib/mutant/mutator/node/literal/regex.rb +0 -39
  52. data/lib/mutant/mutator/node/send.rb +13 -12
  53. data/lib/mutant/parallel.rb +61 -40
  54. data/lib/mutant/parallel/driver.rb +59 -0
  55. data/lib/mutant/parallel/source.rb +6 -2
  56. data/lib/mutant/parallel/worker.rb +63 -45
  57. data/lib/mutant/range.rb +15 -0
  58. data/lib/mutant/reporter/cli.rb +5 -11
  59. data/lib/mutant/reporter/cli/format.rb +3 -46
  60. data/lib/mutant/reporter/cli/printer/config.rb +5 -6
  61. data/lib/mutant/reporter/cli/printer/env.rb +40 -0
  62. data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
  63. data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
  64. data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
  65. data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
  66. data/lib/mutant/repository.rb +0 -65
  67. data/lib/mutant/repository/diff.rb +104 -0
  68. data/lib/mutant/repository/diff/ranges.rb +52 -0
  69. data/lib/mutant/result.rb +16 -7
  70. data/lib/mutant/runner.rb +38 -47
  71. data/lib/mutant/runner/sink.rb +1 -1
  72. data/lib/mutant/selector/null.rb +19 -0
  73. data/lib/mutant/subject.rb +3 -1
  74. data/lib/mutant/subject/method/instance.rb +3 -1
  75. data/lib/mutant/transform.rb +511 -0
  76. data/lib/mutant/variable.rb +282 -0
  77. data/lib/mutant/version.rb +1 -1
  78. data/lib/mutant/warnings.rb +113 -0
  79. data/meta/case.rb +1 -0
  80. data/meta/class.rb +0 -9
  81. data/meta/def.rb +1 -26
  82. data/meta/regexp.rb +10 -20
  83. data/meta/send.rb +14 -46
  84. data/mutant-minitest.gemspec +1 -1
  85. data/mutant-rspec.gemspec +2 -2
  86. data/mutant.gemspec +15 -16
  87. data/mutant.yml +6 -0
  88. data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
  89. data/spec/integration/mutant/minitest_spec.rb +3 -2
  90. data/spec/integration/mutant/rspec_spec.rb +4 -3
  91. data/spec/integrations.yml +16 -13
  92. data/spec/shared/base_behavior.rb +45 -0
  93. data/spec/shared/framework_integration_behavior.rb +43 -14
  94. data/spec/spec_helper.rb +21 -17
  95. data/spec/support/corpus.rb +56 -95
  96. data/spec/support/shared_context.rb +37 -14
  97. data/spec/support/xspec.rb +7 -3
  98. data/spec/unit/mutant/bootstrap_spec.rb +216 -0
  99. data/spec/unit/mutant/cli_spec.rb +173 -117
  100. data/spec/unit/mutant/config_spec.rb +126 -0
  101. data/spec/unit/mutant/either_spec.rb +247 -0
  102. data/spec/unit/mutant/env_spec.rb +162 -40
  103. data/spec/unit/mutant/expression/method_spec.rb +16 -0
  104. data/spec/unit/mutant/expression/parser_spec.rb +29 -33
  105. data/spec/unit/mutant/expression_spec.rb +5 -7
  106. data/spec/unit/mutant/integration_spec.rb +100 -9
  107. data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
  108. data/spec/unit/mutant/isolation/result_spec.rb +33 -1
  109. data/spec/unit/mutant/license_spec.rb +257 -0
  110. data/spec/unit/mutant/loader_spec.rb +50 -11
  111. data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
  112. data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
  113. data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
  114. data/spec/unit/mutant/matcher_spec.rb +102 -0
  115. data/spec/unit/mutant/maybe_spec.rb +60 -0
  116. data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
  117. data/spec/unit/mutant/mutation_spec.rb +13 -6
  118. data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
  119. data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
  120. data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
  121. data/spec/unit/mutant/parallel_spec.rb +105 -8
  122. data/spec/unit/mutant/range_spec.rb +141 -0
  123. data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
  124. data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
  125. data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
  126. data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
  127. data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
  128. data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
  129. data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
  130. data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
  131. data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
  132. data/spec/unit/mutant/repository/diff_spec.rb +84 -71
  133. data/spec/unit/mutant/require_highjack_spec.rb +1 -1
  134. data/spec/unit/mutant/result/env_spec.rb +39 -9
  135. data/spec/unit/mutant/result/test_spec.rb +14 -0
  136. data/spec/unit/mutant/runner_spec.rb +88 -41
  137. data/spec/unit/mutant/selector/expression_spec.rb +11 -10
  138. data/spec/unit/mutant/selector/null_spec.rb +17 -0
  139. data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
  140. data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
  141. data/spec/unit/mutant/subject_spec.rb +9 -1
  142. data/spec/unit/mutant/transform/array_spec.rb +92 -0
  143. data/spec/unit/mutant/transform/bool_spec.rb +63 -0
  144. data/spec/unit/mutant/transform/error_spec.rb +132 -0
  145. data/spec/unit/mutant/transform/exception_spec.rb +44 -0
  146. data/spec/unit/mutant/transform/hash_spec.rb +236 -0
  147. data/spec/unit/mutant/transform/index_spec.rb +92 -0
  148. data/spec/unit/mutant/transform/named_spec.rb +49 -0
  149. data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
  150. data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
  151. data/spec/unit/mutant/variable_spec.rb +618 -0
  152. data/spec/unit/mutant/warnings_spec.rb +89 -0
  153. data/spec/unit/mutant/world_spec.rb +63 -0
  154. data/test_app/Gemfile.minitest +0 -2
  155. metadata +79 -113
  156. data/.gitattributes +0 -1
  157. data/.ruby-gemset +0 -1
  158. data/config/triage.yml +0 -2
  159. data/lib/mutant/actor.rb +0 -57
  160. data/lib/mutant/actor/env.rb +0 -31
  161. data/lib/mutant/actor/mailbox.rb +0 -34
  162. data/lib/mutant/actor/receiver.rb +0 -42
  163. data/lib/mutant/actor/sender.rb +0 -26
  164. data/lib/mutant/ast/meta/restarg.rb +0 -19
  165. data/lib/mutant/ast/regexp.rb +0 -42
  166. data/lib/mutant/ast/regexp/transformer.rb +0 -187
  167. data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
  168. data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
  169. data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
  170. data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
  171. data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
  172. data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
  173. data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
  174. data/lib/mutant/env/bootstrap.rb +0 -160
  175. data/lib/mutant/matcher/compiler.rb +0 -60
  176. data/lib/mutant/mutator/node/regexp.rb +0 -35
  177. data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
  178. data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
  179. data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
  180. data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
  181. data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
  182. data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
  183. data/lib/mutant/parallel/master.rb +0 -181
  184. data/lib/mutant/reporter/cli/printer/status.rb +0 -53
  185. data/lib/mutant/reporter/cli/tput.rb +0 -46
  186. data/lib/mutant/warning_filter.rb +0 -61
  187. data/meta/regexp/character_types.rb +0 -23
  188. data/meta/regexp/regexp_alternation_meta.rb +0 -13
  189. data/meta/regexp/regexp_bol_anchor.rb +0 -10
  190. data/meta/regexp/regexp_bos_anchor.rb +0 -18
  191. data/meta/regexp/regexp_capture_group.rb +0 -19
  192. data/meta/regexp/regexp_eol_anchor.rb +0 -10
  193. data/meta/regexp/regexp_eos_anchor.rb +0 -8
  194. data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
  195. data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
  196. data/meta/regexp/regexp_root_expression.rb +0 -10
  197. data/meta/restarg.rb +0 -10
  198. data/spec/support/fake_actor.rb +0 -111
  199. data/spec/support/warning.rb +0 -66
  200. data/spec/unit/mutant/actor/binding_spec.rb +0 -34
  201. data/spec/unit/mutant/actor/env_spec.rb +0 -31
  202. data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
  203. data/spec/unit/mutant/actor/message_spec.rb +0 -25
  204. data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
  205. data/spec/unit/mutant/actor/sender_spec.rb +0 -24
  206. data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
  207. data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
  208. data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
  209. data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
  210. data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
  211. data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
  212. data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
  213. data/spec/unit/mutant/parallel/master_spec.rb +0 -338
  214. data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
  215. data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
  216. data/spec/unit/mutant/warning_filter_spec.rb +0 -106
  217. data/spec/unit/mutant_spec.rb +0 -17
  218. 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
- let(:object) { Mutant::Config::DEFAULT.expression_parser }
5
-
6
- describe '#call' do
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
- it 'raises an exception' do
13
- expect { subject }.to raise_error(
14
- Mutant::Expression::Parser::InvalidExpressionError,
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 { should eql(Mutant::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
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 nonsense' do
25
+ context 'on invalid input' do
31
26
  let(:input) { 'foo bar' }
32
27
 
33
- it { should be(nil) }
34
- end
35
-
36
- context 'on a valid expression' do
37
- let(:input) { 'Foo' }
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 expression' do
43
- let(:object) { described_class.new([test_a, test_b]) }
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 'raises expected exception' do
62
- expect { subject }.to raise_error(
63
- Mutant::Expression::Parser::AmbiguousExpressionError,
64
- 'Ambiguous expression: "test-syntax"'
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) { parser.call('Foo*') }
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) { parser.call('Foo::Bar') }
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) { parser.call('Bar') }
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 'on successful parse' do
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 'on unsuccessful parse' do
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
- subject { object.setup }
13
- it_should_behave_like 'a command method'
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
- subject { described_class.setup(kernel, name) }
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(:name) { 'null' }
20
- let(:kernel) { class_double(Kernel) }
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
- expect(kernel).to receive(:require)
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 { should be(Mutant::Integration::Null) }
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(:pid) { class_double(0.class) }
20
- let(:reader) { instance_double(IO, :reader) }
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
- let(:writer_close) do
65
+ def close(descriptor)
53
66
  {
54
- receiver: writer,
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: [reader],
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: reader,
136
+ receiver: log_reader,
75
137
  selector: :close
76
138
  },
77
139
  {
78
- receiver: writer,
79
- selector: :binmode
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: [nullio]
146
+ arguments: [log_writer]
92
147
  },
93
148
  {
94
149
  receiver: stdout,
95
150
  selector: :reopen,
96
- arguments: [nullio]
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: writer,
162
+ receiver: result_writer,
108
163
  selector: :syswrite,
109
164
  arguments: [block_return_blob]
110
165
  },
111
- writer_close
166
+ close(result_writer),
167
+ close(log_writer)
112
168
  ]
113
169
  end
114
170
 
115
171
  describe '#call' do
116
- let(:object) do
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
- subject { object.call(&isolated_block) }
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: [[reader, writer]]
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
- writer_close,
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(subject).to eql(Mutant::Isolation::Result::Success.new(block_return))
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 reading from child' do
162
- [ArgumentError, EOFError].each do |exception_class|
163
- context "on #{exception_class}" do
164
- let(:exception) { exception_class.new }
165
-
166
- let(:expectations) do
167
- [
168
- *prefork_expectations,
169
- fork_success,
170
- *killfork,
171
- {
172
- receiver: writer,
173
- selector: :close,
174
- reaction: {
175
- exception: exception
176
- }
177
- },
178
- child_wait
179
- ].map(&XSpec::MessageExpectation.method(:parse))
180
- end
181
-
182
- specify do
183
- XSpec::ExpectationVerifier.verify(self, expectations) do
184
- expect(subject).to eql(Mutant::Isolation::Result::Exception.new(exception))
185
- end
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(subject).to eql(result_class.new)
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
- writer_close,
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(subject).to eql(expected_result)
304
+ expect(apply).to eql(expected_result)
247
305
  end
248
306
  end
249
307
  end