|
1
|
|
|
import os |
|
2
|
|
|
import re |
|
3
|
|
|
import sys |
|
4
|
|
|
import unittest |
|
5
|
|
|
|
|
6
|
|
|
from coalib import coala |
|
7
|
|
|
from coalib.misc.ContextManagers import prepare_file |
|
8
|
|
|
from coalib.tests.test_bears.LineCountTestBear import ( |
|
9
|
|
|
LineCountTestBear) |
|
10
|
|
|
from coalib.tests.TestUtilities import execute_coala, bear_test_module |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class coalaTest(unittest.TestCase): |
|
14
|
|
|
|
|
15
|
|
|
def setUp(self): |
|
16
|
|
|
self.old_argv = sys.argv |
|
17
|
|
|
|
|
18
|
|
|
def tearDown(self): |
|
19
|
|
|
sys.argv = self.old_argv |
|
20
|
|
|
|
|
21
|
|
|
def test_coala(self): |
|
22
|
|
|
with bear_test_module(), \ |
|
23
|
|
|
prepare_file(["#fixme"], None) as (lines, filename): |
|
24
|
|
|
retval, output = execute_coala( |
|
25
|
|
|
coala.main, |
|
26
|
|
|
"coala", "-c", os.devnull, |
|
27
|
|
|
"-f", re.escape(filename), |
|
28
|
|
|
"-b", "LineCountTestBear") |
|
29
|
|
|
self.assertIn("This file has 1 lines.", |
|
30
|
|
|
output, |
|
31
|
|
|
"The output should report count as 1 lines") |
|
32
|
|
|
|
|
33
|
|
|
def test_did_nothing(self): |
|
34
|
|
|
retval, output = execute_coala(coala.main, "coala", "-c", os.devnull, |
|
35
|
|
|
"-S", "default.enabled=false") |
|
36
|
|
|
self.assertEqual(retval, 0) |
|
37
|
|
|
self.assertIn("No existent section was targeted or enabled", output) |
|
38
|
|
|
|
|
39
|
|
|
def test_show_bears(self): |
|
40
|
|
|
retval, output = execute_coala(coala.main, "coala", "-A") |
|
41
|
|
|
self.assertEqual(retval, 0) |
|
42
|
|
|
lines = output.splitlines() |
|
43
|
|
|
bear_missing_lines = sum(1 for line in lines if "WARNING" in line) |
|
44
|
|
|
self.assertEqual(bear_missing_lines, 0) |
|
45
|
|
|
|
|
46
|
|
|
with bear_test_module(): |
|
47
|
|
|
retval, output = execute_coala(coala.main, "coala", "-A") |
|
48
|
|
|
self.assertEqual(retval, 0) |
|
49
|
|
|
|
|
50
|
|
|
lines = output.splitlines() |
|
51
|
|
|
bear_lines = sum(1 for line in lines if line.startswith(" * ")) |
|
52
|
|
|
self.assertEqual(bear_lines, 2) |
|
53
|
|
|
|
|
54
|
|
|
bear_missing_lines = sum(1 for line in lines if "WARNING" in line) |
|
55
|
|
|
self.assertEqual(bear_missing_lines, 0) |
|
56
|
|
|
|
|
57
|
|
|
retval, output = execute_coala(coala.main, "coala", "-B", |
|
58
|
|
|
"-b", "LineCountTestBear", |
|
59
|
|
|
"-c", os.devnull) |
|
60
|
|
|
self.assertEqual(retval, 0) |
|
61
|
|
|
self.assertIn(LineCountTestBear.run.__doc__.strip(), output) |
|
62
|
|
|
|