|
1
|
|
|
import subprocess |
|
2
|
|
|
import sys |
|
3
|
|
|
import unittest |
|
4
|
|
|
from queue import Queue |
|
5
|
|
|
|
|
6
|
|
|
sys.path.insert(0, ".") |
|
7
|
|
|
from bears.tests.LocalBearTestHelper import LocalBearTestHelper |
|
8
|
|
|
from bears.c_languages.IndentBear import IndentBear |
|
9
|
|
|
from coalib.settings.Section import Section |
|
10
|
|
|
from coalib.settings.Setting import Setting |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class IndentBearTest(LocalBearTestHelper): |
|
14
|
|
|
def setUp(self): |
|
15
|
|
|
self.section = Section('name') |
|
16
|
|
|
self.section.append(Setting("use_spaces", "true")) |
|
17
|
|
|
self.section.append(Setting("max_line_length", "80")) |
|
18
|
|
|
self.uut = IndentBear(self.section, Queue()) |
|
19
|
|
|
|
|
20
|
|
|
def test_valid(self): |
|
21
|
|
|
self.assertLinesValid(self.uut, ["int\n", |
|
22
|
|
|
"main ()\n", |
|
23
|
|
|
"{\n", |
|
24
|
|
|
" return 0;\n", |
|
25
|
|
|
"}\n"]) |
|
26
|
|
|
|
|
27
|
|
|
def test_tab_width(self): |
|
28
|
|
|
self.section.append(Setting("tab_width", "2")) |
|
29
|
|
|
self.assertLinesValid(self.uut, ["int\n", |
|
30
|
|
|
"main ()\n", |
|
31
|
|
|
"{\n", |
|
32
|
|
|
" return 0;\n", |
|
33
|
|
|
"}\n"]) |
|
34
|
|
|
|
|
35
|
|
|
def test_tabs(self): |
|
36
|
|
|
test_code = ["int\n", "main ()\n", "{\n", "\treturn 0;\n", "}\n"] |
|
37
|
|
|
self.assertLinesInvalid(self.uut, test_code) |
|
38
|
|
|
|
|
39
|
|
|
self.section.append(Setting("use_spaces", "nope")) |
|
40
|
|
|
self.assertLinesValid(self.uut, test_code) |
|
41
|
|
|
|
|
42
|
|
|
def test_invalid(self): |
|
43
|
|
|
self.assertLinesInvalid(self.uut, ["int main() {\n", |
|
44
|
|
|
" return 0;\n", |
|
45
|
|
|
"}\n"]) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def skip_test(): |
|
49
|
|
|
try: |
|
50
|
|
|
subprocess.Popen([IndentBear.BINARY, '--version'], |
|
51
|
|
|
stdout=subprocess.PIPE, |
|
52
|
|
|
stderr=subprocess.PIPE) |
|
53
|
|
|
return False |
|
54
|
|
|
except OSError: |
|
55
|
|
|
return "indent is not installed." |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
if __name__ == '__main__': |
|
59
|
|
|
unittest.main(verbosity=2) |
|
60
|
|
|
|