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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/git_test.rb +71 -32
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a08b5114f7450afd35cb3e24cd592da94a3931ef
4
- data.tar.gz: fcbdb9fb1d757847639364de4536d01faa5e71dc
3
+ metadata.gz: b73d571a58194483a14486ea7254d14473701d08
4
+ data.tar.gz: fbac66cc87250b307dc314e83a218d5818086afe
5
5
  SHA512:
6
- metadata.gz: bbba31cefdf670c38a2730338bb6e2d14863852ec00141d2eaf3322a4576cd21742df36db071b8cb24f1f99d5715fe61732fa2dcdb88c7ffc4d90cf331a82857
7
- data.tar.gz: 71dc4d3545de9f08bda722379e02f6dff7651017e877b2f1146f53e0e417a19d4a8883f5521a20d61fad52f7e4b93c6a7c5fbf0c1c18bcf124f986c02eeb31b2
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
- default_task :test
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
- method_option :output, aliases: '-o', enum: ['csv','dot'], default: 'csv', desc: "The output format of the test recommendation"
9
- desc "test", ""
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 mapping file:\n #{e}"
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
- covered << rhs
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
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Recommend
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-recommend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Rolfsnes