Skip to content

Commit 5310c42

Browse files
committed
[cloc] Fix cloc error due to mulitple word language-name
This commit fixes error produced due to language names with multiple words Signed-off-by: inishchith <[email protected]>
1 parent 8444dc9 commit 5310c42

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ def setUpClass(cls):
5858
def tearDownClass(cls):
5959
shutil.rmtree(cls.tmp_path)
6060

61+
def test_parser(self):
62+
""" Test wheteher cloc parser logic returns expected type of results"""
63+
64+
file_path = os.path.join(self.data_path, ANALYZER_TEST_FILE)
65+
66+
message = subprocess.check_output(['cloc', file_path]).decode("utf-8")
67+
68+
flag = False
69+
parser_results = [0, 0, 0, 0]
70+
71+
for line in message.strip().split("\n"):
72+
if flag:
73+
if not line.startswith("-----"):
74+
parser_results = map(int, line.split()[-4:])
75+
break
76+
77+
if line.lower().startswith("language"):
78+
flag = True
79+
80+
n_files, blank_lines, commented_lines, loc = parser_results
81+
self.assertTrue(type(n_files), int)
82+
self.assertTrue(type(blank_lines), int)
83+
self.assertTrue(type(commented_lines), int)
84+
self.assertTrue(type(loc), int)
85+
6186
def test_analyze(self):
6287
"""Test whether cloc returns the expected fields data"""
6388

0 commit comments

Comments
 (0)