-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
isolation_result.rb
112 lines (94 loc) · 3.05 KB
/
isolation_result.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true
module Mutant
class Reporter
class CLI
class Printer
# Reporter for mutation results
#
# :reek:TooManyConstants
class IsolationResult < self
CHILD_ERROR_MESSAGE = <<~'MESSAGE'
Killfork exited nonzero. Its result (if any) was ignored:
%s
MESSAGE
EXCEPTION_ERROR_MESSAGE = <<~'MESSAGE'
Killing the mutation resulted in an integration error.
This is the case when the tests selected for the current mutation
did not produce a test result, but instead an exception was raised.
This may point to the following problems:
* Bug in mutant
* Bug in the ruby interpreter
* Bug in your test suite
* Bug in your test suite under concurrency
The following exception was raised:
```
%s
%s
```
MESSAGE
FORK_ERROR_MESSAGE = <<~'MESSAGE'
Forking the child process to isolate the mutation in failed.
This meant that either the RubyVM or your OS was under too much
pressure to add another child process.
Possible solutions are:
* Reduce concurrency
* Reduce locks
MESSAGE
MAP = {
Isolation::Fork::ChildError => :visit_child_error,
Isolation::Fork::ForkError => :visit_fork_error,
Isolation::Result::ErrorChain => :visit_chain,
Isolation::Result::Exception => :visit_exception,
Isolation::Result::Success => :visit_success
}.freeze
private_constant(*constants(false))
# Run report printer
#
# @return [undefined]
def run
__send__(MAP.fetch(object.class))
end
private
# Visit successful isolation result
#
# @return [undefined]
def visit_success
visit(TestResult, object.value)
end
# Visit child error isolation result
#
# @return [undefined]
def visit_child_error
puts(CHILD_ERROR_MESSAGE % object.value.inspect)
end
# Visit fork error isolation result
#
# @return [undefined]
def visit_fork_error
puts(FORK_ERROR_MESSAGE)
end
# Visit exception isolation result
#
# @return [undefined]
def visit_exception
exception = object.value
puts(
EXCEPTION_ERROR_MESSAGE % [
exception.inspect,
exception.backtrace.join("\n")
]
)
end
# Visit chain
#
# @return [undefined]
def visit_chain
printer = self.class
visit(printer, object.value)
visit(printer, object.next)
end
end # IsolationResult
end # Printer
end # CLI
end # Reporter
end # Mutant