tdx 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95245c7a074cd4558a7a747c309708e6f27a214a
4
- data.tar.gz: 20f7390a431a3fb77823a0777197124abf559671
3
+ metadata.gz: 2766078e04e0d81fd9017e362c86f3a8a9f5fef6
4
+ data.tar.gz: 0752b9c0baa666bfaad9dda3023695196ee11886
5
5
  SHA512:
6
- metadata.gz: c792a91dabb0e941dc8c26c48fec04d344d9cbe5be3062430227836f5fc0c77f9421adc72ba84b4f62478d7d5852602a195269cf4e25d314d929d3209b2c8b65
7
- data.tar.gz: 732b553ff646c0a292eac7928a63bd03cf93ab63fbde25d46609464d5fc25e78e2f8d9fd4ed229f12fee86d20a540770c952d53dee050a59d75e74f885e26439
6
+ metadata.gz: 82426a60cdfaed678185ad17f07e5e5fc76fc8c5d0cfeab1127dd8e30758aec78acabb76a5afa75889fe1dee032008fe571d4981d42446d2fb8349bd1b55ad07
7
+ data.tar.gz: e5c1f836bbb0153debf140fee05ff6929eb6728c0b23e14dbc9391a8482f940ef467764413e432dc23ff6b4d0be164a5acf45079e6acca0d488dcec9acca7fd6
data/.rubocop.yml CHANGED
@@ -2,11 +2,11 @@ AllCops:
2
2
  DisplayCopNames: true
3
3
 
4
4
  Metrics/MethodLength:
5
- Max: 50
5
+ Max: 150
6
6
  Metrics/ClassLength:
7
7
  Max: 150
8
8
  Metrics/AbcSize:
9
- Max: 50
9
+ Max: 100
10
10
  Style/MultilineMethodCallIndentation:
11
11
  Enabled: false
12
12
  Style/IndentationWidth:
data/bin/tdx CHANGED
@@ -34,7 +34,7 @@ opts = Slop.parse(args, strict: true, help: true) do |o|
34
34
  o.bool '-v', '--version', 'Show current version'
35
35
  o.array(
36
36
  '--tests',
37
- 'Comma-separated list of relative paths with test-related files',
37
+ 'Comma-separated list of glob masks with test-related files',
38
38
  delimiter: ','
39
39
  )
40
40
  o.string '--login', 'GitHub login'
data/lib/tdx/base.rb CHANGED
@@ -41,22 +41,52 @@ module TDX
41
41
  end
42
42
 
43
43
  def svg
44
- dat = Tempfile.new('tdx')
45
44
  version = Exec.new('git --version').stdout.split(/ /)[2]
46
45
  raise "git version #{version} is too old, upgrade it to 2.0+" unless
47
46
  Gem::Version.new(version) >= Gem::Version.new('2.0')
48
47
  path = checkout
49
-
50
48
  commits = Exec.new('git log "--pretty=format:%H %cI" --reverse', path)
51
49
  .stdout.split(/\n/).map { |c| c.split(' ') }
52
50
  issues = issues(commits)
53
51
  puts "Date\t\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA"
54
- commits.each do |sha, date|
52
+ metrics = commits.map do |sha, date|
55
53
  Exec.new("git checkout --quiet #{sha}", path).stdout
56
- line = "#{date[0, 16]}\t#{tests(path)}\t#{hoc(path)}\t#{files(path)}\t\
57
- #{loc(path)}\t#{issues[sha]}\t#{sha[0, 7]}"
58
- dat << "#{line}\n"
59
- puts line
54
+ {
55
+ date: date,
56
+ pure: pure(path),
57
+ hoc: hoc(path),
58
+ files: files(path),
59
+ loc: loc(path),
60
+ issues: issues[sha],
61
+ sha: sha
62
+ }
63
+ end
64
+ metrics.each do |m|
65
+ puts "#{m[:date][0, 16]}\t#{m[:pure]}\t#{m[:hoc]}\t#{m[:files]}\t\
66
+ #{m[:loc]}\t#{m[:issues]}\t#{m[:sha][0, 7]}"
67
+ end
68
+ max = { pure: 0, hoc: 0, files: 0, loc: 0, issues: 0 }
69
+ max = metrics.inject(max) do |m, t|
70
+ {
71
+ pure: [m[:pure], t[:pure], 1].max,
72
+ hoc: [m[:hoc], t[:hoc], 1].max,
73
+ files: [m[:files], t[:files], 1].max,
74
+ loc: [m[:loc], t[:loc], 1].max,
75
+ issues: [m[:issues], t[:issues], 1].max
76
+ }
77
+ end
78
+ dat = Tempfile.new('tdx')
79
+ metrics.each do |m|
80
+ dat << [
81
+ m[:date],
82
+ 100.0 * m[:pure] / max[:pure],
83
+ 100.0 * (m[:pure] - m[:hoc]) / (max[:pure] - max[:hoc]),
84
+ 100.0 * m[:hoc] / max[:hoc],
85
+ 100.0 * m[:files] / max[:files],
86
+ 100.0 * m[:loc] / max[:loc],
87
+ 100.0 * m[:issues] / max[:issues],
88
+ m[:sha]
89
+ ].join(' ') + "\n"
60
90
  end
61
91
  dat.close
62
92
  svg = Tempfile.new('tdx')
@@ -66,19 +96,17 @@ module TDX
66
96
  'set termoption font "monospace,10"',
67
97
  'set xdata time',
68
98
  'set timefmt "%Y-%m"',
69
- 'set ytics format "%.0f%%" textcolor rgb "#81b341"',
99
+ 'set ytics format "%.0f%%" textcolor rgb "black"',
70
100
  'set grid linecolor rgb "gray"',
71
101
  'set xtics format "%b/%y" font "monospace,8" textcolor rgb "black"',
72
102
  'set autoscale',
73
103
  'set style fill solid',
74
104
  'set boxwidth 0.75 relative',
75
105
  [
76
- "plot \"#{dat.path}\" using 1:2 with boxes",
106
+ "plot \"#{dat.path}\" using 1:3 with lines",
77
107
  'title "Test HoC" linecolor rgb "#81b341"',
78
- ', "" using 1:3 with boxes title "HoC" linecolor rgb "red"',
79
- ', "" using 1:4 with boxes title "Files" linecolor rgb "black"',
80
- ', "" using 1:5 with boxes title "LoC" linecolor rgb "cyan"',
81
- ', "" using 1:6 with boxes title "Issues" linecolor rgb "orange"'
108
+ ', "" using 1:4 with lines title "HoC" linecolor rgb "red"',
109
+ ', "" using 1:7 with lines title "Issues" linecolor rgb "orange"'
82
110
  ].join(' ')
83
111
  ]
84
112
  Exec.new("gnuplot -e '#{gpi.join('; ')}'").stdout
@@ -107,15 +135,23 @@ module TDX
107
135
 
108
136
  def loc(path)
109
137
  Nokogiri::XML.parse(Exec.new('cloc . --xml --quiet', path).stdout)
110
- .xpath('/results/languages/total/@code')
138
+ .xpath('/results/languages/total/@code')[0].to_s.to_i
111
139
  end
112
140
 
113
- def hoc(path)
114
- Exec.new('hoc', path).stdout.strip
141
+ def pure(path)
142
+ exclude = if @opts[:tests]
143
+ @opts[:tests].map { |e| "--exclude=#{e}" }
144
+ else
145
+ []
146
+ end
147
+ Exec.new(
148
+ 'hoc ' + exclude.join(' '),
149
+ path
150
+ ).stdout.strip.to_i
115
151
  end
116
152
 
117
- def tests(path)
118
- Exec.new('hoc', path).stdout.strip
153
+ def hoc(path)
154
+ Exec.new('hoc', path).stdout.strip.to_i
119
155
  end
120
156
 
121
157
  def issues(commits)
data/lib/tdx/exec.rb CHANGED
@@ -40,7 +40,7 @@ module TDX
40
40
 
41
41
  def stdout
42
42
  out = `cd #{@dir} && #{@cmd} 2>/dev/null`
43
- raise 'Previous command failed' unless $CHILD_STATUS.exitstatus == 0
43
+ raise "This one failed: #{@cmd}" unless $CHILD_STATUS.exitstatus == 0
44
44
  out
45
45
  end
46
46
  end
data/lib/tdx/version.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2017 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module TDX
28
- VERSION = '0.2.3'.freeze
28
+ VERSION = '0.2.4'.freeze
29
29
  end
data/test/test__helper.rb CHANGED
@@ -23,3 +23,5 @@
23
23
  require 'simplecov'
24
24
  require 'tdx'
25
25
  require 'minitest/autorun'
26
+
27
+ STDOUT.sync = true
data/test/test_tdx.rb CHANGED
@@ -33,11 +33,6 @@ class TestPDD < Minitest::Test
33
33
  def test_git_repo
34
34
  skip if Gem.win_platform?
35
35
  Dir.mktmpdir 'test' do |dir|
36
- opts = opts(
37
- [
38
- '--tests', 'tests'
39
- ]
40
- )
41
36
  raise unless system("
42
37
  set -e
43
38
  cd '#{dir}'
@@ -52,17 +47,20 @@ class TestPDD < Minitest::Test
52
47
  ")
53
48
  assert(
54
49
  TDX::Base.new(
55
- "file:///#{File.join(dir, 'repo')}", opts
50
+ "file:///#{File.join(dir, 'repo')}",
51
+ opts(['--tests', 'tests/**/*'])
56
52
  ).svg.include?('<path ')
57
53
  )
58
54
  end
59
55
  end
60
56
 
61
57
  def test_real_github_repo
62
- assert(
58
+ File.write(
59
+ '/tmp/a.svg',
63
60
  TDX::Base.new(
64
- 'https://github.com/yegor256/tdx.git', opts([])
65
- ).svg.include?('<path ')
61
+ 'https://github.com/yegor256/jare.git',
62
+ opts(['--tests', 'src/test/**/*'])
63
+ ).svg
66
64
  )
67
65
  end
68
66
 
@@ -70,7 +68,7 @@ class TestPDD < Minitest::Test
70
68
 
71
69
  def opts(args)
72
70
  Slop.parse args do |o|
73
- o.string '-t', '--tests', argument: :required
71
+ o.array '-t', '--tests', argument: :required
74
72
  end
75
73
  end
76
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko