Skip to content

Commit 54589cb

Browse files
committed
Merge remote-tracking branch 'inishchith/fix_cloc_bug'
Merges #46
2 parents 8444dc9 + 0e3fd71 commit 54589cb

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

graal/backends/core/analyzers/cloc.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Cloc(Analyzer):
3232
This class allows to call Cloc over a file, parses
3333
the result of the analysis and returns it as a dict.
3434
"""
35-
version = '0.2.0'
35+
version = '0.2.1'
3636

3737
def __analyze_file(self, message):
3838
"""Add information about LOC, blank and commented lines using CLOC for a given file
@@ -52,11 +52,8 @@ def __analyze_file(self, message):
5252
for line in message.strip().split("\n"):
5353
if flag:
5454
if not line.startswith("-----"):
55-
digested = " ".join(line.split())
56-
info_file = digested.split(" ")
57-
blank_lines = int(info_file[2])
58-
commented_lines = int(info_file[3])
59-
loc = int(info_file[4])
55+
file_info = line.split()[-3:]
56+
blank_lines, commented_lines, loc = map(int, file_info)
6057
results["blanks"] = blank_lines
6158
results["comments"] = commented_lines
6259
results["loc"] = loc
@@ -83,14 +80,12 @@ def __analyze_repository(self, message):
8380
if line.lower().startswith("sum"):
8481
break
8582
elif not line.startswith("-----"):
86-
digested = " ".join(line.split())
87-
info_file = digested.split(" ")
88-
blank_lines = int(info_file[2])
89-
commented_lines = int(info_file[3])
90-
loc = int(info_file[4])
91-
language = info_file[0]
83+
digested_split = line.split()
84+
langauge, files_info = digested_split[:-4], digested_split[-4:]
85+
language = " ".join(langauge)
86+
total_files, blank_lines, commented_lines, loc = map(int, files_info)
9287
language_result = {
93-
"total_files": int(info_file[1]),
88+
"total_files": total_files,
9489
"blanks": blank_lines,
9590
"comments": commented_lines,
9691
"loc": loc

tests/test_cloc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ def test_analyze(self):
6767

6868
self.assertIn('blanks', result)
6969
self.assertTrue(type(result['blanks']), int)
70+
self.assertTrue(result['blanks'], 27)
7071
self.assertIn('comments', result)
7172
self.assertTrue(type(result['comments']), int)
73+
self.assertTrue(result['comments'], 31)
7274
self.assertIn('loc', result)
7375
self.assertTrue(type(result['loc']), int)
76+
self.assertTrue(result['loc'], 67)
7477

7578
def test_analyze_repository_level(self):
7679
"""Test whether cloc returns the expected fields data for repository level"""

0 commit comments

Comments
 (0)