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.Constants import VERSION |
|
|
|
|
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
|
|
|
print(output) |
35
|
|
|
output = json.loads(output) |
36
|
|
|
self.assertRegex(output["results"]["todos"][0]["message"], |
37
|
|
|
r'The line contains the keyword `# \w+`.', |
38
|
|
|
"coala-json output should be empty when running " |
39
|
|
|
"over its own code. (Target section: todos)") |
40
|
|
|
self.assertNotEqual(retval, |
41
|
|
|
0, |
42
|
|
|
"coala-json must return nonzero when running over " |
43
|
|
|
"its own code. (Target section: todos)") |
44
|
|
|
|
45
|
|
|
def test_fail_acquire_settings(self): |
46
|
|
|
retval, output = execute_coala( |
47
|
|
|
coala_json.main, 'coala-json', '-b', |
48
|
|
|
'SpaceConsistencyBear', '-c', os.devnull) |
49
|
|
|
output = json.loads(output) |
50
|
|
|
found = False |
51
|
|
|
for msg in output["logs"]: |
52
|
|
|
if "During execution, we found that some" in msg["message"]: |
53
|
|
|
found = True |
54
|
|
|
self.assertTrue(found) |
55
|
|
|
|
56
|
|
|
def test_version(self): |
57
|
|
|
retval, output = execute_coala(coala_json.main, 'coala-json', '-v') |
58
|
|
|
self.assertEquals(retval, 0) |
59
|
|
|
self.assertNotIn("{", output) |
60
|
|
|
|
61
|
|
|
def test_text_logs(self): |
62
|
|
|
retval, output = execute_coala( |
63
|
|
|
coala_json.main, 'coala-json', '--text-logs', '-c', 'nonex') |
64
|
|
|
self.assertRegex( |
65
|
|
|
output, |
66
|
|
|
".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n") |
67
|
|
|
|