flog 3.2.3 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +13 -0
- data/Manifest.txt +2 -0
- data/Rakefile +17 -6
- data/bin/flog +4 -5
- data/lib/flog.rb +105 -259
- data/lib/flog_cli.rb +237 -0
- data/lib/flog_task.rb +26 -0
- data/lib/gauntlet_flog.rb +5 -3
- data/test/test_flog.rb +77 -214
- data/test/test_flog_cli.rb +202 -0
- metadata +16 -13
- metadata.gz.sig +0 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
require "test/test_flog"
|
2
|
+
require "flog_cli"
|
3
|
+
|
4
|
+
class FlogCLI
|
5
|
+
def_delegators :@flog, :totals # FIX: test_report_all is overreaching?
|
6
|
+
def_delegators :@flog, :calls # FIX: refactor?
|
7
|
+
def_delegators :@flog, :mass # FIX: refactor?
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestFlogCLI < FlogTest
|
11
|
+
def setup
|
12
|
+
@flog = FlogCLI.new :parser => RubyParser
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_cls_expand_dirs_to_files
|
16
|
+
expected = %w(lib/flog.rb lib/flog_cli.rb lib/flog_task.rb lib/gauntlet_flog.rb)
|
17
|
+
assert_equal expected, FlogCLI.expand_dirs_to_files('lib')
|
18
|
+
expected = %w(Rakefile)
|
19
|
+
assert_equal expected, FlogCLI.expand_dirs_to_files('Rakefile')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_cls_parse_options
|
23
|
+
# defaults
|
24
|
+
opts = FlogCLI.parse_options
|
25
|
+
assert_equal false, opts[:quiet]
|
26
|
+
assert_equal false, opts[:continue]
|
27
|
+
|
28
|
+
{
|
29
|
+
"-a" => :all,
|
30
|
+
"--all" => :all,
|
31
|
+
"-b" => :blame,
|
32
|
+
"--blame" => :blame,
|
33
|
+
"-c" => :continue,
|
34
|
+
"--continue" => :continue,
|
35
|
+
"-d" => :details,
|
36
|
+
"--details" => :details,
|
37
|
+
"-g" => :group,
|
38
|
+
"--group" => :group,
|
39
|
+
"-m" => :methods,
|
40
|
+
"--methods-only" => :methods,
|
41
|
+
"-q" => :quiet,
|
42
|
+
"--quiet" => :quiet,
|
43
|
+
"-s" => :score,
|
44
|
+
"--score" => :score,
|
45
|
+
"-v" => :verbose,
|
46
|
+
"--verbose" => :verbose,
|
47
|
+
}.each do |key, val|
|
48
|
+
assert_equal true, FlogCLI.parse_options(key)[val]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_cls_parse_options_path
|
53
|
+
old_path = $:.dup
|
54
|
+
FlogCLI.parse_options("-Ia,b,c")
|
55
|
+
assert_equal old_path + %w(a b c), $:
|
56
|
+
|
57
|
+
FlogCLI.parse_options(["-I", "d,e,f"])
|
58
|
+
assert_equal old_path + %w(a b c d e f), $:
|
59
|
+
|
60
|
+
FlogCLI.parse_options(["-I", "g", "-Ih"])
|
61
|
+
assert_equal old_path + %w(a b c d e f g h), $:
|
62
|
+
ensure
|
63
|
+
$:.replace old_path
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_cls_parse_options_help
|
67
|
+
def FlogCLI.exit
|
68
|
+
raise "happy"
|
69
|
+
end
|
70
|
+
|
71
|
+
ex = nil
|
72
|
+
o, e = capture_io do
|
73
|
+
ex = assert_raises RuntimeError do
|
74
|
+
FlogCLI.parse_options "-h"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_equal "happy", ex.message
|
79
|
+
assert_match(/methods-only/, o)
|
80
|
+
assert_equal "", e
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_output_details
|
84
|
+
@flog.option[:all] = true
|
85
|
+
setup_flog
|
86
|
+
|
87
|
+
o = StringIO.new
|
88
|
+
@flog.output_details o
|
89
|
+
|
90
|
+
expected = "\n 1.6: main#none\n"
|
91
|
+
|
92
|
+
assert_equal expected, o.string
|
93
|
+
assert_equal 1.6, @flog.totals["main#none"]
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_output_details_grouped
|
97
|
+
setup_flog
|
98
|
+
|
99
|
+
o = StringIO.new
|
100
|
+
@flog.calculate_total_scores
|
101
|
+
@flog.output_details_grouped o
|
102
|
+
|
103
|
+
expected = "\n 1.6: main total\n 1.6: main#none\n"
|
104
|
+
|
105
|
+
assert_equal expected, o.string
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_output_details_methods
|
109
|
+
@flog.option[:methods] = true
|
110
|
+
|
111
|
+
setup_flog
|
112
|
+
|
113
|
+
o = StringIO.new
|
114
|
+
@flog.output_details o
|
115
|
+
|
116
|
+
# HACK assert_equal "", o.string
|
117
|
+
assert_equal 0, @flog.totals["main#none"]
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_output_details_detailed
|
121
|
+
@flog.option[:details] = true
|
122
|
+
|
123
|
+
setup_flog
|
124
|
+
|
125
|
+
o = StringIO.new
|
126
|
+
@flog.output_details o, nil
|
127
|
+
|
128
|
+
expected = "\n 1.6: main#none
|
129
|
+
1.0: +
|
130
|
+
0.6: lit_fixnum
|
131
|
+
|
132
|
+
"
|
133
|
+
|
134
|
+
assert_equal expected, o.string
|
135
|
+
assert_equal 1.6, @flog.totals["main#none"]
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_report
|
139
|
+
setup_flog
|
140
|
+
|
141
|
+
o = StringIO.new
|
142
|
+
@flog.report o
|
143
|
+
|
144
|
+
expected = " 1.6: flog total
|
145
|
+
1.6: flog/method average
|
146
|
+
|
147
|
+
1.6: main#none
|
148
|
+
"
|
149
|
+
|
150
|
+
assert_equal expected, o.string
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_report_all
|
154
|
+
old_stdin = $stdin
|
155
|
+
$stdin = StringIO.new "2 + 3"
|
156
|
+
$stdin.rewind
|
157
|
+
|
158
|
+
@flog.flog "-"
|
159
|
+
|
160
|
+
exp = { "main#none" => { :+ => 1.0, :lit_fixnum => 0.6 } }
|
161
|
+
assert_equal exp, @flog.calls
|
162
|
+
|
163
|
+
@flog.option[:all] = true
|
164
|
+
@flog.calculate_total_scores
|
165
|
+
|
166
|
+
assert_equal 1.6, @flog.total_score unless @flog.option[:methods]
|
167
|
+
assert_equal 3, @flog.mass["-"]
|
168
|
+
|
169
|
+
o = StringIO.new
|
170
|
+
@flog.report o
|
171
|
+
|
172
|
+
expected = " 1.6: flog total
|
173
|
+
1.6: flog/method average
|
174
|
+
|
175
|
+
1.6: main#none
|
176
|
+
"
|
177
|
+
|
178
|
+
assert_equal expected, o.string
|
179
|
+
# FIX: add thresholded output
|
180
|
+
ensure
|
181
|
+
$stdin = old_stdin
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_report_group
|
185
|
+
# TODO: add second group to ensure proper output
|
186
|
+
@flog.option[:group] = true
|
187
|
+
|
188
|
+
setup_flog
|
189
|
+
|
190
|
+
o = StringIO.new
|
191
|
+
@flog.report o
|
192
|
+
|
193
|
+
expected = " 1.6: flog total
|
194
|
+
1.6: flog/method average
|
195
|
+
|
196
|
+
1.6: main total
|
197
|
+
1.6: main#none
|
198
|
+
"
|
199
|
+
|
200
|
+
assert_equal expected, o.string
|
201
|
+
end
|
202
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version:
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 4.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Davis
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
FBHgymkyj/AOSqKRIpXPhjC6
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2013-
|
39
|
+
date: 2013-04-18 00:00:00 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sexp_processor
|
@@ -99,11 +99,11 @@ dependencies:
|
|
99
99
|
requirements:
|
100
100
|
- - ~>
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
hash:
|
102
|
+
hash: 27
|
103
103
|
segments:
|
104
|
-
-
|
105
|
-
-
|
106
|
-
version: "
|
104
|
+
- 4
|
105
|
+
- 0
|
106
|
+
version: "4.0"
|
107
107
|
type: :development
|
108
108
|
version_requirements: *id004
|
109
109
|
- !ruby/object:Gem::Dependency
|
@@ -114,11 +114,11 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
hash:
|
117
|
+
hash: 11
|
118
118
|
segments:
|
119
119
|
- 3
|
120
|
-
-
|
121
|
-
version: "3.
|
120
|
+
- 6
|
121
|
+
version: "3.6"
|
122
122
|
type: :development
|
123
123
|
version_requirements: *id005
|
124
124
|
description: |-
|
@@ -142,9 +142,11 @@ files:
|
|
142
142
|
- Rakefile
|
143
143
|
- bin/flog
|
144
144
|
- lib/flog.rb
|
145
|
+
- lib/flog_cli.rb
|
145
146
|
- lib/flog_task.rb
|
146
147
|
- lib/gauntlet_flog.rb
|
147
148
|
- test/test_flog.rb
|
149
|
+
- test/test_flog_cli.rb
|
148
150
|
- .gemtest
|
149
151
|
homepage: http://ruby.sadi.st/
|
150
152
|
licenses: []
|
@@ -182,3 +184,4 @@ specification_version: 3
|
|
182
184
|
summary: Flog reports the most tortured code in an easy to read pain report
|
183
185
|
test_files:
|
184
186
|
- test/test_flog.rb
|
187
|
+
- test/test_flog_cli.rb
|
metadata.gz.sig
CHANGED
Binary file
|