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 iuwandbox_pp |
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', '--compiler', 'gcc-10.2.0'] |
30
|
|
|
test_opt_nomain = test_opt_default |
31
|
|
|
test_opt = ['-f"-DIUTEST_USE_MAIN"'] |
32
|
|
|
test_opt.extend(test_opt_default) |
33
|
|
|
test_opt_verbose = ['--verbose'] |
34
|
|
|
test_opt_dryrun = ['--dryrun'] |
35
|
|
|
test_opt_no_min = ['--no-iutest-use-wandbox-min'] |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def eprint(*args, **kwargs): |
39
|
|
|
print(*args, file=sys.stderr, **kwargs) |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class iuwandbox_test_base(unittest.TestCase): |
43
|
|
|
dir = None |
44
|
|
|
|
45
|
|
|
def setUp(self): |
46
|
|
|
self.capture = StringIO() |
47
|
|
|
sys.stdout = self.capture |
48
|
|
|
self.dir = os.getcwd() |
49
|
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__))) |
50
|
|
|
return super(iuwandbox_test_base, self).setUp() |
51
|
|
|
|
52
|
|
|
def tearDown(self): |
53
|
|
|
sys.stdout = sys.__stdout__ |
54
|
|
|
os.chdir(self.dir) |
55
|
|
|
self.capture.close() |
56
|
|
|
return super(iuwandbox_test_base, self).tearDown() |
57
|
|
|
|
58
|
|
|
def dump(self): |
59
|
|
|
value = self.capture.getvalue() |
60
|
|
|
eprint(value) |
61
|
|
|
return value |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
class nofused_iuwandbox_test(iuwandbox_test_base): |
65
|
|
|
def setUp(self): |
66
|
|
|
if 'SCRUTINIZER' in os.environ: |
67
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
68
|
|
|
for f in ['iutest.hpp', 'iutest.min.hpp', 'iutest.wandbox.min.hpp']: |
69
|
|
|
if os.path.exists(os.path.join(fused_src, f)): |
70
|
|
|
try: |
71
|
|
|
os.remove(os.path.join(fused_src, f)) |
72
|
|
|
except Exception as e: |
73
|
|
|
self.skipTest('fused-src/' + f + ' remove failed... : ' + str(e)) |
74
|
|
|
if os.path.exists(os.path.join(fused_src, f)): |
75
|
|
|
self.skipTest('fused-src/' + f + ' is exists') |
76
|
|
|
return super(nofused_iuwandbox_test, self).setUp() |
77
|
|
|
|
78
|
|
|
def test_nofused(self): |
79
|
|
|
sys.argv[1:] = [test_src] |
80
|
|
|
sys.argv.extend(test_opt) |
81
|
|
|
with self.assertRaises(SystemExit) as cm: |
82
|
|
|
iuwandbox.main() |
83
|
|
|
self.dump() |
84
|
|
|
output = self.capture.getvalue() |
85
|
|
|
self.assertEqual(cm.exception.code, 1, output) |
86
|
|
|
self.assertRegex(output, '.*please try \"make fused\".*') |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
class iuwandbox_test(iuwandbox_test_base): |
90
|
|
|
def setUp(self): |
91
|
|
|
need_make_fused = False |
92
|
|
|
for f in ['iutest.hpp', 'iutest.min.hpp', 'iutest.wandbox.min.hpp']: |
93
|
|
|
if not os.path.exists(os.path.join(fused_src, f)): |
94
|
|
|
need_make_fused = True |
95
|
|
|
if need_make_fused: |
96
|
|
|
try: |
97
|
|
|
fused_iutest_files.FusedAll(fused_iutest_files.IUTEST_INCLUDE_DIR, fused_src) |
98
|
|
|
iuwandbox_pp.default_pp() |
99
|
|
|
# os.system('python ' + root + '/tools/fused/fused_iutest_files.py ' + fused_src) |
100
|
|
|
except: |
101
|
|
|
pass |
102
|
|
|
if not os.path.exists(os.path.join(fused_src, 'iutest.min.hpp')): |
103
|
|
|
self.skipTest('fused-src is not exists') |
104
|
|
|
if not os.path.exists(os.path.join(fused_src, 'iutest.wandbox.min.hpp')): |
105
|
|
|
self.skipTest('fused-src (wandbox) is not exists') |
106
|
|
|
return super(iuwandbox_test, self).setUp() |
107
|
|
|
|
108
|
|
View Code Duplication |
def test_nomain(self): |
|
|
|
|
109
|
|
|
if 'SCRUTINIZER' in os.environ: |
110
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
111
|
|
|
sys.argv[1:] = [test_src] |
112
|
|
|
sys.argv.extend(test_opt_nomain) |
113
|
|
|
print(sys.argv) |
114
|
|
|
with self.assertRaises(SystemExit) as cm: |
115
|
|
|
iuwandbox.main() |
116
|
|
|
output = self.dump() |
117
|
|
|
self.assertEqual(cm.exception.code, 1, output) |
118
|
|
|
self.assertRegex(output, '.*hint:.*') |
119
|
|
|
self.assertRegex(output, '.*In "iutest" you can omit the definition of the main function, please define IUTEST_USE_MAIN. (--iutest-use-main or -f"-DIUTEST_USE_MAIN")*') |
120
|
|
|
|
121
|
|
View Code Duplication |
def test_use_main(self): |
|
|
|
|
122
|
|
|
if 'SCRUTINIZER' in os.environ: |
123
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
124
|
|
|
sys.argv[1:] = [test_src] |
125
|
|
|
sys.argv.extend(test_opt_nomain) |
126
|
|
|
sys.argv.append('--iutest-use-main') |
127
|
|
|
print(sys.argv) |
128
|
|
|
with self.assertRaises(SystemExit) as cm: |
129
|
|
|
iuwandbox.main() |
130
|
|
|
output = self.dump() |
131
|
|
|
self.assertEqual(cm.exception.code, 0, output) |
132
|
|
|
self.assertRegex(output, '.*OK.*') |
133
|
|
|
|
134
|
|
|
def test_define_wandbox(self): |
135
|
|
|
if 'SCRUTINIZER' in os.environ: |
136
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
137
|
|
|
sys.argv[1:] = [test_src] |
138
|
|
|
sys.argv.extend(test_opt) |
139
|
|
|
sys.argv.extend(test_opt_dryrun) |
140
|
|
|
sys.argv.extend(test_opt_verbose) |
141
|
|
|
sys.argv.append('-f"-DTEST"') |
142
|
|
|
print(sys.argv) |
143
|
|
|
with self.assertRaises(SystemExit) as cm: |
144
|
|
|
iuwandbox.main() |
145
|
|
|
output = self.dump() |
146
|
|
|
self.assertEqual(cm.exception.code, 0, output) |
147
|
|
|
self.assertRegex(output, '.*-D__WANDBOX__.*') |
148
|
|
|
self.assertRegex(output, '.*-DTEST.*') |
149
|
|
|
|
150
|
|
View Code Duplication |
def test_boosttest_workarround(self): |
|
|
|
|
151
|
|
|
if 'SCRUTINIZER' in os.environ: |
152
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
153
|
|
|
sys.argv[1:] = [test_src] |
154
|
|
|
sys.argv.extend(test_opt_nomain) |
155
|
|
|
sys.argv.extend(['--boost', '1.65.0']) |
156
|
|
|
print(sys.argv) |
157
|
|
|
with self.assertRaises(SystemExit) as cm: |
158
|
|
|
iuwandbox.main() |
159
|
|
|
output = self.dump() |
160
|
|
|
self.assertEqual(cm.exception.code, 1, output) |
161
|
|
|
self.assertRegex(output, '.*hint:.*') |
162
|
|
|
self.assertRegex(output, '.*If you do not use boost test, please specify the file with the main function first..*') |
163
|
|
|
|
164
|
|
View Code Duplication |
def test_run(self): |
|
|
|
|
165
|
|
|
if 'SCRUTINIZER' in os.environ: |
166
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
167
|
|
|
sys.argv[1:] = [test_src] |
168
|
|
|
sys.argv.extend(test_opt) |
169
|
|
|
print(sys.argv) |
170
|
|
|
with self.assertRaises(SystemExit) as cm: |
171
|
|
|
iuwandbox.main() |
172
|
|
|
output = self.dump() |
173
|
|
|
self.assertEqual(cm.exception.code, 0, output) |
174
|
|
|
self.assertRegex(output, r'\[ \s+OK \]') |
175
|
|
|
self.assertFalse('-Wmisleading-indentation' in output) |
176
|
|
|
|
177
|
|
|
def test_same_filename(self): |
178
|
|
|
sys.argv[1:] = ['src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp'] |
179
|
|
|
sys.argv.extend(test_opt_nomain) |
180
|
|
|
print(sys.argv) |
181
|
|
|
with self.assertRaises(SystemExit) as cm: |
182
|
|
|
iuwandbox.main() |
183
|
|
|
output = self.dump() |
184
|
|
|
self.assertEqual(cm.exception.code, 0, output) |
185
|
|
|
self.assertRegex(output, '.*OK.*') |
186
|
|
|
self.assertFalse('-Wmisleading-indentation' in output) |
187
|
|
|
|
188
|
|
|
# def test_no_min_run(self): |
189
|
|
|
# if 'SCRUTINIZER' in os.environ: |
190
|
|
|
# self.skipTest('this test is not run on SCRUTINIZER.') |
191
|
|
|
# sys.argv[1:] = [test_src] |
192
|
|
|
# sys.argv.extend(test_opt) |
193
|
|
|
# sys.argv.extend(test_opt_no_min) |
194
|
|
|
# print(sys.argv) |
195
|
|
|
# with self.assertRaises(SystemExit) as cm: |
196
|
|
|
# iuwandbox.main() |
197
|
|
|
# output = self.dump() |
198
|
|
|
# self.assertEqual(cm.exception.code, 0, output) |
199
|
|
|
# self.assertRegex(output, r'\[ \s+OK \]') |
200
|
|
|
# # false positive : IUTEST_COND_LIKELY/IUTEST_COND_UNLIKELY |
201
|
|
|
# # self.assertFalse('-Wmisleading-indentation' in output) |
202
|
|
|
|
203
|
|
View Code Duplication |
def test_make_run(self): |
|
|
|
|
204
|
|
|
if 'SCRUTINIZER' in os.environ: |
205
|
|
|
self.skipTest('this test is not run on SCRUTINIZER.') |
206
|
|
|
sys.argv[1:] = [test_src] |
207
|
|
|
sys.argv.extend(test_opt) |
208
|
|
|
sys.argv.extend(['--make']) |
209
|
|
|
print(sys.argv) |
210
|
|
|
with self.assertRaises(SystemExit) as cm: |
211
|
|
|
iuwandbox.main() |
212
|
|
|
output = self.dump() |
213
|
|
|
self.assertEqual(cm.exception.code, 0, output) |
214
|
|
|
self.assertRegex(output, r'\[ \s+OK \]') |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
if __name__ == "__main__": |
218
|
|
|
unittest.main() |
219
|
|
|
|