1
|
|
|
#!/usr/bin/env python |
|
|
|
|
2
|
|
|
# |
3
|
|
|
# test_iuwandbox.py |
4
|
|
|
# |
5
|
|
|
|
6
|
|
|
from __future__ import print_function |
7
|
|
|
|
8
|
|
|
import sys |
9
|
|
|
import os |
10
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../fused') |
11
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../wandbox') |
12
|
|
|
|
13
|
|
|
try: |
|
|
|
|
14
|
|
|
import unittest2 as unittest |
|
|
|
|
15
|
|
|
except: |
|
|
|
|
16
|
|
|
import unittest |
|
|
|
|
17
|
|
|
import iuwandbox |
18
|
|
|
import fused_iutest_files |
|
|
|
|
19
|
|
|
import shutil |
20
|
|
|
|
21
|
|
|
try: |
|
|
|
|
22
|
|
|
from StringIO import StringIO |
|
|
|
|
23
|
|
|
except ImportError: |
24
|
|
|
from io import StringIO |
|
|
|
|
25
|
|
|
|
26
|
|
|
root = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../../../') |
27
|
|
|
fused_src = root + '/fused-src' |
28
|
|
|
test_src = root + '/test/syntax_tests.cpp' |
|
|
|
|
29
|
|
|
test_opt_default = [ '--encoding', 'utf-8-sig' ] |
|
|
|
|
30
|
|
|
test_opt_nomain = test_opt_default |
|
|
|
|
31
|
|
|
test_opt = [ '-f"-DIUTEST_USE_MAIN"' ] |
|
|
|
|
32
|
|
|
test_opt.extend(test_opt_default) |
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def eprint(*args, **kwargs): |
|
|
|
|
36
|
|
|
print(*args, file=sys.stderr, **kwargs) |
|
|
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
class iuwandbox_test_base(unittest.TestCase): |
|
|
|
|
40
|
|
|
dir = None |
|
|
|
|
41
|
|
|
|
42
|
|
|
def setUp(self): |
|
|
|
|
43
|
|
|
self.capture = StringIO() |
|
|
|
|
44
|
|
|
sys.stdout = self.capture |
|
|
|
|
45
|
|
|
self.dir = os.getcwd() |
|
|
|
|
46
|
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
47
|
|
|
return super(iuwandbox_test_base, self).setUp() |
|
|
|
|
48
|
|
|
|
49
|
|
|
def tearDown(self): |
|
|
|
|
50
|
|
|
sys.stdout = sys.__stdout__ |
|
|
|
|
51
|
|
|
os.chdir(self.dir) |
|
|
|
|
52
|
|
|
self.capture.close() |
|
|
|
|
53
|
|
|
return super(iuwandbox_test_base, self).tearDown() |
|
|
|
|
54
|
|
|
|
55
|
|
|
def dump(self): |
|
|
|
|
56
|
|
|
value = self.capture.getvalue() |
|
|
|
|
57
|
|
|
eprint(value) |
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
class nofused_iuwandbox_test(iuwandbox_test_base): |
|
|
|
|
61
|
|
|
def setUp(self): |
|
|
|
|
62
|
|
|
if 'SCRUTINIZER' in os.environ: |
|
|
|
|
63
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
|
|
|
|
64
|
|
|
if os.path.exists(fused_src): |
|
|
|
|
65
|
|
|
try: |
|
|
|
|
66
|
|
|
shutil.rmtree(fused_src) |
|
|
|
|
67
|
|
|
except: |
|
|
|
|
68
|
|
|
pass |
|
|
|
|
69
|
|
|
if os.path.exists(os.path.join(fused_src, 'iutest.min.hpp')): |
|
|
|
|
70
|
|
|
self.skipTest('fused-src is exists') |
|
|
|
|
71
|
|
|
return super(nofused_iuwandbox_test, self).setUp() |
|
|
|
|
72
|
|
|
|
73
|
|
View Code Duplication |
def test_nofused(self): |
|
|
|
|
74
|
|
|
sys.argv[1:] = [ test_src ] |
|
|
|
|
75
|
|
|
sys.argv.extend(test_opt) |
|
|
|
|
76
|
|
|
with self.assertRaises(SystemExit) as cm: |
|
|
|
|
77
|
|
|
iuwandbox.main() |
|
|
|
|
78
|
|
|
self.dump() |
|
|
|
|
79
|
|
|
self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) |
|
|
|
|
80
|
|
|
self.assertRegex(self.capture.getvalue(), '.*please try \"make fused\".*') |
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
class iuwandbox_test(iuwandbox_test_base): |
|
|
|
|
84
|
|
|
def setUp(self): |
|
|
|
|
85
|
|
|
if not os.path.exists(fused_src): |
|
|
|
|
86
|
|
|
try: |
|
|
|
|
87
|
|
|
fused_iutest_files.FusedAll(fused_iutest_files.IUTEST_INCLUDE_DIR, fused_src) |
|
|
|
|
88
|
|
|
# os.system('python ' + root + '/tools/fused/fused_iutest_files.py ' + fused_src) |
89
|
|
|
except: |
|
|
|
|
90
|
|
|
pass |
|
|
|
|
91
|
|
|
if not os.path.exists(os.path.join(fused_src, 'iutest.min.hpp')): |
|
|
|
|
92
|
|
|
self.skipTest('fused-src is not exists') |
|
|
|
|
93
|
|
|
return super(iuwandbox_test, self).setUp() |
|
|
|
|
94
|
|
|
|
95
|
|
View Code Duplication |
def test_nomain(self): |
|
|
|
|
96
|
|
|
sys.argv = sys.argv[:1] |
|
|
|
|
97
|
|
|
sys.argv[1:] = [ test_src ] |
|
|
|
|
98
|
|
|
sys.argv.extend(test_opt_nomain) |
|
|
|
|
99
|
|
|
with self.assertRaises(SystemExit) as cm: |
|
|
|
|
100
|
|
|
iuwandbox.main() |
|
|
|
|
101
|
|
|
self.dump() |
|
|
|
|
102
|
|
|
self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) |
|
|
|
|
103
|
|
|
self.assertRegex(self.capture.getvalue(), '.*hint:.*') |
|
|
|
|
104
|
|
|
self.assertRegex(self.capture.getvalue(), '.*If you do not use boost test, please specify the file with the main function first..*') |
|
|
|
|
105
|
|
|
|
106
|
|
View Code Duplication |
def test_run(self): |
|
|
|
|
107
|
|
|
sys.argv[1:] = [ test_src ] |
|
|
|
|
108
|
|
|
sys.argv.extend(test_opt) |
|
|
|
|
109
|
|
|
print(sys.argv) |
|
|
|
|
110
|
|
|
with self.assertRaises(SystemExit) as cm: |
|
|
|
|
111
|
|
|
iuwandbox.main() |
|
|
|
|
112
|
|
|
self.dump() |
|
|
|
|
113
|
|
|
self.assertEqual(cm.exception.code, 0, self.capture.getvalue()) |
|
|
|
|
114
|
|
|
self.assertRegex(self.capture.getvalue(), '.*OK.*') |
|
|
|
|
115
|
|
|
|
116
|
|
View Code Duplication |
def test_same_filename(self): |
|
|
|
|
117
|
|
|
sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ] |
|
|
|
|
118
|
|
|
sys.argv.extend(test_opt_nomain) |
|
|
|
|
119
|
|
|
print(sys.argv) |
|
|
|
|
120
|
|
|
with self.assertRaises(SystemExit) as cm: |
|
|
|
|
121
|
|
|
iuwandbox.main() |
|
|
|
|
122
|
|
|
self.dump() |
|
|
|
|
123
|
|
|
self.assertEqual(cm.exception.code, 0, self.capture.getvalue()) |
|
|
|
|
124
|
|
|
self.assertRegex(self.capture.getvalue(), '.*OK.*') |
|
|
|
|
125
|
|
|
|
126
|
|
|
if __name__ == "__main__": |
127
|
|
|
unittest.main() |
|
|
|
|
128
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.