rdist 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +10 -3
- data/Rakefile +80 -77
- data/bin/rdist +2 -3
- data/lib/rdist.rb +2 -2
- data/lib/rdist/analyzer/base.rb +13 -10
- data/lib/rdist/analyzer/state.rb +1 -0
- data/lib/rdist/analyzer/state/afterendofcodemarker.rb +12 -0
- data/lib/rdist/analyzer/state/base.rb +2 -0
- data/lib/rdist/analyzer/state/waitingblock.rb +26 -0
- data/lib/rdist/{commandlineinterface.rb → runner.rb} +3 -3
- data/lib/rdist/setting.rb +6 -2
- data/spec/bin_spec.rb +8 -0
- data/spec/fixtures/with_end_of_code_marker.rb +5 -0
- data/spec/fixtures/with_one_linear_definition.rb +20 -0
- data/spec/runner_spec.rb +101 -0
- data/spec/setting_spec.rb +17 -0
- data/spec/spec_helper.rb +4 -2
- metadata +9 -4
- data/spec/commandlineinterface_spec.rb +0 -43
data/ChangeLog
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
2008-02-
|
|
1
|
+
2008-02-29 Yoshifumi Shimono <yoshifumi.shimono@gmail.com>
|
|
2
2
|
|
|
3
|
-
* 0.0.
|
|
4
|
-
|
|
3
|
+
* 0.0.2 / 2008-02-30
|
|
4
|
+
* recognize __END__
|
|
5
|
+
* ignore one-linear definition
|
|
6
|
+
* increase test coverage
|
|
7
|
+
|
|
8
|
+
2008-02-25 Yoshifumi Shimono <yoshifumi.shimono@gmail.com>
|
|
9
|
+
|
|
10
|
+
* 0.0.1 / 2008-02-25
|
|
11
|
+
* initial release
|
|
5
12
|
|
data/Rakefile
CHANGED
|
@@ -25,111 +25,114 @@ BIN_FILES = %w( rdist )
|
|
|
25
25
|
VERS = RDist::VERSION
|
|
26
26
|
|
|
27
27
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
|
28
|
-
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
|
28
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'html']
|
|
29
29
|
RDOC_OPTS = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
]
|
|
30
|
+
'--title', "#{NAME} documentation",
|
|
31
|
+
"--charset", "utf-8",
|
|
32
|
+
"--opname", "index.html",
|
|
33
|
+
"--line-numbers",
|
|
34
|
+
"--main", "README",
|
|
35
|
+
"--inline-source",
|
|
36
|
+
]
|
|
37
37
|
|
|
38
38
|
task :default => [:spec]
|
|
39
39
|
task :package => [:clean]
|
|
40
40
|
|
|
41
41
|
Spec::Rake::SpecTask.new do |t|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
43
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
|
44
|
+
t.rcov = false
|
|
45
|
+
t.verbose = true
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
spec = Gem::Specification.new do |s|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
s.name = NAME
|
|
50
|
+
s.version = VERS
|
|
51
|
+
s.platform = Gem::Platform::RUBY
|
|
52
|
+
s.has_rdoc = true
|
|
53
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
|
54
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
|
55
|
+
s.summary = DESCRIPTION
|
|
56
|
+
s.description = DESCRIPTION
|
|
57
|
+
s.author = AUTHOR
|
|
58
|
+
s.email = EMAIL
|
|
59
|
+
s.homepage = HOMEPATH
|
|
60
|
+
s.executables = BIN_FILES
|
|
61
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
|
62
|
+
s.bindir = "bin"
|
|
63
|
+
s.require_path = "lib"
|
|
64
|
+
s.test_files = Dir["test/test_*.rb"]
|
|
65
|
+
|
|
66
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
|
67
|
+
#s.required_ruby_version = '>= 1.8.2'
|
|
68
|
+
|
|
69
|
+
s.files = %w(README ChangeLog Rakefile) +
|
|
70
|
+
Dir.glob("{bin,doc,spec,test,lib,templates,generator,extras,website,script}/**/*") +
|
|
71
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
|
72
|
+
Dir.glob("examples/**/*.rb") +
|
|
73
|
+
Dir.glob("tools/*.rb")
|
|
74
|
+
|
|
75
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
Rake::GemPackageTask.new(spec) do |p|
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
p.need_tar = true
|
|
80
|
+
p.gem_spec = spec
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
task :install do
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
name = "#{NAME}-#{VERS}.gem"
|
|
85
|
+
sh %{rake package}
|
|
86
|
+
sh %{sudo gem install pkg/#{name}}
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
task :uninstall => [:clean] do
|
|
90
|
-
|
|
90
|
+
sh %{sudo gem uninstall #{NAME}}
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
Rake::RDocTask.new do |rdoc|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
rdoc.rdoc_dir = 'html'
|
|
96
|
+
rdoc.options += RDOC_OPTS
|
|
97
|
+
rdoc.template = "resh"
|
|
98
|
+
#rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
|
99
|
+
if ENV['DOC_FILES']
|
|
100
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
|
101
|
+
else
|
|
102
|
+
rdoc.rdoc_files.include('README', 'ChangeLog')
|
|
103
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
104
|
+
#rdoc.rdoc_files.include('ext/**/*.c')
|
|
105
|
+
end
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
desc "Publish to RubyForge"
|
|
109
109
|
task :rubyforge => [:rdoc, :package] do
|
|
110
|
-
|
|
110
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'shimono').upload
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
desc 'Package and upload the release to rubyforge.'
|
|
114
114
|
task :release => [:clean, :package] do |t|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
|
116
|
+
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
|
117
|
+
unless File.read('ChangeLog').include?(v)
|
|
118
|
+
abort "You forget writing release notes to the ChangeLog."
|
|
119
|
+
end
|
|
120
|
+
pkg = "pkg/#{NAME}-#{VERS}"
|
|
121
|
+
|
|
122
|
+
rf = RubyForge.new
|
|
123
|
+
puts "Logging in"
|
|
124
|
+
rf.login
|
|
125
|
+
|
|
126
|
+
c = rf.userconfig
|
|
127
|
+
# c["release_notes"] = description if description
|
|
128
|
+
# c["release_changes"] = changes if changes
|
|
129
|
+
c["preformatted"] = true
|
|
130
|
+
|
|
131
|
+
files = [
|
|
132
|
+
"#{pkg}.tgz",
|
|
133
|
+
"#{pkg}.gem"
|
|
134
|
+
].compact
|
|
135
|
+
|
|
136
|
+
puts "Releasing #{NAME} v. #{VERS}"
|
|
137
|
+
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
|
135
138
|
end
|
data/bin/rdist
CHANGED
data/lib/rdist.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'rdist/analyzer'
|
|
2
|
-
require 'rdist/
|
|
2
|
+
require 'rdist/runner'
|
|
3
3
|
require 'rdist/debuglogger'
|
|
4
4
|
require 'rdist/histogram'
|
|
5
5
|
require 'rdist/ranking'
|
|
@@ -7,7 +7,7 @@ require 'rdist/setting'
|
|
|
7
7
|
require 'rdist/targetfilefinder'
|
|
8
8
|
|
|
9
9
|
module RDist
|
|
10
|
-
VERSION = '0.0.
|
|
10
|
+
VERSION = '0.0.2'
|
|
11
11
|
|
|
12
12
|
ALLOW_NESTING = true
|
|
13
13
|
DENY_NESTING = false
|
data/lib/rdist/analyzer/base.rb
CHANGED
|
@@ -14,7 +14,7 @@ module RDist
|
|
|
14
14
|
@allow_nesting = allow_nesting
|
|
15
15
|
@histogram_interval = histogram_interval
|
|
16
16
|
init_count()
|
|
17
|
-
|
|
17
|
+
init_state_objects()
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
attr_reader :pattern_open_token
|
|
@@ -33,7 +33,7 @@ module RDist
|
|
|
33
33
|
def analyze(path)
|
|
34
34
|
@path = path
|
|
35
35
|
DebugLogger.debug "Analyzing ``#{@path}''"
|
|
36
|
-
|
|
36
|
+
init_state()
|
|
37
37
|
open(path, 'r') do |input|
|
|
38
38
|
input.each_line do |line|
|
|
39
39
|
@current_line_id = input.lineno
|
|
@@ -41,7 +41,7 @@ module RDist
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
@current_line_id = nil
|
|
44
|
-
|
|
44
|
+
reset_state_objects()
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def histogram
|
|
@@ -72,6 +72,7 @@ module RDist
|
|
|
72
72
|
|
|
73
73
|
def_state_setter :waiting_block
|
|
74
74
|
def_state_setter :in_multi_line_comment
|
|
75
|
+
def_state_setter :after_end_of_code_marker
|
|
75
76
|
def_state_setter :in_block
|
|
76
77
|
alias __set_state_in_block__ set_state_in_block
|
|
77
78
|
|
|
@@ -90,19 +91,21 @@ module RDist
|
|
|
90
91
|
@count_of = {}
|
|
91
92
|
end
|
|
92
93
|
|
|
93
|
-
def
|
|
94
|
+
def init_state
|
|
95
|
+
set_state_waiting_block()
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def init_state_objects
|
|
94
99
|
@state_for = {
|
|
95
100
|
:waiting_block => State::WaitingBlock.new(self),
|
|
96
101
|
:in_block => State::InBlock.new(self),
|
|
97
|
-
:in_multi_line_comment
|
|
98
|
-
=> State::
|
|
102
|
+
:in_multi_line_comment => State::InMultiLineComment.new(self),
|
|
103
|
+
:after_end_of_code_marker => State::AfterEndOfCodeMarker.new(self),
|
|
99
104
|
}
|
|
100
105
|
end
|
|
101
106
|
|
|
102
|
-
def
|
|
103
|
-
@state_for.
|
|
104
|
-
state.reset
|
|
105
|
-
end
|
|
107
|
+
def reset_state_objects
|
|
108
|
+
@state_for.each_value{|state| state.reset}
|
|
106
109
|
end
|
|
107
110
|
end
|
|
108
111
|
end
|
data/lib/rdist/analyzer/state.rb
CHANGED
|
@@ -5,13 +5,18 @@ module RDist
|
|
|
5
5
|
def initialize(analyzer)
|
|
6
6
|
super(analyzer)
|
|
7
7
|
@pattern_open_token = analyzer.pattern_open_token
|
|
8
|
+
@pattern_close_token = analyzer.pattern_close_token
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
public
|
|
11
12
|
def analyze(line)
|
|
13
|
+
if end_of_code?(line)
|
|
14
|
+
return @analyzer.set_state_after_end_of_code_marker
|
|
15
|
+
end
|
|
12
16
|
if multi_line_comment_begin?(line)
|
|
13
17
|
return @analyzer.set_state_in_multi_line_comment
|
|
14
18
|
end
|
|
19
|
+
return if one_linear_block?(line)
|
|
15
20
|
return unless (match_data = have_open_token?(line))
|
|
16
21
|
indent = get_indent_from(match_data)
|
|
17
22
|
block_name = get_block_name_from(match_data)
|
|
@@ -19,10 +24,31 @@ module RDist
|
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
private
|
|
27
|
+
def end_of_code?(line)
|
|
28
|
+
PATTERN_END_OF_CODE_MARKER =~ line
|
|
29
|
+
end
|
|
30
|
+
|
|
22
31
|
def multi_line_comment_begin?(line)
|
|
23
32
|
PATTERN_MULTI_LINE_COMMENT_BEGIN =~ line
|
|
24
33
|
end
|
|
25
34
|
|
|
35
|
+
def one_linear_block?(line)
|
|
36
|
+
pattern_one_linear_block =~ line
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
PATTERN_SEMICOLON = /\;/nxm
|
|
40
|
+
def pattern_one_linear_block
|
|
41
|
+
%r/
|
|
42
|
+
\A
|
|
43
|
+
(#{PATTERN_INDENT})
|
|
44
|
+
#{@pattern_open_token}
|
|
45
|
+
\s+
|
|
46
|
+
(#{PATTERN_SECOND_TOKEN})
|
|
47
|
+
.+ #{PATTERN_SEMICOLON}
|
|
48
|
+
.+ #{@pattern_close_token}
|
|
49
|
+
/nxm
|
|
50
|
+
end
|
|
51
|
+
|
|
26
52
|
def have_open_token?(line)
|
|
27
53
|
pattern_have_open_token.match(line)
|
|
28
54
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module RDist
|
|
2
|
-
#
|
|
3
|
-
class
|
|
2
|
+
# The main class used for the rdist command.
|
|
3
|
+
class Runner
|
|
4
4
|
DEFAULT_OUTPUT = $stdout
|
|
5
5
|
|
|
6
6
|
private_class_method :new
|
|
@@ -9,7 +9,7 @@ module RDist
|
|
|
9
9
|
# Analysis result is the distribution histogram and the rankings.
|
|
10
10
|
# If +argv+ includes '--verbose' option,
|
|
11
11
|
# then print all analyzing file names too.
|
|
12
|
-
def self.
|
|
12
|
+
def self.run(argv, output=DEFAULT_OUTPUT)
|
|
13
13
|
begin
|
|
14
14
|
new(argv, output)
|
|
15
15
|
rescue OptionParser::ParseError => err
|
data/lib/rdist/setting.rb
CHANGED
|
@@ -7,11 +7,15 @@ module RDist
|
|
|
7
7
|
|
|
8
8
|
private_class_method :new
|
|
9
9
|
|
|
10
|
+
# Creates a new setting from +argv+.
|
|
11
|
+
# +argv+ is destructively parsed.
|
|
12
|
+
# Items for command line options are removed
|
|
13
|
+
# and pathes (directories/files) are remained.
|
|
10
14
|
def self.for_argv(argv)
|
|
11
15
|
new(argv)
|
|
12
16
|
end
|
|
13
17
|
|
|
14
|
-
def initialize(argv)
|
|
18
|
+
def initialize(argv) #:nodoc:
|
|
15
19
|
@argv = argv
|
|
16
20
|
init_attributes()
|
|
17
21
|
configure_option_parser()
|
|
@@ -27,7 +31,7 @@ module RDist
|
|
|
27
31
|
DEFAULT_NUM_RANKING = 5
|
|
28
32
|
def init_attributes
|
|
29
33
|
@analyzer_class = Analyzer::MethodLength
|
|
30
|
-
@banner = 'Method length
|
|
34
|
+
@banner = 'Method length distribution:'
|
|
31
35
|
@num_ranking = DEFAULT_NUM_RANKING
|
|
32
36
|
@interval = nil
|
|
33
37
|
init_parser()
|
data/spec/bin_spec.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'go/vertex'
|
|
2
|
+
require 'go/ren'
|
|
3
|
+
require 'go/board/vertexmap'
|
|
4
|
+
|
|
5
|
+
module Go
|
|
6
|
+
class BoardError < Exception; end
|
|
7
|
+
|
|
8
|
+
class Board
|
|
9
|
+
class IllegalColorError < BoardError; end
|
|
10
|
+
class IllegalVertexError < BoardError; end
|
|
11
|
+
|
|
12
|
+
DEFAULT_SIZE = 19
|
|
13
|
+
NUM_PLAYERS = 2
|
|
14
|
+
def initialize(size=DEFAULT_SIZE)
|
|
15
|
+
@size = size
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
attr_reader :size
|
|
19
|
+
end
|
|
20
|
+
end
|
data/spec/runner_spec.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require 'stringio'
|
|
2
|
+
|
|
3
|
+
def check_output(string_io, count_of,
|
|
4
|
+
histogram_interval=5, num_ranking=5,
|
|
5
|
+
banner='Method length distribution:',
|
|
6
|
+
ranking_banner='Ranking Top 5:')
|
|
7
|
+
histogram = Histogram.new(count_of, histogram_interval)
|
|
8
|
+
ranking = Ranking.new(count_of)
|
|
9
|
+
expected_string = "#{banner}\n"
|
|
10
|
+
expected_string << histogram.to_s
|
|
11
|
+
expected_string << "\n#{ranking_banner}\n"
|
|
12
|
+
expected_string << ranking.string_top(num_ranking)
|
|
13
|
+
string_io.string.should == expected_string
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_count_hash(count_sets, path)
|
|
17
|
+
hash = {}
|
|
18
|
+
count_sets.each do |name, line_id, score|
|
|
19
|
+
hash["#{name} (at #{path}:#{line_id})"] = score
|
|
20
|
+
end
|
|
21
|
+
hash
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
COUNT_SETS_IN_NORMAL_CODE_RB = [
|
|
25
|
+
['initialize', 3, 4].freeze,
|
|
26
|
+
['each_vertex', 14, 3].freeze,
|
|
27
|
+
['surrounded?', 20, 1].freeze,
|
|
28
|
+
['concat', 24, 6].freeze,
|
|
29
|
+
['init_edge_vertices', 34, 10].freeze,
|
|
30
|
+
['dame_vertices', 47, 3].freeze,
|
|
31
|
+
['space?', 53, 1].freeze,
|
|
32
|
+
].freeze
|
|
33
|
+
COUNT_OF_IN_NORMAL_CODE_RB = get_count_hash(COUNT_SETS_IN_NORMAL_CODE_RB,
|
|
34
|
+
(FIXTURE_DIR + '/normal_code.rb'))
|
|
35
|
+
COUNT_OF_IN_NORMAL_CODE_RB.freeze
|
|
36
|
+
describe Runner, %q[when ``normal_code.rb'' is given] do
|
|
37
|
+
before do
|
|
38
|
+
@path = FIXTURE_DIR + '/normal_code.rb'
|
|
39
|
+
@string_io = StringIO.new
|
|
40
|
+
@expected_count_of = COUNT_OF_IN_NORMAL_CODE_RB
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'should count number of method length correctly' do
|
|
44
|
+
Runner.run(['--interval', '1', @path], @string_io)
|
|
45
|
+
check_output(@string_io, @expected_count_of, 1, 5)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it %q[should show entire ranking if '--verbose' option is given] do
|
|
49
|
+
Runner.run(['--verbose', @path], @string_io)
|
|
50
|
+
check_output(@string_io, @expected_count_of, 5, 7,
|
|
51
|
+
'Method length distribution:', 'Entire Ranking:')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe Runner, %q[when ``with_end_of_code_marker.rb'' is given] do
|
|
56
|
+
before do
|
|
57
|
+
@path = FIXTURE_DIR + '/with_end_of_code_marker.rb'
|
|
58
|
+
@string_io = StringIO.new
|
|
59
|
+
@expected_count_of = {}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'should ignore lines after the __END__ marker' do
|
|
63
|
+
Runner.run([@path], @string_io)
|
|
64
|
+
check_output(@string_io, @expected_count_of)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe(Runner,
|
|
69
|
+
%q[when ``with_end_of_code_marker.rb'' and ``normal_code.rb'' are given])do
|
|
70
|
+
before do
|
|
71
|
+
@pathes = [
|
|
72
|
+
'/with_end_of_code_marker.rb',
|
|
73
|
+
'/normal_code.rb',
|
|
74
|
+
].collect{|path| FIXTURE_DIR + path}
|
|
75
|
+
@string_io = StringIO.new
|
|
76
|
+
@expected_count_of = COUNT_OF_IN_NORMAL_CODE_RB
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'should correctly count' do
|
|
80
|
+
Runner.run(@pathes, @string_io)
|
|
81
|
+
check_output(@string_io, @expected_count_of)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe Runner, %q[when ``with_one_linear_definition.rb'' is given] do
|
|
86
|
+
before do
|
|
87
|
+
@path = FIXTURE_DIR + '/with_one_linear_definition.rb'
|
|
88
|
+
@string_io = StringIO.new
|
|
89
|
+
count_sets = [
|
|
90
|
+
['Go', 5, 1],
|
|
91
|
+
['Board', 8, 8],
|
|
92
|
+
]
|
|
93
|
+
@expected_count_of = get_count_hash(count_sets, @path)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should recognize one-linear definitions' do
|
|
97
|
+
Runner.run(['-c', '--interval', '1', @path], @string_io)
|
|
98
|
+
check_output(@string_io, @expected_count_of, 1, 5,
|
|
99
|
+
'Distribution of number of lines in Class/Module:')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
describe Setting, 'when given +argv+ is empty' do
|
|
2
|
+
before do
|
|
3
|
+
@setting = Setting.for_argv([])
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it 'should return an instance of Analyzer::MethodLength as analyzer' do
|
|
7
|
+
@setting.analyzer.should be_instance_of(Analyzer::MethodLength)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'should return 5 as num_ranking' do
|
|
11
|
+
@setting.num_ranking.should == 5
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it %q[should have banner 'Method length distribution:'] do
|
|
15
|
+
@setting.banner.should == 'Method length distribution:'
|
|
16
|
+
end
|
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
PROJECT_ROOT = File.dirname(__FILE__) + '/..'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
BIN_DIR = PROJECT_ROOT + '/bin'
|
|
4
|
+
LIB_DIR = PROJECT_ROOT + '/lib'
|
|
5
5
|
SPEC_DIR = PROJECT_ROOT + '/spec'
|
|
6
6
|
FIXTURE_DIR = SPEC_DIR + '/fixtures'
|
|
7
7
|
|
|
8
|
+
$LOAD_PATH.unshift LIB_DIR
|
|
9
|
+
|
|
8
10
|
require 'rdist'
|
|
9
11
|
|
|
10
12
|
include RDist
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rdist
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yoshifumi Shimono
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-
|
|
12
|
+
date: 2008-03-01 00:00:00 +09:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -28,13 +28,18 @@ files:
|
|
|
28
28
|
- Rakefile
|
|
29
29
|
- bin/rdist
|
|
30
30
|
- spec/spec.opts
|
|
31
|
+
- spec/bin_spec.rb
|
|
31
32
|
- spec/spec_helper.rb
|
|
32
|
-
- spec/
|
|
33
|
+
- spec/setting_spec.rb
|
|
34
|
+
- spec/runner_spec.rb
|
|
33
35
|
- spec/fixtures
|
|
34
36
|
- spec/ranking_spec.rb
|
|
37
|
+
- spec/fixtures/with_end_of_code_marker.rb
|
|
38
|
+
- spec/fixtures/with_one_linear_definition.rb
|
|
35
39
|
- spec/fixtures/normal_code.rb
|
|
36
40
|
- lib/rdist
|
|
37
41
|
- lib/rdist.rb
|
|
42
|
+
- lib/rdist/runner.rb
|
|
38
43
|
- lib/rdist/histogram.rb
|
|
39
44
|
- lib/rdist/targetfilefinder.rb
|
|
40
45
|
- lib/rdist/analyzer.rb
|
|
@@ -43,7 +48,6 @@ files:
|
|
|
43
48
|
- lib/rdist/debuglogger.rb
|
|
44
49
|
- lib/rdist/analyzer
|
|
45
50
|
- lib/rdist/ranking.rb
|
|
46
|
-
- lib/rdist/commandlineinterface.rb
|
|
47
51
|
- lib/rdist/setting/macros.rb
|
|
48
52
|
- lib/rdist/analyzer/macros.rb
|
|
49
53
|
- lib/rdist/analyzer/methodlength.rb
|
|
@@ -56,6 +60,7 @@ files:
|
|
|
56
60
|
- lib/rdist/analyzer/state/inblock.rb
|
|
57
61
|
- lib/rdist/analyzer/state/waitingblock.rb
|
|
58
62
|
- lib/rdist/analyzer/state/base.rb
|
|
63
|
+
- lib/rdist/analyzer/state/afterendofcodemarker.rb
|
|
59
64
|
has_rdoc: true
|
|
60
65
|
homepage: http://rdist.rubyforge.org
|
|
61
66
|
post_install_message:
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require 'stringio'
|
|
2
|
-
|
|
3
|
-
describe CommandLineInterface, %q[when ``normal_code.rb'' given] do
|
|
4
|
-
def check_output(string_io, count_of,
|
|
5
|
-
histogram_interval, num_ranking,
|
|
6
|
-
banner='Method length Distribution:',
|
|
7
|
-
ranking_banner='Ranking Top 5:')
|
|
8
|
-
histogram = Histogram.new(count_of, histogram_interval)
|
|
9
|
-
ranking = Ranking.new(count_of)
|
|
10
|
-
expected_string = "#{banner}\n"
|
|
11
|
-
expected_string << histogram.to_s
|
|
12
|
-
expected_string << "\n#{ranking_banner}\n"
|
|
13
|
-
expected_string << ranking.string_top(num_ranking)
|
|
14
|
-
string_io.string.should == expected_string
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
before do
|
|
18
|
-
@fixture_path = FIXTURE_DIR + '/normal_code.rb'
|
|
19
|
-
@string_io = StringIO.new
|
|
20
|
-
@expected_count_of = {
|
|
21
|
-
'initialize (at ./spec/../spec/fixtures/normal_code.rb:3)' => 4,
|
|
22
|
-
'each_vertex (at ./spec/../spec/fixtures/normal_code.rb:14)' => 3,
|
|
23
|
-
'surrounded? (at ./spec/../spec/fixtures/normal_code.rb:20)' => 1,
|
|
24
|
-
'concat (at ./spec/../spec/fixtures/normal_code.rb:24)' => 6,
|
|
25
|
-
'init_edge_vertices (at ./spec/../spec/fixtures/normal_code.rb:34)' => 10,
|
|
26
|
-
'dame_vertices (at ./spec/../spec/fixtures/normal_code.rb:47)' => 3,
|
|
27
|
-
'space? (at ./spec/../spec/fixtures/normal_code.rb:53)' => 1,
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'should count number of method length correctly' do
|
|
32
|
-
CommandLineInterface.analyze(['--interval', '1', @fixture_path],
|
|
33
|
-
@string_io)
|
|
34
|
-
check_output(@string_io, @expected_count_of, 1, 5)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it %q[should show entire ranking if '--verbose' option is given] do
|
|
38
|
-
CommandLineInterface.analyze(['--verbose', @fixture_path], @string_io)
|
|
39
|
-
check_output(@string_io, @expected_count_of, 5, 7,
|
|
40
|
-
'Method length Distribution:',
|
|
41
|
-
'Entire Ranking:')
|
|
42
|
-
end
|
|
43
|
-
end
|