churn 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.md +137 -120
- data/bin/churn +27 -12
- data/churn.gemspec +7 -21
- data/lib/churn/calculator.rb +24 -11
- data/lib/churn/history.rb +1 -1
- data/lib/churn/location_mapping.rb +1 -1
- data/lib/churn/options.rb +7 -3
- data/lib/churn/scm/bzr_analyzer.rb +11 -4
- data/lib/churn/scm/git_analyzer.rb +5 -3
- data/lib/churn/scm/hg_analyzer.rb +11 -4
- data/lib/churn/scm/source_control.rb +6 -8
- data/lib/churn/scm/svn_analyzer.rb +9 -3
- data/lib/churn/version.rb +1 -1
- metadata +24 -190
- data/.deferred_server +0 -1
- data/.document +0 -5
- data/.gitignore +0 -11
- data/.travis.yml +0 -6
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -79
- data/Rakefile +0 -41
- data/doc/Churn.html +0 -165
- data/doc/Churn/BzrAnalyzer.html +0 -276
- data/doc/Churn/ChurnCalculator.html +0 -578
- data/doc/Churn/ChurnHistory.html +0 -250
- data/doc/Churn/ChurnOptions.html +0 -393
- data/doc/Churn/GitAnalyzer.html +0 -311
- data/doc/Churn/HgAnalyzer.html +0 -276
- data/doc/Churn/LocationMapping.html +0 -448
- data/doc/Churn/SourceControl.html +0 -451
- data/doc/Churn/SvnAnalyzer.html +0 -311
- data/doc/LICENSE.html +0 -123
- data/doc/Object.html +0 -246
- data/doc/created.rid +0 -15
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -100
- data/doc/js/darkfish.js +0 -155
- data/doc/js/jquery.js +0 -18
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -595
- data/doc/table_of_contents.html +0 -167
- data/test/data/churn_calculator.rb +0 -217
- data/test/data/test_helper.rb +0 -14
- data/test/test_helper.rb +0 -21
- data/test/unit/bzr_analyzer_test.rb +0 -65
- data/test/unit/churn_calculator_test.rb +0 -181
- data/test/unit/churn_history_test.rb +0 -24
- data/test/unit/churn_options_test.rb +0 -16
- data/test/unit/git_analyzer_test.rb +0 -88
- data/test/unit/hg_analyzer_test.rb +0 -66
- data/test/unit/location_mapping_test.rb +0 -35
- data/test/unit/source_control_test.rb +0 -22
- data/test/unit/svn_analyzer_test.rb +0 -65
@@ -1,181 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class ChurnCalculatorTest < Minitest::Test
|
4
|
-
|
5
|
-
should "use minimum churn count" do
|
6
|
-
within_construct do |container|
|
7
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
8
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
9
|
-
|
10
|
-
churn.stubs(:parse_log_for_changes).returns([['file.rb', 4],['less.rb',1]])
|
11
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['revision'])
|
12
|
-
churn.stubs(:analyze)
|
13
|
-
report = churn.report(false)
|
14
|
-
assert_equal 1, report[:churn][:changes].length
|
15
|
-
assert_equal ["file.rb", 4], report[:churn][:changes].first
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
should "ensure that minimum churn count is initialized as a Fixnum" do
|
20
|
-
within_construct do |container|
|
21
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
22
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => "3"})
|
23
|
-
|
24
|
-
assert_equal 3, churn.instance_variable_get(:@minimum_churn_count)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
should "use ignores filter" do
|
29
|
-
within_construct do |container|
|
30
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
31
|
-
churn = Churn::ChurnCalculator.new({:ignores => "file.rb"})
|
32
|
-
|
33
|
-
churn.stubs(:parse_log_for_changes).returns([['file.rb', 10],['new.rb',11]])
|
34
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['revision'])
|
35
|
-
churn.stubs(:analyze)
|
36
|
-
report = churn.report(false)
|
37
|
-
assert_equal 1, report[:churn][:changes].length
|
38
|
-
assert_equal ["new.rb", 11], report[:churn][:changes].first
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
should "use ignores with regex" do
|
43
|
-
within_construct do |container|
|
44
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
45
|
-
churn = Churn::ChurnCalculator.new({:ignores => "f.*le.rb"})
|
46
|
-
|
47
|
-
churn.stubs(:parse_log_for_changes).returns([['file.rb', 10],['new.rb',11]])
|
48
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['revision'])
|
49
|
-
churn.stubs(:analyze)
|
50
|
-
report = churn.report(false)
|
51
|
-
assert_equal 1, report[:churn][:changes].length
|
52
|
-
assert_equal ["new.rb", 11], report[:churn][:changes].first
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
should "use ignores with regex and directories" do
|
57
|
-
within_construct do |container|
|
58
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
59
|
-
churn = Churn::ChurnCalculator.new({:ignores => "lib/.*"})
|
60
|
-
|
61
|
-
churn.stubs(:parse_log_for_changes).returns([['lib/file.rb', 10],['new.rb',11]])
|
62
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['revision'])
|
63
|
-
churn.stubs(:analyze)
|
64
|
-
report = churn.report(false)
|
65
|
-
assert_equal 1, report[:churn][:changes].length
|
66
|
-
assert_equal ["new.rb", 11], report[:churn][:changes].first
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should "analyze sorts changes" do
|
71
|
-
within_construct do |container|
|
72
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
73
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
74
|
-
|
75
|
-
churn.stubs(:parse_log_for_changes).returns([['file.rb', 4],['most.rb', 9],['less.rb',1]])
|
76
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['revision'])
|
77
|
-
report = churn.report(false)
|
78
|
-
assert_equal 2, report[:churn][:changes].length
|
79
|
-
top = {:file_path => "most.rb", :times_changed => 9}
|
80
|
-
assert_equal top, report[:churn][:changes].first
|
81
|
-
bottom = {:file_path => "file.rb", :times_changed => 4}
|
82
|
-
assert_equal bottom, report[:churn][:changes].last
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
should "have correct changed_files data" do
|
87
|
-
within_construct do |container|
|
88
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
89
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
90
|
-
|
91
|
-
churn.stubs(:parse_log_for_changes).returns([['less.rb',1]])
|
92
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['first'])
|
93
|
-
churn.stubs(:parse_logs_for_updated_files).returns({'fake_file.rb'=>[]})
|
94
|
-
report = churn.report(false)
|
95
|
-
assert_equal ["fake_file.rb"], report[:churn][:changed_files]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
should "have correct changed classes and methods data" do
|
100
|
-
within_construct do |container|
|
101
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
102
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
103
|
-
|
104
|
-
churn.stubs(:parse_log_for_changes).returns([['less.rb',1]])
|
105
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['first'])
|
106
|
-
churn.stubs(:parse_logs_for_updated_files).returns({'fake_file.rb'=>[]})
|
107
|
-
klasses = [{"klass"=>"LocationMapping", "file"=>"lib/churn/location_mapping.rb"}]
|
108
|
-
methods = [{"klass"=>"LocationMapping", "method"=>"LocationMapping#process_class", "file"=>"lib/churn/location_mapping.rb"}]
|
109
|
-
churn.stubs(:get_changes).returns([klasses,methods])
|
110
|
-
report = churn.report(false)
|
111
|
-
assert_equal [{"klass"=>"LocationMapping", "method"=>"LocationMapping#process_class", "file"=>"lib/churn/location_mapping.rb"}], report[:churn][:changed_methods]
|
112
|
-
assert_equal [{"klass"=>"LocationMapping", "file"=>"lib/churn/location_mapping.rb"}], report[:churn][:changed_classes]
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
should "have correct churn method and classes at 1 change" do
|
117
|
-
within_construct do |container|
|
118
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(true)
|
119
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
120
|
-
|
121
|
-
churn.stubs(:parse_log_for_changes).returns([['less.rb',1]])
|
122
|
-
churn.stubs(:parse_log_for_revision_changes).returns(['first'])
|
123
|
-
churn.stubs(:parse_logs_for_updated_files).returns({'fake_file.rb'=>[]})
|
124
|
-
klasses = [{"klass"=>"LocationMapping", "file"=>"lib/churn/location_mapping.rb"}]
|
125
|
-
methods = [{"klass"=>"LocationMapping", "method"=>"LocationMapping#process_class", "file"=>"lib/churn/location_mapping.rb"}]
|
126
|
-
churn.stubs(:get_changes).returns([klasses,methods])
|
127
|
-
report = churn.report(false)
|
128
|
-
assert_equal [{"method"=>{"klass"=>"LocationMapping", "method"=>"LocationMapping#process_class", "file"=>"lib/churn/location_mapping.rb"}, "times_changed"=>1}], report[:churn][:method_churn]
|
129
|
-
assert_equal [{"klass"=>{"klass"=>"LocationMapping", "file"=>"lib/churn/location_mapping.rb"}, "times_changed"=>1}], report[:churn][:class_churn]
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
should "have expected output for self.to_s" do
|
134
|
-
output = Churn::ChurnCalculator.to_s({})
|
135
|
-
assert_match /Revision Changes/, output
|
136
|
-
assert_match /Project Churn/, output
|
137
|
-
end
|
138
|
-
|
139
|
-
should "have expected output for to_s" do
|
140
|
-
calc = Churn::ChurnCalculator.new
|
141
|
-
calc.expects(:to_h).returns({:churn => {}})
|
142
|
-
output = calc.to_s
|
143
|
-
assert_match /Revision Changes/, output
|
144
|
-
assert_match /Project Churn/, output
|
145
|
-
end
|
146
|
-
|
147
|
-
should "initialize a churn calculator for hg repositories" do
|
148
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(false)
|
149
|
-
Churn::HgAnalyzer.expects(:`).with("hg branch 2>&1").returns(true) #` fix syntax hilighting
|
150
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
151
|
-
assert churn.instance_variable_get(:@source_control).is_a?(Churn::HgAnalyzer)
|
152
|
-
end
|
153
|
-
|
154
|
-
should "initialize a churn calculator for bzr repositories" do
|
155
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(false)
|
156
|
-
Churn::HgAnalyzer.stubs(:supported?).returns(false)
|
157
|
-
Churn::BzrAnalyzer.expects(:`).with("bzr nick 2>&1").returns(true) #` fix syntax hilighting
|
158
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
159
|
-
assert churn.instance_variable_get(:@source_control).is_a?(Churn::BzrAnalyzer)
|
160
|
-
end
|
161
|
-
|
162
|
-
should "initialize a churn calculator for svn repositories" do
|
163
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(false)
|
164
|
-
Churn::HgAnalyzer.stubs(:supported?).returns(false)
|
165
|
-
Churn::BzrAnalyzer.stubs(:supported?).returns(false)
|
166
|
-
File.stubs(:exist?).returns(true)
|
167
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
168
|
-
assert churn.instance_variable_get(:@source_control).is_a?(Churn::SvnAnalyzer)
|
169
|
-
end
|
170
|
-
|
171
|
-
should "raise exception on a churn calculator for unknown repositories" do
|
172
|
-
Churn::GitAnalyzer.stubs(:supported?).returns(false)
|
173
|
-
Churn::HgAnalyzer.stubs(:supported?).returns(false)
|
174
|
-
Churn::BzrAnalyzer.stubs(:supported?).returns(false)
|
175
|
-
File.stubs(:exist?).returns(false)
|
176
|
-
assert_raises RuntimeError do
|
177
|
-
churn = Churn::ChurnCalculator.new({:minimum_churn_count => 3})
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class ChurnHistoryTest < Minitest::Test
|
4
|
-
|
5
|
-
should "store results" do
|
6
|
-
within_construct do |container|
|
7
|
-
Churn::ChurnHistory.store_revision_history('aaa','data','tmp/churn/')
|
8
|
-
assert File.exists?('tmp/churn/aaa.json')
|
9
|
-
data = File.read('tmp/churn/aaa.json')
|
10
|
-
assert data =~ /data/
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
should "restores results" do
|
15
|
-
within_construct do |container|
|
16
|
-
container.file('tmp/churn/aaa.json', '{"churn":{"changes":[{"file_path":".gitignore","times_changed":2},{"file_path":"lib\/churn.rb","times_changed":2},{"file_path":"Rakefile","times_changed":2},{"file_path":"README.rdoc","times_changed":2},{"file_path":"lib\/churn\/source_control.rb","times_changed":1},{"file_path":"lib\/churn\/svn_analyzer.rb","times_changed":1},{"file_path":"lib\/tasks\/churn_tasks.rb","times_changed":1},{"file_path":"LICENSE","times_changed":1},{"file_path":"test\/churn_test.rb","times_changed":1},{"file_path":"lib\/churn\/locationmapping.rb","times_changed":1},{"file_path":"lib\/churn\/git_analyzer.rb","times_changed":1},{"file_path":".document","times_changed":1},{"file_path":"test\/test_helper.rb","times_changed":1},{"file_path":"lib\/churn\/churn_calculator.rb","times_changed":1}],"method_churn":[],"changed_files":[".gitignore","lib\/churn\/source_control.rb","lib\/tasks\/churn_tasks.rb","lib\/churn\/svn_analyzer.rb","Rakefile","README.rdoc","lib\/churn\/locationmapping.rb","lib\/churn\/git_analyzer.rb","\/dev\/null","lib\/churn\/churn_calculator.rb","lib\/churn.rb"],"class_churn":[],"changed_classes":[{"klass":"ChurnTest","file":"test\/churn_test.rb"},{"klass":"ChurnCalculator","file":"lib\/churn\/churn_calculator.rb"}],"changed_methods":[{"klass":"","method":"#report_churn","file":"lib\/tasks\/churn_tasks.rb"}]}}')
|
17
|
-
changed_files, changed_classes, changed_methods = Churn::ChurnHistory.load_revision_data('aaa', 'tmp/churn/')
|
18
|
-
assert changed_files.include?("lib/churn/source_control.rb")
|
19
|
-
assert_equal 2, changed_classes.length
|
20
|
-
assert_equal 1, changed_methods.length
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class ChurnOptionsTest < Minitest::Test
|
4
|
-
|
5
|
-
should "store get default directory" do
|
6
|
-
assert_equal Churn::ChurnOptions::DEFAULT_CHURN_DIRECTORY, Churn::ChurnOptions.new.data_directory
|
7
|
-
end
|
8
|
-
|
9
|
-
should "store get over ride directory" do
|
10
|
-
options = Churn::ChurnOptions.new
|
11
|
-
tmp_dir = '/tmp/fake'
|
12
|
-
options.set_options({:data_directory => tmp_dir})
|
13
|
-
assert_equal tmp_dir, options.data_directory
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class GitAnalyzerTest < Minitest::Test
|
4
|
-
|
5
|
-
should "parses logs correctly" do
|
6
|
-
git_analyzer = Churn::GitAnalyzer.new
|
7
|
-
revision = 'first'
|
8
|
-
revisions = ['first']
|
9
|
-
lines = ["--- a/lib/churn/churn_calculator.rb", "+++ b/lib/churn/churn_calculator.rb", "@@ -18,0 +19 @@ module Churn"]
|
10
|
-
git_analyzer.stubs(:get_updated_files_from_log).returns(lines)
|
11
|
-
updated = git_analyzer.get_updated_files_change_info(revision, revisions)
|
12
|
-
expected_hash = {"lib/churn/churn_calculator.rb"=>[18..18, 19..19]}
|
13
|
-
assert_equal = updated
|
14
|
-
end
|
15
|
-
|
16
|
-
should "run get_logs correctly" do
|
17
|
-
git_analyzer = Churn::GitAnalyzer.new
|
18
|
-
git_analyzer.expects(:`).returns(git_logs_output) #`fix syntax hilighting
|
19
|
-
assert_equal ["public/css/application.css", "views/layout.erb", "README.md", "app.rb"], git_analyzer.get_logs
|
20
|
-
end
|
21
|
-
|
22
|
-
should "run get_revisions correctly" do
|
23
|
-
git_analyzer = Churn::GitAnalyzer.new
|
24
|
-
git_analyzer.expects(:`).returns(git_revisions_output) #`fix syntax hilighting
|
25
|
-
assert_equal ["0aef1f56d5b3b546457e996450fd9ceca379f0a8",
|
26
|
-
"8038f1b17c3749540650aaab3f4e5e846cfc3b47",
|
27
|
-
"4d7e4859b2ed8a7e4f73e3540e7879c00cba9783"], git_analyzer.get_revisions
|
28
|
-
end
|
29
|
-
|
30
|
-
should "run date range correctly" do
|
31
|
-
git_analyzer = Churn::GitAnalyzer.new(Date.parse('3/3/2010'))
|
32
|
-
assert_equal "--after=2010-03-03", git_analyzer.send(:date_range)
|
33
|
-
end
|
34
|
-
|
35
|
-
should "run get_diff correctly" do
|
36
|
-
git_analyzer = Churn::GitAnalyzer.new
|
37
|
-
git_analyzer.expects(:`).returns(git_git_diff_output) #`fix syntax hilighting
|
38
|
-
assert_equal ["--- a/public/css/application.css",
|
39
|
-
"+++ b/public/css/application.css",
|
40
|
-
"@@ -18,0 +19,4 @@ footer{",
|
41
|
-
"--- a/views/layout.erb",
|
42
|
-
"+++ b/views/layout.erb",
|
43
|
-
"@@ -43,0 +44 @@"], git_analyzer.send(:get_diff, 'rev', 'prev_rev')
|
44
|
-
end
|
45
|
-
|
46
|
-
protected
|
47
|
-
|
48
|
-
# ran in a project
|
49
|
-
# git log --after=2013-09-05 --name-only --pretty=format:
|
50
|
-
def git_logs_output
|
51
|
-
"public/css/application.css
|
52
|
-
views/layout.erb
|
53
|
-
|
54
|
-
README.md
|
55
|
-
app.rb"
|
56
|
-
end
|
57
|
-
|
58
|
-
# ran in a project
|
59
|
-
# git log --after=2013-09-05 --pretty=format:"%H"
|
60
|
-
def git_revisions_output
|
61
|
-
"0aef1f56d5b3b546457e996450fd9ceca379f0a8
|
62
|
-
8038f1b17c3749540650aaab3f4e5e846cfc3b47
|
63
|
-
4d7e4859b2ed8a7e4f73e3540e7879c00cba9783"
|
64
|
-
end
|
65
|
-
|
66
|
-
# ran in a project
|
67
|
-
# git diff 4d7e4859b2ed8a7e4f73e3540e7879c00cba9783 8038f1b17c3749540650aaab3f4e5e846cfc3b47 --unified=0
|
68
|
-
def git_git_diff_output
|
69
|
-
output = <<EOF
|
70
|
-
diff --git a/public/css/application.css b/public/css/application.css
|
71
|
-
index 522ca1a..730eb1e 100644
|
72
|
-
--- a/public/css/application.css
|
73
|
-
+++ b/public/css/application.css
|
74
|
-
@@ -18,0 +19,4 @@ footer{
|
75
|
-
+
|
76
|
-
+footer .container .right {
|
77
|
-
+ float:right;
|
78
|
-
+}
|
79
|
-
diff --git a/views/layout.erb b/views/layout.erb
|
80
|
-
index f8d3aea..7f4fb2f 100644
|
81
|
-
--- a/views/layout.erb
|
82
|
-
+++ b/views/layout.erb
|
83
|
-
@@ -43,0 +44 @@
|
84
|
-
+ <span class="right">a part of <a href="http://picoappz.com">picoappz</a></span>
|
85
|
-
EOF
|
86
|
-
output
|
87
|
-
end
|
88
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class HgAnalyzerTest < Minitest::Test
|
4
|
-
|
5
|
-
context "HgAnalyzer#get_logs" do
|
6
|
-
should "return a list of changed files" do
|
7
|
-
hg_analyzer = Churn::HgAnalyzer.new
|
8
|
-
hg_analyzer.expects(:`).with('hg log -v').returns("changeset: 1:4760c1d7cd40\ntag: tip\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:21:28 2010 -0600\nfiles: file1.rb file2.rb file3.rb\ndescription:\nSecond commit with 3 files now.\nLong commit\n\n\nchangeset: 0:3cb77114f02a\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:19:32 2010 -0600\nfiles: file1.rb\ndescription:\nFirst commit\n\n\n")
|
9
|
-
assert_equal ["file1.rb", "file2.rb", "file3.rb", "file1.rb"], hg_analyzer.get_logs
|
10
|
-
end
|
11
|
-
|
12
|
-
should "scope the changed files to an optional date range" do
|
13
|
-
hg_analyzer = Churn::HgAnalyzer.new("1/16/2010")
|
14
|
-
hg_analyzer.expects(:`).with('hg log -v -d "> 2010-01-16"').returns("changeset: 1:4760c1d7cd40\ntag: tip\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:21:28 2010 -0600\nfiles: file1.rb file2.rb file3.rb\ndescription:\nSecond commit with 3 files now.\nLong commit\n\n\nchangeset: 0:3cb77114f02a\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:19:32 2010 -0600\nfiles: file1.rb\ndescription:\nFirst commit\n\n\n")
|
15
|
-
assert_equal ["file1.rb", "file2.rb", "file3.rb", "file1.rb"], hg_analyzer.get_logs
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "HgAnalyzer#get_revisions" do
|
20
|
-
should "return a list of changeset ids" do
|
21
|
-
hg_analyzer = Churn::HgAnalyzer.new
|
22
|
-
hg_analyzer.expects(:`).with('hg log').returns("changeset: 1:4760c1d7cd40\ntag: tip\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:21:28 2010 -0600\nsummary: Second commit with 3 files now.\n\nchangeset: 0:3cb77114f02a\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:19:32 2010 -0600\nsummary: First commit\n\n")
|
23
|
-
assert_equal ["4760c1d7cd40", "3cb77114f02a"], hg_analyzer.get_revisions
|
24
|
-
end
|
25
|
-
|
26
|
-
should "scope the changesets to an optional date range" do
|
27
|
-
hg_analyzer = Churn::HgAnalyzer.new("1/16/2010")
|
28
|
-
hg_analyzer.expects(:`).with('hg log -d "> 2010-01-16"').returns("changeset: 1:4760c1d7cd40\ntag: tip\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:21:28 2010 -0600\nsummary: Second commit with 3 files now.\n\nchangeset: 0:3cb77114f02a\nuser: Adam Walters <awalters@obtiva.com>\ndate: Sat Jan 16 14:19:32 2010 -0600\nsummary: First commit\n\n")
|
29
|
-
assert_equal ["4760c1d7cd40", "3cb77114f02a"], hg_analyzer.get_revisions
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "HgAnalyzer#get_updated_files_from_log(revision, revisions)" do
|
34
|
-
should "return a list of modified files and the change hunks (chunks)" do
|
35
|
-
hg_analyzer = Churn::HgAnalyzer.new
|
36
|
-
hg_analyzer.expects(:`).with('hg diff -r 4760c1d7cd40:3cb77114f02a -U 0').returns("diff -r 4760c1d7cd40 -r 3cb77114f02a file1.rb\n--- a/file1.rb\tSat Jan 16 14:21:28 2010 -0600\n+++ b/file1.rb\tSat Jan 16 14:19:32 2010 -0600\n@@ -1,3 +0,0 @@\n-First\n-Adding sample data\n-Third line\ndiff -r 4760c1d7cd40 -r 3cb77114f02a file2.rb\n--- a/file2.rb\tSat Jan 16 14:21:28 2010 -0600\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,7 +0,0 @@\n-This is the second file.\n-\n-Little more data\n-\n-def cool_method\n- \"hello\"\n-end\ndiff -r 4760c1d7cd40 -r 3cb77114f02a file3.rb\n--- a/file3.rb\tSat Jan 16 14:21:28 2010 -0600\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,5 +0,0 @@\n-Third file here.\n-\n-def another_method\n- \"foo\"\n-end\n")
|
37
|
-
assert_equal ["--- a/file1.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ b/file1.rb\tSat Jan 16 14:19:32 2010 -0600", "@@ -1,3 +0,0 @@", "--- a/file2.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,7 +0,0 @@", "--- a/file3.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,5 +0,0 @@"], hg_analyzer.get_updated_files_from_log("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"])
|
38
|
-
end
|
39
|
-
|
40
|
-
should "return an empty array if it's the final revision" do
|
41
|
-
hg_analyzer = Churn::HgAnalyzer.new
|
42
|
-
assert_equal [], hg_analyzer.get_updated_files_from_log("3cb77114f02a", ["4760c1d7cd40", "3cb77114f02a"])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "HgAnalyzer#get_updated_files_change_info(revision, revisions)" do
|
47
|
-
setup do
|
48
|
-
@hg_analyzer = Churn::HgAnalyzer.new
|
49
|
-
end
|
50
|
-
|
51
|
-
should "return all modified files with their line differences" do
|
52
|
-
@hg_analyzer.expects(:get_updated_files_from_log).with("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]).returns(["--- a/file1.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ b/file1.rb\tSat Jan 16 14:19:32 2010 -0600", "@@ -1,3 +0,0 @@", "--- a/file2.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,7 +0,0 @@", "--- a/file3.rb\tSat Jan 16 14:21:28 2010 -0600", "+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000", "@@ -1,5 +0,0 @@"])
|
53
|
-
assert_equal({"/dev/null" => [1..8, 0..0, 1..6, 0..0], "file3.rb" => [], "file1.rb" => [], "file2.rb" => [], "file1.rb" => [1..4, 0..0]}, @hg_analyzer.get_updated_files_change_info("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]))
|
54
|
-
end
|
55
|
-
|
56
|
-
should "raise an error if it encounters a line it cannot parse" do
|
57
|
-
@hg_analyzer.expects(:get_updated_files_from_log).with("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"]).returns(["foo"])
|
58
|
-
assert_raises RuntimeError do
|
59
|
-
@hg_analyzer.stubs(:puts) # supress output from raised error
|
60
|
-
@hg_analyzer.get_updated_files_change_info("4760c1d7cd40", ["4760c1d7cd40", "3cb77114f02a"])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class LocationMappingTest < Minitest::Test
|
4
|
-
|
5
|
-
#todo unfortunately it looks like ruby parser can't handle construct tmp dirs
|
6
|
-
#<Pathname:/private/var/folders/gl/glhHkYYSGgG5nb6+4OG0yU+++TI/-Tmp-/construct_container-56784-851001101/fake_class.rb>
|
7
|
-
#(rdb:1) p locationmapping.get_info(file.to_s)
|
8
|
-
#RegexpError Exception: invalid regular expression; there's no previous pattern, to which '+' would define cardinality at 2: /^+++/
|
9
|
-
|
10
|
-
should "location_mapping gets correct file classes info" do
|
11
|
-
file = 'test/data/churn_calculator.rb'
|
12
|
-
locationmapping = Churn::LocationMapping.new
|
13
|
-
locationmapping.get_info(file.to_s)
|
14
|
-
klass_hash = {"ChurnCalculator"=>[14..213]}
|
15
|
-
assert_equal klass_hash, locationmapping.klasses_collection
|
16
|
-
end
|
17
|
-
|
18
|
-
should "location_mapping gets correct methods info" do
|
19
|
-
file = 'test/data/churn_calculator.rb'
|
20
|
-
locationmapping = Churn::LocationMapping.new
|
21
|
-
locationmapping.get_info(file.to_s)
|
22
|
-
methods_hash = {"ChurnCalculator#report"=>[32..36], "ChurnCalculator#emit"=>[38..41], "ChurnCalculator#changes_for_type"=>[139..155], "ChurnCalculator#get_klass_for"=>[135..137], "ChurnCalculator#calculate_changes!"=>[109..116], "ChurnCalculator#analyze"=>[43..53], "ChurnCalculator#calculate_revision_data"=>[95..107], "ChurnCalculator#calculate_revision_changes"=>[78..92], "ChurnCalculator#parse_logs_for_updated_files"=>[171..213], "ChurnCalculator#to_h"=>[55..70], "ChurnCalculator#parse_log_for_revision_changes"=>[167..169], "ChurnCalculator#get_changes"=>[118..133], "ChurnCalculator#parse_log_for_changes"=>[157..165], "ChurnCalculator#initialize"=>[16..30]}
|
23
|
-
assert_equal methods_hash.sort, locationmapping.methods_collection.sort
|
24
|
-
end
|
25
|
-
|
26
|
-
should "location_mapping gets correct classes info for test helper files" do
|
27
|
-
file = 'test/data/test_helper.rb'
|
28
|
-
locationmapping = Churn::LocationMapping.new
|
29
|
-
locationmapping.get_info(file.to_s)
|
30
|
-
klass_hash = {"Test"=>[12..15]}
|
31
|
-
assert_equal klass_hash.sort, locationmapping.klasses_collection.sort
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class SourceControlTest < Minitest::Test
|
4
|
-
|
5
|
-
should "get_updated_files_from_log if revision and previous revision" do
|
6
|
-
sc = Churn::SourceControl.new(Date.today)
|
7
|
-
current = 'current'
|
8
|
-
revisions = ['future',current,'past']
|
9
|
-
def sc.get_diff(revision, previous_revision)
|
10
|
-
[previous_revision]
|
11
|
-
end
|
12
|
-
assert_equal ['past'], sc.get_updated_files_from_log(current,revisions)
|
13
|
-
end
|
14
|
-
|
15
|
-
should "get_updated_files_from_log get empty array when no revisions found" do
|
16
|
-
sc = Churn::SourceControl.new(Date.today)
|
17
|
-
current = 'current'
|
18
|
-
revisions = ['future',current]
|
19
|
-
assert_equal [], sc.get_updated_files_from_log(current,revisions)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class SvnAnalyzerTest < Minitest::Test
|
4
|
-
|
5
|
-
should "parses logs correctly" do
|
6
|
-
svn_analyzer = Churn::SvnAnalyzer.new
|
7
|
-
revision = 'first'
|
8
|
-
revisions = ['first']
|
9
|
-
lines = ["--- a/lib/churn/churn_calculator.rb", "+++ b/lib/churn/churn_calculator.rb", "@@ -18,0 +19 @@ module Churn"]
|
10
|
-
svn_analyzer.stubs(:get_updated_files_from_log).returns(lines)
|
11
|
-
updated = svn_analyzer.get_updated_files_change_info(revision, revisions)
|
12
|
-
expected_hash = {"lib/churn/churn_calculator.rb"=>[18..18, 19..19]}
|
13
|
-
assert_equal = updated
|
14
|
-
end
|
15
|
-
|
16
|
-
should "run get_logs correctly" do
|
17
|
-
svn_analyzer = Churn::SvnAnalyzer.new
|
18
|
-
svn_analyzer.expects(:`).returns(svn_output) #`fix syntax hilighting
|
19
|
-
assert_equal ["/trunk", "/trunk/test.txt"], svn_analyzer.get_logs
|
20
|
-
end
|
21
|
-
|
22
|
-
should "run date range correctly" do
|
23
|
-
svn_analyzer = Churn::SvnAnalyzer.new(Date.parse('3/3/2010'))
|
24
|
-
assert_equal " --revision {2010-03-03}:{#{Date.today.to_s}}", svn_analyzer.send(:date_range)
|
25
|
-
end
|
26
|
-
|
27
|
-
context "SvnAnalyzer#get_logs" do
|
28
|
-
should "return a list of changed files" do
|
29
|
-
ENV['SVN_PWD']= nil
|
30
|
-
ENV['SVN_USR']= nil
|
31
|
-
svn_analyzer = Churn::SvnAnalyzer.new
|
32
|
-
svn_analyzer.expects(:`).with('svn log --verbose').returns('
|
33
|
-
A /file1.rb
|
34
|
-
A /dir/file2.rb
|
35
|
-
A /file3.rb
|
36
|
-
M /file1.rb')
|
37
|
-
assert_equal ['/file1.rb', '/dir/file2.rb', '/file3.rb', '/file1.rb'], svn_analyzer.get_logs
|
38
|
-
end
|
39
|
-
should "invoke with svn credentials " do
|
40
|
-
ENV['SVN_PWD']= '123qwe'
|
41
|
-
ENV['SVN_USR']= 'user123'
|
42
|
-
svn_analyzer = Churn::SvnAnalyzer.new
|
43
|
-
svn_analyzer.expects(:`).with('svn log --verbose --username user123 --password 123qwe').returns('
|
44
|
-
A /file1.rb
|
45
|
-
A /dir/file2.rb
|
46
|
-
A /file3.rb
|
47
|
-
M /file1.rb')
|
48
|
-
assert_equal ['/file1.rb', '/dir/file2.rb', '/file3.rb', '/file1.rb'], svn_analyzer.get_logs
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
protected
|
53
|
-
|
54
|
-
def svn_output
|
55
|
-
"------------------------------------------------------------------------
|
56
|
-
r1 | danmayer | 2013-09-07 10:45:32 -0400 (Sat, 07 Sep 2013) | 1 line
|
57
|
-
Changed paths:
|
58
|
-
A /trunk
|
59
|
-
A /trunk/test.txt
|
60
|
-
|
61
|
-
Initial import of project1
|
62
|
-
------------------------------------------------------------------------"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|