From 0e3fd7182e254a3360ede2c560f76e2c2d17cf3f Mon Sep 17 00:00:00 2001 From: inishchith Date: Sat, 20 Jul 2019 13:25:44 +0530 Subject: [PATCH] [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 --- graal/backends/core/analyzers/cloc.py | 21 ++++++++------------- tests/test_cloc.py | 3 +++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/graal/backends/core/analyzers/cloc.py b/graal/backends/core/analyzers/cloc.py index 77ff4d4..4c53933 100644 --- a/graal/backends/core/analyzers/cloc.py +++ b/graal/backends/core/analyzers/cloc.py @@ -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 @@ -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 @@ -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 diff --git a/tests/test_cloc.py b/tests/test_cloc.py index e925ef8..913af50 100644 --- a/tests/test_cloc.py +++ b/tests/test_cloc.py @@ -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"""