-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_kludge.py
executable file
·129 lines (110 loc) · 3.55 KB
/
test_kludge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python
#
# Copyright (c) 2010-2016, Fabric Software Inc. All rights reserved.
#
import os, pytest, subprocess, difflib
test_generate_dir = os.path.join('test', 'generate')
test_generate_tmp_dir_base = os.path.join('test', 'tmp', 'generate')
def collect_test_generate_basenames():
result = []
for dirpath, _subdirs, filenames in os.walk(test_generate_dir):
for filename in filenames:
filebase_and_ext2, fileext1 = os.path.splitext(filename)
if fileext1 == '.py':
filebase, fileext2 = os.path.splitext(filebase_and_ext2)
if fileext2 == '.kludge':
result.append(filebase)
return result
@pytest.mark.parametrize("basename", collect_test_generate_basenames())
def test_generate(basename):
if os.path.isfile(os.path.join(test_generate_dir, basename + '.skip')):
return
test_tmp_dir = os.path.join(test_generate_tmp_dir_base, basename)
if not os.path.isdir(test_tmp_dir):
os.makedirs(test_tmp_dir)
assert subprocess.call(
[
'./kludge', 'generate',
'-o', test_tmp_dir,
# '--debug-type-templates',
basename,
os.path.join(test_generate_dir, basename + '.kludge.py'),
],
) == 0
scons_env = os.environ.copy()
scons_env['CPPPATH'] = os.path.abspath(test_generate_dir)
assert subprocess.call(
[
'scons',
'-f', basename + '.SConstruct',
],
cwd = test_tmp_dir,
env = scons_env,
) == 0
kl_env = os.environ.copy()
kl_env['FABRIC_EXTS_PATH'] = test_tmp_dir
with open(os.path.join(test_tmp_dir, basename + '.test.out')) as expected_kl_output_file:
expected_kl_output = expected_kl_output_file.read().splitlines()
actual_kl_output = subprocess.check_output(
[
'kl',
os.path.join(test_tmp_dir, basename + '.test.kl'),
],
env = kl_env,
).splitlines()
difflines = difflib.unified_diff(expected_kl_output, actual_kl_output)
diffline_count = 0
for diffline in difflines:
print diffline
diffline_count += 1
assert diffline_count == 0
test_discover_dir = os.path.join('test', 'discover')
test_discover_tmp_dir_base = os.path.join('test', 'tmp', 'discover')
def collect_test_discover_basenames():
result = []
for dirpath, _subdirs, filenames in os.walk(test_discover_dir):
for filename in filenames:
basename, fileext = os.path.splitext(filename)
if fileext == '.hpp':
result.append(basename)
return result
@pytest.mark.parametrize("basename", collect_test_discover_basenames())
def test_discover(basename):
if os.path.isfile(os.path.join(test_discover_dir, basename + '.skip')):
return
test_tmp_dir = os.path.join(test_discover_tmp_dir_base, basename)
if not os.path.isdir(test_tmp_dir):
os.makedirs(test_tmp_dir)
discover_args = [
'./kludge', 'discover',
'-I', test_generate_dir,
'-o', test_tmp_dir,
basename,
os.path.join(test_discover_dir, basename + '.hpp'),
]
print 'RUN: ' + ' '.join(discover_args)
assert subprocess.call(discover_args) == 0
generate_args = [
'../../../../kludge', 'generate',
# '--debug-type-templates',
basename,
basename + '.kludge.py',
]
print 'RUN: ' + ' '.join(generate_args)
assert subprocess.call(
generate_args,
cwd = test_tmp_dir,
) == 0
scons_env = os.environ.copy()
scons_env['CPPPATH'] = os.path.abspath('.')
scons_args = [
'scons',
'-f', basename + '.SConstruct',
'VERBOSE=1',
]
print 'RUN: ' + ' '.join(scons_args)
assert subprocess.call(
scons_args,
cwd = test_tmp_dir,
env = scons_env,
) == 0