mutant 0.8.19 → 0.8.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +46 -8
  3. data/Changelog.md +4 -0
  4. data/Gemfile.lock +10 -12
  5. data/README.md +22 -250
  6. data/config/flay.yml +1 -1
  7. data/docs/concurrency.md +39 -0
  8. data/docs/known-problems.md +44 -0
  9. data/docs/limitations.md +50 -0
  10. data/docs/mutant-minitest.md +147 -0
  11. data/docs/mutant-rspec.md +62 -0
  12. data/docs/nomenclature.md +82 -0
  13. data/docs/reading-reports.md +74 -0
  14. data/lib/mutant.rb +4 -3
  15. data/lib/mutant/env.rb +2 -2
  16. data/lib/mutant/expression/namespace.rb +3 -1
  17. data/lib/mutant/runner/sink.rb +2 -2
  18. data/lib/mutant/timer.rb +21 -0
  19. data/lib/mutant/version.rb +1 -1
  20. data/mutant-minitest.gemspec +22 -0
  21. data/mutant.gemspec +4 -5
  22. data/spec/integration/mutant/corpus_spec.rb +1 -7
  23. data/spec/integration/mutant/minitest_spec.rb +10 -0
  24. data/spec/integration/mutant/rspec_spec.rb +1 -1
  25. data/spec/integrations.yml +14 -0
  26. data/spec/shared/framework_integration_behavior.rb +8 -5
  27. data/spec/support/corpus.rb +20 -14
  28. data/spec/unit/mutant/clock_monotonic_spec.rb +52 -0
  29. data/spec/unit/mutant/env_spec.rb +2 -2
  30. data/spec/unit/mutant/expression/namespace/recursive_spec.rb +1 -1
  31. data/spec/unit/mutant/integration/rspec_spec.rb +1 -1
  32. data/spec/unit/mutant/reporter/cli_spec.rb +1 -1
  33. data/spec/unit/mutant/runner/sink_spec.rb +1 -1
  34. data/test_app/Gemfile.minitest +6 -0
  35. data/test_app/{Gemfile.rspec3.6 → Gemfile.rspec3.8} +2 -2
  36. data/test_app/test/unit/test_app/literal_test.rb +16 -0
  37. metadata +23 -26
  38. data/spec/rcov.opts +0 -7
  39. data/spec/support/rb_bug.rb +0 -18
  40. data/test_app/Gemfile.rspec3.4 +0 -7
  41. data/test_app/Gemfile.rspec3.5 +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbaeba3292082f39979c87a1918f1a75a681f4cca1299fee251373779c1f381b
4
- data.tar.gz: b1e57ca598f25e27d1c74e2b17d2033edb1d3b602742eb0fa62a6a7ac1f1058a
3
+ metadata.gz: 71ac041e8b933f1efd758494731566ff133404300a860e41362211c607fe5f0f
4
+ data.tar.gz: d49c6b977cbe88912d3c93203473a3704c4287737fbe3fff14a46aaf951bc2a9
5
5
  SHA512:
6
- metadata.gz: 53d8e07cbcfc3ce3c8f1848ae34438f5e31ee3cbb8af8784e02e1f5a4cccc61554ac9f404d07083c0ce1210b4329de873e0ecb3e274260798484a1cabc53f758
7
- data.tar.gz: 5ca7d7e28311f4c359d07f823d069b1ace3ed8b408bcb5c9f912d6f106ff469be4d38a4e7ea37afd46083d30eab818039c72f306d323ee4a364e5a6fb3b0beb8
6
+ metadata.gz: 5f241945cdedc4d38fd3328b4321c0e685d87c3102d73c122baae658daf5b9b42423b9aa12070e23e42abae6f3232f5752d67cdc27c49c16d8fa150c259655be
7
+ data.tar.gz: 1400ba91b8275ee4c6a12af48ed05bd6bf1a0c290e16a227f87a81a251e536d269c71d9ca8d9d7fc4e4ba6b7dc02d3360061b2809fb21c58fcef9c7d708b89b6
@@ -1,17 +1,55 @@
1
1
  defaults: &defaults
2
2
  working_directory: ~/mutant
3
- steps:
4
- - checkout
5
- - run: bundle install
6
- - run: bundle exec rake ci
3
+ docker:
4
+ - image: circleci/ruby:2.5.3
7
5
  version: 2
8
6
  jobs:
9
- ruby_2_5:
7
+ unit_specs:
10
8
  <<: *defaults
11
- docker:
12
- - image: circleci/ruby:2.5.3
9
+ steps:
10
+ - checkout
11
+ - run: bundle install
12
+ - run: bundle exec rspec spec/unit
13
+ integration_minitest:
14
+ <<: *defaults
15
+ steps:
16
+ - checkout
17
+ - run: bundle install
18
+ - run: bundle exec rspec spec/integration -e minitest
19
+ integration_rspec:
20
+ <<: *defaults
21
+ steps:
22
+ - checkout
23
+ - run: bundle install
24
+ - run: bundle exec rspec spec/integration -e rspec
25
+ integration_mutation_generation:
26
+ <<: *defaults
27
+ steps:
28
+ - checkout
29
+ - run: bundle install
30
+ - run: bundle exec rspec spec/integration -e generation
31
+ metrics:
32
+ <<: *defaults
33
+ steps:
34
+ - checkout
35
+ - run: bundle install
36
+ - run: bundle exec rake metrics:rubocop
37
+ - run: bundle exec rake metrics:reek
38
+ - run: bundle exec rake metrics:flay
39
+ - run: bundle exec rake metrics:flog
40
+ mutant:
41
+ <<: *defaults
42
+ steps:
43
+ - checkout
44
+ - run: bundle install
45
+ - run: bundle exec rake metrics:mutant
13
46
  workflows:
14
47
  version: 2
15
48
  test:
16
49
  jobs:
17
- - ruby_2_5
50
+ - unit_specs
51
+ - integration_rspec
52
+ - integration_minitest
53
+ - integration_mutation_generation
54
+ - metrics
55
+ - mutant
@@ -1,3 +1,7 @@
1
+ # v0.8.20 2018-11-27
2
+
3
+ * Replace internal timers with monotonic ones.
4
+
1
5
  # v0.8.19 2018-11-06
2
6
 
3
7
  * Drop support for Ruby < 2.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mutant (0.8.18)
4
+ mutant (0.8.19)
5
5
  abstract_type (~> 0.0.7)
6
6
  adamantium (~> 0.2.0)
7
7
  anima (~> 0.3.0)
@@ -12,13 +12,12 @@ PATH
12
12
  ice_nine (~> 0.11.1)
13
13
  memoizable (~> 0.4.2)
14
14
  morpher (~> 0.2.6)
15
- parallel (~> 1.3)
16
15
  parser (~> 2.5.1)
17
16
  procto (~> 0.0.2)
18
17
  regexp_parser (~> 1.2)
19
- unparser (~> 0.2.5)
20
- mutant-rspec (0.8.18)
21
- mutant (~> 0.8.18)
18
+ unparser (~> 0.3.0)
19
+ mutant-rspec (0.8.19)
20
+ mutant (~> 0.8.19)
22
21
  rspec-core (>= 3.4.0, < 4.0.0)
23
22
 
24
23
  GEM
@@ -69,7 +68,6 @@ GEM
69
68
  docile (1.3.1)
70
69
  equalizer (0.0.11)
71
70
  erubis (2.7.0)
72
- ffi (1.9.25)
73
71
  flay (2.10.0)
74
72
  erubis (~> 2.7.0)
75
73
  path_expander (~> 1.0)
@@ -95,7 +93,7 @@ GEM
95
93
  ice_nine (~> 0.11.0)
96
94
  procto (~> 0.0.2)
97
95
  parallel (1.12.1)
98
- parser (2.5.1.2)
96
+ parser (2.5.3.0)
99
97
  ast (~> 2.4.0)
100
98
  path_expander (1.0.3)
101
99
  powerpack (0.1.2)
@@ -107,14 +105,14 @@ GEM
107
105
  kwalify (~> 0.7.0)
108
106
  parser (>= 2.5.0.0, < 2.6, != 2.5.1.1)
109
107
  rainbow (>= 2.0, < 4.0)
110
- regexp_parser (1.2.0)
108
+ regexp_parser (1.3.0)
111
109
  rspec (3.8.0)
112
110
  rspec-core (~> 3.8.0)
113
111
  rspec-expectations (~> 3.8.0)
114
112
  rspec-mocks (~> 3.8.0)
115
113
  rspec-core (3.8.0)
116
114
  rspec-support (~> 3.8.0)
117
- rspec-expectations (3.8.1)
115
+ rspec-expectations (3.8.2)
118
116
  diff-lcs (>= 1.2.0, < 2.0)
119
117
  rspec-support (~> 3.8.0)
120
118
  rspec-its (1.2.0)
@@ -124,7 +122,7 @@ GEM
124
122
  diff-lcs (>= 1.2.0, < 2.0)
125
123
  rspec-support (~> 3.8.0)
126
124
  rspec-support (3.8.0)
127
- rubocop (0.59.0)
125
+ rubocop (0.59.2)
128
126
  jaro_winkler (~> 1.5.1)
129
127
  parallel (~> 1.10)
130
128
  parser (>= 2.5, != 2.5.1.1)
@@ -143,7 +141,7 @@ GEM
143
141
  simplecov-html (0.10.2)
144
142
  thread_safe (0.3.6)
145
143
  unicode-display_width (1.4.0)
146
- unparser (0.2.8)
144
+ unparser (0.3.0)
147
145
  abstract_type (~> 0.0.7)
148
146
  adamantium (~> 0.2.0)
149
147
  concord (~> 0.1.5)
@@ -166,8 +164,8 @@ PLATFORMS
166
164
  DEPENDENCIES
167
165
  bundler (~> 1.10)
168
166
  devtools (~> 0.1.21)
169
- ffi (~> 1.9.6)
170
167
  mutant!
168
+ parallel (~> 1.3)
171
169
 
172
170
  BUNDLED WITH
173
171
  1.17.1
data/README.md CHANGED
@@ -12,108 +12,37 @@ Mutant is a mutation testing tool for Ruby.
12
12
  The idea is that if code can be changed and your tests do not notice, then either that code isn't being covered
13
13
  or it does not have a speced side effect.
14
14
 
15
- Mutant supports ruby >= 2.1, while support for JRuby is planned.
16
- It should also work under any Ruby engine that supports POSIX-fork(2) semantics.
15
+ Mutant supports ruby >= 2.5, MRI only.
17
16
 
18
17
  Mutant uses a pure Ruby [parser](https://github.com/whitequark/parser) and an [unparser](https://github.com/mbj/unparser)
19
18
  to do its magic.
20
19
 
21
- Mutant does not have really good "getting started" documentation currently so please refer to presentations and blog posts below.
20
+ Topics
21
+ ------
22
22
 
23
- Installation
24
- ------------
23
+ * [Nomenclature](/docs/nomenclature.md)
24
+ * [Reading Reports](/docs/reading-reports.md)
25
+ * [Known Problems](/docs/known-problems.md)
26
+ * [Limitations](/docs/limitations.md)
27
+ * [Concurrency](/docs/concurrency.md)
28
+ * [Rspec Integration](/docs/mutant-rspec.md)
29
+ * [Minitest Integration](/docs/mutant-minitest.md)
25
30
 
26
- As mutant right now only supports rspec, install the gem `mutant-rspec` via your preferred method.
27
- It'll pull the `mutant` gem (in the correct version), that contains the main engine.
28
-
29
- ```ruby
30
- gem install mutant-rspec
31
- ```
32
-
33
- The minitest integration is still in the [works](https://github.com/mbj/mutant/pull/445).
34
-
35
- Examples
36
- --------
37
-
38
- ```
39
- cd virtus
40
- # Run mutant on virtus namespace
41
- bundle exec mutant --include lib --require virtus --use rspec Virtus*
42
- # Run mutant on specific virtus class
43
- bundle exec mutant --include lib --require virtus --use rspec Virtus::Attribute
44
- # Run mutant on specific virtus class method
45
- bundle exec mutant --include lib --require virtus --use rspec Virtus::Attribute.build
46
- # Run mutant on specific virtus instance method
47
- bundle exec mutant --include lib --require virtus --use rspec Virtus::Attribute#type
48
- ```
49
-
50
- Rails
51
- -------
52
-
53
- To mutation test Rails models with rspec, comment out ```require 'rspec/autorun'``` from your spec_helper.rb file. Having done so you should be able to use commands like the following:
54
-
55
- ```sh
56
- RAILS_ENV=test bundle exec mutant -r ./config/environment --use rspec User
57
- ```
58
-
59
- Passing in RSpec Options
60
- ------------------------
61
-
62
- **NOTE: Experimental**
63
-
64
- You can control some aspects of RSpec using the `SPEC_OPTS` environment variable as usual. If you want mutant to only pay attention to specs in a certain directory, you can run
65
-
66
- ```sh
67
- SPEC_OPTS="--pattern spec/subdir_only/**/*_spec.rb" bundle exec mutant --use rspec SomeClass
68
- ```
69
-
70
- Limitations
71
- -----------
72
-
73
- Mutant cannot emit mutations for...
74
-
75
- * methods defined within a closure. For example, methods defined using `module_eval`, `class_eval`,
76
- `define_method`, or `define_singleton_method`:
77
-
78
- ```ruby
79
- class Example
80
- class_eval do
81
- def example1
82
- end
83
- end
84
-
85
- module_eval do
86
- def example2
87
- end
88
- end
89
-
90
- define_method(:example3) do
91
- end
92
-
93
- define_singleton_method(:example4) do
94
- end
95
- end
96
- ```
97
-
98
- * singleton methods not defined on a constant or `self`
31
+ Sponsoring
32
+ ----------
99
33
 
100
- ```ruby
101
- class Foo
102
- def self.bar; end # ok
103
- def Foo.baz; end # ok
34
+ Mutant, as published in the opensource version, would not exist without the help
35
+ of [contributors](https://github.com/mbj/mutant/graphs/contributors) spending lots
36
+ of their private time.
104
37
 
105
- myself = self
106
- def myself.qux; end # cannot mutate
107
- end
108
- ```
38
+ Additionally, the following features where sponsored by organizations:
109
39
 
110
- * methods defined with eval:
40
+ * The `mutant-minitest` integration was sponsored by [Arkency](https://arkency.com/)
41
+ * Mutant's initial concurrency support was sponsored by an undisclosed company that does
42
+ currently not wish to be listed here.
111
43
 
112
- ```ruby
113
- class Foo
114
- class_eval('def bar; end') # cannot mutate
115
- end
116
- ```
44
+ If your organization is interested in sponsoring a feature, general maintainership or bugfixes, contact
45
+ [Markus Schirp](mailto:mbj@schirp-dso.com).
117
46
 
118
47
  Mutation-Operators
119
48
  ------------------
@@ -123,118 +52,6 @@ The `mutant-meta` is arranged to the AST-Node-Types of parser. Refer to parsers
123
52
 
124
53
  There is no easy and universal way to count the number of mutation operators a tool supports.
125
54
 
126
- Subjects
127
- --------
128
-
129
- Mutant currently mutates code in instance and singleton methods. It is planned to support mutation
130
- of constant definitions and domain specific languages, DSL probably as plugins.
131
-
132
- Test-Selection
133
- --------------
134
-
135
- Mutation testing is slow. The key to making it fast is selecting the correct set of tests to run.
136
- Mutant currently supports the following built-in strategy for selecting tests/specs:
137
-
138
- Mutant uses the "longest rspec example group descriptions prefix match" to select the tests to run.
139
-
140
- Example for a subject like `Foo::Bar#baz` it will run all example groups with description prefixes in
141
- `Foo::Bar#baz`, `Foo::Bar` and `Foo`. The order is important, so if mutant finds example groups in the
142
- current prefix level, these example groups *must* kill the mutation.
143
-
144
- Reading Reports
145
- ---------------
146
-
147
- Mutation output is grouped by selection groups. Each group contains three sections:
148
-
149
- 1. An identifier for the current group.
150
-
151
- **Format**:
152
-
153
- ```text
154
- [SUBJECT EXPRESSION]:[SOURCE LOCATION]:[LINENO]
155
- ```
156
-
157
- **Example**:
158
-
159
- ```text
160
- Book#add_page:Book#add_page:/home/dev/mutant-examples/lib/book.rb:18
161
- ```
162
-
163
- 2. A list of specs that mutant ran to try to kill mutations for the current group.
164
-
165
- **Format**:
166
-
167
- ```text
168
- - [INTEGRATION]:0:[SPEC LOCATION]:[SPEC DESCRIPTION]
169
- - [INTEGRATION]:1:[SPEC LOCATION]:[SPEC DESCRIPTION]
170
- ```
171
-
172
- **Example**:
173
-
174
- ```text
175
- - rspec:0:./spec/unit/book_spec.rb:9/Book#add_page should return self
176
- - rspec:1:./spec/unit/book_spec.rb:13/Book#add_page should add page to book
177
- ```
178
-
179
- 3. A list of unkilled mutations diffed against the original unparsed source
180
-
181
- **Format**:
182
-
183
- ```text
184
- [MUTATION TYPE]:[SUBJECT EXPRESSION]:[SOURCE LOCATION]:[SOURCE LINENO]:[IDENTIFIER]
185
- [DIFF]
186
- -----------------------
187
- ```
188
-
189
- - `[MUTATION TYPE]` will be one of the following:
190
- - `evil` - a mutation of your source was not killed by your tests
191
- - `neutral` your original source was injected and one or more tests failed
192
- - `[IDENTIFIER]` - Unique identifier for this mutation
193
-
194
- **Example**:
195
-
196
- ```diff
197
- evil:Book#add_page:Book#add_page:/home/dev/mutant-examples/lib/book.rb:18:01f69
198
- @@ -1,6 +1,6 @@
199
- def add_page(page)
200
- - @pages << page
201
- + @pages
202
- @index[page.number] = page
203
- self
204
- end
205
- -----------------------
206
- evil:Book#add_page:Book#add_page:/home/dev/mutant-examples/lib/book.rb:18:b1ff2
207
- @@ -1,6 +1,6 @@
208
- def add_page(page)
209
- - @pages << page
210
- + self
211
- @index[page.number] = page
212
- self
213
- end
214
- -----------------------
215
- ```
216
-
217
- Concurrency
218
- -----------
219
-
220
- By default, mutant will test mutations in parallel by running up to one process for each core on your system. You can control the number of processes created using the `--jobs` argument.
221
-
222
- Mutant forks a new process for each mutation to be tested to prevent side affects in your specs and the lack of thread safety in rspec from impacting the results.
223
-
224
- If the code under test relies on a database, you may experience problems when running mutant because of conflicting data in the database. For example, if you have a test like this:
225
- ```
226
- m = MyModel.create!(...)
227
- expect(MyModel.first.name).to eql(m.name)
228
- ```
229
- It might fail if some other test wrote a record to the MyModel table at the same time as this test was executed. (It would find the MyModel record created by the other test.) Most of these issues can be fixed by writing more specific tests. Here is a concurrent safe version of the same test:
230
- ```
231
- m = MyModel.create!(...)
232
- expect(MyModel.find_by_id(m.id).name).to eql(m.name)
233
- ```
234
- You may also try wrapping your test runs in transactions.
235
-
236
- Note that some databases, SQLite in particular, are not designed for concurrent access and will fail if used in this manner. If you are using SQLite, you should set the `--jobs` to 1.
237
-
238
55
  Neutral (noop) Tests
239
56
  --------------------
240
57
 
@@ -254,55 +71,11 @@ Only Mutating Changed Code
254
71
  --------------------------
255
72
 
256
73
  Running mutant for the first time on an existing codebase can be a rather disheartening experience due to the large number of alive mutations found! Mutant has a setting that can help. Using the `--since` argument, mutant will only mutate code that has been modified. This allows you to introduce mutant into an existing code base without drowning in errors. Example usage that will mutate all code changed between master and the current branch:
74
+
257
75
  ```
258
76
  bundle exec mutant --include lib --require virtus --since master --use rspec Virtus::Attribute#type
259
77
  ```
260
78
 
261
- Known Problems
262
- ==============
263
-
264
- Mutations with Infinite Runtimes
265
- ---------------------------------
266
-
267
- Occasionally mutant will produce a mutation with an infinite runtime. When this happens
268
- mutant will look like it is running indefinitely without killing a remaining mutation. To
269
- avoid mutations like this, consider adding a timeout around your tests. For example, in
270
- RSpec you can add the following to your `spec_helper`:
271
- ```ruby
272
- config.around(:each) do |example|
273
- Timeout.timeout(5, &example)
274
- end
275
- ```
276
- which will fail specs which run for longer than 5 seconds.
277
-
278
- The Crash / Stuck Problem (MRI)
279
- -------------------------------
280
-
281
- Mutations generated by mutant can cause MRI to enter VM states its not prepared for.
282
- All MRI versions > 1.9 and < 2.2.1 are affected by this depending on your compiler flags,
283
- compiler version, and OS scheduling behavior.
284
-
285
- This can have the following unintended effects:
286
-
287
- * MRI crashes with a segfault. Mutant kills each mutation in a dedicated fork to isolate
288
- the mutations side effects when this fork terminates abnormally (segfault) mutant
289
- counts the mutation as killed.
290
-
291
- * MRI crashes with a segfault and gets stuck when handling the segfault.
292
- Depending on the number of active kill jobs mutant might appear to continue normally until
293
- all workers are stuck into this state when it begins to hang.
294
- Currently mutant must assume that your test suite simply not terminated yet as from the outside
295
- (parent process) the difference between a long running test and a stuck MRI is not observable.
296
- Its planned to implement a timeout enforced from the parent process, but ideally MRI simply gets fixed.
297
-
298
- References:
299
-
300
- * [MRI fix](https://github.com/ruby/ruby/commit/8fe95fea9d238a6deb70c8953ceb3a28a67f4636)
301
- * [MRI backport to 2.2.1](https://github.com/ruby/ruby/commit/8fe95fea9d238a6deb70c8953ceb3a28a67f4636)
302
- * [Mutant issue](https://github.com/mbj/mutant/issues/265)
303
- * [Upstream bug redmine](https://bugs.ruby-lang.org/issues/10460)
304
- * [Upstream bug github](https://github.com/ruby/ruby/pull/822)
305
-
306
79
  Presentations
307
80
  -------------
308
81
 
@@ -313,7 +86,6 @@ There are some presentations about mutant in the wild:
313
86
  * [eurucamp 2013](http://2013.eurucamp.org/) / FrOSCon-2013 http://slid.es/markusschirp/mutation-testing
314
87
  * [Cologne.rb](http://www.colognerb.de/topics/mutation-testing-mit-mutant) / https://github.com/DonSchado/colognerb-on-mutant/blob/master/mutation_testing_slides.pdf
315
88
 
316
-
317
89
  Planning a presentation?
318
90
  ------------------------
319
91