what_to_run 0.0.0 → 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -42
- data/ext/coverage_peeker/extconf.rb +3 -0
- data/lib/coverage_peeker.rb +5 -0
- data/lib/coverage_peeker/coverage_peeker.bundle +0 -0
- data/lib/what_to_run.rb +35 -41
- data/lib/what_to_run/minitest.rb +4 -3
- data/lib/what_to_run/rspec.rb +5 -3
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fd560629ae7b8791f59fe5cfb47d9049febbe04
|
4
|
+
data.tar.gz: 58c24411992a29a737103d1072e62594e311b0eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3861db56557e5f50e273a43caf790aa19163068b69a0e27f9cdc7ef8bf79189a3f9878017b3eda49c1aa9241778395e86e7e068fc622446f3c5c127de90b1159
|
7
|
+
data.tar.gz: 87d098e0915aad867239ebf93280d44d1487dab7b288294fbcc46fb05fb2908d48e6dba83c8481a1199b2c60628a4d51978e2a021bba98735d4f90b3d7b64c7d
|
data/README.md
CHANGED
@@ -1,67 +1,77 @@
|
|
1
|
-
#
|
1
|
+
# What To Run
|
2
2
|
|
3
|
-
|
3
|
+
What To Run is a lib for regression test selection, use it to predict which tests you should run when you make any modification on your codebase.
|
4
4
|
|
5
|
-
|
5
|
+
This lib is based on [@tenderlove](https://github.com/tenderlove) idea and guidance, make sure to read his [blog post](http://tenderlovemaking.com/2015/02/13/predicting-test-failues.html) on the subject.
|
6
6
|
|
7
|
-
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
- Project must be inside a Git repository
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
8
14
|
|
9
15
|
```
|
10
|
-
|
16
|
+
gem 'what_to_run'
|
11
17
|
```
|
12
18
|
|
13
|
-
|
19
|
+
And then execute
|
14
20
|
|
15
|
-
```
|
16
|
-
|
17
|
-
index 806deff..eb057b9 100644
|
18
|
-
--- a/lib/my_thing.rb
|
19
|
-
+++ b/lib/my_thing.rb
|
20
|
-
@@ -4,7 +4,7 @@ class Whatever
|
21
|
-
end
|
22
|
-
|
23
|
-
def bar
|
24
|
-
- "bar #{@foo}"
|
25
|
-
+ raise
|
26
|
-
end
|
27
|
-
|
28
|
-
def baz
|
21
|
+
```
|
22
|
+
$ bundle
|
29
23
|
```
|
30
24
|
|
31
|
-
|
25
|
+
Or install it yourself as:
|
32
26
|
|
33
27
|
```
|
34
|
-
|
28
|
+
gem install what_to_run
|
35
29
|
```
|
36
30
|
|
37
|
-
##
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Require the lib with:
|
38
34
|
|
39
|
-
|
35
|
+
Minitest
|
40
36
|
|
41
37
|
```
|
42
|
-
|
38
|
+
require 'what_to_run/minitest'
|
43
39
|
```
|
44
40
|
|
45
|
-
|
41
|
+
RSpec
|
46
42
|
|
47
|
-
```
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
+ raise
|
58
|
-
end
|
59
|
-
|
60
|
-
def baz
|
43
|
+
```
|
44
|
+
require 'what_to_run/rspec'
|
45
|
+
```
|
46
|
+
|
47
|
+
Run your tests on a clean git branch
|
48
|
+
|
49
|
+
Minitest
|
50
|
+
|
51
|
+
```
|
52
|
+
$ COLLECTION=1 bundle exec rake test
|
61
53
|
```
|
62
54
|
|
63
|
-
|
55
|
+
RSpec
|
64
56
|
|
65
57
|
```
|
66
|
-
$
|
58
|
+
$ COLLECTION=1 bundle exec rspec
|
67
59
|
```
|
60
|
+
|
61
|
+
This will create the initial coverage information. Then make your desired modifications on your code.
|
62
|
+
|
63
|
+
Now to predict which tests is likely fail, run this:
|
64
|
+
|
65
|
+
```
|
66
|
+
$ what_to_run
|
67
|
+
```
|
68
|
+
|
69
|
+
:warning: A `run_log.json` file will be created in the current directory, you might want to include it in your `.gitignore`.
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
Open an [issue](https://github.com/DyegoCosta/what_to_run/issues) or fork it and submit a [pull-request](https://help.github.com/articles/using-pull-requests/).
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
What To Run is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
Binary file
|
data/lib/what_to_run.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'shellwords'
|
3
2
|
require 'rugged'
|
4
3
|
require 'set'
|
5
4
|
|
@@ -8,22 +7,20 @@ module WhatToRun
|
|
8
7
|
|
9
8
|
def predict
|
10
9
|
lines_to_run.inject([]) do |tests, (file, line)|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
tests
|
10
|
+
path = File.expand_path(file)
|
11
|
+
tests += Array cov_map[path][line]
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
18
15
|
def lines_to_run
|
19
|
-
repo = Rugged::Repository.new
|
16
|
+
repo = Rugged::Repository.new('.')
|
20
17
|
lines_to_run = Set.new
|
21
18
|
|
22
|
-
repo.index.diff.each_patch
|
19
|
+
repo.index.diff.each_patch do |patch|
|
23
20
|
file = patch.delta.old_file[:path]
|
24
21
|
|
25
|
-
patch.each_hunk
|
26
|
-
hunk.each_line
|
22
|
+
patch.each_hunk do |hunk|
|
23
|
+
hunk.each_line do |line|
|
27
24
|
case line.line_origin
|
28
25
|
when :addition
|
29
26
|
lines_to_run << [file, line.new_lineno]
|
@@ -32,31 +29,25 @@ module WhatToRun
|
|
32
29
|
when :context
|
33
30
|
# do nothing
|
34
31
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
38
35
|
|
39
36
|
lines_to_run
|
40
37
|
end
|
41
38
|
|
42
|
-
def
|
43
|
-
after.each_with_object({}) do |(file_name,
|
44
|
-
|
39
|
+
def cov_delta(before, after)
|
40
|
+
after.each_with_object({}) do |(file_name, lines_cov), delta|
|
41
|
+
before_lines_cov = before[file_name]
|
45
42
|
|
46
43
|
# skip arrays that are exactly the same
|
47
|
-
next if
|
44
|
+
next if before_lines_cov == lines_cov
|
48
45
|
|
49
46
|
# subtract the old coverage from the new coverage
|
50
|
-
cov =
|
51
|
-
if line_after
|
52
|
-
line_after - line_before
|
53
|
-
else
|
54
|
-
line_after
|
55
|
-
end
|
56
|
-
end
|
47
|
+
cov = lines_cov_delta(before_lines_cov, lines_cov)
|
57
48
|
|
58
49
|
# add the "diffed" coverage to the hash
|
59
|
-
|
50
|
+
delta[file_name] = cov
|
60
51
|
end
|
61
52
|
end
|
62
53
|
|
@@ -64,29 +55,17 @@ module WhatToRun
|
|
64
55
|
cov_map = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
|
65
56
|
|
66
57
|
File.open('run_log.json') do |f|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
desc = args.first(2).join('#')
|
71
|
-
else # for RSpec
|
72
|
-
desc = args.first
|
73
|
-
end
|
74
|
-
|
75
|
-
before, after = args.last(2)
|
58
|
+
JSON.parse(f.read).each do |cov_info|
|
59
|
+
before, after = cov_info.last(2)
|
60
|
+
desc = build_test_desc(cov_info)
|
76
61
|
|
77
|
-
|
78
|
-
delta = diff before, after
|
62
|
+
delta = cov_delta(before, after)
|
79
63
|
|
80
64
|
delta.each_pair do |file, lines|
|
81
65
|
file_map = cov_map[file]
|
82
66
|
|
83
67
|
lines.each_with_index do |val, i|
|
84
|
-
|
85
|
-
next unless val && val > 0
|
86
|
-
|
87
|
-
# add the test name to the map. Multiple tests can execute the same
|
88
|
-
# line, so we need to use an array.
|
89
|
-
file_map[i + 1] << desc
|
68
|
+
file_map[i + 1] << desc if line_executed?(val)
|
90
69
|
end
|
91
70
|
end
|
92
71
|
end
|
@@ -94,4 +73,19 @@ module WhatToRun
|
|
94
73
|
|
95
74
|
cov_map
|
96
75
|
end
|
76
|
+
|
77
|
+
def build_test_desc(cov_info)
|
78
|
+
using_minitest = cov_info.length == 4
|
79
|
+
using_minitest ? cov_info.first(2).join('#') : cov_info.first
|
80
|
+
end
|
81
|
+
|
82
|
+
def line_executed?(line)
|
83
|
+
line.to_i > 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def lines_cov_delta(before_lines_cov, after_lines_cov)
|
87
|
+
after_lines_cov.zip(before_lines_cov).map do |lines_after, lines_before|
|
88
|
+
lines_after ? lines_after - lines_before : lines_after
|
89
|
+
end
|
90
|
+
end
|
97
91
|
end
|
data/lib/what_to_run/minitest.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'coverage'
|
2
1
|
require 'json'
|
2
|
+
require 'coverage'
|
3
|
+
require 'coverage_peeker'
|
3
4
|
|
4
5
|
Coverage.start
|
5
6
|
|
@@ -16,9 +17,9 @@ class Minitest::Runnable
|
|
16
17
|
alias :old_run_one_method :run_one_method
|
17
18
|
|
18
19
|
def run_one_method klass, method_name, reporter
|
19
|
-
before =
|
20
|
+
before = CoveragePeeker.peek_result
|
20
21
|
old_run_one_method klass, method_name, reporter
|
21
|
-
after =
|
22
|
+
after = CoveragePeeker.peek_result
|
22
23
|
LOGS << [ klass.name, method_name.to_s, before, after ]
|
23
24
|
end
|
24
25
|
end
|
data/lib/what_to_run/rspec.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require 'coverage'
|
2
1
|
require 'json'
|
3
2
|
require 'rspec'
|
4
3
|
|
4
|
+
require 'coverage'
|
5
|
+
require 'coverage_peeker'
|
6
|
+
|
5
7
|
LOGS = []
|
6
8
|
Coverage.start
|
7
9
|
|
@@ -10,8 +12,8 @@ RSpec.configuration.after(:suite) {
|
|
10
12
|
}
|
11
13
|
|
12
14
|
RSpec.configuration.around(:example) do |example|
|
13
|
-
before =
|
15
|
+
before = CoveragePeeker.peek_result
|
14
16
|
example.call
|
15
|
-
after =
|
17
|
+
after = CoveragePeeker.peek_result
|
16
18
|
LOGS << [ example.full_description, before, after ]
|
17
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what_to_run
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -35,11 +35,15 @@ description: Predict which tests are likely to fail after you’ve changed the c
|
|
35
35
|
email: dyego@dyegocosta.com
|
36
36
|
executables:
|
37
37
|
- what_to_run
|
38
|
-
extensions:
|
38
|
+
extensions:
|
39
|
+
- ext/coverage_peeker/extconf.rb
|
39
40
|
extra_rdoc_files: []
|
40
41
|
files:
|
41
42
|
- README.md
|
42
43
|
- bin/what_to_run
|
44
|
+
- ext/coverage_peeker/extconf.rb
|
45
|
+
- lib/coverage_peeker.rb
|
46
|
+
- lib/coverage_peeker/coverage_peeker.bundle
|
43
47
|
- lib/what_to_run.rb
|
44
48
|
- lib/what_to_run/minitest.rb
|
45
49
|
- lib/what_to_run/rspec.rb
|
@@ -53,17 +57,17 @@ require_paths:
|
|
53
57
|
- lib
|
54
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
59
|
requirements:
|
56
|
-
- - "
|
60
|
+
- - "~>"
|
57
61
|
- !ruby/object:Gem::Version
|
58
|
-
version: '
|
62
|
+
version: '2.3'
|
59
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
64
|
requirements:
|
61
|
-
- - "
|
65
|
+
- - ">"
|
62
66
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
67
|
+
version: 1.3.1
|
64
68
|
requirements: []
|
65
69
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.2.2
|
67
71
|
signing_key:
|
68
72
|
specification_version: 4
|
69
73
|
summary: Regression test selection
|