1
|
|
|
import sys |
2
|
|
|
import os |
3
|
|
|
import unittest |
4
|
|
|
import re |
5
|
|
|
import json |
6
|
|
|
|
7
|
|
|
from coalib import coala_json |
8
|
|
|
from coalib.tests.TestUtilities import execute_coala |
9
|
|
|
from coalib.misc import Constants |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class coalaJSONTest(unittest.TestCase): |
13
|
|
|
|
14
|
|
|
def setUp(self): |
15
|
|
|
self.old_argv = sys.argv |
16
|
|
|
self.unescaped_coafile = os.path.abspath("./.coafile") |
17
|
|
|
self.coafile = re.escape(self.unescaped_coafile) |
18
|
|
|
|
19
|
|
|
def tearDown(self): |
20
|
|
|
sys.argv = self.old_argv |
21
|
|
|
|
22
|
|
|
def test_nonexistent(self): |
23
|
|
|
retval, output = execute_coala( |
24
|
|
|
coala_json.main, "coala-json", "-c", 'nonex', "test") |
25
|
|
|
output = json.loads(output) |
26
|
|
|
self.assertRegex( |
27
|
|
|
output["logs"][0]["message"], |
28
|
|
|
"The requested coafile '.*' does not exist.") |
29
|
|
|
|
30
|
|
|
def test_find_issues(self): |
31
|
|
|
retval, output = execute_coala( |
32
|
|
|
coala_json.main, "coala-json", "todos", "-c", |
33
|
|
|
self.coafile) |
34
|
|
|
output = json.loads(output) |
35
|
|
|
self.assertRegex(output["results"]["todos"][0]["message"], |
36
|
|
|
r'The line contains the keyword `# \w+`.', |
37
|
|
|
"coala-json output should be empty when running " |
38
|
|
|
"over its own code. (Target section: todos)") |
39
|
|
|
self.assertNotEqual(retval, |
40
|
|
|
0, |
41
|
|
|
"coala-json must return nonzero when running over " |
42
|
|
|
"its own code. (Target section: todos)") |
43
|
|
|
|
44
|
|
|
def test_fail_acquire_settings(self): |
45
|
|
|
retval, output = execute_coala( |
46
|
|
|
coala_json.main, 'coala-json', '-b', |
47
|
|
|
'SpaceConsistencyBear', '-c', os.devnull) |
48
|
|
|
output = json.loads(output) |
49
|
|
|
found = False |
50
|
|
|
for msg in output["logs"]: |
51
|
|
|
if "During execution, we found that some" in msg["message"]: |
52
|
|
|
found = True |
53
|
|
|
self.assertTrue(found) |
54
|
|
|
|
55
|
|
|
def test_version(self): |
56
|
|
|
retval, output = execute_coala(coala_json.main, 'coala-json', '-v') |
57
|
|
|
self.assertEqual(retval, 0) |
58
|
|
|
self.assertEqual(output.strip(), Constants.VERSION) |
59
|
|
|
|
60
|
|
|
def test_text_logs(self): |
61
|
|
|
retval, output = execute_coala( |
62
|
|
|
coala_json.main, 'coala-json', '--text-logs', '-c', 'nonex') |
63
|
|
|
self.assertRegex( |
64
|
|
|
output, |
65
|
|
|
".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n") |
66
|
|
|
|