Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions graal/backends/core/analyzers/cloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Cloc(Analyzer):
This class allows to call Cloc over a file, parses
the result of the analysis and returns it as a dict.
"""
version = '0.2.0'
version = '0.2.1'

def __analyze_file(self, message):
"""Add information about LOC, blank and commented lines using CLOC for a given file
Expand All @@ -52,11 +52,8 @@ def __analyze_file(self, message):
for line in message.strip().split("\n"):
if flag:
if not line.startswith("-----"):
digested = " ".join(line.split())
info_file = digested.split(" ")
blank_lines = int(info_file[2])
commented_lines = int(info_file[3])
loc = int(info_file[4])
file_info = line.split()[-3:]
blank_lines, commented_lines, loc = map(int, file_info)
results["blanks"] = blank_lines
results["comments"] = commented_lines
results["loc"] = loc
Expand All @@ -83,14 +80,12 @@ def __analyze_repository(self, message):
if line.lower().startswith("sum"):
break
elif not line.startswith("-----"):
digested = " ".join(line.split())
info_file = digested.split(" ")
blank_lines = int(info_file[2])
commented_lines = int(info_file[3])
loc = int(info_file[4])
language = info_file[0]
digested_split = line.split()
langauge, files_info = digested_split[:-4], digested_split[-4:]
language = " ".join(langauge)
total_files, blank_lines, commented_lines, loc = map(int, files_info)
language_result = {
"total_files": int(info_file[1]),
"total_files": total_files,
"blanks": blank_lines,
"comments": commented_lines,
"loc": loc
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ def test_analyze(self):

self.assertIn('blanks', result)
self.assertTrue(type(result['blanks']), int)
self.assertTrue(result['blanks'], 27)
self.assertIn('comments', result)
self.assertTrue(type(result['comments']), int)
self.assertTrue(result['comments'], 31)
self.assertIn('loc', result)
self.assertTrue(type(result['loc']), int)
self.assertTrue(result['loc'], 67)

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