Skip to content

Commit 12ec87e

Browse files
committed
test: add test using /usr/bin/env and PYTHONPATH
1 parent cda3e40 commit 12ec87e

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import argparse
2+
3+
import codegen
4+
5+
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument("output")
8+
args = parser.parse_args()
9+
10+
with open(args.output, "w", encoding="utf-8") as f:
11+
f.write(codegen.get_c_code())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
import textwrap
4+
5+
def get_c_code():
6+
return textwrap.dedent("""\
7+
int im_going_back_to(void) {
8+
return 505;
9+
}
10+
""")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project(
2+
'python command sequence',
3+
'c',
4+
default_options: ['buildtype=release'],
5+
)
6+
7+
py = import('python').find_installation(pure: false)
8+
9+
ct = custom_target(
10+
'ct',
11+
input : 'gen.py',
12+
output : 'ct.c',
13+
command : [py, '@INPUT@', '@OUTPUT@'],
14+
)
15+
16+
exe = executable('test_generated_code', ct, 'test_generated_code.c')
17+
18+
test('runtest', exe)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int im_going_back_to(void);
2+
3+
int main(void) {
4+
if (im_going_back_to() == 505) {
5+
return 0;
6+
}
7+
8+
return 1;
9+
}

unittests/machinefiletests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,29 @@ def test_python_module(self):
273273
raise SkipTest('Not running Python 2 tests because dev packages not installed.')
274274
self._simple_test('python', binary, entry='python')
275275

276+
@skipIf(is_windows(), '/usr/bin/env is not available on Windows')
277+
def test_python_command_sequence(self):
278+
testcase = Path(
279+
self.src_root, 'test cases', 'native', '14 python command sequence'
280+
)
281+
codegen_lib = testcase / 'lib'
282+
283+
config = self.helper_create_native_file(
284+
{
285+
'binaries': {
286+
'python': [
287+
'/usr/bin/env',
288+
f'PYTHONPATH={codegen_lib}',
289+
'python3',
290+
]
291+
}
292+
}
293+
)
294+
295+
self.init(str(testcase), extra_args=['--native-file', config])
296+
self.build()
297+
self.run_tests()
298+
276299
@skipIf(is_windows(), 'Setting up multiple compilers on windows is hard')
277300
@skip_if_env_set('CC')
278301
def test_c_compiler(self):

0 commit comments

Comments
 (0)