1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# |
3
|
|
|
# test_iuwandbox.py |
4
|
|
|
# |
5
|
|
|
|
6
|
|
|
import sys |
7
|
|
|
import os |
8
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../fused') |
9
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../wandbox') |
10
|
|
|
|
11
|
|
|
try: |
12
|
|
|
import unittest2 as unittest |
13
|
|
|
except: |
14
|
|
|
import unittest |
15
|
|
|
import iuwandbox |
16
|
|
|
import shutil |
17
|
|
|
|
18
|
|
|
try: |
19
|
|
|
from StringIO import StringIO |
20
|
|
|
except ImportError: |
21
|
|
|
from io import StringIO |
22
|
|
|
|
23
|
|
|
root = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../../../') |
24
|
|
|
fused_src = root + '/fused-src' |
25
|
|
|
test_src = root + '/test/syntax_tests.cpp' |
26
|
|
|
test_opt_nomain = [ '--encoding', 'utf-8-sig' ] |
27
|
|
|
test_opt = [ '--encoding', 'utf-8-sig', '-f"-DIUTEST_USE_MAIN"' ] |
28
|
|
|
|
29
|
|
|
class iuwandbox_test_base(unittest.TestCase): |
30
|
|
|
def setUp(self): |
31
|
|
|
self.capture = StringIO() |
32
|
|
|
sys.stdout = self.capture |
33
|
|
|
return super(iuwandbox_test_base, self).setUp() |
34
|
|
|
|
35
|
|
|
def tearDown(self): |
36
|
|
|
sys.stdout = sys.__stdout__ |
37
|
|
|
return super(iuwandbox_test_base, self).tearDown() |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class nofused_iuwandbox_test(iuwandbox_test_base): |
41
|
|
|
def setUp(self): |
42
|
|
|
if os.path.exists(fused_src): |
43
|
|
|
shutil.rmtree(fused_src) |
44
|
|
|
return super(nofused_iuwandbox_test, self).setUp() |
45
|
|
|
|
46
|
|
|
def test_nofused(self): |
47
|
|
|
sys.argv[1:] = [ test_src ] |
48
|
|
|
sys.argv.extend(test_opt) |
49
|
|
|
with self.assertRaises(SystemExit) as cm: |
50
|
|
|
iuwandbox.main() |
51
|
|
|
self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) |
52
|
|
|
self.assertRegex(self.capture.getvalue(), '.*please try \"make fused\".*') |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class iuwandbox_test(iuwandbox_test_base): |
56
|
|
|
def setUp(self): |
57
|
|
|
if not os.path.exists(fused_src): |
58
|
|
|
os.system('python ' + root + '/tools/fused/fused_iutest_files.py ' + fused_src) |
59
|
|
|
return super(iuwandbox_test, self).setUp() |
60
|
|
|
|
61
|
|
|
def test_nomain(self): |
62
|
|
|
sys.argv[1:] = [ test_src ] |
63
|
|
|
sys.argv.extend(test_opt_nomain) |
64
|
|
|
with self.assertRaises(SystemExit) as cm: |
65
|
|
|
iuwandbox.main() |
66
|
|
|
self.assertEqual(cm.exception.code, 1, self.capture.getvalue()) |
67
|
|
|
self.assertRegex(self.capture.getvalue(), '.*hint:.*') |
68
|
|
|
self.assertRegex(self.capture.getvalue(), '.*If you do not use boost test, please specify the file with the main function first..*') |
69
|
|
|
|
70
|
|
|
def test_run(self): |
71
|
|
|
sys.argv[1:] = [ test_src ] |
72
|
|
|
sys.argv.extend(test_opt) |
73
|
|
|
with self.assertRaises(SystemExit) as cm: |
74
|
|
|
iuwandbox.main() |
75
|
|
|
self.assertEqual(cm.exception.code, 0, self.capture.getvalue()) |
76
|
|
|
self.assertRegex(self.capture.getvalue(), '.*OK.*') |
77
|
|
|
|
78
|
|
|
if __name__ == "__main__": |
79
|
|
|
unittest.main() |