git-recommend 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git_test.rb +71 -32
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73d571a58194483a14486ea7254d14473701d08
|
4
|
+
data.tar.gz: fbac66cc87250b307dc314e83a218d5818086afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44f08a73639231b50ca8d20f1f871be6fced27f33ae392efcaa25ae2813bd1862f5438bcb8c612e2a1cd0338c7486314f2c6db687af2e443da119fb546262813
|
7
|
+
data.tar.gz: 2edcb0a49a7b2df8aaf0ff1cca792a62f40bba9a369ee0f4d98f1eeacfba7a60517306ab465f91b08d204b073b43fa91c9e255178a87c15f28773a770373060b
|
data/lib/git_test.rb
CHANGED
@@ -1,57 +1,96 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class GitTest < Thor
|
4
|
-
|
4
|
+
|
5
|
+
method_option :change_recommendation, aliases: '-c', type: :string, required: true, desc: "Path to test augmented change recommendation"
|
6
|
+
desc "plan", "Generates a prioritized test plan given a test augmented change recommendation (output of 'git-test join')"
|
7
|
+
def plan
|
8
|
+
begin
|
9
|
+
change_rec = CSV.read(options[:change_recommendation], headers: true)
|
10
|
+
rescue CSV::MalformedCSVError, ArgumentError => e
|
11
|
+
$stderr.puts "An error occured when parsing the change recommendation '#{options[:change_recommendation]}':\n #{e}"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
test_plan = Hash.new
|
16
|
+
coverage = {"lhs" => Set.new, "rhs" => Set.new}
|
17
|
+
|
18
|
+
change_rec.each do |row|
|
19
|
+
support = row["support"].to_r.to_f
|
20
|
+
# find relevant tests
|
21
|
+
["lhs","rhs"].each do |side|
|
22
|
+
tests = (row["#{side}_tested_by"].nil? ? [] : row["#{side}_tested_by"].split(","))
|
23
|
+
tests.each do |test|
|
24
|
+
coverage[side] << row[side]
|
25
|
+
if test_plan[test].nil?
|
26
|
+
test_plan[test] = {'cg' => 0, 'lhs' => 0, 'rhs' => 0}
|
27
|
+
end
|
28
|
+
test_plan[test]['cg'] += support
|
29
|
+
test_plan[test][side] += 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# normalize the cumulative gain
|
34
|
+
max_cg = test_plan.map {|_,v| v['cg']}.max
|
35
|
+
test_plan.each {|test,v| test_plan[test]['cg'] = v['cg']/max_cg}
|
36
|
+
|
37
|
+
# print warnings to stderr if any
|
38
|
+
["lhs","rhs"].each do |side|
|
39
|
+
items_in_plan = change_rec.map {|row| row[side]}.to_set
|
40
|
+
if coverage[side].size < items_in_plan.size
|
41
|
+
uncovered = items_in_plan - coverage[side]
|
42
|
+
type_of_impact = ((side == "lhs") ? "changed" : "impacted")
|
43
|
+
$stderr.puts "#{uncovered.size} #{type_of_impact} items were not covered by at least 1 test. The first 10 were: \n #{uncovered.take(10).join("\n")}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
# print testplan to stdout
|
47
|
+
$stdout.puts "test,impact,changed_items_covered,impacted_items_covered"
|
48
|
+
test_plan.sort_by {|k,v| [v['lhs'],v['rhs']].max}.each do |test,v|
|
49
|
+
$stdout.puts "#{test},#{v['cg']},#{v['lhs']},#{v['rhs']}"
|
50
|
+
end
|
51
|
+
end
|
5
52
|
|
6
53
|
method_option :mapping, aliases: '-m', type: :string, required: true, desc: "Path to test<->code mapping file"
|
7
54
|
method_option :change_recommendation, aliases: '-c', type: :string, required: true ,desc: "Path to change recommendation"
|
8
|
-
|
9
|
-
|
10
|
-
def test
|
55
|
+
desc "join", "Adds a column \"tested_by\", which for each potentially impacted item lists the tests which test this item."
|
56
|
+
def join
|
11
57
|
begin
|
12
58
|
mapping = CSV.read(options[:mapping], headers: true)
|
59
|
+
rescue CSV::MalformedCSVError, ArgumentError => e
|
60
|
+
$stderr.puts "An error occured when parsing the mapping file '#{options[:mapping]}:\n #{e}"
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
|
64
|
+
begin
|
13
65
|
change_rec = CSV.read(options[:change_recommendation], headers: true)
|
14
|
-
rescue CSV::MalformedCSVError => e
|
15
|
-
$stderr.puts "An error occured when parsing the
|
66
|
+
rescue CSV::MalformedCSVError, ArgumentError => e
|
67
|
+
$stderr.puts "An error occured when parsing the change recommendation '#{options[:change_recommendation]}:\n #{e}"
|
68
|
+
exit 1
|
16
69
|
end
|
17
70
|
|
18
|
-
test_plan = Hash.new
|
19
|
-
covered = Set.new
|
20
|
-
uniq_impacted_items = change_rec.map {|row| row["rhs"]}.to_set
|
21
71
|
|
72
|
+
# print header
|
73
|
+
CSV {|r| r << %w(lhs rhs support lhs_tested_by rhs_tested_by)}
|
22
74
|
change_rec.each do |row|
|
23
75
|
lhs = row["lhs"]
|
24
76
|
rhs = row["rhs"]
|
25
77
|
support = row["support"].to_r.to_f
|
78
|
+
# find relevant tests
|
79
|
+
lhs_tests = []
|
80
|
+
rhs_tests = []
|
26
81
|
mapping.each do |mapping_row|
|
27
82
|
pattern = Regexp.new(mapping_row["pattern"], Regexp::IGNORECASE)
|
28
83
|
test = mapping_row["test"]
|
84
|
+
if lhs =~ pattern
|
85
|
+
lhs_tests << test
|
86
|
+
end
|
87
|
+
|
29
88
|
if rhs =~ pattern
|
30
|
-
|
31
|
-
if test_plan[test].nil?
|
32
|
-
test_plan[test] = {impact: support, covers: 1}
|
33
|
-
else
|
34
|
-
test_plan[test][:impact] += support
|
35
|
-
test_plan[test][:covers] += 1
|
36
|
-
end
|
89
|
+
rhs_tests << test
|
37
90
|
end
|
38
91
|
end
|
92
|
+
# print new row
|
93
|
+
CSV {|r| r << [lhs, rhs, support, (lhs_tests.empty? ? nil : lhs_tests.join(",")), (rhs_tests.empty? ? nil : rhs_tests.join(","))]}
|
39
94
|
end
|
40
|
-
# print warnings to stderr if any
|
41
|
-
if covered.size < uniq_impacted_items.size
|
42
|
-
uncovered = uniq_impacted_items - covered
|
43
|
-
if uncovered.size < 11
|
44
|
-
$stderr.puts "The following potentially impacted items were not covered by at least 1 test:\n #{uncovered.to_a.join("\n")}"
|
45
|
-
else
|
46
|
-
$stderr.puts "#{uncovered.size} potentially impacted items were not covered by at least 1 test. The first 10 were: \n #{uncovered.take(10).join("\n")}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# print testplan to stdout
|
51
|
-
$stdout.puts "test,impact,covers"
|
52
|
-
test_plan.sort_by {|k,v| -v[:impact]}.each do |test,relevance|
|
53
|
-
$stdout.puts "#{test},#{relevance[:impact]},#{relevance[:covers]}"
|
54
|
-
end
|
55
95
|
end
|
56
|
-
|
57
96
|
end
|
data/lib/version.rb
CHANGED